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.
Files changed (138) hide show
  1. qontract_reconcile-0.10.2.dev1.dist-info/METADATA +500 -0
  2. {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/RECORD +12 -130
  3. {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/WHEEL +1 -2
  4. {qontract_reconcile-0.10.1rc1202.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/entry_points.txt +1 -0
  5. reconcile/aws_account_manager/README.md +5 -0
  6. reconcile/change_owners/README.md +34 -0
  7. reconcile/glitchtip/README.md +150 -0
  8. reconcile/gql_definitions/introspection.json +51176 -0
  9. reconcile/run_integration.py +293 -0
  10. reconcile/utils/binary.py +2 -2
  11. reconcile/utils/mr/README.md +198 -0
  12. reconcile/utils/oc_map.py +2 -2
  13. tools/qontract_cli.py +0 -0
  14. qontract_reconcile-0.10.1rc1202.dist-info/METADATA +0 -64
  15. qontract_reconcile-0.10.1rc1202.dist-info/top_level.txt +0 -3
  16. reconcile/test/__init__.py +0 -0
  17. reconcile/test/conftest.py +0 -157
  18. reconcile/test/fixtures.py +0 -24
  19. reconcile/test/saas_auto_promotions_manager/__init__.py +0 -0
  20. reconcile/test/saas_auto_promotions_manager/conftest.py +0 -170
  21. reconcile/test/saas_auto_promotions_manager/merge_request_manager/__init__.py +0 -0
  22. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/__init__.py +0 -0
  23. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/conftest.py +0 -115
  24. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/data_keys.py +0 -19
  25. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_desired_state.py +0 -66
  26. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_merge_request_manager.py +0 -86
  27. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_mr_parser.py +0 -352
  28. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_reconciler.py +0 -494
  29. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/__init__.py +0 -0
  30. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/conftest.py +0 -25
  31. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_multiple_namespaces.py +0 -37
  32. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_namespace.py +0 -81
  33. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_target.py +0 -61
  34. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_json_path_selector.py +0 -74
  35. reconcile/test/saas_auto_promotions_manager/test_integration_test.py +0 -52
  36. reconcile/test/saas_auto_promotions_manager/utils/__init__.py +0 -0
  37. reconcile/test/test_acs_notifiers.py +0 -393
  38. reconcile/test/test_acs_policies.py +0 -497
  39. reconcile/test/test_acs_rbac.py +0 -865
  40. reconcile/test/test_aggregated_list.py +0 -237
  41. reconcile/test/test_amtool.py +0 -37
  42. reconcile/test/test_aws_ami_cleanup.py +0 -230
  43. reconcile/test/test_aws_ami_share.py +0 -68
  44. reconcile/test/test_aws_cloudwatch_log_retention.py +0 -434
  45. reconcile/test/test_aws_iam_keys.py +0 -70
  46. reconcile/test/test_aws_iam_password_reset.py +0 -35
  47. reconcile/test/test_aws_support_cases_sos.py +0 -23
  48. reconcile/test/test_checkpoint.py +0 -178
  49. reconcile/test/test_cli.py +0 -41
  50. reconcile/test/test_closedbox_endpoint_monitoring.py +0 -207
  51. reconcile/test/test_dashdotdb_dora.py +0 -245
  52. reconcile/test/test_database_access_manager.py +0 -660
  53. reconcile/test/test_deadmanssnitch.py +0 -290
  54. reconcile/test/test_gabi_authorized_users.py +0 -72
  55. reconcile/test/test_gcr_mirror.py +0 -14
  56. reconcile/test/test_github_org.py +0 -156
  57. reconcile/test/test_github_repo_invites.py +0 -119
  58. reconcile/test/test_gitlab_housekeeping.py +0 -333
  59. reconcile/test/test_gitlab_labeler.py +0 -126
  60. reconcile/test/test_gitlab_members.py +0 -219
  61. reconcile/test/test_gitlab_permissions.py +0 -164
  62. reconcile/test/test_instrumented_wrappers.py +0 -18
  63. reconcile/test/test_integrations_manager.py +0 -1252
  64. reconcile/test/test_jenkins_worker_fleets.py +0 -57
  65. reconcile/test/test_jira_permissions_validator.py +0 -519
  66. reconcile/test/test_jump_host.py +0 -114
  67. reconcile/test/test_ldap_users.py +0 -125
  68. reconcile/test/test_make.py +0 -28
  69. reconcile/test/test_ocm_additional_routers.py +0 -133
  70. reconcile/test/test_ocm_clusters.py +0 -798
  71. reconcile/test/test_ocm_clusters_manifest_updates.py +0 -87
  72. reconcile/test/test_ocm_machine_pools.py +0 -1103
  73. reconcile/test/test_ocm_update_recommended_version.py +0 -145
  74. reconcile/test/test_ocm_upgrade_scheduler_org_updater.py +0 -125
  75. reconcile/test/test_openshift_base.py +0 -1269
  76. reconcile/test/test_openshift_cluster_bots.py +0 -240
  77. reconcile/test/test_openshift_namespace_labels.py +0 -344
  78. reconcile/test/test_openshift_namespaces.py +0 -256
  79. reconcile/test/test_openshift_resource.py +0 -443
  80. reconcile/test/test_openshift_resources_base.py +0 -478
  81. reconcile/test/test_openshift_saas_deploy.py +0 -188
  82. reconcile/test/test_openshift_saas_deploy_change_tester.py +0 -308
  83. reconcile/test/test_openshift_saas_deploy_trigger_cleaner.py +0 -65
  84. reconcile/test/test_openshift_serviceaccount_tokens.py +0 -282
  85. reconcile/test/test_openshift_tekton_resources.py +0 -265
  86. reconcile/test/test_openshift_upgrade_watcher.py +0 -223
  87. reconcile/test/test_prometheus_rules_tester.py +0 -151
  88. reconcile/test/test_quay_membership.py +0 -86
  89. reconcile/test/test_quay_mirror.py +0 -172
  90. reconcile/test/test_quay_mirror_org.py +0 -82
  91. reconcile/test/test_quay_repos.py +0 -59
  92. reconcile/test/test_queries.py +0 -53
  93. reconcile/test/test_repo_owners.py +0 -47
  94. reconcile/test/test_requests_sender.py +0 -139
  95. reconcile/test/test_saasherder.py +0 -1611
  96. reconcile/test/test_saasherder_allowed_secret_paths.py +0 -125
  97. reconcile/test/test_secret_reader.py +0 -153
  98. reconcile/test/test_slack_base.py +0 -183
  99. reconcile/test/test_slack_usergroups.py +0 -785
  100. reconcile/test/test_sql_query.py +0 -316
  101. reconcile/test/test_status_board.py +0 -258
  102. reconcile/test/test_terraform_aws_route53.py +0 -29
  103. reconcile/test/test_terraform_cloudflare_dns.py +0 -117
  104. reconcile/test/test_terraform_cloudflare_resources.py +0 -408
  105. reconcile/test/test_terraform_cloudflare_users.py +0 -747
  106. reconcile/test/test_terraform_repo.py +0 -440
  107. reconcile/test/test_terraform_resources.py +0 -519
  108. reconcile/test/test_terraform_tgw_attachments.py +0 -1295
  109. reconcile/test/test_terraform_users.py +0 -152
  110. reconcile/test/test_terraform_vpc_peerings.py +0 -576
  111. reconcile/test/test_terraform_vpc_peerings_build_desired_state.py +0 -1434
  112. reconcile/test/test_three_way_diff_strategy.py +0 -131
  113. reconcile/test/test_utils_jinja2.py +0 -130
  114. reconcile/test/test_vault_replication.py +0 -534
  115. reconcile/test/test_vault_utils.py +0 -47
  116. reconcile/test/test_version_bump.py +0 -18
  117. reconcile/test/test_vpc_peerings_validator.py +0 -194
  118. reconcile/test/test_wrong_region.py +0 -78
  119. release/__init__.py +0 -0
  120. release/test_version.py +0 -50
  121. release/version.py +0 -104
  122. tools/cli_commands/test/__init__.py +0 -0
  123. tools/cli_commands/test/conftest.py +0 -332
  124. tools/cli_commands/test/test_aws_cost_report.py +0 -258
  125. tools/cli_commands/test/test_cost_management_api.py +0 -326
  126. tools/cli_commands/test/test_gpg_encrypt.py +0 -235
  127. tools/cli_commands/test/test_openshift_cost_optimization_report.py +0 -255
  128. tools/cli_commands/test/test_openshift_cost_report.py +0 -295
  129. tools/cli_commands/test/test_util.py +0 -70
  130. tools/test/__init__.py +0 -0
  131. tools/test/conftest.py +0 -77
  132. tools/test/test_app_interface_metrics_exporter.py +0 -48
  133. tools/test/test_erv2.py +0 -80
  134. tools/test/test_get_container_images.py +0 -230
  135. tools/test/test_qontract_cli.py +0 -197
  136. tools/test/test_saas_promotion_state.py +0 -187
  137. tools/test/test_sd_app_sre_alert_report.py +0 -74
  138. tools/test/test_sre_checkpoints.py +0 -79
@@ -1,434 +0,0 @@
1
- from collections.abc import Generator
2
- from datetime import UTC, datetime, timedelta
3
- from typing import (
4
- TYPE_CHECKING,
5
- Any,
6
- )
7
- from unittest.mock import MagicMock
8
-
9
- import boto3
10
- import pytest
11
- from moto import mock_logs
12
- from pytest_mock import MockerFixture
13
-
14
- from reconcile.aws_cloudwatch_log_retention.integration import (
15
- get_desired_cleanup_options_by_region,
16
- run,
17
- )
18
-
19
- if TYPE_CHECKING:
20
- from mypy_boto3_logs import CloudWatchLogsClient # type: ignore
21
- else:
22
- CloudWatchLogsClient = object
23
- CreateImageResultTypeDef = dict
24
-
25
-
26
- @pytest.fixture
27
- def cloudwatchlogs_client() -> Generator[CloudWatchLogsClient, None, None]:
28
- with mock_logs():
29
- yield boto3.client("logs", region_name="us-east-1")
30
-
31
-
32
- @pytest.fixture(autouse=True)
33
- def log_group_tf_tag(cloudwatchlogs_client: CloudWatchLogsClient) -> list:
34
- log_group_name1 = "some-group"
35
- tags1 = {"key": "value", "managed_by_integration": "terraform_resources"}
36
-
37
- cloudwatchlogs_client.create_log_group(logGroupName=log_group_name1)
38
- cloudwatchlogs_client.tag_log_group(logGroupName=log_group_name1, tags=tags1)
39
-
40
- log_group_name2 = "some-group2"
41
- tags2 = {"key2": "value2"}
42
-
43
- cloudwatchlogs_client.create_log_group(logGroupName=log_group_name2)
44
- cloudwatchlogs_client.tag_log_group(logGroupName=log_group_name2, tags=tags2)
45
-
46
- describe_log_output = cloudwatchlogs_client.describe_log_groups(
47
- logGroupNamePattern="some"
48
- )
49
- log_output_list = describe_log_output.get("logGroups")
50
-
51
- return log_output_list
52
-
53
-
54
- @pytest.fixture
55
- def test_cloudwatch_account() -> dict[str, Any]:
56
- return {
57
- "accountOwners": [{"email": "some-email@email.com", "name": "Some Team"}],
58
- "cleanup": [
59
- {
60
- "provider": "cloudwatch",
61
- "regex": "some-path*",
62
- "retention_in_days": 30,
63
- "delete_empty_log_group": None,
64
- "region": None,
65
- },
66
- {
67
- "provider": "cloudwatch",
68
- "regex": "some-other-path*",
69
- "retention_in_days": 60,
70
- "delete_empty_log_group": True,
71
- "region": "us-east-1",
72
- },
73
- ],
74
- "consoleUrl": "https://some-url.com/console",
75
- "name": "some-account-name",
76
- "uid": "0123456789",
77
- "resourcesDefaultRegion": "us-east-1",
78
- "disable": None,
79
- }
80
-
81
-
82
- def test_get_desired_cleanup_options(
83
- test_cloudwatch_account: dict,
84
- ) -> None:
85
- desired_cleanup_options_by_region = get_desired_cleanup_options_by_region(
86
- test_cloudwatch_account
87
- )
88
- assert len(desired_cleanup_options_by_region) == 1
89
- assert len(desired_cleanup_options_by_region["us-east-1"]) == 2
90
-
91
-
92
- def setup_mocks(
93
- mocker: MockerFixture,
94
- aws_accounts: list[dict],
95
- log_groups: list[dict],
96
- tags: dict[str, Any],
97
- utcnow: datetime = datetime.now(UTC), # noqa: B008
98
- ) -> MagicMock:
99
- mocker.patch(
100
- "reconcile.aws_cloudwatch_log_retention.integration.get_aws_accounts",
101
- return_value=aws_accounts,
102
- )
103
- mocker.patch(
104
- "reconcile.aws_cloudwatch_log_retention.integration.queries.get_secret_reader_settings",
105
- return_value={},
106
- )
107
- mocked_datetime = mocker.patch(
108
- "reconcile.aws_cloudwatch_log_retention.integration.datetime",
109
- wraps=datetime,
110
- )
111
- mocked_datetime.utcnow.return_value = utcnow
112
- aws_api = mocker.patch(
113
- "reconcile.aws_cloudwatch_log_retention.integration.AWSApi",
114
- autospec=True,
115
- )
116
- mocked_aws_api = aws_api.return_value.__enter__.return_value
117
- mocked_aws_api.get_cloudwatch_log_groups.return_value = iter(log_groups)
118
- mocked_aws_api.get_cloudwatch_log_group_tags.return_value = tags
119
- return mocked_aws_api
120
-
121
-
122
- @pytest.fixture
123
- def log_group_with_unset_retention() -> dict[str, Any]:
124
- return {
125
- "logGroupName": "group-without-retention",
126
- "storedBytes": 123,
127
- "creationTime": 1433189500783,
128
- "arn": "arn:aws:logs:us-west-2:0123456789012:log-group:group-without-retention:*",
129
- }
130
-
131
-
132
- @pytest.fixture
133
- def empty_tags() -> dict[str, str]:
134
- return {}
135
-
136
-
137
- @pytest.fixture
138
- def managed_by_aws_cloudwatch_log_retention_tags() -> dict[str, str]:
139
- return {
140
- "managed_by_integration": "aws_cloudwatch_log_retention",
141
- }
142
-
143
-
144
- @pytest.fixture
145
- def managed_by_terraform_resources_tags() -> dict[str, str]:
146
- return {
147
- "managed_by_integration": "terraform_resources",
148
- }
149
-
150
-
151
- def test_run_with_unset_retention_log_group_and_default_cleanup(
152
- mocker: MockerFixture,
153
- test_cloudwatch_account: dict[str, Any],
154
- log_group_with_unset_retention: dict[str, Any],
155
- empty_tags: dict[str, Any],
156
- ) -> None:
157
- mocked_aws_api = setup_mocks(
158
- mocker,
159
- aws_accounts=[test_cloudwatch_account],
160
- log_groups=[log_group_with_unset_retention],
161
- tags=empty_tags,
162
- )
163
-
164
- run(dry_run=False, thread_pool_size=1)
165
-
166
- mocked_aws_api.get_cloudwatch_log_group_tags.assert_called_once_with(
167
- test_cloudwatch_account["name"],
168
- log_group_with_unset_retention["arn"],
169
- "us-east-1",
170
- )
171
-
172
- mocked_aws_api.create_cloudwatch_tag.assert_called_once_with(
173
- test_cloudwatch_account["name"],
174
- log_group_with_unset_retention["arn"],
175
- {"managed_by_integration": "aws_cloudwatch_log_retention"},
176
- "us-east-1",
177
- )
178
-
179
- mocked_aws_api.set_cloudwatch_log_retention.assert_called_once_with(
180
- test_cloudwatch_account["name"],
181
- "group-without-retention",
182
- 90,
183
- "us-east-1",
184
- )
185
-
186
-
187
- @pytest.fixture
188
- def log_group_with_unset_retention_and_matching_name() -> dict[str, Any]:
189
- return {
190
- "logGroupName": "some-path-group-without-retention",
191
- "storedBytes": 0,
192
- "creationTime": 1433189500783,
193
- "arn": "arn:aws:logs:us-west-2:0123456789012:log-group:some-path-group-without-retention:*",
194
- }
195
-
196
-
197
- def test_run_with_unset_retention_log_group_and_matching_cleanup(
198
- mocker: MockerFixture,
199
- test_cloudwatch_account: dict[str, Any],
200
- log_group_with_unset_retention_and_matching_name: dict[str, Any],
201
- empty_tags: dict[str, Any],
202
- ) -> None:
203
- mocked_aws_api = setup_mocks(
204
- mocker,
205
- aws_accounts=[test_cloudwatch_account],
206
- log_groups=[log_group_with_unset_retention_and_matching_name],
207
- tags=empty_tags,
208
- )
209
-
210
- run(dry_run=False, thread_pool_size=1)
211
-
212
- mocked_aws_api.get_cloudwatch_log_group_tags.assert_called_once_with(
213
- test_cloudwatch_account["name"],
214
- log_group_with_unset_retention_and_matching_name["arn"],
215
- "us-east-1",
216
- )
217
-
218
- mocked_aws_api.create_cloudwatch_tag.assert_called_once_with(
219
- test_cloudwatch_account["name"],
220
- log_group_with_unset_retention_and_matching_name["arn"],
221
- {"managed_by_integration": "aws_cloudwatch_log_retention"},
222
- "us-east-1",
223
- )
224
-
225
- mocked_aws_api.set_cloudwatch_log_retention.assert_called_once_with(
226
- test_cloudwatch_account["name"],
227
- "some-path-group-without-retention",
228
- 30,
229
- "us-east-1",
230
- )
231
-
232
-
233
- @pytest.fixture
234
- def log_group_with_desired_retention() -> dict[str, Any]:
235
- return {
236
- "logGroupName": "group-with-desired-retention",
237
- "retentionInDays": 90,
238
- "storedBytes": 123,
239
- "creationTime": 1433189500783,
240
- "arn": "arn:aws:logs:us-west-2:0123456789012:log-group:group-with-desired-retention:*",
241
- }
242
-
243
-
244
- def test_run_with_matching_retention_log_group(
245
- mocker: MockerFixture,
246
- test_cloudwatch_account: dict[str, Any],
247
- log_group_with_desired_retention: dict[str, Any],
248
- managed_by_aws_cloudwatch_log_retention_tags: dict[str, Any],
249
- ) -> None:
250
- mocked_aws_api = setup_mocks(
251
- mocker,
252
- aws_accounts=[test_cloudwatch_account],
253
- log_groups=[log_group_with_desired_retention],
254
- tags=managed_by_aws_cloudwatch_log_retention_tags,
255
- )
256
-
257
- run(dry_run=False, thread_pool_size=1)
258
-
259
- mocked_aws_api.get_cloudwatch_log_group_tags.assert_not_called()
260
- mocked_aws_api.create_cloudwatch_tag.assert_not_called()
261
- mocked_aws_api.set_cloudwatch_log_retention.assert_not_called()
262
-
263
-
264
- def test_run_with_log_group_managed_by_terraform_resources(
265
- mocker: MockerFixture,
266
- test_cloudwatch_account: dict[str, Any],
267
- log_group_with_unset_retention: dict[str, Any],
268
- managed_by_terraform_resources_tags: dict[str, Any],
269
- ) -> None:
270
- mocked_aws_api = setup_mocks(
271
- mocker,
272
- aws_accounts=[test_cloudwatch_account],
273
- log_groups=[log_group_with_unset_retention],
274
- tags=managed_by_terraform_resources_tags,
275
- )
276
-
277
- run(dry_run=False, thread_pool_size=1)
278
-
279
- mocked_aws_api.get_cloudwatch_log_group_tags.assert_called_once_with(
280
- test_cloudwatch_account["name"],
281
- log_group_with_unset_retention["arn"],
282
- "us-east-1",
283
- )
284
- mocked_aws_api.delete_cloudwatch_log_group.assert_not_called()
285
- mocked_aws_api.create_cloudwatch_tag.assert_not_called()
286
- mocked_aws_api.set_cloudwatch_log_retention.assert_not_called()
287
-
288
-
289
- @pytest.fixture
290
- def log_group_with_empty_stored_bytes() -> dict[str, Any]:
291
- return {
292
- "logGroupName": "some-other-path-empty-group",
293
- "storedBytes": 0,
294
- "retentionInDays": 90,
295
- "creationTime": 1433189500783,
296
- "arn": "arn:aws:logs:us-east-1:0123456789012:log-group:group-without-retention:*",
297
- }
298
-
299
-
300
- def test_run_with_empty_log_group_after_retention_in_days(
301
- mocker: MockerFixture,
302
- test_cloudwatch_account: dict[str, Any],
303
- log_group_with_empty_stored_bytes: dict[str, Any],
304
- managed_by_aws_cloudwatch_log_retention_tags: dict[str, Any],
305
- ) -> None:
306
- mocked_aws_api = setup_mocks(
307
- mocker,
308
- aws_accounts=[test_cloudwatch_account],
309
- log_groups=[log_group_with_empty_stored_bytes],
310
- tags=managed_by_aws_cloudwatch_log_retention_tags,
311
- utcnow=datetime.fromtimestamp(
312
- log_group_with_empty_stored_bytes["creationTime"] / 1000
313
- )
314
- + timedelta(days=61),
315
- )
316
-
317
- run(dry_run=False, thread_pool_size=1)
318
-
319
- mocked_aws_api.get_cloudwatch_log_group_tags.assert_called_once_with(
320
- test_cloudwatch_account["name"],
321
- log_group_with_empty_stored_bytes["arn"],
322
- "us-east-1",
323
- )
324
- mocked_aws_api.delete_cloudwatch_log_group.assert_called_once_with(
325
- test_cloudwatch_account["name"],
326
- log_group_with_empty_stored_bytes["logGroupName"],
327
- "us-east-1",
328
- )
329
- mocked_aws_api.create_cloudwatch_tag.assert_not_called()
330
- mocked_aws_api.set_cloudwatch_log_retention.assert_not_called()
331
-
332
-
333
- def test_run_with_empty_log_group_before_retention_in_days(
334
- mocker: MockerFixture,
335
- test_cloudwatch_account: dict[str, Any],
336
- log_group_with_empty_stored_bytes: dict[str, Any],
337
- managed_by_aws_cloudwatch_log_retention_tags: dict[str, Any],
338
- ) -> None:
339
- mocked_aws_api = setup_mocks(
340
- mocker,
341
- aws_accounts=[test_cloudwatch_account],
342
- log_groups=[log_group_with_empty_stored_bytes],
343
- tags=managed_by_aws_cloudwatch_log_retention_tags,
344
- utcnow=datetime.fromtimestamp(
345
- log_group_with_empty_stored_bytes["creationTime"] / 1000
346
- )
347
- + timedelta(days=59),
348
- )
349
-
350
- run(dry_run=False, thread_pool_size=1)
351
-
352
- mocked_aws_api.get_cloudwatch_log_group_tags.assert_called_once_with(
353
- test_cloudwatch_account["name"],
354
- log_group_with_empty_stored_bytes["arn"],
355
- "us-east-1",
356
- )
357
- mocked_aws_api.delete_cloudwatch_log_group.assert_not_called()
358
- mocked_aws_api.create_cloudwatch_tag.assert_not_called()
359
- mocked_aws_api.set_cloudwatch_log_retention.assert_called_once_with(
360
- test_cloudwatch_account["name"],
361
- "some-other-path-empty-group",
362
- 60,
363
- "us-east-1",
364
- )
365
-
366
-
367
- @pytest.fixture
368
- def account_with_disabled_integration() -> dict[str, Any]:
369
- return {
370
- "name": "disabled-account-name",
371
- "disable": {
372
- "integrations": ["aws-cloudwatch-log-retention"],
373
- },
374
- }
375
-
376
-
377
- def test_run_with_disabled_integration_account(
378
- mocker: MockerFixture,
379
- account_with_disabled_integration: dict[str, Any],
380
- ) -> None:
381
- mocked_aws_api = setup_mocks(
382
- mocker,
383
- aws_accounts=[account_with_disabled_integration],
384
- log_groups=[],
385
- tags={},
386
- )
387
-
388
- run(dry_run=False, thread_pool_size=1)
389
-
390
- mocked_aws_api.get_cloudwatch_log_groups.assert_not_called()
391
-
392
-
393
- @pytest.fixture
394
- def test_cloudwatch_account_with_multiple_regions() -> dict[str, Any]:
395
- return {
396
- "cleanup": [
397
- {
398
- "provider": "cloudwatch",
399
- "regex": "some-path*",
400
- "retention_in_days": 30,
401
- "delete_empty_log_group": None,
402
- "region": None,
403
- },
404
- {
405
- "provider": "cloudwatch",
406
- "regex": "some-other-path*",
407
- "retention_in_days": 60,
408
- "delete_empty_log_group": True,
409
- "region": "us-west-2",
410
- },
411
- ],
412
- "name": "account-name-with-multiple_regions",
413
- "uid": "0123456789",
414
- "resourcesDefaultRegion": "us-east-1",
415
- }
416
-
417
-
418
- def test_run_with_multiple_regions_account(
419
- mocker: MockerFixture,
420
- test_cloudwatch_account_with_multiple_regions: dict[str, Any],
421
- ) -> None:
422
- mocked_aws_api = setup_mocks(
423
- mocker,
424
- aws_accounts=[test_cloudwatch_account_with_multiple_regions],
425
- log_groups=[],
426
- tags={},
427
- )
428
-
429
- run(dry_run=False, thread_pool_size=1)
430
-
431
- assert mocked_aws_api.get_cloudwatch_log_groups.call_count == 2
432
- calls = mocked_aws_api.get_cloudwatch_log_groups.call_args_list
433
- called_regions = {call[0][1] for call in calls}
434
- assert called_regions == {"us-east-1", "us-west-2"}
@@ -1,70 +0,0 @@
1
- import pytest
2
-
3
- import reconcile.aws_iam_keys as integ
4
-
5
-
6
- def test_filter_accounts_with_account_name():
7
- a = {"name": "a", "deleteKeys": ["AKIA"]}
8
- b = {"name": "b", "deleteKeys": ["AKIA"]}
9
- accounts = [a, b]
10
- filtered = integ.filter_accounts(accounts, a["name"])
11
- assert filtered == [a]
12
-
13
-
14
- def test_filter_accounts_without_account_name():
15
- a = {"name": "a", "deleteKeys": ["AKIA"]}
16
- b = {"name": "b", "deleteKeys": ["AKIA"]}
17
- accounts = [a, b]
18
- filtered = integ.filter_accounts(accounts, None)
19
- assert filtered == accounts
20
-
21
-
22
- def test_filter_accounts_without_delete_keys():
23
- a = {"name": "a", "deleteKeys": ["AKIA"]}
24
- b = {"name": "b"}
25
- accounts = [a, b]
26
- filtered = integ.filter_accounts(accounts, None)
27
- assert filtered == [a]
28
-
29
-
30
- def test_get_keys_to_delete():
31
- a = {"name": "a", "deleteKeys": ["k1", "k2"]}
32
- b = {"name": "b", "deleteKeys": None}
33
- c = {"name": "c", "deleteKeys": []}
34
- accounts = [a, b, c]
35
- expected_result = {a["name"]: a["deleteKeys"]}
36
- keys_to_delete = integ.get_keys_to_delete(accounts)
37
- assert keys_to_delete == expected_result
38
-
39
-
40
- class StateMock:
41
- def __init__(self):
42
- self.data = {}
43
-
44
- def get(self, key, *args):
45
- return self.data.get(key, args[0])
46
-
47
- def add(self, key, value, force):
48
- self.data[key] = value
49
-
50
-
51
- @pytest.fixture
52
- def state():
53
- return StateMock()
54
-
55
-
56
- def test_should_run_true(state):
57
- keys_to_delete = {"a": ["k1"]}
58
- assert integ.should_run(state, keys_to_delete) is True
59
-
60
-
61
- def test_should_run_false(state):
62
- keys_to_delete = {"a": ["k1"]}
63
- state.data.update(keys_to_delete)
64
- assert integ.should_run(state, keys_to_delete) is False
65
-
66
-
67
- def test_update_state(state):
68
- keys_to_update = {"a": ["k1"]}
69
- integ.update_state(state, keys_to_update)
70
- assert state.data == keys_to_update
@@ -1,35 +0,0 @@
1
- from typing import Any
2
-
3
- import pytest
4
-
5
- from reconcile.aws_iam_password_reset import (
6
- account_in_roles,
7
- get_roles,
8
- )
9
-
10
-
11
- @pytest.fixture
12
- def roles() -> list[dict[str, Any]]:
13
- return [
14
- {
15
- "org_username": "foobar",
16
- "roles": [
17
- {"name": "test", "aws_groups": None},
18
- {"name": "test2", "aws_groups": [{"account": {"name": "testaws1"}}]},
19
- ],
20
- },
21
- {"org_username": "barfoo"},
22
- ]
23
-
24
-
25
- def test_get_roles(roles: list[dict[str, Any]]):
26
- r = get_roles(roles, "barfoo")
27
- assert r and r["org_username"] == "barfoo"
28
- r = get_roles(roles, "foo")
29
- assert not r
30
-
31
-
32
- def test_account_in_roles(roles: list[dict[str, Any]]):
33
- r = get_roles(roles, "foobar")
34
- assert r and account_in_roles(r["roles"], "testaws1")
35
- assert r and not account_in_roles(r["roles"], "a")
@@ -1,23 +0,0 @@
1
- from unittest import TestCase
2
-
3
- import reconcile.aws_support_cases_sos as integ
4
-
5
-
6
- class TestSupportFunctions(TestCase):
7
- def test_filter_accounts(self):
8
- a = {"name": "a", "premiumSupport": True}
9
- b = {"name": "b", "premiumSupport": False}
10
- c = {"name": "c", "premiumSupport": None}
11
- d = {"name": "d"}
12
- accounts = [a, b, c, d]
13
- filtered = integ.filter_accounts(accounts)
14
- self.assertEqual(filtered, [a])
15
-
16
- def test_get_deleted_keys(self):
17
- a = {"name": "a", "deleteKeys": ["k1", "k2"]}
18
- b = {"name": "b", "deleteKeys": None}
19
- c = {"name": "c", "deleteKeys": []}
20
- accounts = [a, b, c]
21
- expected_result = {a["name"]: a["deleteKeys"]}
22
- keys_to_delete = integ.get_deleted_keys(accounts)
23
- self.assertEqual(keys_to_delete, expected_result)