-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathtest_deps.py
More file actions
230 lines (189 loc) · 6.1 KB
/
Copy pathtest_deps.py
File metadata and controls
230 lines (189 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import os
from contextlib import contextmanager
from shutil import rmtree
from tempfile import mkdtemp
import pytest
from galaxy.dependencies import ConditionalDependencies
AZURE_BLOB_TEST_CONFIG = """<object_store type="azure_blob">
blah...
</object_store>
"""
AZURE_BLOB_TEST_CONFIG_YAML = """
type: azure_blob
other_attributes: blah
"""
DISTRIBUTED_WITH_AZURE_CONFIG_YAML = """
type: distributed
backends:
- id: files1
type: azure_blob
"""
FILES_SOURCES_CONFIG = """
- type: webdav
- type: dropbox
- type: googledrive
- type: irods
"""
JOB_CONF_YAML = """
runners:
runner1:
load: job_runner_A
"""
JOB_CONF_HTCONDOR_YAML = """
runners:
htcondor:
load: galaxy.jobs.runners.htcondor:HTCondorJobRunner
"""
VAULT_CONF_HASHICORP = """
type: hashicorp
"""
def test_default_objectstore():
with _config_context() as cc:
cds = cc.get_cond_deps()
assert not cds.check_azure_storage()
def test_azure_objectstore_xml():
with _config_context() as cc:
object_store_config = cc.write_config("objectstore.xml", AZURE_BLOB_TEST_CONFIG)
config = {
"object_store_config_file": object_store_config,
}
cds = cc.get_cond_deps(config)
assert cds.check_azure_storage()
def test_azure_objectstore_yaml():
with _config_context() as cc:
object_store_config = cc.write_config("objectstore.yml", AZURE_BLOB_TEST_CONFIG_YAML)
config = {
"object_store_config_file": object_store_config,
}
cds = cc.get_cond_deps(config)
assert cds.check_azure_storage()
def test_azure_objectstore_nested_yaml():
with _config_context() as cc:
object_store_config = cc.write_config("objectstore.yml", DISTRIBUTED_WITH_AZURE_CONFIG_YAML)
config = {
"object_store_config_file": object_store_config,
}
cds = cc.get_cond_deps(config)
assert cds.check_azure_storage()
def test_fs_default():
with _config_context() as cc:
cds = cc.get_cond_deps()
assert not cds.check_gdrive_fsspec()
assert not cds.check_dropboxdrivefs()
assert not cds.check_webdav4()
def test_fs_configured():
with _config_context() as cc:
file_sources_conf = cc.write_config("file_sources.yml", FILES_SOURCES_CONFIG)
config = {
"file_sources_config_file": file_sources_conf,
}
cds = cc.get_cond_deps(config=config)
assert cds.check_gdrive_fsspec()
assert cds.check_dropboxdrivefs()
assert cds.check_webdav4()
assert cds.check_fs_irods()
assert cds.check_mangofs()
def test_yaml_jobconf_runners():
with _config_context() as cc:
job_conf_file = cc.write_config("job_conf.yml", JOB_CONF_YAML)
config = {
"job_config_file": job_conf_file,
}
cds = cc.get_cond_deps(config=config)
assert "job_runner_A" in cds.job_runners
def test_htcondor_not_required_by_default():
with _config_context() as cc:
cds = cc.get_cond_deps()
assert not cds.check_htcondor()
def test_htcondor_required_when_runner_configured():
with _config_context() as cc:
job_conf_file = cc.write_config("job_conf.yml", JOB_CONF_HTCONDOR_YAML)
config = {"job_config_file": job_conf_file}
cds = cc.get_cond_deps(config=config)
assert cds.check_htcondor()
def test_vault_hashicorp_configured():
with _config_context() as cc:
vault_conf = cc.write_config("vault_conf.yml", VAULT_CONF_HASHICORP)
config = {
"vault_config_file": vault_conf,
}
cds = cc.get_cond_deps(config=config)
assert cds.check_hvac()
def test_pkce_default_disabled():
with _config_context() as cc:
cds = cc.get_cond_deps()
assert cds.check_pkce() is False
def test_pkce_enabled_when_enable_oidc():
with _config_context() as cc:
cds = cc.get_cond_deps(config={"enable_oidc": True})
assert cds.check_pkce() is True
def test_pkce_disabled_when_enable_oidc_off():
with _config_context() as cc:
cds = cc.get_cond_deps(config={"enable_oidc": False})
assert cds.check_pkce() is False
def test_pkce_enabled_via_auth_pipeline():
with _config_context() as cc:
cds = cc.get_cond_deps(config={"oidc_auth_pipeline": ["galaxy.authnz.psa_authnz.verify"]})
assert cds.check_pkce() is True
def test_pkce_enabled_via_auth_pipeline_extra():
with _config_context() as cc:
cds = cc.get_cond_deps(config={"oidc_auth_pipeline_extra": ["galaxy.authnz.psa_authnz.verify"]})
assert cds.check_pkce() is True
@pytest.mark.parametrize(
"config,expected",
[
(
{
"enable_celery_tasks": True,
},
False,
),
(
{
"enable_celery_tasks": True,
"celery_conf": {"result_backend": None},
},
False,
),
(
{
"enable_celery_tasks": True,
"celery_conf": {"broker_url": "redis://localhost:6379/0"},
},
True,
),
(
{
"enable_celery_tasks": True,
"celery_conf": {"result_backend": "redis://localhost:6379/0"},
},
True,
),
],
)
def test_conditional_redis(config, expected):
with _config_context() as cc:
cds = cc.get_cond_deps(config=config)
assert cds.check_redis() is expected
@contextmanager
def _config_context():
config_dir = mkdtemp()
try:
yield ConfigContext(config_dir)
finally:
rmtree(config_dir)
class ConfigContext:
def __init__(self, directory):
self.tempdir = directory
def write_config(self, path, contents):
config_path = os.path.join(self.tempdir, path)
with open(config_path, "w") as f:
f.write(contents)
return config_path
def get_cond_deps(self, config=None):
config = config or {}
config_file = os.path.join(self.tempdir, "config.yml")
return ConditionalDependencies(
config_file,
config=config,
)