qontract-reconcile 0.10.1rc1202__py3-none-any.whl → 0.10.2.dev1__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.dev1.dist-info/METADATA +500 -0
- {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/RECORD +12 -130
- {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/WHEEL +1 -2
- {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.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,1434 +0,0 @@
|
|
1
|
-
from typing import cast
|
2
|
-
|
3
|
-
import pytest
|
4
|
-
import testslide
|
5
|
-
from pytest_mock import MockerFixture
|
6
|
-
|
7
|
-
import reconcile.terraform_vpc_peerings as sut
|
8
|
-
from reconcile.test.test_terraform_vpc_peerings import (
|
9
|
-
MockAWSAPI,
|
10
|
-
MockOCM,
|
11
|
-
build_accepter_connection,
|
12
|
-
build_cluster,
|
13
|
-
build_requester_connection,
|
14
|
-
)
|
15
|
-
from reconcile.utils import (
|
16
|
-
aws_api,
|
17
|
-
ocm,
|
18
|
-
)
|
19
|
-
|
20
|
-
|
21
|
-
def test_c2c_all_clusters() -> None:
|
22
|
-
"""
|
23
|
-
happy path
|
24
|
-
"""
|
25
|
-
|
26
|
-
accepter_cluster = build_cluster(
|
27
|
-
name="accepter_cluster",
|
28
|
-
vpc="accepter_vpc",
|
29
|
-
network_mgmt_accounts=["acc"],
|
30
|
-
peering_connections=[
|
31
|
-
build_accepter_connection(name="peername", cluster="requester_cluster")
|
32
|
-
],
|
33
|
-
)
|
34
|
-
requester_cluster = build_cluster(
|
35
|
-
name="requester_cluster",
|
36
|
-
vpc="requester_vpc",
|
37
|
-
network_mgmt_accounts=["acc"],
|
38
|
-
peering_connections=[
|
39
|
-
build_requester_connection(name="peername", peer_cluster=accepter_cluster)
|
40
|
-
],
|
41
|
-
)
|
42
|
-
|
43
|
-
ocm_map = {
|
44
|
-
"requester_cluster": MockOCM()
|
45
|
-
.register("requester_cluster", "acc", "terraform", "r")
|
46
|
-
.register("accepter_cluster", "acc", "terraform", "a")
|
47
|
-
}
|
48
|
-
|
49
|
-
awsapi = (
|
50
|
-
MockAWSAPI()
|
51
|
-
.register(
|
52
|
-
vpc="accepter_vpc",
|
53
|
-
vpc_id="accepter_vpc_id",
|
54
|
-
route_tables=["accepter_rt_id"],
|
55
|
-
)
|
56
|
-
.register(
|
57
|
-
vpc="requester_vpc",
|
58
|
-
vpc_id="requester_vpc_id",
|
59
|
-
route_tables=["requester_rt_id"],
|
60
|
-
)
|
61
|
-
)
|
62
|
-
|
63
|
-
expected = [
|
64
|
-
{
|
65
|
-
"connection_provider": "cluster-vpc-requester",
|
66
|
-
"connection_name": "peername",
|
67
|
-
"infra_account_name": "acc",
|
68
|
-
"requester": {
|
69
|
-
"cidr_block": "requester_vpc",
|
70
|
-
"region": "region",
|
71
|
-
"vpc_id": "requester_vpc_id",
|
72
|
-
"route_table_ids": ["requester_rt_id"],
|
73
|
-
"api_security_group_id": None,
|
74
|
-
"account": {
|
75
|
-
"name": "acc",
|
76
|
-
"uid": "acc",
|
77
|
-
"terraformUsername": "terraform",
|
78
|
-
"automationToken": {},
|
79
|
-
"assume_role": "arn::::r",
|
80
|
-
"assume_region": "region",
|
81
|
-
"assume_cidr": "requester_vpc",
|
82
|
-
},
|
83
|
-
"peer_owner_id": "a",
|
84
|
-
},
|
85
|
-
"accepter": {
|
86
|
-
"cidr_block": "accepter_vpc",
|
87
|
-
"region": "region",
|
88
|
-
"vpc_id": "accepter_vpc_id",
|
89
|
-
"route_table_ids": ["accepter_rt_id"],
|
90
|
-
"api_security_group_id": None,
|
91
|
-
"account": {
|
92
|
-
"name": "acc",
|
93
|
-
"uid": "acc",
|
94
|
-
"terraformUsername": "terraform",
|
95
|
-
"automationToken": {},
|
96
|
-
"assume_role": "arn::::a",
|
97
|
-
"assume_region": "region",
|
98
|
-
"assume_cidr": "accepter_vpc",
|
99
|
-
},
|
100
|
-
},
|
101
|
-
"deleted": False,
|
102
|
-
}
|
103
|
-
]
|
104
|
-
|
105
|
-
# no account filter
|
106
|
-
result, error = sut.build_desired_state_all_clusters(
|
107
|
-
[requester_cluster],
|
108
|
-
ocm_map, # type: ignore
|
109
|
-
awsapi, # type: ignore
|
110
|
-
account_filter=None,
|
111
|
-
)
|
112
|
-
assert result == expected
|
113
|
-
assert not error
|
114
|
-
|
115
|
-
# correct account filter
|
116
|
-
result, error = sut.build_desired_state_all_clusters(
|
117
|
-
[requester_cluster],
|
118
|
-
ocm_map, # type: ignore
|
119
|
-
awsapi, # type: ignore
|
120
|
-
account_filter="acc",
|
121
|
-
)
|
122
|
-
assert result == expected
|
123
|
-
assert not error
|
124
|
-
|
125
|
-
# wrong account filter
|
126
|
-
result, error = sut.build_desired_state_all_clusters(
|
127
|
-
[requester_cluster],
|
128
|
-
ocm_map, # type: ignore
|
129
|
-
awsapi, # type: ignore
|
130
|
-
account_filter="another_account",
|
131
|
-
)
|
132
|
-
assert not result
|
133
|
-
assert not error
|
134
|
-
|
135
|
-
|
136
|
-
def test_c2c_one_cluster_failing_recoverable(mocker: MockerFixture) -> None:
|
137
|
-
"""
|
138
|
-
in this scenario, the handling of a single cluster fails with known
|
139
|
-
exceptions
|
140
|
-
"""
|
141
|
-
build_desired_state_single_cluster = mocker.patch.object(
|
142
|
-
sut, "build_desired_state_single_cluster"
|
143
|
-
)
|
144
|
-
build_desired_state_single_cluster.side_effect = sut.BadTerraformPeeringState(
|
145
|
-
"something bad"
|
146
|
-
)
|
147
|
-
|
148
|
-
result, error = sut.build_desired_state_all_clusters(
|
149
|
-
[{"name": "cluster"}],
|
150
|
-
None,
|
151
|
-
None, # type: ignore
|
152
|
-
account_filter=None,
|
153
|
-
)
|
154
|
-
|
155
|
-
assert not result
|
156
|
-
assert error
|
157
|
-
|
158
|
-
|
159
|
-
def test_c2c_one_cluster_failing_weird(mocker: MockerFixture) -> None:
|
160
|
-
"""
|
161
|
-
in this scenario, the handling of a single cluster fails with unexpected
|
162
|
-
exceptions
|
163
|
-
"""
|
164
|
-
build_desired_state_single_cluster = mocker.patch.object(
|
165
|
-
sut, "build_desired_state_single_cluster"
|
166
|
-
)
|
167
|
-
SOMETHING_UNEXPECTED = "nobody expects the spanish inquisition"
|
168
|
-
build_desired_state_single_cluster.side_effect = ValueError(SOMETHING_UNEXPECTED)
|
169
|
-
|
170
|
-
with pytest.raises(ValueError) as ex:
|
171
|
-
sut.build_desired_state_all_clusters(
|
172
|
-
[{"name": "cluster"}],
|
173
|
-
None,
|
174
|
-
None, # type: ignore
|
175
|
-
account_filter=None,
|
176
|
-
)
|
177
|
-
|
178
|
-
assert str(ex.value) == SOMETHING_UNEXPECTED
|
179
|
-
|
180
|
-
|
181
|
-
@pytest.mark.parametrize(
|
182
|
-
"accepter_hcp, accepter_private, requester_hcp, requester_private, expected_accepter_security_group, expected_requester_security_group",
|
183
|
-
[
|
184
|
-
(True, True, True, True, "sg-accepter", "sg-requester"),
|
185
|
-
(True, False, True, True, None, "sg-requester"),
|
186
|
-
(False, True, True, True, None, "sg-requester"),
|
187
|
-
(False, False, True, True, None, "sg-requester"),
|
188
|
-
(True, True, True, False, "sg-accepter", None),
|
189
|
-
(True, True, False, True, "sg-accepter", None),
|
190
|
-
(True, True, False, False, "sg-accepter", None),
|
191
|
-
],
|
192
|
-
)
|
193
|
-
def test_c2c_hcp(
|
194
|
-
accepter_hcp: bool,
|
195
|
-
accepter_private: bool,
|
196
|
-
requester_hcp: bool,
|
197
|
-
requester_private: bool,
|
198
|
-
expected_accepter_security_group: str | None,
|
199
|
-
expected_requester_security_group: str | None,
|
200
|
-
) -> None:
|
201
|
-
accepter_cluster = build_cluster(
|
202
|
-
name="accepter_cluster",
|
203
|
-
vpc="accepter_vpc",
|
204
|
-
network_mgmt_accounts=["acc"],
|
205
|
-
peering_connections=[
|
206
|
-
build_accepter_connection(name="peername", cluster="requester_cluster")
|
207
|
-
],
|
208
|
-
hcp=accepter_hcp,
|
209
|
-
private=accepter_private,
|
210
|
-
)
|
211
|
-
requester_cluster = build_cluster(
|
212
|
-
name="requester_cluster",
|
213
|
-
vpc="requester_vpc",
|
214
|
-
network_mgmt_accounts=["acc"],
|
215
|
-
peering_connections=[
|
216
|
-
build_requester_connection(name="peername", peer_cluster=accepter_cluster)
|
217
|
-
],
|
218
|
-
hcp=requester_hcp,
|
219
|
-
private=requester_private,
|
220
|
-
)
|
221
|
-
ocm = (
|
222
|
-
MockOCM()
|
223
|
-
.register("requester_cluster", "acc", "terraform", "r")
|
224
|
-
.register("accepter_cluster", "acc", "terraform", "a")
|
225
|
-
)
|
226
|
-
|
227
|
-
awsapi = (
|
228
|
-
MockAWSAPI()
|
229
|
-
.register(
|
230
|
-
vpc="accepter_vpc",
|
231
|
-
vpc_id="accepter_vpc_id",
|
232
|
-
route_tables=["accepter_rt_id"],
|
233
|
-
vpce_sg=expected_accepter_security_group,
|
234
|
-
)
|
235
|
-
.register(
|
236
|
-
vpc="requester_vpc",
|
237
|
-
vpc_id="requester_vpc_id",
|
238
|
-
route_tables=["requester_rt_id"],
|
239
|
-
vpce_sg=expected_requester_security_group,
|
240
|
-
)
|
241
|
-
)
|
242
|
-
|
243
|
-
expected = [
|
244
|
-
{
|
245
|
-
"connection_provider": "cluster-vpc-requester",
|
246
|
-
"connection_name": "peername",
|
247
|
-
"infra_account_name": "acc",
|
248
|
-
"requester": {
|
249
|
-
"cidr_block": "requester_vpc",
|
250
|
-
"region": "region",
|
251
|
-
"vpc_id": "requester_vpc_id",
|
252
|
-
"route_table_ids": ["requester_rt_id"],
|
253
|
-
"api_security_group_id": expected_requester_security_group,
|
254
|
-
"account": {
|
255
|
-
"name": "acc",
|
256
|
-
"uid": "acc",
|
257
|
-
"terraformUsername": "terraform",
|
258
|
-
"automationToken": {},
|
259
|
-
"assume_role": "arn::::r",
|
260
|
-
"assume_region": "region",
|
261
|
-
"assume_cidr": "requester_vpc",
|
262
|
-
},
|
263
|
-
"peer_owner_id": "a",
|
264
|
-
},
|
265
|
-
"accepter": {
|
266
|
-
"cidr_block": "accepter_vpc",
|
267
|
-
"region": "region",
|
268
|
-
"vpc_id": "accepter_vpc_id",
|
269
|
-
"route_table_ids": ["accepter_rt_id"],
|
270
|
-
"api_security_group_id": expected_accepter_security_group,
|
271
|
-
"account": {
|
272
|
-
"name": "acc",
|
273
|
-
"uid": "acc",
|
274
|
-
"terraformUsername": "terraform",
|
275
|
-
"automationToken": {},
|
276
|
-
"assume_role": "arn::::a",
|
277
|
-
"assume_region": "region",
|
278
|
-
"assume_cidr": "accepter_vpc",
|
279
|
-
},
|
280
|
-
},
|
281
|
-
"deleted": False,
|
282
|
-
}
|
283
|
-
]
|
284
|
-
|
285
|
-
# no account filtering
|
286
|
-
result = sut.build_desired_state_single_cluster(
|
287
|
-
requester_cluster,
|
288
|
-
ocm, # type: ignore
|
289
|
-
awsapi, # type: ignore
|
290
|
-
account_filter=None,
|
291
|
-
)
|
292
|
-
assert result == expected
|
293
|
-
|
294
|
-
# correct account filtering
|
295
|
-
result = sut.build_desired_state_single_cluster(
|
296
|
-
requester_cluster,
|
297
|
-
ocm, # type: ignore
|
298
|
-
awsapi, # type: ignore
|
299
|
-
account_filter="acc",
|
300
|
-
)
|
301
|
-
assert result == expected
|
302
|
-
|
303
|
-
# correct account filtering
|
304
|
-
result = sut.build_desired_state_single_cluster(
|
305
|
-
requester_cluster,
|
306
|
-
ocm, # type: ignore
|
307
|
-
awsapi, # type: ignore
|
308
|
-
account_filter="another_account",
|
309
|
-
)
|
310
|
-
assert not result
|
311
|
-
|
312
|
-
|
313
|
-
def test_c2c_base() -> None:
|
314
|
-
"""
|
315
|
-
happy path
|
316
|
-
"""
|
317
|
-
accepter_cluster = build_cluster(
|
318
|
-
name="accepter_cluster",
|
319
|
-
vpc="accepter_vpc",
|
320
|
-
network_mgmt_accounts=["acc"],
|
321
|
-
peering_connections=[
|
322
|
-
build_accepter_connection(name="peername", cluster="requester_cluster")
|
323
|
-
],
|
324
|
-
)
|
325
|
-
requester_cluster = build_cluster(
|
326
|
-
name="requester_cluster",
|
327
|
-
vpc="requester_vpc",
|
328
|
-
network_mgmt_accounts=["acc"],
|
329
|
-
peering_connections=[
|
330
|
-
build_requester_connection(name="peername", peer_cluster=accepter_cluster)
|
331
|
-
],
|
332
|
-
)
|
333
|
-
ocm = (
|
334
|
-
MockOCM()
|
335
|
-
.register("requester_cluster", "acc", "terraform", "r")
|
336
|
-
.register("accepter_cluster", "acc", "terraform", "a")
|
337
|
-
)
|
338
|
-
|
339
|
-
awsapi = (
|
340
|
-
MockAWSAPI()
|
341
|
-
.register(
|
342
|
-
vpc="accepter_vpc",
|
343
|
-
vpc_id="accepter_vpc_id",
|
344
|
-
route_tables=["accepter_rt_id"],
|
345
|
-
)
|
346
|
-
.register(
|
347
|
-
vpc="requester_vpc",
|
348
|
-
vpc_id="requester_vpc_id",
|
349
|
-
route_tables=["requester_rt_id"],
|
350
|
-
)
|
351
|
-
)
|
352
|
-
|
353
|
-
expected = [
|
354
|
-
{
|
355
|
-
"connection_provider": "cluster-vpc-requester",
|
356
|
-
"connection_name": "peername",
|
357
|
-
"infra_account_name": "acc",
|
358
|
-
"requester": {
|
359
|
-
"cidr_block": "requester_vpc",
|
360
|
-
"region": "region",
|
361
|
-
"vpc_id": "requester_vpc_id",
|
362
|
-
"route_table_ids": ["requester_rt_id"],
|
363
|
-
"api_security_group_id": None,
|
364
|
-
"account": {
|
365
|
-
"name": "acc",
|
366
|
-
"uid": "acc",
|
367
|
-
"terraformUsername": "terraform",
|
368
|
-
"automationToken": {},
|
369
|
-
"assume_role": "arn::::r",
|
370
|
-
"assume_region": "region",
|
371
|
-
"assume_cidr": "requester_vpc",
|
372
|
-
},
|
373
|
-
"peer_owner_id": "a",
|
374
|
-
},
|
375
|
-
"accepter": {
|
376
|
-
"cidr_block": "accepter_vpc",
|
377
|
-
"region": "region",
|
378
|
-
"vpc_id": "accepter_vpc_id",
|
379
|
-
"route_table_ids": ["accepter_rt_id"],
|
380
|
-
"api_security_group_id": None,
|
381
|
-
"account": {
|
382
|
-
"name": "acc",
|
383
|
-
"uid": "acc",
|
384
|
-
"terraformUsername": "terraform",
|
385
|
-
"automationToken": {},
|
386
|
-
"assume_role": "arn::::a",
|
387
|
-
"assume_region": "region",
|
388
|
-
"assume_cidr": "accepter_vpc",
|
389
|
-
},
|
390
|
-
},
|
391
|
-
"deleted": False,
|
392
|
-
}
|
393
|
-
]
|
394
|
-
|
395
|
-
# no account filtering
|
396
|
-
result = sut.build_desired_state_single_cluster(
|
397
|
-
requester_cluster,
|
398
|
-
ocm, # type: ignore
|
399
|
-
awsapi, # type: ignore
|
400
|
-
account_filter=None,
|
401
|
-
)
|
402
|
-
assert result == expected
|
403
|
-
|
404
|
-
# correct account filtering
|
405
|
-
result = sut.build_desired_state_single_cluster(
|
406
|
-
requester_cluster,
|
407
|
-
ocm, # type: ignore
|
408
|
-
awsapi, # type: ignore
|
409
|
-
account_filter="acc",
|
410
|
-
)
|
411
|
-
assert result == expected
|
412
|
-
|
413
|
-
# correct account filtering
|
414
|
-
result = sut.build_desired_state_single_cluster(
|
415
|
-
requester_cluster,
|
416
|
-
ocm, # type: ignore
|
417
|
-
awsapi, # type: ignore
|
418
|
-
account_filter="another_account",
|
419
|
-
)
|
420
|
-
assert not result
|
421
|
-
|
422
|
-
|
423
|
-
def test_c2c_no_peerings() -> None:
|
424
|
-
"""
|
425
|
-
in this scenario, the requester cluster has no peerings defines,
|
426
|
-
which results in an empty desired state
|
427
|
-
"""
|
428
|
-
requester_cluster = build_cluster(
|
429
|
-
name="requester_cluster",
|
430
|
-
vpc="requester_vpc",
|
431
|
-
network_mgmt_accounts=["acc"],
|
432
|
-
peering_connections=[],
|
433
|
-
)
|
434
|
-
result = sut.build_desired_state_single_cluster(
|
435
|
-
requester_cluster,
|
436
|
-
MockOCM(), # type: ignore
|
437
|
-
MockAWSAPI(), # type: ignore
|
438
|
-
account_filter=None,
|
439
|
-
)
|
440
|
-
assert not result
|
441
|
-
|
442
|
-
|
443
|
-
def test_c2c_no_matches() -> None:
|
444
|
-
"""
|
445
|
-
in this scenario, the accepter cluster has no cluster-vpc-accepter
|
446
|
-
connection that references back to the requester cluster
|
447
|
-
"""
|
448
|
-
accepter_cluster = build_cluster(
|
449
|
-
name="accepter_cluster",
|
450
|
-
vpc="accepter_vpc",
|
451
|
-
network_mgmt_accounts=["acc"],
|
452
|
-
peering_connections=[
|
453
|
-
build_accepter_connection(name="peername", cluster="not_a_matching_cluster")
|
454
|
-
],
|
455
|
-
)
|
456
|
-
requester_cluster = build_cluster(
|
457
|
-
name="requester_cluster",
|
458
|
-
vpc="requester_vpc",
|
459
|
-
network_mgmt_accounts=["acc"],
|
460
|
-
peering_connections=[
|
461
|
-
build_requester_connection(name="peername", peer_cluster=accepter_cluster)
|
462
|
-
],
|
463
|
-
)
|
464
|
-
|
465
|
-
with pytest.raises(sut.BadTerraformPeeringState) as ex:
|
466
|
-
sut.build_desired_state_single_cluster(
|
467
|
-
requester_cluster,
|
468
|
-
MockOCM(), # type: ignore
|
469
|
-
MockAWSAPI(), # type: ignore
|
470
|
-
account_filter=None,
|
471
|
-
)
|
472
|
-
assert str(ex.value).startswith("[no_matching_peering]")
|
473
|
-
|
474
|
-
|
475
|
-
def test_c2c_no_vpc_in_aws() -> None:
|
476
|
-
"""
|
477
|
-
in this scenario, there are no VPCs found in AWS
|
478
|
-
"""
|
479
|
-
accepter_cluster = build_cluster(
|
480
|
-
name="accepter_cluster",
|
481
|
-
vpc="accepter_vpc",
|
482
|
-
network_mgmt_accounts=["acc"],
|
483
|
-
peering_connections=[
|
484
|
-
build_accepter_connection(name="peername", cluster="requester_cluster")
|
485
|
-
],
|
486
|
-
)
|
487
|
-
requester_cluster = build_cluster(
|
488
|
-
name="requester_cluster",
|
489
|
-
vpc="requester_vpc",
|
490
|
-
network_mgmt_accounts=["acc"],
|
491
|
-
peering_connections=[
|
492
|
-
build_requester_connection(name="peername", peer_cluster=accepter_cluster)
|
493
|
-
],
|
494
|
-
)
|
495
|
-
|
496
|
-
ocm = (
|
497
|
-
MockOCM()
|
498
|
-
.register("requester_cluster", "acc", "terraform", "r")
|
499
|
-
.register("accepter_cluster", "acc", "terraform", "a")
|
500
|
-
)
|
501
|
-
|
502
|
-
awsapi = MockAWSAPI()
|
503
|
-
|
504
|
-
desired_state = sut.build_desired_state_single_cluster(
|
505
|
-
requester_cluster,
|
506
|
-
ocm, # type: ignore
|
507
|
-
awsapi, # type: ignore
|
508
|
-
account_filter=None,
|
509
|
-
)
|
510
|
-
assert desired_state == []
|
511
|
-
|
512
|
-
|
513
|
-
def test_c2c_no_peer_account() -> None:
|
514
|
-
"""
|
515
|
-
in this scenario, the accepters connection and the accepters cluster
|
516
|
-
have no aws infrastructura account available to set up the peering″
|
517
|
-
"""
|
518
|
-
accepter_cluster = build_cluster(
|
519
|
-
# no network_mgmt_accounts here
|
520
|
-
name="accepter_cluster",
|
521
|
-
vpc="accepter_vpc",
|
522
|
-
peering_connections=[
|
523
|
-
build_accepter_connection(
|
524
|
-
# no network_mgmt_accounts here
|
525
|
-
name="peername",
|
526
|
-
cluster="requester_cluster",
|
527
|
-
)
|
528
|
-
],
|
529
|
-
)
|
530
|
-
requester_cluster = build_cluster(
|
531
|
-
name="requester_cluster",
|
532
|
-
vpc="requester_vpc",
|
533
|
-
network_mgmt_accounts=["acc"],
|
534
|
-
peering_connections=[
|
535
|
-
build_requester_connection(name="peername", peer_cluster=accepter_cluster)
|
536
|
-
],
|
537
|
-
)
|
538
|
-
|
539
|
-
ocm = MockOCM()
|
540
|
-
awsapi = MockAWSAPI()
|
541
|
-
|
542
|
-
with pytest.raises(sut.BadTerraformPeeringState) as ex:
|
543
|
-
sut.build_desired_state_single_cluster(
|
544
|
-
requester_cluster,
|
545
|
-
ocm, # type: ignore
|
546
|
-
awsapi, # type: ignore
|
547
|
-
account_filter=None,
|
548
|
-
)
|
549
|
-
assert str(ex.value).startswith("[no_account_available]")
|
550
|
-
|
551
|
-
|
552
|
-
class TestBuildDesiredStateVpcMesh(testslide.TestCase):
|
553
|
-
def setUp(self) -> None:
|
554
|
-
super().setUp()
|
555
|
-
self.clusters = [
|
556
|
-
{
|
557
|
-
"name": "clustername",
|
558
|
-
"spec": {
|
559
|
-
"region": "mars-plain-1",
|
560
|
-
},
|
561
|
-
"network": {
|
562
|
-
"vpc": "172.16.0.0/12",
|
563
|
-
"service": "10.0.0.0/8",
|
564
|
-
"pod": "192.168.0.0/16",
|
565
|
-
},
|
566
|
-
"peering": {
|
567
|
-
"connections": [
|
568
|
-
{
|
569
|
-
"provider": "account-vpc-mesh",
|
570
|
-
"name": "peername",
|
571
|
-
"vpc": {"$ref": "/aws/account/vpcs/mars-plain-1"},
|
572
|
-
"manageRoutes": True,
|
573
|
-
"tags": '["tag1"]',
|
574
|
-
},
|
575
|
-
]
|
576
|
-
},
|
577
|
-
}
|
578
|
-
]
|
579
|
-
self.peer = {
|
580
|
-
"vpc": "172.17.0.0/12",
|
581
|
-
"service": "10.1.0.0/8",
|
582
|
-
"pod": "192.168.1.0/16",
|
583
|
-
}
|
584
|
-
self.peer_cluster = {
|
585
|
-
"name": "apeerclustername",
|
586
|
-
"spec": {
|
587
|
-
"region": "mars-olympus-2",
|
588
|
-
},
|
589
|
-
"network": self.peer,
|
590
|
-
"peering": {
|
591
|
-
"connections": [
|
592
|
-
{
|
593
|
-
"provider": "cluster-vpc-requester",
|
594
|
-
"name": "peername",
|
595
|
-
"vpc": {"$ref": "/aws/account/vpcs/mars-plain-1"},
|
596
|
-
"manageRoutes": True,
|
597
|
-
"tags": '["tag1"]',
|
598
|
-
},
|
599
|
-
]
|
600
|
-
},
|
601
|
-
}
|
602
|
-
|
603
|
-
self.aws_account = {
|
604
|
-
"name": "accountname",
|
605
|
-
"uid": "anuid",
|
606
|
-
"terraformUsername": "aterraformusename",
|
607
|
-
"automationtoken": "anautomationtoken",
|
608
|
-
"assume_role": "arole:very:useful:indeed:it:is",
|
609
|
-
"assume_region": "moon-tranquility-1",
|
610
|
-
"assume_cidr": "172.25.0.0/12",
|
611
|
-
}
|
612
|
-
self.peer_account = {
|
613
|
-
"name": "peer_account",
|
614
|
-
"uid": "peeruid",
|
615
|
-
"terraformUsername": "peerterraformusename",
|
616
|
-
"automationtoken": "peeranautomationtoken",
|
617
|
-
"assume_role": "a:peer:role:indeed:it:is",
|
618
|
-
"assume_region": "mars-hellas-1",
|
619
|
-
"assume_cidr": "172.25.0.0/12",
|
620
|
-
}
|
621
|
-
self.clusters[0]["peering"]["connections"][0]["cluster"] = self.peer_cluster # type: ignore
|
622
|
-
self.clusters[0]["peering"]["connections"][0]["account"] = self.peer_account # type: ignore
|
623
|
-
self.peer_vpc = {
|
624
|
-
"cidr_block": "172.30.0.0/12",
|
625
|
-
"vpc_id": "peervpcid",
|
626
|
-
"route_table_ids": ["peer_route_table_id"],
|
627
|
-
}
|
628
|
-
self.vpc_mesh_single_cluster = self.mock_callable(
|
629
|
-
sut, "build_desired_state_vpc_mesh_single_cluster"
|
630
|
-
)
|
631
|
-
self.maxDiff = None
|
632
|
-
self.ocm = testslide.StrictMock(ocm.OCM)
|
633
|
-
self.ocm_map = cast(
|
634
|
-
ocm.OCMMap, {"clustername": self.ocm}
|
635
|
-
) # the cast is to make mypy happy
|
636
|
-
self.ocm.get_aws_infrastructure_access_terraform_assume_role = (
|
637
|
-
lambda cluster, uid, tfuser: self.peer_account["assume_role"]
|
638
|
-
)
|
639
|
-
self.awsapi = cast(
|
640
|
-
aws_api.AWSApi, testslide.StrictMock(aws_api.AWSApi)
|
641
|
-
) # the cast is to make mypy happy
|
642
|
-
self.account_vpcs = [
|
643
|
-
{
|
644
|
-
"vpc_id": "vpc1",
|
645
|
-
"region": "moon-dark-1",
|
646
|
-
"cidr_block": "192.168.3.0/24",
|
647
|
-
"route_table_ids": ["vpc1_route_table"],
|
648
|
-
},
|
649
|
-
{
|
650
|
-
"vpc_id": "vpc2",
|
651
|
-
"region": "mars-utopia-2",
|
652
|
-
"cidr_block": "192.168.4.0/24",
|
653
|
-
"route_table_ids": ["vpc2_route_table"],
|
654
|
-
},
|
655
|
-
]
|
656
|
-
self.addCleanup(testslide.mock_callable.unpatch_all_callable_mocks)
|
657
|
-
|
658
|
-
def test_all_fine(self) -> None:
|
659
|
-
expected = [
|
660
|
-
{
|
661
|
-
"connection_provider": "account-vpc-mesh",
|
662
|
-
"connection_name": "peername_peer_account-vpc1",
|
663
|
-
"requester": {
|
664
|
-
"vpc_id": "vpc_id",
|
665
|
-
"route_table_ids": ["route_table_id"],
|
666
|
-
"account": self.peer_account,
|
667
|
-
"region": "mars-plain-1",
|
668
|
-
"cidr_block": "172.16.0.0/12",
|
669
|
-
},
|
670
|
-
"accepter": {
|
671
|
-
"vpc_id": "vpc1",
|
672
|
-
"region": "moon-dark-1",
|
673
|
-
"cidr_block": "192.168.3.0/24",
|
674
|
-
"route_table_ids": ["vpc1_route_table"],
|
675
|
-
"account": self.peer_account,
|
676
|
-
},
|
677
|
-
"deleted": False,
|
678
|
-
},
|
679
|
-
{
|
680
|
-
"connection_provider": "account-vpc-mesh",
|
681
|
-
"connection_name": "peername_peer_account-vpc2",
|
682
|
-
"requester": {
|
683
|
-
"vpc_id": "vpc_id",
|
684
|
-
"route_table_ids": ["route_table_id"],
|
685
|
-
"account": self.peer_account,
|
686
|
-
"region": "mars-plain-1",
|
687
|
-
"cidr_block": "172.16.0.0/12",
|
688
|
-
},
|
689
|
-
"accepter": {
|
690
|
-
"vpc_id": "vpc2",
|
691
|
-
"region": "mars-utopia-2",
|
692
|
-
"cidr_block": "192.168.4.0/24",
|
693
|
-
"route_table_ids": ["vpc2_route_table"],
|
694
|
-
"account": self.peer_account,
|
695
|
-
},
|
696
|
-
"deleted": False,
|
697
|
-
},
|
698
|
-
]
|
699
|
-
self.vpc_mesh_single_cluster.for_call(
|
700
|
-
self.clusters[0],
|
701
|
-
self.ocm,
|
702
|
-
self.awsapi,
|
703
|
-
None,
|
704
|
-
).to_return_value(expected)
|
705
|
-
|
706
|
-
rs = sut.build_desired_state_vpc_mesh(
|
707
|
-
self.clusters,
|
708
|
-
self.ocm_map,
|
709
|
-
self.awsapi,
|
710
|
-
None,
|
711
|
-
)
|
712
|
-
self.assertEqual(rs, (expected, False))
|
713
|
-
|
714
|
-
def test_cluster_raises(self) -> None:
|
715
|
-
self.vpc_mesh_single_cluster.to_raise(
|
716
|
-
sut.BadTerraformPeeringState("This is wrong")
|
717
|
-
)
|
718
|
-
rs = sut.build_desired_state_vpc_mesh(
|
719
|
-
self.clusters,
|
720
|
-
self.ocm_map,
|
721
|
-
self.awsapi,
|
722
|
-
None,
|
723
|
-
)
|
724
|
-
self.assertEqual(rs, ([], True))
|
725
|
-
|
726
|
-
def test_cluster_raises_unexpected(self) -> None:
|
727
|
-
self.vpc_mesh_single_cluster.to_raise(ValueError("Nope"))
|
728
|
-
with self.assertRaises(ValueError):
|
729
|
-
sut.build_desired_state_vpc_mesh(
|
730
|
-
self.clusters,
|
731
|
-
self.ocm_map,
|
732
|
-
self.awsapi,
|
733
|
-
None,
|
734
|
-
)
|
735
|
-
|
736
|
-
|
737
|
-
class TestBuildDesiredStateVpcMeshSingleCluster(testslide.TestCase):
|
738
|
-
def setUp(self) -> None:
|
739
|
-
super().setUp()
|
740
|
-
self.cluster = {
|
741
|
-
"name": "clustername",
|
742
|
-
"spec": {
|
743
|
-
"region": "mars-plain-1",
|
744
|
-
},
|
745
|
-
"network": {
|
746
|
-
"vpc": "172.16.0.0/12",
|
747
|
-
"service": "10.0.0.0/8",
|
748
|
-
"pod": "192.168.0.0/16",
|
749
|
-
},
|
750
|
-
"peering": {
|
751
|
-
"connections": [
|
752
|
-
{
|
753
|
-
"provider": "account-vpc-mesh",
|
754
|
-
"name": "peername",
|
755
|
-
"vpc": {"$ref": "/aws/account/vpcs/mars-plain-1"},
|
756
|
-
"manageRoutes": True,
|
757
|
-
"tags": '["tag1"]',
|
758
|
-
},
|
759
|
-
]
|
760
|
-
},
|
761
|
-
}
|
762
|
-
self.peer = {
|
763
|
-
"vpc": "172.17.0.0/12",
|
764
|
-
"service": "10.1.0.0/8",
|
765
|
-
"pod": "192.168.1.0/16",
|
766
|
-
}
|
767
|
-
self.peer_cluster = {
|
768
|
-
"name": "apeerclustername",
|
769
|
-
"spec": {
|
770
|
-
"region": "mars-olympus-2",
|
771
|
-
},
|
772
|
-
"network": self.peer,
|
773
|
-
"peering": {
|
774
|
-
"connections": [
|
775
|
-
{
|
776
|
-
"provider": "cluster-vpc-requester",
|
777
|
-
"name": "peername",
|
778
|
-
"vpc": {"$ref": "/aws/account/vpcs/mars-plain-1"},
|
779
|
-
"manageRoutes": True,
|
780
|
-
"tags": '["tag1"]',
|
781
|
-
},
|
782
|
-
]
|
783
|
-
},
|
784
|
-
}
|
785
|
-
self.awsapi = cast(
|
786
|
-
aws_api.AWSApi, testslide.StrictMock(aws_api.AWSApi)
|
787
|
-
) # the cast is to make mypy happy
|
788
|
-
self.mock_constructor(aws_api, "AWSApi").to_return_value(self.awsapi)
|
789
|
-
self.find_matching_peering = self.mock_callable(sut, "find_matching_peering")
|
790
|
-
self.aws_account = {
|
791
|
-
"name": "accountname",
|
792
|
-
"uid": "anuid",
|
793
|
-
"terraformUsername": "aterraformusename",
|
794
|
-
"automationtoken": "anautomationtoken",
|
795
|
-
"assume_role": "arole:very:useful:indeed:it:is",
|
796
|
-
"assume_region": "moon-tranquility-1",
|
797
|
-
"assume_cidr": "172.25.0.0/12",
|
798
|
-
}
|
799
|
-
self.peer_account = {
|
800
|
-
"name": "peer_account",
|
801
|
-
"uid": "peeruid",
|
802
|
-
"terraformUsername": "peerterraformusename",
|
803
|
-
"automationtoken": "peeranautomationtoken",
|
804
|
-
"assume_role": "a:peer:role:indeed:it:is",
|
805
|
-
"assume_region": "mars-hellas-1",
|
806
|
-
"assume_cidr": "172.25.0.0/12",
|
807
|
-
}
|
808
|
-
self.cluster["peering"]["connections"][0]["cluster"] = self.peer_cluster # type: ignore
|
809
|
-
self.cluster["peering"]["connections"][0]["account"] = self.peer_account # type: ignore
|
810
|
-
self.peer_vpc = {
|
811
|
-
"cidr_block": "172.30.0.0/12",
|
812
|
-
"vpc_id": "peervpcid",
|
813
|
-
"route_table_ids": ["peer_route_table_id"],
|
814
|
-
}
|
815
|
-
self.maxDiff = None
|
816
|
-
self.addCleanup(testslide.mock_callable.unpatch_all_callable_mocks)
|
817
|
-
self.ocm = cast(
|
818
|
-
ocm.OCM, testslide.StrictMock(template=ocm.OCM)
|
819
|
-
) # the cast is to make mypy happy
|
820
|
-
self.ocm.get_aws_infrastructure_access_terraform_assume_role = ( # type: ignore
|
821
|
-
lambda cluster, uid, tfuser: self.peer_account["assume_role"]
|
822
|
-
)
|
823
|
-
self.account_vpcs = [
|
824
|
-
{
|
825
|
-
"vpc_id": "vpc1",
|
826
|
-
"region": "moon-dark-1",
|
827
|
-
"cidr_block": "192.168.3.0/24",
|
828
|
-
"route_table_ids": ["vpc1_route_table"],
|
829
|
-
},
|
830
|
-
{
|
831
|
-
"vpc_id": "vpc2",
|
832
|
-
"region": "mars-utopia-2",
|
833
|
-
"cidr_block": "192.168.4.0/24",
|
834
|
-
"route_table_ids": ["vpc2_route_table"],
|
835
|
-
},
|
836
|
-
]
|
837
|
-
|
838
|
-
def test_one_cluster(self) -> None:
|
839
|
-
req_account = {
|
840
|
-
**self.peer_account,
|
841
|
-
"assume_region": "mars-plain-1",
|
842
|
-
"assume_cidr": "172.16.0.0/12",
|
843
|
-
}
|
844
|
-
self.mock_callable(self.awsapi, "get_cluster_vpc_details").for_call(
|
845
|
-
req_account, route_tables=True, hcp_vpc_endpoint_sg=False
|
846
|
-
).to_return_value((
|
847
|
-
"vpc_id",
|
848
|
-
["route_table_id"],
|
849
|
-
"subnet_id",
|
850
|
-
None,
|
851
|
-
)).and_assert_called_once()
|
852
|
-
|
853
|
-
self.mock_callable(self.awsapi, "get_vpcs_details").for_call(
|
854
|
-
req_account, tags=["tag1"], route_tables=True
|
855
|
-
).to_return_value(self.account_vpcs).and_assert_called_once()
|
856
|
-
|
857
|
-
expected = [
|
858
|
-
{
|
859
|
-
"connection_provider": "account-vpc-mesh",
|
860
|
-
"connection_name": "peername_peer_account-vpc1",
|
861
|
-
"infra_account_name": self.peer_account["name"],
|
862
|
-
"requester": {
|
863
|
-
"vpc_id": "vpc_id",
|
864
|
-
"route_table_ids": ["route_table_id"],
|
865
|
-
"api_security_group_id": None,
|
866
|
-
"account": self.peer_account,
|
867
|
-
"region": "mars-plain-1",
|
868
|
-
"cidr_block": "172.16.0.0/12",
|
869
|
-
},
|
870
|
-
"accepter": {
|
871
|
-
"vpc_id": "vpc1",
|
872
|
-
"region": "moon-dark-1",
|
873
|
-
"cidr_block": "192.168.3.0/24",
|
874
|
-
"route_table_ids": ["vpc1_route_table"],
|
875
|
-
"account": self.peer_account,
|
876
|
-
},
|
877
|
-
"deleted": False,
|
878
|
-
},
|
879
|
-
{
|
880
|
-
"connection_provider": "account-vpc-mesh",
|
881
|
-
"connection_name": "peername_peer_account-vpc2",
|
882
|
-
"infra_account_name": self.peer_account["name"],
|
883
|
-
"requester": {
|
884
|
-
"vpc_id": "vpc_id",
|
885
|
-
"route_table_ids": ["route_table_id"],
|
886
|
-
"api_security_group_id": None,
|
887
|
-
"account": self.peer_account,
|
888
|
-
"region": "mars-plain-1",
|
889
|
-
"cidr_block": "172.16.0.0/12",
|
890
|
-
},
|
891
|
-
"accepter": {
|
892
|
-
"vpc_id": "vpc2",
|
893
|
-
"region": "mars-utopia-2",
|
894
|
-
"cidr_block": "192.168.4.0/24",
|
895
|
-
"route_table_ids": ["vpc2_route_table"],
|
896
|
-
"account": self.peer_account,
|
897
|
-
},
|
898
|
-
"deleted": False,
|
899
|
-
},
|
900
|
-
]
|
901
|
-
|
902
|
-
rs = sut.build_desired_state_vpc_mesh_single_cluster(
|
903
|
-
self.cluster,
|
904
|
-
self.ocm,
|
905
|
-
self.awsapi,
|
906
|
-
None,
|
907
|
-
)
|
908
|
-
self.assertEqual(rs, expected)
|
909
|
-
|
910
|
-
def test_one_cluster_private_hcp(self) -> None:
|
911
|
-
self.cluster["spec"] = {
|
912
|
-
"region": "mars-plain-1",
|
913
|
-
"hypershift": True,
|
914
|
-
"private": True,
|
915
|
-
}
|
916
|
-
req_account = {
|
917
|
-
**self.peer_account,
|
918
|
-
"assume_region": "mars-plain-1",
|
919
|
-
"assume_cidr": "172.16.0.0/12",
|
920
|
-
}
|
921
|
-
self.mock_callable(self.awsapi, "get_cluster_vpc_details").for_call(
|
922
|
-
req_account, route_tables=True, hcp_vpc_endpoint_sg=True
|
923
|
-
).to_return_value((
|
924
|
-
"vpc_id",
|
925
|
-
["route_table_id"],
|
926
|
-
"subnet_id",
|
927
|
-
"sg-vpce",
|
928
|
-
)).and_assert_called_once()
|
929
|
-
|
930
|
-
self.mock_callable(self.awsapi, "get_vpcs_details").for_call(
|
931
|
-
req_account, tags=["tag1"], route_tables=True
|
932
|
-
).to_return_value(self.account_vpcs).and_assert_called_once()
|
933
|
-
|
934
|
-
expected = [
|
935
|
-
{
|
936
|
-
"connection_provider": "account-vpc-mesh",
|
937
|
-
"connection_name": "peername_peer_account-vpc1",
|
938
|
-
"infra_account_name": self.peer_account["name"],
|
939
|
-
"requester": {
|
940
|
-
"vpc_id": "vpc_id",
|
941
|
-
"route_table_ids": ["route_table_id"],
|
942
|
-
"api_security_group_id": "sg-vpce",
|
943
|
-
"account": self.peer_account,
|
944
|
-
"region": "mars-plain-1",
|
945
|
-
"cidr_block": "172.16.0.0/12",
|
946
|
-
},
|
947
|
-
"accepter": {
|
948
|
-
"vpc_id": "vpc1",
|
949
|
-
"region": "moon-dark-1",
|
950
|
-
"cidr_block": "192.168.3.0/24",
|
951
|
-
"route_table_ids": ["vpc1_route_table"],
|
952
|
-
"account": self.peer_account,
|
953
|
-
},
|
954
|
-
"deleted": False,
|
955
|
-
},
|
956
|
-
{
|
957
|
-
"connection_provider": "account-vpc-mesh",
|
958
|
-
"connection_name": "peername_peer_account-vpc2",
|
959
|
-
"infra_account_name": self.peer_account["name"],
|
960
|
-
"requester": {
|
961
|
-
"vpc_id": "vpc_id",
|
962
|
-
"route_table_ids": ["route_table_id"],
|
963
|
-
"api_security_group_id": "sg-vpce",
|
964
|
-
"account": self.peer_account,
|
965
|
-
"region": "mars-plain-1",
|
966
|
-
"cidr_block": "172.16.0.0/12",
|
967
|
-
},
|
968
|
-
"accepter": {
|
969
|
-
"vpc_id": "vpc2",
|
970
|
-
"region": "mars-utopia-2",
|
971
|
-
"cidr_block": "192.168.4.0/24",
|
972
|
-
"route_table_ids": ["vpc2_route_table"],
|
973
|
-
"account": self.peer_account,
|
974
|
-
},
|
975
|
-
"deleted": False,
|
976
|
-
},
|
977
|
-
]
|
978
|
-
|
979
|
-
rs = sut.build_desired_state_vpc_mesh_single_cluster(
|
980
|
-
self.cluster, self.ocm, self.awsapi, None
|
981
|
-
)
|
982
|
-
self.assertEqual(rs, expected)
|
983
|
-
|
984
|
-
def test_no_peering_connections(self) -> None:
|
985
|
-
self.cluster["peering"]["connections"] = [] # type: ignore
|
986
|
-
rs = sut.build_desired_state_vpc_mesh_single_cluster(
|
987
|
-
self.cluster, self.ocm, self.awsapi, None
|
988
|
-
)
|
989
|
-
self.assertEqual(rs, [])
|
990
|
-
|
991
|
-
def test_no_peer_vpc_id(self) -> None:
|
992
|
-
self.mock_callable(self.awsapi, "get_cluster_vpc_details").to_return_value((
|
993
|
-
None,
|
994
|
-
[None],
|
995
|
-
None,
|
996
|
-
None,
|
997
|
-
)).and_assert_called_once()
|
998
|
-
|
999
|
-
desired_state = sut.build_desired_state_vpc_mesh_single_cluster(
|
1000
|
-
self.cluster, self.ocm, self.awsapi, None
|
1001
|
-
)
|
1002
|
-
assert desired_state == []
|
1003
|
-
|
1004
|
-
|
1005
|
-
class TestBuildDesiredStateVpc(testslide.TestCase):
|
1006
|
-
def setUp(self) -> None:
|
1007
|
-
super().setUp()
|
1008
|
-
self.peer = {
|
1009
|
-
"vpc": "172.17.0.0/12",
|
1010
|
-
"service": "10.1.0.0/8",
|
1011
|
-
"pod": "192.168.1.0/16",
|
1012
|
-
}
|
1013
|
-
self.aws_account = {
|
1014
|
-
"name": "accountname",
|
1015
|
-
"uid": "anuid",
|
1016
|
-
"terraformUsername": "aterraformusename",
|
1017
|
-
"automationtoken": "anautomationtoken",
|
1018
|
-
"assume_role": "arole:very:useful:indeed:it:is",
|
1019
|
-
"assume_region": "moon-tranquility-1",
|
1020
|
-
"assume_cidr": "172.25.0.0/12",
|
1021
|
-
}
|
1022
|
-
|
1023
|
-
self.clusters = [
|
1024
|
-
{
|
1025
|
-
"name": "clustername",
|
1026
|
-
"spec": {
|
1027
|
-
"region": "mars-plain-1",
|
1028
|
-
},
|
1029
|
-
"network": {
|
1030
|
-
"vpc": "172.16.0.0/12",
|
1031
|
-
"service": "10.0.0.0/8",
|
1032
|
-
"pod": "192.168.0.0/16",
|
1033
|
-
},
|
1034
|
-
"peering": {
|
1035
|
-
"connections": [
|
1036
|
-
{
|
1037
|
-
"provider": "account-vpc",
|
1038
|
-
"name": "peername",
|
1039
|
-
"vpc": {
|
1040
|
-
"$ref": "/aws/account/vpcs/mars-plain-1",
|
1041
|
-
"cidr_block": "172.30.0.0/12",
|
1042
|
-
"vpc_id": "avpcid",
|
1043
|
-
**self.peer,
|
1044
|
-
"region": "mars-olympus-2",
|
1045
|
-
"account": self.aws_account,
|
1046
|
-
},
|
1047
|
-
"manageRoutes": True,
|
1048
|
-
},
|
1049
|
-
]
|
1050
|
-
},
|
1051
|
-
}
|
1052
|
-
]
|
1053
|
-
|
1054
|
-
self.peer_cluster = {
|
1055
|
-
"name": "apeerclustername",
|
1056
|
-
"spec": {
|
1057
|
-
"region": "mars-olympus-2",
|
1058
|
-
},
|
1059
|
-
"network": self.peer,
|
1060
|
-
"peering": {
|
1061
|
-
"connections": [
|
1062
|
-
{
|
1063
|
-
"provider": "account-vpc",
|
1064
|
-
"name": "peername",
|
1065
|
-
"vpc": {"$ref": "/aws/account/vpcs/mars-plain-1"},
|
1066
|
-
"manageRoutes": True,
|
1067
|
-
},
|
1068
|
-
]
|
1069
|
-
},
|
1070
|
-
}
|
1071
|
-
self.clusters[0]["peering"]["connections"][0]["cluster"] = self.peer_cluster # type: ignore
|
1072
|
-
self.build_single_cluster = self.mock_callable(
|
1073
|
-
sut, "build_desired_state_single_cluster"
|
1074
|
-
)
|
1075
|
-
self.ocm = testslide.StrictMock(template=ocm.OCM)
|
1076
|
-
self.ocm_map: ocm.OCMMap = {"clustername": self.ocm} # type: ignore
|
1077
|
-
self.awsapi = cast(
|
1078
|
-
aws_api.AWSApi, testslide.StrictMock(aws_api.AWSApi)
|
1079
|
-
) # the cast is to make mypy happy
|
1080
|
-
|
1081
|
-
self.build_single_cluster = self.mock_callable(
|
1082
|
-
sut, "build_desired_state_vpc_single_cluster"
|
1083
|
-
)
|
1084
|
-
self.addCleanup(testslide.mock_callable.unpatch_all_callable_mocks)
|
1085
|
-
self.maxDiff = None
|
1086
|
-
|
1087
|
-
def test_all_fine(self) -> None:
|
1088
|
-
expected = [
|
1089
|
-
{
|
1090
|
-
"accepter": {
|
1091
|
-
"account": {
|
1092
|
-
"assume_cidr": "172.16.0.0/12",
|
1093
|
-
"assume_region": "mars-plain-1",
|
1094
|
-
"assume_role": "this:wonderful:role:hell:yeah",
|
1095
|
-
"automationtoken": "anautomationtoken",
|
1096
|
-
"name": "accountname",
|
1097
|
-
"terraformUsername": "aterraformusename",
|
1098
|
-
"uid": "anuid",
|
1099
|
-
},
|
1100
|
-
"cidr_block": "172.30.0.0/12",
|
1101
|
-
"region": "mars-olympus-2",
|
1102
|
-
"vpc_id": "avpcid",
|
1103
|
-
},
|
1104
|
-
"connection_name": "peername",
|
1105
|
-
"connection_provider": "account-vpc",
|
1106
|
-
"deleted": False,
|
1107
|
-
"requester": {
|
1108
|
-
"account": {
|
1109
|
-
"assume_cidr": "172.16.0.0/12",
|
1110
|
-
"assume_region": "mars-plain-1",
|
1111
|
-
"assume_role": "this:wonderful:role:hell:yeah",
|
1112
|
-
"automationtoken": "anautomationtoken",
|
1113
|
-
"name": "accountname",
|
1114
|
-
"terraformUsername": "aterraformusename",
|
1115
|
-
"uid": "anuid",
|
1116
|
-
},
|
1117
|
-
"cidr_block": "172.16.0.0/12",
|
1118
|
-
"region": "mars-plain-1",
|
1119
|
-
"route_table_ids": ["routetableid"],
|
1120
|
-
"vpc_id": "vpcid",
|
1121
|
-
},
|
1122
|
-
}
|
1123
|
-
]
|
1124
|
-
self.build_single_cluster.for_call(
|
1125
|
-
self.clusters[0], self.ocm, self.awsapi, None
|
1126
|
-
).to_return_value(expected).and_assert_called_once()
|
1127
|
-
|
1128
|
-
rs = sut.build_desired_state_vpc(
|
1129
|
-
self.clusters, self.ocm_map, self.awsapi, account_filter=None
|
1130
|
-
)
|
1131
|
-
self.assertEqual(rs, (expected, False))
|
1132
|
-
|
1133
|
-
def test_cluster_fails(self) -> None:
|
1134
|
-
self.build_single_cluster.to_raise(
|
1135
|
-
sut.BadTerraformPeeringState("I have failed")
|
1136
|
-
)
|
1137
|
-
|
1138
|
-
self.assertEqual(
|
1139
|
-
sut.build_desired_state_vpc(
|
1140
|
-
self.clusters, self.ocm_map, self.awsapi, account_filter=None
|
1141
|
-
),
|
1142
|
-
([], True),
|
1143
|
-
)
|
1144
|
-
|
1145
|
-
def test_error_persists(self) -> None:
|
1146
|
-
self.clusters.append(self.clusters[0].copy())
|
1147
|
-
self.clusters[1]["name"] = "afailingcluster"
|
1148
|
-
self.ocm_map["afailingcluster"] = self.ocm # type: ignore
|
1149
|
-
self.build_single_cluster.for_call(
|
1150
|
-
self.clusters[0], self.ocm, self.awsapi, None
|
1151
|
-
).to_return_value([{"a dict": "a value"}]).and_assert_called_once()
|
1152
|
-
self.mock_callable(sut, "build_desired_state_vpc_single_cluster").for_call(
|
1153
|
-
self.clusters[1],
|
1154
|
-
self.ocm,
|
1155
|
-
self.awsapi,
|
1156
|
-
None,
|
1157
|
-
).to_raise(sut.BadTerraformPeeringState("Fail!")).and_assert_called_once()
|
1158
|
-
|
1159
|
-
self.assertEqual(
|
1160
|
-
sut.build_desired_state_vpc(
|
1161
|
-
self.clusters, self.ocm_map, self.awsapi, account_filter=None
|
1162
|
-
),
|
1163
|
-
([{"a dict": "a value"}], True),
|
1164
|
-
)
|
1165
|
-
|
1166
|
-
def test_other_exceptions_raise(self) -> None:
|
1167
|
-
self.clusters.append(self.clusters[0].copy())
|
1168
|
-
self.clusters[1]["name"] = "afailingcluster"
|
1169
|
-
self.ocm_map["afailingcluster"] = self.ocm # type: ignore
|
1170
|
-
self.build_single_cluster.for_call(
|
1171
|
-
self.clusters[0], self.ocm, self.awsapi, None
|
1172
|
-
).to_raise(ValueError("I am not planned!")).and_assert_called_once()
|
1173
|
-
with self.assertRaises(ValueError):
|
1174
|
-
sut.build_desired_state_vpc(
|
1175
|
-
self.clusters, self.ocm_map, self.awsapi, account_filter=None
|
1176
|
-
)
|
1177
|
-
|
1178
|
-
|
1179
|
-
class TestBuildDesiredStateVpcSingleCluster(testslide.TestCase):
|
1180
|
-
def setUp(self) -> None:
|
1181
|
-
super().setUp()
|
1182
|
-
self.peer = {
|
1183
|
-
"vpc": "172.17.0.0/12",
|
1184
|
-
"service": "10.1.0.0/8",
|
1185
|
-
"pod": "192.168.1.0/16",
|
1186
|
-
}
|
1187
|
-
self.aws_account = {
|
1188
|
-
"name": "accountname",
|
1189
|
-
"uid": "anuid",
|
1190
|
-
"terraformUsername": "aterraformusename",
|
1191
|
-
"automationtoken": "anautomationtoken",
|
1192
|
-
"assume_role": "arole:very:useful:indeed:it:is",
|
1193
|
-
"assume_region": "moon-tranquility-1",
|
1194
|
-
"assume_cidr": "172.25.0.0/12",
|
1195
|
-
}
|
1196
|
-
|
1197
|
-
self.cluster = {
|
1198
|
-
"name": "clustername",
|
1199
|
-
"spec": {
|
1200
|
-
"region": "mars-plain-1",
|
1201
|
-
},
|
1202
|
-
"network": {
|
1203
|
-
"vpc": "172.16.0.0/12",
|
1204
|
-
"service": "10.0.0.0/8",
|
1205
|
-
"pod": "192.168.0.0/16",
|
1206
|
-
},
|
1207
|
-
"peering": {
|
1208
|
-
"connections": [
|
1209
|
-
{
|
1210
|
-
"provider": "account-vpc",
|
1211
|
-
"name": "peername",
|
1212
|
-
"vpc": {
|
1213
|
-
"$ref": "/aws/account/vpcs/mars-plain-1",
|
1214
|
-
"cidr_block": "172.30.0.0/12",
|
1215
|
-
"vpc_id": "avpcid",
|
1216
|
-
**self.peer,
|
1217
|
-
"region": "mars-olympus-2",
|
1218
|
-
"account": self.aws_account,
|
1219
|
-
},
|
1220
|
-
"manageRoutes": True,
|
1221
|
-
},
|
1222
|
-
]
|
1223
|
-
},
|
1224
|
-
}
|
1225
|
-
|
1226
|
-
self.peer_cluster = {
|
1227
|
-
"name": "apeerclustername",
|
1228
|
-
"spec": {
|
1229
|
-
"region": "mars-olympus-2",
|
1230
|
-
},
|
1231
|
-
"network": self.peer,
|
1232
|
-
"peering": {
|
1233
|
-
"connections": [
|
1234
|
-
{
|
1235
|
-
"provider": "account-vpc",
|
1236
|
-
"name": "peername",
|
1237
|
-
"vpc": {"$ref": "/aws/account/vpcs/mars-plain-1"},
|
1238
|
-
"manageRoutes": True,
|
1239
|
-
},
|
1240
|
-
]
|
1241
|
-
},
|
1242
|
-
}
|
1243
|
-
self.cluster["peering"]["connections"][0]["cluster"] = self.peer_cluster # type: ignore
|
1244
|
-
self.build_single_cluster = self.mock_callable(
|
1245
|
-
sut, "build_desired_state_single_cluster"
|
1246
|
-
)
|
1247
|
-
self.ocm = cast(
|
1248
|
-
ocm.OCM, testslide.StrictMock(template=ocm.OCM)
|
1249
|
-
) # the cast is to make mypy happy
|
1250
|
-
self.awsapi = cast(
|
1251
|
-
aws_api.AWSApi, testslide.StrictMock(aws_api.AWSApi)
|
1252
|
-
) # the cast is to make mypy happy
|
1253
|
-
self.mock_constructor(aws_api, "AWSApi").to_return_value(self.awsapi)
|
1254
|
-
self.ocm.get_aws_infrastructure_access_terraform_assume_role = ( # type: ignore
|
1255
|
-
lambda cluster, uid, tfuser: self.aws_account["assume_role"]
|
1256
|
-
)
|
1257
|
-
self.addCleanup(testslide.mock_callable.unpatch_all_callable_mocks)
|
1258
|
-
self.maxDiff = None
|
1259
|
-
|
1260
|
-
def test_all_fine(self) -> None:
|
1261
|
-
expected = [
|
1262
|
-
{
|
1263
|
-
"accepter": {
|
1264
|
-
"account": {
|
1265
|
-
"assume_cidr": "172.16.0.0/12",
|
1266
|
-
"assume_region": "mars-plain-1",
|
1267
|
-
"assume_role": "this:wonderful:role:hell:yeah",
|
1268
|
-
"automationtoken": "anautomationtoken",
|
1269
|
-
"name": "accountname",
|
1270
|
-
"terraformUsername": "aterraformusename",
|
1271
|
-
"uid": "anuid",
|
1272
|
-
},
|
1273
|
-
"cidr_block": "172.30.0.0/12",
|
1274
|
-
"region": "mars-olympus-2",
|
1275
|
-
"vpc_id": "avpcid",
|
1276
|
-
},
|
1277
|
-
"connection_name": "peername",
|
1278
|
-
"connection_provider": "account-vpc",
|
1279
|
-
"infra_account_name": "accountname",
|
1280
|
-
"deleted": False,
|
1281
|
-
"requester": {
|
1282
|
-
"account": {
|
1283
|
-
"assume_cidr": "172.16.0.0/12",
|
1284
|
-
"assume_region": "mars-plain-1",
|
1285
|
-
"assume_role": "this:wonderful:role:hell:yeah",
|
1286
|
-
"automationtoken": "anautomationtoken",
|
1287
|
-
"name": "accountname",
|
1288
|
-
"terraformUsername": "aterraformusename",
|
1289
|
-
"uid": "anuid",
|
1290
|
-
},
|
1291
|
-
"cidr_block": "172.16.0.0/12",
|
1292
|
-
"region": "mars-plain-1",
|
1293
|
-
"route_table_ids": ["routetableid"],
|
1294
|
-
"api_security_group_id": None,
|
1295
|
-
"vpc_id": "vpcid",
|
1296
|
-
},
|
1297
|
-
}
|
1298
|
-
]
|
1299
|
-
self.mock_callable(
|
1300
|
-
self.awsapi,
|
1301
|
-
"get_cluster_vpc_details",
|
1302
|
-
).for_call(
|
1303
|
-
self.aws_account, route_tables=True, hcp_vpc_endpoint_sg=False
|
1304
|
-
).to_return_value((
|
1305
|
-
"vpcid",
|
1306
|
-
["routetableid"],
|
1307
|
-
{},
|
1308
|
-
None,
|
1309
|
-
)).and_assert_called_once()
|
1310
|
-
self.mock_callable(
|
1311
|
-
self.ocm, "get_aws_infrastructure_access_terraform_assume_role"
|
1312
|
-
).for_call(
|
1313
|
-
self.cluster["name"],
|
1314
|
-
self.aws_account["uid"],
|
1315
|
-
self.aws_account["terraformUsername"],
|
1316
|
-
).to_return_value("this:wonderful:role:hell:yeah").and_assert_called_once()
|
1317
|
-
rs = sut.build_desired_state_vpc_single_cluster(
|
1318
|
-
self.cluster, self.ocm, self.awsapi, None
|
1319
|
-
)
|
1320
|
-
self.assertEqual(rs, expected)
|
1321
|
-
|
1322
|
-
def test_private_hcp(self) -> None:
|
1323
|
-
self.cluster["spec"] = {
|
1324
|
-
"region": "mars-plain-1",
|
1325
|
-
"hypershift": True,
|
1326
|
-
"private": True,
|
1327
|
-
}
|
1328
|
-
expected = [
|
1329
|
-
{
|
1330
|
-
"accepter": {
|
1331
|
-
"account": {
|
1332
|
-
"assume_cidr": "172.16.0.0/12",
|
1333
|
-
"assume_region": "mars-plain-1",
|
1334
|
-
"assume_role": "this:wonderful:role:hell:yeah",
|
1335
|
-
"automationtoken": "anautomationtoken",
|
1336
|
-
"name": "accountname",
|
1337
|
-
"terraformUsername": "aterraformusename",
|
1338
|
-
"uid": "anuid",
|
1339
|
-
},
|
1340
|
-
"cidr_block": "172.30.0.0/12",
|
1341
|
-
"region": "mars-olympus-2",
|
1342
|
-
"vpc_id": "avpcid",
|
1343
|
-
},
|
1344
|
-
"connection_name": "peername",
|
1345
|
-
"connection_provider": "account-vpc",
|
1346
|
-
"infra_account_name": "accountname",
|
1347
|
-
"deleted": False,
|
1348
|
-
"requester": {
|
1349
|
-
"account": {
|
1350
|
-
"assume_cidr": "172.16.0.0/12",
|
1351
|
-
"assume_region": "mars-plain-1",
|
1352
|
-
"assume_role": "this:wonderful:role:hell:yeah",
|
1353
|
-
"automationtoken": "anautomationtoken",
|
1354
|
-
"name": "accountname",
|
1355
|
-
"terraformUsername": "aterraformusename",
|
1356
|
-
"uid": "anuid",
|
1357
|
-
},
|
1358
|
-
"cidr_block": "172.16.0.0/12",
|
1359
|
-
"region": "mars-plain-1",
|
1360
|
-
"route_table_ids": ["routetableid"],
|
1361
|
-
"api_security_group_id": "sg-vpce",
|
1362
|
-
"vpc_id": "vpcid",
|
1363
|
-
},
|
1364
|
-
}
|
1365
|
-
]
|
1366
|
-
self.mock_callable(
|
1367
|
-
self.awsapi,
|
1368
|
-
"get_cluster_vpc_details",
|
1369
|
-
).for_call(
|
1370
|
-
self.aws_account, route_tables=True, hcp_vpc_endpoint_sg=True
|
1371
|
-
).to_return_value((
|
1372
|
-
"vpcid",
|
1373
|
-
["routetableid"],
|
1374
|
-
{},
|
1375
|
-
"sg-vpce",
|
1376
|
-
)).and_assert_called_once()
|
1377
|
-
self.mock_callable(
|
1378
|
-
self.ocm, "get_aws_infrastructure_access_terraform_assume_role"
|
1379
|
-
).for_call(
|
1380
|
-
self.cluster["name"],
|
1381
|
-
self.aws_account["uid"],
|
1382
|
-
self.aws_account["terraformUsername"],
|
1383
|
-
).to_return_value("this:wonderful:role:hell:yeah").and_assert_called_once()
|
1384
|
-
rs = sut.build_desired_state_vpc_single_cluster(
|
1385
|
-
self.cluster, self.ocm, self.awsapi, None
|
1386
|
-
)
|
1387
|
-
self.assertEqual(rs, expected)
|
1388
|
-
|
1389
|
-
def test_different_provider(self) -> None:
|
1390
|
-
self.cluster["peering"]["connections"][0]["provider"] = "something-else" # type: ignore
|
1391
|
-
self.assertEqual(
|
1392
|
-
sut.build_desired_state_vpc_single_cluster(
|
1393
|
-
self.cluster,
|
1394
|
-
self.ocm,
|
1395
|
-
self.awsapi,
|
1396
|
-
None,
|
1397
|
-
),
|
1398
|
-
[],
|
1399
|
-
)
|
1400
|
-
|
1401
|
-
def test_no_vpc_id(self) -> None:
|
1402
|
-
self.mock_callable(self.awsapi, "get_cluster_vpc_details").to_return_value((
|
1403
|
-
None,
|
1404
|
-
None,
|
1405
|
-
None,
|
1406
|
-
None,
|
1407
|
-
)).and_assert_called_once()
|
1408
|
-
|
1409
|
-
self.mock_callable(
|
1410
|
-
self.ocm, "get_aws_infrastructure_access_terraform_assume_role"
|
1411
|
-
).to_return_value("a:role:that:you:will:like").and_assert_called_once()
|
1412
|
-
|
1413
|
-
desired_state = sut.build_desired_state_vpc_single_cluster(
|
1414
|
-
self.cluster, self.ocm, self.awsapi, None
|
1415
|
-
)
|
1416
|
-
assert desired_state == []
|
1417
|
-
|
1418
|
-
def test_aws_exception(self) -> None:
|
1419
|
-
exc_txt = "AWS Problem!"
|
1420
|
-
self.mock_callable(self.awsapi, "get_cluster_vpc_details").to_raise(
|
1421
|
-
Exception(exc_txt)
|
1422
|
-
)
|
1423
|
-
|
1424
|
-
self.mock_callable(
|
1425
|
-
self.ocm, "get_aws_infrastructure_access_terraform_assume_role"
|
1426
|
-
).to_return_value("a:role:that:you:will:like").and_assert_called_once()
|
1427
|
-
|
1428
|
-
with pytest.raises(Exception, match=exc_txt):
|
1429
|
-
sut.build_desired_state_vpc_single_cluster(
|
1430
|
-
self.cluster,
|
1431
|
-
self.ocm,
|
1432
|
-
self.awsapi,
|
1433
|
-
None,
|
1434
|
-
)
|