qontract-reconcile 0.10.1rc1202__py3-none-any.whl → 0.10.2.dev2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qontract_reconcile-0.10.2.dev2.dist-info/METADATA +500 -0
- {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev2.dist-info}/RECORD +12 -130
- {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev2.dist-info}/WHEEL +1 -2
- {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev2.dist-info}/entry_points.txt +1 -0
- reconcile/aws_account_manager/README.md +5 -0
- reconcile/change_owners/README.md +34 -0
- reconcile/glitchtip/README.md +150 -0
- reconcile/gql_definitions/introspection.json +51176 -0
- reconcile/run_integration.py +293 -0
- reconcile/utils/binary.py +2 -2
- reconcile/utils/mr/README.md +198 -0
- reconcile/utils/oc_map.py +2 -2
- tools/qontract_cli.py +0 -0
- qontract_reconcile-0.10.1rc1202.dist-info/METADATA +0 -64
- qontract_reconcile-0.10.1rc1202.dist-info/top_level.txt +0 -3
- reconcile/test/__init__.py +0 -0
- reconcile/test/conftest.py +0 -157
- reconcile/test/fixtures.py +0 -24
- reconcile/test/saas_auto_promotions_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/conftest.py +0 -170
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/conftest.py +0 -115
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/data_keys.py +0 -19
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_desired_state.py +0 -66
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_merge_request_manager.py +0 -86
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_mr_parser.py +0 -352
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_reconciler.py +0 -494
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/__init__.py +0 -0
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/conftest.py +0 -25
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_multiple_namespaces.py +0 -37
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_namespace.py +0 -81
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_target.py +0 -61
- reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_json_path_selector.py +0 -74
- reconcile/test/saas_auto_promotions_manager/test_integration_test.py +0 -52
- reconcile/test/saas_auto_promotions_manager/utils/__init__.py +0 -0
- reconcile/test/test_acs_notifiers.py +0 -393
- reconcile/test/test_acs_policies.py +0 -497
- reconcile/test/test_acs_rbac.py +0 -865
- reconcile/test/test_aggregated_list.py +0 -237
- reconcile/test/test_amtool.py +0 -37
- reconcile/test/test_aws_ami_cleanup.py +0 -230
- reconcile/test/test_aws_ami_share.py +0 -68
- reconcile/test/test_aws_cloudwatch_log_retention.py +0 -434
- reconcile/test/test_aws_iam_keys.py +0 -70
- reconcile/test/test_aws_iam_password_reset.py +0 -35
- reconcile/test/test_aws_support_cases_sos.py +0 -23
- reconcile/test/test_checkpoint.py +0 -178
- reconcile/test/test_cli.py +0 -41
- reconcile/test/test_closedbox_endpoint_monitoring.py +0 -207
- reconcile/test/test_dashdotdb_dora.py +0 -245
- reconcile/test/test_database_access_manager.py +0 -660
- reconcile/test/test_deadmanssnitch.py +0 -290
- reconcile/test/test_gabi_authorized_users.py +0 -72
- reconcile/test/test_gcr_mirror.py +0 -14
- reconcile/test/test_github_org.py +0 -156
- reconcile/test/test_github_repo_invites.py +0 -119
- reconcile/test/test_gitlab_housekeeping.py +0 -333
- reconcile/test/test_gitlab_labeler.py +0 -126
- reconcile/test/test_gitlab_members.py +0 -219
- reconcile/test/test_gitlab_permissions.py +0 -164
- reconcile/test/test_instrumented_wrappers.py +0 -18
- reconcile/test/test_integrations_manager.py +0 -1252
- reconcile/test/test_jenkins_worker_fleets.py +0 -57
- reconcile/test/test_jira_permissions_validator.py +0 -519
- reconcile/test/test_jump_host.py +0 -114
- reconcile/test/test_ldap_users.py +0 -125
- reconcile/test/test_make.py +0 -28
- reconcile/test/test_ocm_additional_routers.py +0 -133
- reconcile/test/test_ocm_clusters.py +0 -798
- reconcile/test/test_ocm_clusters_manifest_updates.py +0 -87
- reconcile/test/test_ocm_machine_pools.py +0 -1103
- reconcile/test/test_ocm_update_recommended_version.py +0 -145
- reconcile/test/test_ocm_upgrade_scheduler_org_updater.py +0 -125
- reconcile/test/test_openshift_base.py +0 -1269
- reconcile/test/test_openshift_cluster_bots.py +0 -240
- reconcile/test/test_openshift_namespace_labels.py +0 -344
- reconcile/test/test_openshift_namespaces.py +0 -256
- reconcile/test/test_openshift_resource.py +0 -443
- reconcile/test/test_openshift_resources_base.py +0 -478
- reconcile/test/test_openshift_saas_deploy.py +0 -188
- reconcile/test/test_openshift_saas_deploy_change_tester.py +0 -308
- reconcile/test/test_openshift_saas_deploy_trigger_cleaner.py +0 -65
- reconcile/test/test_openshift_serviceaccount_tokens.py +0 -282
- reconcile/test/test_openshift_tekton_resources.py +0 -265
- reconcile/test/test_openshift_upgrade_watcher.py +0 -223
- reconcile/test/test_prometheus_rules_tester.py +0 -151
- reconcile/test/test_quay_membership.py +0 -86
- reconcile/test/test_quay_mirror.py +0 -172
- reconcile/test/test_quay_mirror_org.py +0 -82
- reconcile/test/test_quay_repos.py +0 -59
- reconcile/test/test_queries.py +0 -53
- reconcile/test/test_repo_owners.py +0 -47
- reconcile/test/test_requests_sender.py +0 -139
- reconcile/test/test_saasherder.py +0 -1611
- reconcile/test/test_saasherder_allowed_secret_paths.py +0 -125
- reconcile/test/test_secret_reader.py +0 -153
- reconcile/test/test_slack_base.py +0 -183
- reconcile/test/test_slack_usergroups.py +0 -785
- reconcile/test/test_sql_query.py +0 -316
- reconcile/test/test_status_board.py +0 -258
- reconcile/test/test_terraform_aws_route53.py +0 -29
- reconcile/test/test_terraform_cloudflare_dns.py +0 -117
- reconcile/test/test_terraform_cloudflare_resources.py +0 -408
- reconcile/test/test_terraform_cloudflare_users.py +0 -747
- reconcile/test/test_terraform_repo.py +0 -440
- reconcile/test/test_terraform_resources.py +0 -519
- reconcile/test/test_terraform_tgw_attachments.py +0 -1295
- reconcile/test/test_terraform_users.py +0 -152
- reconcile/test/test_terraform_vpc_peerings.py +0 -576
- reconcile/test/test_terraform_vpc_peerings_build_desired_state.py +0 -1434
- reconcile/test/test_three_way_diff_strategy.py +0 -131
- reconcile/test/test_utils_jinja2.py +0 -130
- reconcile/test/test_vault_replication.py +0 -534
- reconcile/test/test_vault_utils.py +0 -47
- reconcile/test/test_version_bump.py +0 -18
- reconcile/test/test_vpc_peerings_validator.py +0 -194
- reconcile/test/test_wrong_region.py +0 -78
- release/__init__.py +0 -0
- release/test_version.py +0 -50
- release/version.py +0 -104
- tools/cli_commands/test/__init__.py +0 -0
- tools/cli_commands/test/conftest.py +0 -332
- tools/cli_commands/test/test_aws_cost_report.py +0 -258
- tools/cli_commands/test/test_cost_management_api.py +0 -326
- tools/cli_commands/test/test_gpg_encrypt.py +0 -235
- tools/cli_commands/test/test_openshift_cost_optimization_report.py +0 -255
- tools/cli_commands/test/test_openshift_cost_report.py +0 -295
- tools/cli_commands/test/test_util.py +0 -70
- tools/test/__init__.py +0 -0
- tools/test/conftest.py +0 -77
- tools/test/test_app_interface_metrics_exporter.py +0 -48
- tools/test/test_erv2.py +0 -80
- tools/test/test_get_container_images.py +0 -230
- tools/test/test_qontract_cli.py +0 -197
- tools/test/test_saas_promotion_state.py +0 -187
- tools/test/test_sd_app_sre_alert_report.py +0 -74
- tools/test/test_sre_checkpoints.py +0 -79
@@ -1,1252 +0,0 @@
|
|
1
|
-
import copy
|
2
|
-
import json
|
3
|
-
import os
|
4
|
-
from collections.abc import (
|
5
|
-
Callable,
|
6
|
-
Iterable,
|
7
|
-
)
|
8
|
-
from typing import Any
|
9
|
-
|
10
|
-
import pytest
|
11
|
-
|
12
|
-
import reconcile.integrations_manager as intop
|
13
|
-
from reconcile.gql_definitions.common.clusters_minimal import ClusterV1
|
14
|
-
from reconcile.gql_definitions.fragments.deplopy_resources import DeployResourcesFields
|
15
|
-
from reconcile.gql_definitions.fragments.minimal_ocm_organization import (
|
16
|
-
MinimalOCMOrganization,
|
17
|
-
)
|
18
|
-
from reconcile.gql_definitions.fragments.vault_secret import VaultSecret
|
19
|
-
from reconcile.gql_definitions.integrations.integrations import (
|
20
|
-
AWSAccountShardSpecOverrideV1,
|
21
|
-
EnvironmentV1,
|
22
|
-
IntegrationSpecV1,
|
23
|
-
IntegrationV1,
|
24
|
-
OCMOrganizationShardingV1,
|
25
|
-
OCMOrganizationShardSpecOverrideV1,
|
26
|
-
OpenshiftClusterShardSpecOverrideV1,
|
27
|
-
OpenshiftClusterShardSpecOverrideV1_ClusterV1,
|
28
|
-
StaticSubShardingV1,
|
29
|
-
)
|
30
|
-
from reconcile.gql_definitions.sharding import aws_accounts as sharding_aws_accounts
|
31
|
-
from reconcile.gql_definitions.terraform_cloudflare_dns.terraform_cloudflare_zones import (
|
32
|
-
AWSAccountV1 as AWSAccountV1_CloudFlare,
|
33
|
-
)
|
34
|
-
from reconcile.gql_definitions.terraform_cloudflare_dns.terraform_cloudflare_zones import (
|
35
|
-
CloudflareAccountV1,
|
36
|
-
CloudflareDnsRecordV1,
|
37
|
-
CloudflareDnsZoneV1,
|
38
|
-
)
|
39
|
-
from reconcile.integrations_manager import (
|
40
|
-
INTEGRATION_UPSTREAM_REPOS_PARAM,
|
41
|
-
HelmIntegrationSpec,
|
42
|
-
)
|
43
|
-
from reconcile.utils.openshift_resource import ResourceInventory
|
44
|
-
from reconcile.utils.runtime.meta import IntegrationMeta
|
45
|
-
from reconcile.utils.runtime.sharding import (
|
46
|
-
AWSAccountShardingStrategy,
|
47
|
-
AWSAccountShardingV1,
|
48
|
-
CloudflareDnsZoneShardingStrategy,
|
49
|
-
CloudflareDNSZoneShardingV1,
|
50
|
-
IntegrationShardManager,
|
51
|
-
OCMOrganizationShardingStrategy,
|
52
|
-
OpenshiftClusterShardingStrategy,
|
53
|
-
OpenshiftClusterShardingV1,
|
54
|
-
ShardSpec,
|
55
|
-
StaticShardingStrategy,
|
56
|
-
StaticShardingV1,
|
57
|
-
)
|
58
|
-
|
59
|
-
AWS_INTEGRATION = "aws_integration"
|
60
|
-
CLOUDFLARE_INTEGRATION = "cloudflare_integration"
|
61
|
-
OPENSHIFT_INTEGRATION = "openshift_integration"
|
62
|
-
OCM_INTEGRATION = "ocm_integration"
|
63
|
-
|
64
|
-
|
65
|
-
#
|
66
|
-
# collect_parameters test
|
67
|
-
#
|
68
|
-
|
69
|
-
|
70
|
-
def test_collect_parameters() -> None:
|
71
|
-
template = {
|
72
|
-
"parameters": [
|
73
|
-
{
|
74
|
-
"name": "TPLT_PARAM",
|
75
|
-
"value": "default",
|
76
|
-
}
|
77
|
-
]
|
78
|
-
}
|
79
|
-
os.environ["TPLT_PARAM"] = "override"
|
80
|
-
environment = EnvironmentV1(name="e", parameters='{"env_param": "test"}')
|
81
|
-
|
82
|
-
parameters = intop.collect_parameters(template, environment, "", "", None)
|
83
|
-
expected = {
|
84
|
-
"env_param": "test",
|
85
|
-
"TPLT_PARAM": "override",
|
86
|
-
}
|
87
|
-
assert parameters == expected
|
88
|
-
|
89
|
-
|
90
|
-
def test_collect_parameters_env_stronger() -> None:
|
91
|
-
template = {
|
92
|
-
"parameters": [
|
93
|
-
{
|
94
|
-
"name": "env_param",
|
95
|
-
"value": "default",
|
96
|
-
}
|
97
|
-
]
|
98
|
-
}
|
99
|
-
environment = EnvironmentV1(name="env", parameters='{"env_param": "override"}')
|
100
|
-
parameters = intop.collect_parameters(template, environment, "", "", None)
|
101
|
-
expected = {
|
102
|
-
"env_param": "override",
|
103
|
-
}
|
104
|
-
assert parameters == expected
|
105
|
-
|
106
|
-
|
107
|
-
def test_collect_parameters_os_env_strongest() -> None:
|
108
|
-
template = {
|
109
|
-
"parameters": [
|
110
|
-
{
|
111
|
-
"name": "ENV_PARAM",
|
112
|
-
"value": "default",
|
113
|
-
}
|
114
|
-
]
|
115
|
-
}
|
116
|
-
os.environ["ENV_PARAM"] = "strongest"
|
117
|
-
environment = EnvironmentV1(name="env", parameters='{"ENV_PARAM": "override"}')
|
118
|
-
parameters = intop.collect_parameters(template, environment, "", "", None)
|
119
|
-
expected = {
|
120
|
-
"ENV_PARAM": "strongest",
|
121
|
-
}
|
122
|
-
assert parameters == expected
|
123
|
-
|
124
|
-
|
125
|
-
def test_collect_parameters_image_tag_from_ref(mocker) -> None:
|
126
|
-
template = {
|
127
|
-
"parameters": [
|
128
|
-
{
|
129
|
-
"name": "IMAGE_TAG",
|
130
|
-
"value": "dummy",
|
131
|
-
}
|
132
|
-
]
|
133
|
-
}
|
134
|
-
os.environ["IMAGE_TAG"] = "override"
|
135
|
-
environment = EnvironmentV1(name="env", parameters='{"IMAGE_TAG": "default"}')
|
136
|
-
image_tag_from_ref = {"env": "f44e417"}
|
137
|
-
mocker.patch(
|
138
|
-
"reconcile.integrations_manager.get_image_tag_from_ref", return_value="f44e417"
|
139
|
-
)
|
140
|
-
parameters = intop.collect_parameters(
|
141
|
-
template, environment, "", "", image_tag_from_ref
|
142
|
-
)
|
143
|
-
expected = {
|
144
|
-
"IMAGE_TAG": "f44e417",
|
145
|
-
}
|
146
|
-
assert parameters == expected
|
147
|
-
|
148
|
-
|
149
|
-
def test_collect_parameters_namespace_environment_parameter(mocker) -> None:
|
150
|
-
upstream = "https://github.com/some-upstream-repo"
|
151
|
-
template = {
|
152
|
-
"parameters": [
|
153
|
-
{
|
154
|
-
"name": "IMAGE_TAG",
|
155
|
-
"value": "dummy",
|
156
|
-
}
|
157
|
-
]
|
158
|
-
}
|
159
|
-
os.environ["IMAGE_TAG"] = "env override"
|
160
|
-
environment = EnvironmentV1(
|
161
|
-
name="env",
|
162
|
-
parameters=json.dumps({
|
163
|
-
"IMAGE_TAG": "env-file-general-override",
|
164
|
-
INTEGRATION_UPSTREAM_REPOS_PARAM: [
|
165
|
-
{
|
166
|
-
"repo": upstream,
|
167
|
-
"ref": "master",
|
168
|
-
}
|
169
|
-
],
|
170
|
-
}),
|
171
|
-
)
|
172
|
-
mocker.patch(
|
173
|
-
"reconcile.integrations_manager.get_image_tag_from_ref", return_value="f44e417"
|
174
|
-
)
|
175
|
-
parameters = intop.collect_parameters(template, environment, upstream, "", None)
|
176
|
-
assert parameters["IMAGE_TAG"] == "f44e417"
|
177
|
-
|
178
|
-
|
179
|
-
@pytest.fixture
|
180
|
-
def resources() -> dict[str, Any]:
|
181
|
-
return {
|
182
|
-
"requests": {
|
183
|
-
"cpu": "100m",
|
184
|
-
"memory": "1Mi",
|
185
|
-
},
|
186
|
-
"limits": {
|
187
|
-
"cpu": "100m",
|
188
|
-
"memory": "1Mi",
|
189
|
-
},
|
190
|
-
}
|
191
|
-
|
192
|
-
|
193
|
-
@pytest.fixture
|
194
|
-
def resources_2() -> dict[str, Any]:
|
195
|
-
return {
|
196
|
-
"requests": {
|
197
|
-
"cpu": "200m",
|
198
|
-
"memory": "2Mi",
|
199
|
-
},
|
200
|
-
"limits": {
|
201
|
-
"cpu": "200m",
|
202
|
-
"memory": "2Mi",
|
203
|
-
},
|
204
|
-
}
|
205
|
-
|
206
|
-
|
207
|
-
@pytest.fixture
|
208
|
-
def basic_integration_spec(
|
209
|
-
gql_class_factory: Callable[..., IntegrationSpecV1], resources: dict[str, Any]
|
210
|
-
) -> IntegrationSpecV1:
|
211
|
-
return gql_class_factory(
|
212
|
-
IntegrationSpecV1, {"extraArgs": "integ-extra-arg", "resources": resources}
|
213
|
-
)
|
214
|
-
|
215
|
-
|
216
|
-
@pytest.fixture
|
217
|
-
def basic_integration(
|
218
|
-
gql_class_factory: Callable[..., IntegrationV1],
|
219
|
-
basic_integration_spec: IntegrationSpecV1,
|
220
|
-
) -> IntegrationV1:
|
221
|
-
return gql_class_factory(
|
222
|
-
IntegrationV1,
|
223
|
-
{
|
224
|
-
"name": "basic-integration",
|
225
|
-
"managed": [
|
226
|
-
{
|
227
|
-
"namespace": {
|
228
|
-
"path": "path",
|
229
|
-
"name": "ns",
|
230
|
-
"cluster": {"name": "cluster"},
|
231
|
-
"environment": {"name": "test"},
|
232
|
-
},
|
233
|
-
"spec": basic_integration_spec.dict(
|
234
|
-
exclude_none=True, by_alias=True
|
235
|
-
),
|
236
|
-
"sharding": None,
|
237
|
-
}
|
238
|
-
],
|
239
|
-
},
|
240
|
-
)
|
241
|
-
|
242
|
-
|
243
|
-
@pytest.fixture
|
244
|
-
def helm_integration_spec(
|
245
|
-
basic_integration_spec: IntegrationSpecV1,
|
246
|
-
) -> HelmIntegrationSpec:
|
247
|
-
return HelmIntegrationSpec(
|
248
|
-
**basic_integration_spec.dict(by_alias=True), name="basic-integration"
|
249
|
-
)
|
250
|
-
|
251
|
-
|
252
|
-
def test_build_helm_values_empty():
|
253
|
-
integrations_specs: list[HelmIntegrationSpec] = []
|
254
|
-
expected: dict[str, list] = {
|
255
|
-
"integrations": [],
|
256
|
-
"cronjobs": [],
|
257
|
-
}
|
258
|
-
values = intop.build_helm_values(integrations_specs)
|
259
|
-
assert values == expected
|
260
|
-
|
261
|
-
|
262
|
-
def test_build_helm_values(
|
263
|
-
helm_integration_spec: HelmIntegrationSpec, resources: dict[str, Any]
|
264
|
-
) -> None:
|
265
|
-
his1 = helm_integration_spec
|
266
|
-
his2 = copy.deepcopy(his1)
|
267
|
-
|
268
|
-
his2.name = "cron1"
|
269
|
-
his2.cron = "yup"
|
270
|
-
|
271
|
-
integrations_specs: list[HelmIntegrationSpec] = [his1, his2]
|
272
|
-
expected = {
|
273
|
-
"integrations": [
|
274
|
-
{
|
275
|
-
"name": "basic-integration",
|
276
|
-
"extraArgs": "integ-extra-arg",
|
277
|
-
"resources": resources,
|
278
|
-
"shard_specs": [],
|
279
|
-
},
|
280
|
-
],
|
281
|
-
"cronjobs": [
|
282
|
-
{
|
283
|
-
"name": "cron1",
|
284
|
-
"cron": "yup",
|
285
|
-
"extraArgs": "integ-extra-arg",
|
286
|
-
"resources": resources,
|
287
|
-
"shard_specs": [],
|
288
|
-
},
|
289
|
-
],
|
290
|
-
}
|
291
|
-
values = intop.build_helm_values(integrations_specs)
|
292
|
-
assert values == expected
|
293
|
-
|
294
|
-
|
295
|
-
#
|
296
|
-
# Per-AWS-account Tests
|
297
|
-
#
|
298
|
-
|
299
|
-
|
300
|
-
@pytest.fixture
|
301
|
-
def aws_accounts(
|
302
|
-
gql_class_factory: Callable[..., sharding_aws_accounts.AWSAccountV1],
|
303
|
-
) -> list[sharding_aws_accounts.AWSAccountV1]:
|
304
|
-
a1 = gql_class_factory(sharding_aws_accounts.AWSAccountV1, {"name": "acc-1"})
|
305
|
-
a2 = gql_class_factory(
|
306
|
-
sharding_aws_accounts.AWSAccountV1,
|
307
|
-
{"name": "acc-2", "disable": {"integrations": None}},
|
308
|
-
)
|
309
|
-
a3 = gql_class_factory(
|
310
|
-
sharding_aws_accounts.AWSAccountV1,
|
311
|
-
{"name": "acc-3", "disable": {"integrations": []}},
|
312
|
-
)
|
313
|
-
a4 = gql_class_factory(
|
314
|
-
sharding_aws_accounts.AWSAccountV1,
|
315
|
-
{"name": "acc-4", "disable": {"integrations": [AWS_INTEGRATION]}},
|
316
|
-
)
|
317
|
-
return [a1, a2, a3, a4]
|
318
|
-
|
319
|
-
|
320
|
-
@pytest.fixture
|
321
|
-
def aws_account_sharding_strategy(
|
322
|
-
aws_accounts: list[sharding_aws_accounts.AWSAccountV1],
|
323
|
-
) -> AWSAccountShardingStrategy:
|
324
|
-
return AWSAccountShardingStrategy(aws_accounts)
|
325
|
-
|
326
|
-
|
327
|
-
@pytest.fixture
|
328
|
-
def cloudflare_records():
|
329
|
-
return [
|
330
|
-
CloudflareDnsRecordV1(
|
331
|
-
identifier="id",
|
332
|
-
name="subdomain",
|
333
|
-
type="CNAME",
|
334
|
-
ttl=10,
|
335
|
-
value="foo.com",
|
336
|
-
priority=None,
|
337
|
-
data=None,
|
338
|
-
proxied=None,
|
339
|
-
)
|
340
|
-
]
|
341
|
-
|
342
|
-
|
343
|
-
@pytest.fixture
|
344
|
-
def aws_account_for_cloudflare():
|
345
|
-
return AWSAccountV1_CloudFlare(
|
346
|
-
name="foo",
|
347
|
-
consoleUrl="url",
|
348
|
-
terraformUsername="bar",
|
349
|
-
automationToken=VaultSecret(path="foo", field="bar", format=None, version=None),
|
350
|
-
terraformState=None,
|
351
|
-
)
|
352
|
-
|
353
|
-
|
354
|
-
@pytest.fixture
|
355
|
-
def cloudflare_account(aws_account_for_cloudflare):
|
356
|
-
return CloudflareAccountV1(
|
357
|
-
name="fakeaccount",
|
358
|
-
type="free",
|
359
|
-
description="description",
|
360
|
-
providerVersion="0.0",
|
361
|
-
enforceTwofactor=False,
|
362
|
-
apiCredentials=VaultSecret(
|
363
|
-
path="foo/bar", field="foo", format="bar", version=2
|
364
|
-
),
|
365
|
-
terraformStateAccount=aws_account_for_cloudflare,
|
366
|
-
deletionApprovals=None,
|
367
|
-
)
|
368
|
-
|
369
|
-
|
370
|
-
@pytest.fixture
|
371
|
-
def cloudflare_dns_zones(cloudflare_account, cloudflare_records):
|
372
|
-
return [
|
373
|
-
CloudflareDnsZoneV1(
|
374
|
-
identifier="zone1",
|
375
|
-
zone="fakezone1.com",
|
376
|
-
account=cloudflare_account,
|
377
|
-
records=cloudflare_records,
|
378
|
-
type="full",
|
379
|
-
plan="free",
|
380
|
-
delete=False,
|
381
|
-
max_records=None,
|
382
|
-
),
|
383
|
-
CloudflareDnsZoneV1(
|
384
|
-
identifier="zone2",
|
385
|
-
zone="fakezone2.com",
|
386
|
-
account=cloudflare_account,
|
387
|
-
records=cloudflare_records,
|
388
|
-
type="full",
|
389
|
-
plan="free",
|
390
|
-
delete=False,
|
391
|
-
max_records=None,
|
392
|
-
),
|
393
|
-
]
|
394
|
-
|
395
|
-
|
396
|
-
@pytest.fixture
|
397
|
-
def cloudflare_zone_sharding_strategy(
|
398
|
-
cloudflare_dns_zones: list[CloudflareDnsZoneV1],
|
399
|
-
) -> CloudflareDnsZoneShardingStrategy:
|
400
|
-
return CloudflareDnsZoneShardingStrategy(cloudflare_dns_zones)
|
401
|
-
|
402
|
-
|
403
|
-
@pytest.fixture
|
404
|
-
def openshift_clusters(gql_class_factory: Callable[..., ClusterV1]) -> list[ClusterV1]:
|
405
|
-
return [
|
406
|
-
gql_class_factory(
|
407
|
-
ClusterV1,
|
408
|
-
{"name": "cluster-1", "auth": [{"service": "github-org", "org": "redhat"}]},
|
409
|
-
),
|
410
|
-
gql_class_factory(
|
411
|
-
ClusterV1,
|
412
|
-
{"name": "cluster-2", "auth": [{"service": "github-org", "org": "redhat"}]},
|
413
|
-
),
|
414
|
-
]
|
415
|
-
|
416
|
-
|
417
|
-
@pytest.fixture
|
418
|
-
def openshift_cluster_sharding_strategy(
|
419
|
-
openshift_clusters: list[ClusterV1],
|
420
|
-
) -> OpenshiftClusterShardingStrategy:
|
421
|
-
return OpenshiftClusterShardingStrategy(openshift_clusters)
|
422
|
-
|
423
|
-
|
424
|
-
@pytest.fixture
|
425
|
-
def ocm_organizations(
|
426
|
-
gql_class_factory: Callable[..., MinimalOCMOrganization],
|
427
|
-
) -> list[MinimalOCMOrganization]:
|
428
|
-
return [
|
429
|
-
gql_class_factory(
|
430
|
-
MinimalOCMOrganization, {"name": "org-1", "orgId": "org-id-A"}
|
431
|
-
),
|
432
|
-
gql_class_factory(
|
433
|
-
MinimalOCMOrganization, {"name": "org-2", "orgId": "org-id-B"}
|
434
|
-
),
|
435
|
-
gql_class_factory(
|
436
|
-
MinimalOCMOrganization, {"name": "org-3", "orgId": "org-id-C"}
|
437
|
-
),
|
438
|
-
]
|
439
|
-
|
440
|
-
|
441
|
-
@pytest.fixture
|
442
|
-
def ocm_organization_sharding_strategy(
|
443
|
-
ocm_organizations: list[MinimalOCMOrganization],
|
444
|
-
) -> OCMOrganizationShardingStrategy:
|
445
|
-
return OCMOrganizationShardingStrategy(ocm_organizations=ocm_organizations)
|
446
|
-
|
447
|
-
|
448
|
-
@pytest.fixture
|
449
|
-
def shard_manager(
|
450
|
-
aws_account_sharding_strategy: AWSAccountShardingStrategy,
|
451
|
-
cloudflare_zone_sharding_strategy: CloudflareDnsZoneShardingStrategy,
|
452
|
-
openshift_cluster_sharding_strategy: OpenshiftClusterShardingStrategy,
|
453
|
-
ocm_organization_sharding_strategy: OCMOrganizationShardingStrategy,
|
454
|
-
) -> IntegrationShardManager:
|
455
|
-
return IntegrationShardManager(
|
456
|
-
strategies={
|
457
|
-
StaticShardingStrategy.IDENTIFIER: StaticShardingStrategy(),
|
458
|
-
aws_account_sharding_strategy.IDENTIFIER: aws_account_sharding_strategy,
|
459
|
-
openshift_cluster_sharding_strategy.IDENTIFIER: openshift_cluster_sharding_strategy,
|
460
|
-
cloudflare_zone_sharding_strategy.IDENTIFIER: cloudflare_zone_sharding_strategy,
|
461
|
-
ocm_organization_sharding_strategy.IDENTIFIER: ocm_organization_sharding_strategy,
|
462
|
-
},
|
463
|
-
integration_runtime_meta={
|
464
|
-
"basic-integration": IntegrationMeta(
|
465
|
-
name="basic-integration",
|
466
|
-
short_help="",
|
467
|
-
args=["--arg"],
|
468
|
-
),
|
469
|
-
AWS_INTEGRATION: IntegrationMeta(
|
470
|
-
name=AWS_INTEGRATION, short_help="", args=["--account-name"]
|
471
|
-
),
|
472
|
-
CLOUDFLARE_INTEGRATION: IntegrationMeta(
|
473
|
-
name=CLOUDFLARE_INTEGRATION, short_help="", args=["--zone-name"]
|
474
|
-
),
|
475
|
-
OPENSHIFT_INTEGRATION: IntegrationMeta(
|
476
|
-
name=OPENSHIFT_INTEGRATION,
|
477
|
-
short_help="",
|
478
|
-
args=["--arg", "--cluster-name"],
|
479
|
-
),
|
480
|
-
OCM_INTEGRATION: IntegrationMeta(
|
481
|
-
name=OCM_INTEGRATION, short_help="", args=["--org-id"]
|
482
|
-
),
|
483
|
-
},
|
484
|
-
)
|
485
|
-
|
486
|
-
|
487
|
-
def test_shard_manager_aws_account_filtering(
|
488
|
-
aws_account_sharding_strategy: AWSAccountShardingStrategy,
|
489
|
-
) -> None:
|
490
|
-
assert [
|
491
|
-
a.name
|
492
|
-
for a in aws_account_sharding_strategy.filter_objects("another-integration")
|
493
|
-
] == ["acc-1", "acc-2", "acc-3", "acc-4"]
|
494
|
-
|
495
|
-
|
496
|
-
def test_shard_manager_aws_account_filtering_disabled(
|
497
|
-
aws_account_sharding_strategy: AWSAccountShardingStrategy,
|
498
|
-
) -> None:
|
499
|
-
# acc-4 is disabled for AWS_INTEGRATION
|
500
|
-
assert [
|
501
|
-
a.name for a in aws_account_sharding_strategy.filter_objects(AWS_INTEGRATION)
|
502
|
-
] == ["acc-1", "acc-2", "acc-3"]
|
503
|
-
|
504
|
-
|
505
|
-
#
|
506
|
-
# Static Sharding Tests
|
507
|
-
#
|
508
|
-
|
509
|
-
|
510
|
-
def test_build_helm_integration_spec_no_shards(
|
511
|
-
basic_integration: IntegrationV1,
|
512
|
-
shard_manager: IntegrationShardManager,
|
513
|
-
) -> None:
|
514
|
-
wr = intop.collect_integrations_environment(
|
515
|
-
[basic_integration], "test", shard_manager
|
516
|
-
)
|
517
|
-
|
518
|
-
expected_shard_spec = ShardSpec(
|
519
|
-
shards="1",
|
520
|
-
shard_id="0",
|
521
|
-
shard_spec_overrides=None,
|
522
|
-
shard_key="",
|
523
|
-
shard_name_suffix="",
|
524
|
-
extra_args="integ-extra-arg",
|
525
|
-
)
|
526
|
-
|
527
|
-
assert len(wr) == 1
|
528
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
529
|
-
assert len(shards) == 1
|
530
|
-
assert shards[0] == expected_shard_spec
|
531
|
-
|
532
|
-
|
533
|
-
def test_initialize_shard_specs_two_shards_explicit(
|
534
|
-
basic_integration: IntegrationV1,
|
535
|
-
shard_manager: intop.IntegrationShardManager,
|
536
|
-
) -> None:
|
537
|
-
static_sharding = StaticShardingV1(
|
538
|
-
strategy=StaticShardingStrategy.IDENTIFIER, shards=2
|
539
|
-
)
|
540
|
-
if basic_integration.managed:
|
541
|
-
basic_integration.managed[0].sharding = static_sharding
|
542
|
-
|
543
|
-
wr = intop.collect_integrations_environment(
|
544
|
-
[basic_integration], "test", shard_manager
|
545
|
-
)
|
546
|
-
|
547
|
-
expected = [
|
548
|
-
ShardSpec(
|
549
|
-
shard_id="0",
|
550
|
-
shards="2",
|
551
|
-
shard_name_suffix="-0",
|
552
|
-
extra_args="integ-extra-arg",
|
553
|
-
),
|
554
|
-
ShardSpec(
|
555
|
-
shard_id="1",
|
556
|
-
shards="2",
|
557
|
-
shard_name_suffix="-1",
|
558
|
-
extra_args="integ-extra-arg",
|
559
|
-
),
|
560
|
-
]
|
561
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
562
|
-
assert expected == shards
|
563
|
-
|
564
|
-
|
565
|
-
#
|
566
|
-
# Per-AWS-Account tests
|
567
|
-
#
|
568
|
-
|
569
|
-
|
570
|
-
def test_initialize_shard_specs_aws_account_shards(
|
571
|
-
basic_integration: IntegrationV1,
|
572
|
-
shard_manager: IntegrationShardManager,
|
573
|
-
) -> None:
|
574
|
-
"""
|
575
|
-
this test shows how the per-aws-account strategy fills the shard_specs and ignores
|
576
|
-
aws accounts where the integration is disabled
|
577
|
-
"""
|
578
|
-
aws_acc_sharding = AWSAccountShardingV1(
|
579
|
-
strategy="per-aws-account", shardSpecOverrides=None
|
580
|
-
)
|
581
|
-
|
582
|
-
basic_integration.name = AWS_INTEGRATION
|
583
|
-
if basic_integration.managed:
|
584
|
-
basic_integration.managed[0].sharding = aws_acc_sharding
|
585
|
-
|
586
|
-
wr = intop.collect_integrations_environment(
|
587
|
-
[basic_integration], "test", shard_manager
|
588
|
-
)
|
589
|
-
|
590
|
-
expected = [
|
591
|
-
ShardSpec(
|
592
|
-
shard_name_suffix="-acc-1",
|
593
|
-
shard_key="acc-1",
|
594
|
-
extra_args="integ-extra-arg --account-name acc-1",
|
595
|
-
),
|
596
|
-
ShardSpec(
|
597
|
-
shard_name_suffix="-acc-2",
|
598
|
-
shard_key="acc-2",
|
599
|
-
extra_args="integ-extra-arg --account-name acc-2",
|
600
|
-
),
|
601
|
-
ShardSpec(
|
602
|
-
shard_name_suffix="-acc-3",
|
603
|
-
shard_key="acc-3",
|
604
|
-
extra_args="integ-extra-arg --account-name acc-3",
|
605
|
-
),
|
606
|
-
]
|
607
|
-
|
608
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
609
|
-
assert expected == shards
|
610
|
-
|
611
|
-
|
612
|
-
@pytest.fixture
|
613
|
-
def aws_shard_overrides(
|
614
|
-
gql_class_factory: Callable[..., DeployResourcesFields],
|
615
|
-
resources: dict[str, Any],
|
616
|
-
aws_accounts: list[sharding_aws_accounts.AWSAccountV1],
|
617
|
-
) -> list[AWSAccountShardSpecOverrideV1]:
|
618
|
-
o1 = AWSAccountShardSpecOverrideV1(
|
619
|
-
shard=aws_accounts[0], imageRef="acc1-image", disabled=False, resources=None
|
620
|
-
)
|
621
|
-
resources["requests"]["cpu"] = "200m"
|
622
|
-
resources["requests"]["memory"] = "2Mi"
|
623
|
-
resources["limits"]["cpu"] = "300m"
|
624
|
-
resources["limits"]["memory"] = "3Mi"
|
625
|
-
|
626
|
-
deploy_resources = gql_class_factory(DeployResourcesFields, resources)
|
627
|
-
o2 = AWSAccountShardSpecOverrideV1(
|
628
|
-
shard=aws_accounts[1],
|
629
|
-
imageRef=None,
|
630
|
-
resources=deploy_resources,
|
631
|
-
disabled=False,
|
632
|
-
)
|
633
|
-
o3 = AWSAccountShardSpecOverrideV1(
|
634
|
-
shard=aws_accounts[2], resources=None, imageRef=None, disabled=True
|
635
|
-
)
|
636
|
-
|
637
|
-
return [o1, o2, o3]
|
638
|
-
|
639
|
-
|
640
|
-
def test_initialize_shard_specs_aws_account_shards_with_overrides(
|
641
|
-
basic_integration: IntegrationV1,
|
642
|
-
aws_shard_overrides: list[AWSAccountShardSpecOverrideV1],
|
643
|
-
shard_manager: IntegrationShardManager,
|
644
|
-
) -> None:
|
645
|
-
aws_acc_sharding = AWSAccountShardingV1(
|
646
|
-
strategy=AWSAccountShardingStrategy.IDENTIFIER,
|
647
|
-
shardSpecOverrides=aws_shard_overrides,
|
648
|
-
)
|
649
|
-
|
650
|
-
basic_integration.name = AWS_INTEGRATION
|
651
|
-
if basic_integration.managed:
|
652
|
-
basic_integration.managed[0].sharding = aws_acc_sharding
|
653
|
-
|
654
|
-
wr = intop.collect_integrations_environment(
|
655
|
-
[basic_integration], "test", shard_manager
|
656
|
-
)
|
657
|
-
|
658
|
-
expected = [
|
659
|
-
ShardSpec(
|
660
|
-
shard_name_suffix="-acc-1",
|
661
|
-
shard_key="acc-1",
|
662
|
-
extra_args="integ-extra-arg --account-name acc-1",
|
663
|
-
shard_spec_overrides=aws_shard_overrides[0],
|
664
|
-
),
|
665
|
-
ShardSpec(
|
666
|
-
shard_name_suffix="-acc-2",
|
667
|
-
shard_key="acc-2",
|
668
|
-
extra_args="integ-extra-arg --account-name acc-2",
|
669
|
-
shard_spec_overrides=aws_shard_overrides[1],
|
670
|
-
),
|
671
|
-
ShardSpec(
|
672
|
-
shard_name_suffix="-acc-3",
|
673
|
-
shard_key="acc-3",
|
674
|
-
extra_args="integ-extra-arg --account-name acc-3",
|
675
|
-
shard_spec_overrides=aws_shard_overrides[2],
|
676
|
-
),
|
677
|
-
]
|
678
|
-
|
679
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
680
|
-
assert expected == shards
|
681
|
-
|
682
|
-
|
683
|
-
def test_initialize_shard_specs_aws_account_shards_extra_args_aggregation(
|
684
|
-
basic_integration: IntegrationV1,
|
685
|
-
shard_manager: IntegrationShardManager,
|
686
|
-
) -> None:
|
687
|
-
"""
|
688
|
-
this test shows how the per-aws-account strategy fills the shard_specs and ignores
|
689
|
-
aws accounts where the integration is disabled
|
690
|
-
"""
|
691
|
-
aws_acc_sharding = AWSAccountShardingV1(
|
692
|
-
strategy="per-aws-account", shardSpecOverrides=None
|
693
|
-
)
|
694
|
-
|
695
|
-
basic_integration.name = AWS_INTEGRATION
|
696
|
-
if basic_integration.managed:
|
697
|
-
basic_integration.managed[0].sharding = aws_acc_sharding
|
698
|
-
basic_integration.managed[0].spec.extra_args = "--arg"
|
699
|
-
|
700
|
-
wr = intop.collect_integrations_environment(
|
701
|
-
[basic_integration], "test", shard_manager
|
702
|
-
)
|
703
|
-
|
704
|
-
expected = [
|
705
|
-
ShardSpec(
|
706
|
-
shard_name_suffix="-acc-1",
|
707
|
-
shard_key="acc-1",
|
708
|
-
extra_args="--arg --account-name acc-1",
|
709
|
-
),
|
710
|
-
ShardSpec(
|
711
|
-
shard_name_suffix="-acc-2",
|
712
|
-
shard_key="acc-2",
|
713
|
-
extra_args="--arg --account-name acc-2",
|
714
|
-
),
|
715
|
-
ShardSpec(
|
716
|
-
shard_name_suffix="-acc-3",
|
717
|
-
shard_key="acc-3",
|
718
|
-
extra_args="--arg --account-name acc-3",
|
719
|
-
),
|
720
|
-
]
|
721
|
-
|
722
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
723
|
-
assert expected == shards
|
724
|
-
|
725
|
-
|
726
|
-
#
|
727
|
-
# per-ocm-organization tests
|
728
|
-
#
|
729
|
-
|
730
|
-
|
731
|
-
def test_initialize_shard_specs_ocm_organizations_shards(
|
732
|
-
basic_integration: IntegrationV1,
|
733
|
-
shard_manager: IntegrationShardManager,
|
734
|
-
) -> None:
|
735
|
-
"""
|
736
|
-
this test shows how the per-ocm-organization strategy fills the shard_specs and ignores
|
737
|
-
aws accounts where the integration is disabled
|
738
|
-
"""
|
739
|
-
ocm_org_sharding = OCMOrganizationShardingV1(
|
740
|
-
strategy="per-ocm-organization", shardSpecOverrides=None
|
741
|
-
)
|
742
|
-
|
743
|
-
basic_integration.name = OCM_INTEGRATION
|
744
|
-
if basic_integration.managed:
|
745
|
-
basic_integration.managed[0].sharding = ocm_org_sharding
|
746
|
-
|
747
|
-
wr = intop.collect_integrations_environment(
|
748
|
-
[basic_integration], "test", shard_manager
|
749
|
-
)
|
750
|
-
|
751
|
-
expected = [
|
752
|
-
ShardSpec(
|
753
|
-
shard_name_suffix="-org-id-a",
|
754
|
-
shard_key="org-id-A",
|
755
|
-
extra_args="integ-extra-arg --org-id org-id-A",
|
756
|
-
),
|
757
|
-
ShardSpec(
|
758
|
-
shard_name_suffix="-org-id-b",
|
759
|
-
shard_key="org-id-B",
|
760
|
-
extra_args="integ-extra-arg --org-id org-id-B",
|
761
|
-
),
|
762
|
-
ShardSpec(
|
763
|
-
shard_name_suffix="-org-id-c",
|
764
|
-
shard_key="org-id-C",
|
765
|
-
extra_args="integ-extra-arg --org-id org-id-C",
|
766
|
-
),
|
767
|
-
]
|
768
|
-
|
769
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
770
|
-
assert expected == shards
|
771
|
-
|
772
|
-
|
773
|
-
@pytest.fixture
|
774
|
-
def ocm_organizations_shard_overrides(
|
775
|
-
gql_class_factory: Callable[..., DeployResourcesFields],
|
776
|
-
resources: dict[str, Any],
|
777
|
-
ocm_organizations: list[MinimalOCMOrganization],
|
778
|
-
) -> list[OCMOrganizationShardSpecOverrideV1]:
|
779
|
-
o1 = OCMOrganizationShardSpecOverrideV1(
|
780
|
-
shard=ocm_organizations[0],
|
781
|
-
imageRef="org-1-image",
|
782
|
-
disabled=False,
|
783
|
-
resources=None,
|
784
|
-
)
|
785
|
-
resources["requests"]["cpu"] = "200m"
|
786
|
-
resources["requests"]["memory"] = "2Mi"
|
787
|
-
resources["limits"]["cpu"] = "300m"
|
788
|
-
resources["limits"]["memory"] = "3Mi"
|
789
|
-
|
790
|
-
deploy_resources = gql_class_factory(DeployResourcesFields, resources)
|
791
|
-
o2 = OCMOrganizationShardSpecOverrideV1(
|
792
|
-
shard=ocm_organizations[1],
|
793
|
-
imageRef=None,
|
794
|
-
resources=deploy_resources,
|
795
|
-
disabled=False,
|
796
|
-
)
|
797
|
-
o3 = OCMOrganizationShardSpecOverrideV1(
|
798
|
-
shard=ocm_organizations[2], resources=None, imageRef=None, disabled=True
|
799
|
-
)
|
800
|
-
|
801
|
-
return [o1, o2, o3]
|
802
|
-
|
803
|
-
|
804
|
-
def test_initialize_shard_specs_ocm_organizations_shards_with_overrides(
|
805
|
-
basic_integration: IntegrationV1,
|
806
|
-
ocm_organizations_shard_overrides: list[OCMOrganizationShardSpecOverrideV1],
|
807
|
-
shard_manager: IntegrationShardManager,
|
808
|
-
) -> None:
|
809
|
-
org_sharding = OCMOrganizationShardingV1(
|
810
|
-
strategy=OCMOrganizationShardingStrategy.IDENTIFIER,
|
811
|
-
shardSpecOverrides=ocm_organizations_shard_overrides,
|
812
|
-
)
|
813
|
-
|
814
|
-
basic_integration.name = OCM_INTEGRATION
|
815
|
-
if basic_integration.managed:
|
816
|
-
basic_integration.managed[0].sharding = org_sharding
|
817
|
-
|
818
|
-
wr = intop.collect_integrations_environment(
|
819
|
-
[basic_integration], "test", shard_manager
|
820
|
-
)
|
821
|
-
|
822
|
-
expected = [
|
823
|
-
ShardSpec(
|
824
|
-
shard_name_suffix="-org-id-a",
|
825
|
-
shard_key="org-id-A",
|
826
|
-
extra_args="integ-extra-arg --org-id org-id-A",
|
827
|
-
shard_spec_overrides=ocm_organizations_shard_overrides[0],
|
828
|
-
),
|
829
|
-
ShardSpec(
|
830
|
-
shard_name_suffix="-org-id-b",
|
831
|
-
shard_key="org-id-B",
|
832
|
-
extra_args="integ-extra-arg --org-id org-id-B",
|
833
|
-
shard_spec_overrides=ocm_organizations_shard_overrides[1],
|
834
|
-
),
|
835
|
-
ShardSpec(
|
836
|
-
shard_name_suffix="-org-id-c",
|
837
|
-
shard_key="org-id-C",
|
838
|
-
extra_args="integ-extra-arg --org-id org-id-C",
|
839
|
-
shard_spec_overrides=ocm_organizations_shard_overrides[2],
|
840
|
-
),
|
841
|
-
]
|
842
|
-
|
843
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
844
|
-
assert expected == shards
|
845
|
-
|
846
|
-
|
847
|
-
def test_initialize_shard_specs_ocm_organizations_shards_extra_args_aggregation(
|
848
|
-
basic_integration: IntegrationV1,
|
849
|
-
shard_manager: IntegrationShardManager,
|
850
|
-
) -> None:
|
851
|
-
ocm_org_sharding = OCMOrganizationShardingV1(
|
852
|
-
strategy="per-ocm-organization", shardSpecOverrides=None
|
853
|
-
)
|
854
|
-
|
855
|
-
basic_integration.name = OCM_INTEGRATION
|
856
|
-
if basic_integration.managed:
|
857
|
-
basic_integration.managed[0].sharding = ocm_org_sharding
|
858
|
-
basic_integration.managed[0].spec.extra_args = "--arg"
|
859
|
-
|
860
|
-
wr = intop.collect_integrations_environment(
|
861
|
-
[basic_integration], "test", shard_manager
|
862
|
-
)
|
863
|
-
|
864
|
-
expected = [
|
865
|
-
ShardSpec(
|
866
|
-
shard_name_suffix="-org-id-a",
|
867
|
-
shard_key="org-id-A",
|
868
|
-
extra_args="--arg --org-id org-id-A",
|
869
|
-
),
|
870
|
-
ShardSpec(
|
871
|
-
shard_name_suffix="-org-id-b",
|
872
|
-
shard_key="org-id-B",
|
873
|
-
extra_args="--arg --org-id org-id-B",
|
874
|
-
),
|
875
|
-
ShardSpec(
|
876
|
-
shard_name_suffix="-org-id-c",
|
877
|
-
shard_key="org-id-C",
|
878
|
-
extra_args="--arg --org-id org-id-C",
|
879
|
-
),
|
880
|
-
]
|
881
|
-
|
882
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
883
|
-
assert expected == shards
|
884
|
-
|
885
|
-
|
886
|
-
#
|
887
|
-
# Per-Cloudflare-Zone Tests
|
888
|
-
#
|
889
|
-
|
890
|
-
|
891
|
-
@pytest.fixture
|
892
|
-
def cloudflarednszone_sharding() -> CloudflareDNSZoneShardingV1:
|
893
|
-
return CloudflareDNSZoneShardingV1(
|
894
|
-
strategy="per-cloudflare-dns-zone", shardSpecOverrides=None
|
895
|
-
)
|
896
|
-
|
897
|
-
|
898
|
-
def test_initialize_shard_specs_cloudflare_zone_shards(
|
899
|
-
basic_integration: IntegrationV1,
|
900
|
-
cloudflarednszone_sharding: CloudflareDNSZoneShardingV1,
|
901
|
-
shard_manager: intop.IntegrationShardManager,
|
902
|
-
) -> None:
|
903
|
-
"""
|
904
|
-
The per-cloudflare-zone strategy would result in two shards when there is two zones.
|
905
|
-
"""
|
906
|
-
if basic_integration.managed:
|
907
|
-
basic_integration.name = CLOUDFLARE_INTEGRATION
|
908
|
-
basic_integration.managed[0].sharding = cloudflarednszone_sharding
|
909
|
-
|
910
|
-
wr = intop.collect_integrations_environment(
|
911
|
-
[basic_integration], "test", shard_manager
|
912
|
-
)
|
913
|
-
|
914
|
-
expected = [
|
915
|
-
ShardSpec(
|
916
|
-
shard_key="fakeaccount-zone1",
|
917
|
-
shard_name_suffix="-fakeaccount-zone1",
|
918
|
-
extra_args="integ-extra-arg --zone-name zone1",
|
919
|
-
),
|
920
|
-
ShardSpec(
|
921
|
-
shard_key="fakeaccount-zone2",
|
922
|
-
shard_name_suffix="-fakeaccount-zone2",
|
923
|
-
extra_args="integ-extra-arg --zone-name zone2",
|
924
|
-
),
|
925
|
-
]
|
926
|
-
|
927
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
928
|
-
assert shards == expected
|
929
|
-
|
930
|
-
|
931
|
-
def test_initialize_shard_specs_cloudflare_zone_shards_raise_exception(
|
932
|
-
basic_integration: IntegrationV1,
|
933
|
-
cloudflarednszone_sharding: CloudflareDNSZoneShardingV1,
|
934
|
-
shard_manager: intop.IntegrationShardManager,
|
935
|
-
) -> None:
|
936
|
-
"""
|
937
|
-
The per-cloudflare-zone strategy will raise an exception when --zone-name is not set.
|
938
|
-
"""
|
939
|
-
if basic_integration.managed:
|
940
|
-
basic_integration.managed[0].sharding = cloudflarednszone_sharding
|
941
|
-
|
942
|
-
with pytest.raises(ValueError) as e:
|
943
|
-
intop.collect_integrations_environment(
|
944
|
-
[basic_integration], "test", shard_manager
|
945
|
-
)
|
946
|
-
|
947
|
-
assert (
|
948
|
-
e.value.args[0]
|
949
|
-
== f"integration basic-integration does not support the provided argument. --zone-name is required by the '{CloudflareDnsZoneShardingStrategy.IDENTIFIER}' sharding strategy."
|
950
|
-
)
|
951
|
-
|
952
|
-
|
953
|
-
#
|
954
|
-
# Per-Openshift-Clusters tests
|
955
|
-
#
|
956
|
-
|
957
|
-
|
958
|
-
@pytest.fixture
|
959
|
-
def openshift_clusters_sharding() -> OpenshiftClusterShardingV1:
|
960
|
-
return OpenshiftClusterShardingV1(
|
961
|
-
strategy=OpenshiftClusterShardingStrategy.IDENTIFIER, shardSpecOverrides=None
|
962
|
-
)
|
963
|
-
|
964
|
-
|
965
|
-
@pytest.fixture
|
966
|
-
def openshift_clusters_shard_spec_override(
|
967
|
-
openshift_clusters: list[ClusterV1], resources_2: dict[str, Any]
|
968
|
-
) -> OpenshiftClusterShardSpecOverrideV1:
|
969
|
-
return OpenshiftClusterShardSpecOverrideV1(
|
970
|
-
shard=OpenshiftClusterShardSpecOverrideV1_ClusterV1(
|
971
|
-
name=openshift_clusters[0].name
|
972
|
-
),
|
973
|
-
imageRef=None,
|
974
|
-
disabled=False,
|
975
|
-
resources=resources_2,
|
976
|
-
subSharding=None,
|
977
|
-
)
|
978
|
-
|
979
|
-
|
980
|
-
def test_initialize_shard_specs_openshift_clusters(
|
981
|
-
basic_integration: IntegrationV1,
|
982
|
-
openshift_clusters_sharding: OpenshiftClusterShardingV1,
|
983
|
-
shard_manager: IntegrationShardManager,
|
984
|
-
) -> None:
|
985
|
-
if basic_integration.managed:
|
986
|
-
basic_integration.name = OPENSHIFT_INTEGRATION
|
987
|
-
basic_integration.managed[0].sharding = openshift_clusters_sharding
|
988
|
-
|
989
|
-
wr = intop.collect_integrations_environment(
|
990
|
-
[basic_integration], "test", shard_manager
|
991
|
-
)
|
992
|
-
expected = [
|
993
|
-
ShardSpec(
|
994
|
-
shards="",
|
995
|
-
shard_id="",
|
996
|
-
shard_spec_overrides=None,
|
997
|
-
shard_key="cluster-1",
|
998
|
-
shard_name_suffix="-cluster-1",
|
999
|
-
extra_args="integ-extra-arg --cluster-name cluster-1",
|
1000
|
-
),
|
1001
|
-
ShardSpec(
|
1002
|
-
shards="",
|
1003
|
-
shard_id="",
|
1004
|
-
shard_spec_overrides=None,
|
1005
|
-
shard_key="cluster-2",
|
1006
|
-
shard_name_suffix="-cluster-2",
|
1007
|
-
extra_args="integ-extra-arg --cluster-name cluster-2",
|
1008
|
-
),
|
1009
|
-
]
|
1010
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
1011
|
-
assert shards == expected
|
1012
|
-
|
1013
|
-
|
1014
|
-
def test_initialize_shard_specs_openshift_clusters_subsharding_w_overrides(
|
1015
|
-
basic_integration: IntegrationV1,
|
1016
|
-
openshift_clusters_sharding: OpenshiftClusterShardingV1,
|
1017
|
-
openshift_clusters_shard_spec_override: OpenshiftClusterShardSpecOverrideV1,
|
1018
|
-
shard_manager: IntegrationShardManager,
|
1019
|
-
resources_2: dict[str, Any],
|
1020
|
-
) -> None:
|
1021
|
-
openshift_clusters_shard_spec_override.sub_sharding = StaticSubShardingV1(
|
1022
|
-
strategy=StaticShardingStrategy.IDENTIFIER, shards=2
|
1023
|
-
)
|
1024
|
-
|
1025
|
-
openshift_clusters_shard_spec_override.image_ref = "my-test-image"
|
1026
|
-
|
1027
|
-
if basic_integration.managed:
|
1028
|
-
basic_integration.name = OPENSHIFT_INTEGRATION
|
1029
|
-
basic_integration.managed[0].sharding = openshift_clusters_sharding
|
1030
|
-
basic_integration.managed[0].sharding.shard_spec_overrides = [
|
1031
|
-
openshift_clusters_shard_spec_override
|
1032
|
-
]
|
1033
|
-
|
1034
|
-
wr = intop.collect_integrations_environment(
|
1035
|
-
[basic_integration], "test", shard_manager
|
1036
|
-
)
|
1037
|
-
expected = [
|
1038
|
-
ShardSpec(
|
1039
|
-
shards="2",
|
1040
|
-
shard_id="0",
|
1041
|
-
shard_spec_overrides=OpenshiftClusterShardSpecOverrideV1(
|
1042
|
-
shard=OpenshiftClusterShardSpecOverrideV1_ClusterV1(name="cluster-1"),
|
1043
|
-
imageRef="my-test-image",
|
1044
|
-
disabled=False,
|
1045
|
-
resources=resources_2,
|
1046
|
-
subSharding=None,
|
1047
|
-
),
|
1048
|
-
shard_key="cluster-1",
|
1049
|
-
shard_name_suffix="-cluster-1-0",
|
1050
|
-
extra_args="integ-extra-arg --cluster-name cluster-1",
|
1051
|
-
),
|
1052
|
-
ShardSpec(
|
1053
|
-
shards="2",
|
1054
|
-
shard_id="1",
|
1055
|
-
shard_spec_overrides=OpenshiftClusterShardSpecOverrideV1(
|
1056
|
-
shard=OpenshiftClusterShardSpecOverrideV1_ClusterV1(name="cluster-1"),
|
1057
|
-
imageRef="my-test-image",
|
1058
|
-
disabled=False,
|
1059
|
-
resources=resources_2,
|
1060
|
-
subSharding=None,
|
1061
|
-
),
|
1062
|
-
shard_key="cluster-1",
|
1063
|
-
shard_name_suffix="-cluster-1-1",
|
1064
|
-
extra_args="integ-extra-arg --cluster-name cluster-1",
|
1065
|
-
),
|
1066
|
-
ShardSpec(
|
1067
|
-
shards="",
|
1068
|
-
shard_id="",
|
1069
|
-
shard_spec_overrides=None,
|
1070
|
-
shard_key="cluster-2",
|
1071
|
-
shard_name_suffix="-cluster-2",
|
1072
|
-
extra_args="integ-extra-arg --cluster-name cluster-2",
|
1073
|
-
),
|
1074
|
-
]
|
1075
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
1076
|
-
assert shards == expected
|
1077
|
-
|
1078
|
-
|
1079
|
-
def test_initialize_shard_specs_openshift_clusters_disabled_shard(
|
1080
|
-
basic_integration: IntegrationV1,
|
1081
|
-
openshift_clusters_sharding: OpenshiftClusterShardingV1,
|
1082
|
-
openshift_clusters_shard_spec_override: OpenshiftClusterShardSpecOverrideV1,
|
1083
|
-
shard_manager: IntegrationShardManager,
|
1084
|
-
resources_2: dict[str, Any],
|
1085
|
-
) -> None:
|
1086
|
-
openshift_clusters_shard_spec_override.disabled = True
|
1087
|
-
|
1088
|
-
if basic_integration.managed:
|
1089
|
-
basic_integration.name = OPENSHIFT_INTEGRATION
|
1090
|
-
basic_integration.managed[0].sharding = openshift_clusters_sharding
|
1091
|
-
basic_integration.managed[0].sharding.shard_spec_overrides = [
|
1092
|
-
openshift_clusters_shard_spec_override
|
1093
|
-
]
|
1094
|
-
|
1095
|
-
wr = intop.collect_integrations_environment(
|
1096
|
-
[basic_integration], "test", shard_manager
|
1097
|
-
)
|
1098
|
-
expected = [
|
1099
|
-
ShardSpec(
|
1100
|
-
shards="",
|
1101
|
-
shard_id="",
|
1102
|
-
shard_spec_overrides=OpenshiftClusterShardSpecOverrideV1(
|
1103
|
-
shard=OpenshiftClusterShardSpecOverrideV1_ClusterV1(name="cluster-1"),
|
1104
|
-
imageRef=None,
|
1105
|
-
disabled=True,
|
1106
|
-
resources=resources_2,
|
1107
|
-
subSharding=None,
|
1108
|
-
),
|
1109
|
-
shard_key="cluster-1",
|
1110
|
-
shard_name_suffix="-cluster-1",
|
1111
|
-
extra_args="integ-extra-arg --cluster-name cluster-1",
|
1112
|
-
),
|
1113
|
-
ShardSpec(
|
1114
|
-
shards="",
|
1115
|
-
shard_id="",
|
1116
|
-
shard_spec_overrides=None,
|
1117
|
-
shard_key="cluster-2",
|
1118
|
-
shard_name_suffix="-cluster-2",
|
1119
|
-
extra_args="integ-extra-arg --cluster-name cluster-2",
|
1120
|
-
),
|
1121
|
-
]
|
1122
|
-
shards = wr[0].integration_specs[0].shard_specs or []
|
1123
|
-
assert shards == expected
|
1124
|
-
|
1125
|
-
|
1126
|
-
#
|
1127
|
-
# fetch_desired_state tests
|
1128
|
-
#
|
1129
|
-
|
1130
|
-
|
1131
|
-
def test_fetch_desired_state(
|
1132
|
-
basic_integration: IntegrationV1,
|
1133
|
-
shard_manager: intop.IntegrationShardManager,
|
1134
|
-
) -> None:
|
1135
|
-
integrations_environments = intop.collect_integrations_environment(
|
1136
|
-
[basic_integration], "test", shard_manager
|
1137
|
-
)
|
1138
|
-
# intop.initialize_shard_specs(collected_namespaces_env_test1, shard_manager)
|
1139
|
-
ri = ResourceInventory()
|
1140
|
-
ri.initialize_resource_type("cluster", "ns", "Deployment")
|
1141
|
-
ri.initialize_resource_type("cluster", "ns", "Service")
|
1142
|
-
intop.fetch_desired_state(
|
1143
|
-
integrations_environments=integrations_environments,
|
1144
|
-
ri=ri,
|
1145
|
-
upstream="http://localhost",
|
1146
|
-
image="image",
|
1147
|
-
image_tag_from_ref=None,
|
1148
|
-
)
|
1149
|
-
|
1150
|
-
resources = [
|
1151
|
-
(cluster, namespace, kind, list(data["desired"].keys()))
|
1152
|
-
for cluster, namespace, kind, data in list(ri)
|
1153
|
-
]
|
1154
|
-
|
1155
|
-
assert len(resources) == 2
|
1156
|
-
assert (
|
1157
|
-
"cluster",
|
1158
|
-
"ns",
|
1159
|
-
"Deployment",
|
1160
|
-
["qontract-reconcile-basic-integration"],
|
1161
|
-
) in resources
|
1162
|
-
assert ("cluster", "ns", "Service", ["qontract-reconcile"]) in resources
|
1163
|
-
|
1164
|
-
|
1165
|
-
def test_fetch_desired_state_upstream(
|
1166
|
-
basic_integration: IntegrationV1,
|
1167
|
-
shard_manager: intop.IntegrationShardManager,
|
1168
|
-
) -> None:
|
1169
|
-
upstream = "a"
|
1170
|
-
basic_integration.upstream = upstream
|
1171
|
-
|
1172
|
-
integrations_environments = intop.collect_integrations_environment(
|
1173
|
-
[basic_integration], "test", shard_manager
|
1174
|
-
)
|
1175
|
-
|
1176
|
-
ri = ResourceInventory()
|
1177
|
-
ri.initialize_resource_type("cluster", "ns", "Deployment")
|
1178
|
-
ri.initialize_resource_type("cluster", "ns", "Service")
|
1179
|
-
|
1180
|
-
intop.fetch_desired_state(
|
1181
|
-
integrations_environments=integrations_environments,
|
1182
|
-
ri=ri,
|
1183
|
-
upstream=upstream,
|
1184
|
-
image="image",
|
1185
|
-
image_tag_from_ref=None,
|
1186
|
-
)
|
1187
|
-
|
1188
|
-
resources = [
|
1189
|
-
(cluster, namespace, kind, list(data["desired"].keys()), data["desired"])
|
1190
|
-
for cluster, namespace, kind, data in list(ri)
|
1191
|
-
]
|
1192
|
-
|
1193
|
-
assert len(resources) == 2
|
1194
|
-
assert [
|
1195
|
-
x[4]["qontract-reconcile-basic-integration"].caller
|
1196
|
-
for x in resources
|
1197
|
-
if x[3] == ["qontract-reconcile-basic-integration"]
|
1198
|
-
] == [upstream]
|
1199
|
-
|
1200
|
-
|
1201
|
-
#
|
1202
|
-
# collect_integrations_environment tests
|
1203
|
-
#
|
1204
|
-
|
1205
|
-
|
1206
|
-
@pytest.fixture
|
1207
|
-
def integrations(basic_integration: IntegrationV1) -> list[IntegrationV1]:
|
1208
|
-
i1 = basic_integration
|
1209
|
-
i2 = copy.deepcopy(i1)
|
1210
|
-
i3 = copy.deepcopy(i1)
|
1211
|
-
i4 = copy.deepcopy(i1)
|
1212
|
-
if i2.managed:
|
1213
|
-
i2.managed[0].namespace.environment.name = "test2"
|
1214
|
-
if i3.managed:
|
1215
|
-
i3.managed[0].namespace.environment.name = "test2"
|
1216
|
-
if i4.managed:
|
1217
|
-
i4.managed[0].namespace.environment.name = "test3"
|
1218
|
-
return [i1, i2, i3, i4]
|
1219
|
-
|
1220
|
-
|
1221
|
-
def test_collect_ingegrations_environment(
|
1222
|
-
integrations: list[IntegrationV1], shard_manager: IntegrationShardManager
|
1223
|
-
):
|
1224
|
-
ie = intop.collect_integrations_environment(integrations, "test2", shard_manager)
|
1225
|
-
assert len(ie[0].integration_specs) == 2
|
1226
|
-
assert ie[0].namespace.environment.name == "test2"
|
1227
|
-
|
1228
|
-
|
1229
|
-
def test_collect_ingegrations_environment_no_env(
|
1230
|
-
integrations: list[IntegrationV1], shard_manager: IntegrationShardManager
|
1231
|
-
):
|
1232
|
-
ie = intop.collect_integrations_environment(integrations, "", shard_manager)
|
1233
|
-
assert len(ie[0].integration_specs) == 4
|
1234
|
-
|
1235
|
-
|
1236
|
-
def test_filter_with_upstream(integrations: list[IntegrationV1]):
|
1237
|
-
upstream = "an-upstream"
|
1238
|
-
if integrations:
|
1239
|
-
integrations[0].name = "integ-with-upstream"
|
1240
|
-
integrations[0].upstream = upstream
|
1241
|
-
|
1242
|
-
filtered_integrations = intop.filter_integrations(integrations, upstream)
|
1243
|
-
|
1244
|
-
assert isinstance(filtered_integrations, list)
|
1245
|
-
assert len(filtered_integrations) == 1
|
1246
|
-
assert filtered_integrations[0].name == "integ-with-upstream"
|
1247
|
-
|
1248
|
-
|
1249
|
-
def test_filter_with_upstream_none(integrations: Iterable[IntegrationV1]):
|
1250
|
-
filtered_integrations = intop.filter_integrations(integrations, None)
|
1251
|
-
|
1252
|
-
assert filtered_integrations == integrations
|