qontract-reconcile 0.10.1rc1201__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 (140) hide show
  1. qontract_reconcile-0.10.2.dev1.dist-info/METADATA +500 -0
  2. {qontract_reconcile-0.10.1rc1201.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/RECORD +14 -132
  3. {qontract_reconcile-0.10.1rc1201.dist-info → qontract_reconcile-0.10.2.dev1.dist-info}/WHEEL +1 -2
  4. {qontract_reconcile-0.10.1rc1201.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/external_resources/manager.py +12 -1
  8. reconcile/external_resources/model.py +11 -0
  9. reconcile/glitchtip/README.md +150 -0
  10. reconcile/gql_definitions/introspection.json +51176 -0
  11. reconcile/run_integration.py +293 -0
  12. reconcile/utils/binary.py +2 -2
  13. reconcile/utils/mr/README.md +198 -0
  14. reconcile/utils/oc_map.py +2 -2
  15. tools/qontract_cli.py +0 -0
  16. qontract_reconcile-0.10.1rc1201.dist-info/METADATA +0 -64
  17. qontract_reconcile-0.10.1rc1201.dist-info/top_level.txt +0 -3
  18. reconcile/test/__init__.py +0 -0
  19. reconcile/test/conftest.py +0 -157
  20. reconcile/test/fixtures.py +0 -24
  21. reconcile/test/saas_auto_promotions_manager/__init__.py +0 -0
  22. reconcile/test/saas_auto_promotions_manager/conftest.py +0 -170
  23. reconcile/test/saas_auto_promotions_manager/merge_request_manager/__init__.py +0 -0
  24. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/__init__.py +0 -0
  25. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/conftest.py +0 -115
  26. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/data_keys.py +0 -19
  27. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_desired_state.py +0 -66
  28. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_merge_request_manager.py +0 -86
  29. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_mr_parser.py +0 -352
  30. reconcile/test/saas_auto_promotions_manager/merge_request_manager/merge_request_manager/test_reconciler.py +0 -494
  31. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/__init__.py +0 -0
  32. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/conftest.py +0 -25
  33. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_multiple_namespaces.py +0 -37
  34. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_namespace.py +0 -81
  35. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_content_single_target.py +0 -61
  36. reconcile/test/saas_auto_promotions_manager/merge_request_manager/renderer/test_json_path_selector.py +0 -74
  37. reconcile/test/saas_auto_promotions_manager/test_integration_test.py +0 -52
  38. reconcile/test/saas_auto_promotions_manager/utils/__init__.py +0 -0
  39. reconcile/test/test_acs_notifiers.py +0 -393
  40. reconcile/test/test_acs_policies.py +0 -497
  41. reconcile/test/test_acs_rbac.py +0 -865
  42. reconcile/test/test_aggregated_list.py +0 -237
  43. reconcile/test/test_amtool.py +0 -37
  44. reconcile/test/test_aws_ami_cleanup.py +0 -230
  45. reconcile/test/test_aws_ami_share.py +0 -68
  46. reconcile/test/test_aws_cloudwatch_log_retention.py +0 -434
  47. reconcile/test/test_aws_iam_keys.py +0 -70
  48. reconcile/test/test_aws_iam_password_reset.py +0 -35
  49. reconcile/test/test_aws_support_cases_sos.py +0 -23
  50. reconcile/test/test_checkpoint.py +0 -178
  51. reconcile/test/test_cli.py +0 -41
  52. reconcile/test/test_closedbox_endpoint_monitoring.py +0 -207
  53. reconcile/test/test_dashdotdb_dora.py +0 -245
  54. reconcile/test/test_database_access_manager.py +0 -660
  55. reconcile/test/test_deadmanssnitch.py +0 -290
  56. reconcile/test/test_gabi_authorized_users.py +0 -72
  57. reconcile/test/test_gcr_mirror.py +0 -14
  58. reconcile/test/test_github_org.py +0 -156
  59. reconcile/test/test_github_repo_invites.py +0 -119
  60. reconcile/test/test_gitlab_housekeeping.py +0 -333
  61. reconcile/test/test_gitlab_labeler.py +0 -126
  62. reconcile/test/test_gitlab_members.py +0 -219
  63. reconcile/test/test_gitlab_permissions.py +0 -164
  64. reconcile/test/test_instrumented_wrappers.py +0 -18
  65. reconcile/test/test_integrations_manager.py +0 -1252
  66. reconcile/test/test_jenkins_worker_fleets.py +0 -57
  67. reconcile/test/test_jira_permissions_validator.py +0 -519
  68. reconcile/test/test_jump_host.py +0 -114
  69. reconcile/test/test_ldap_users.py +0 -125
  70. reconcile/test/test_make.py +0 -28
  71. reconcile/test/test_ocm_additional_routers.py +0 -133
  72. reconcile/test/test_ocm_clusters.py +0 -798
  73. reconcile/test/test_ocm_clusters_manifest_updates.py +0 -87
  74. reconcile/test/test_ocm_machine_pools.py +0 -1103
  75. reconcile/test/test_ocm_update_recommended_version.py +0 -145
  76. reconcile/test/test_ocm_upgrade_scheduler_org_updater.py +0 -125
  77. reconcile/test/test_openshift_base.py +0 -1269
  78. reconcile/test/test_openshift_cluster_bots.py +0 -240
  79. reconcile/test/test_openshift_namespace_labels.py +0 -344
  80. reconcile/test/test_openshift_namespaces.py +0 -256
  81. reconcile/test/test_openshift_resource.py +0 -443
  82. reconcile/test/test_openshift_resources_base.py +0 -478
  83. reconcile/test/test_openshift_saas_deploy.py +0 -188
  84. reconcile/test/test_openshift_saas_deploy_change_tester.py +0 -308
  85. reconcile/test/test_openshift_saas_deploy_trigger_cleaner.py +0 -65
  86. reconcile/test/test_openshift_serviceaccount_tokens.py +0 -282
  87. reconcile/test/test_openshift_tekton_resources.py +0 -265
  88. reconcile/test/test_openshift_upgrade_watcher.py +0 -223
  89. reconcile/test/test_prometheus_rules_tester.py +0 -151
  90. reconcile/test/test_quay_membership.py +0 -86
  91. reconcile/test/test_quay_mirror.py +0 -172
  92. reconcile/test/test_quay_mirror_org.py +0 -82
  93. reconcile/test/test_quay_repos.py +0 -59
  94. reconcile/test/test_queries.py +0 -53
  95. reconcile/test/test_repo_owners.py +0 -47
  96. reconcile/test/test_requests_sender.py +0 -139
  97. reconcile/test/test_saasherder.py +0 -1611
  98. reconcile/test/test_saasherder_allowed_secret_paths.py +0 -125
  99. reconcile/test/test_secret_reader.py +0 -153
  100. reconcile/test/test_slack_base.py +0 -183
  101. reconcile/test/test_slack_usergroups.py +0 -785
  102. reconcile/test/test_sql_query.py +0 -316
  103. reconcile/test/test_status_board.py +0 -258
  104. reconcile/test/test_terraform_aws_route53.py +0 -29
  105. reconcile/test/test_terraform_cloudflare_dns.py +0 -117
  106. reconcile/test/test_terraform_cloudflare_resources.py +0 -408
  107. reconcile/test/test_terraform_cloudflare_users.py +0 -747
  108. reconcile/test/test_terraform_repo.py +0 -440
  109. reconcile/test/test_terraform_resources.py +0 -519
  110. reconcile/test/test_terraform_tgw_attachments.py +0 -1295
  111. reconcile/test/test_terraform_users.py +0 -152
  112. reconcile/test/test_terraform_vpc_peerings.py +0 -576
  113. reconcile/test/test_terraform_vpc_peerings_build_desired_state.py +0 -1434
  114. reconcile/test/test_three_way_diff_strategy.py +0 -131
  115. reconcile/test/test_utils_jinja2.py +0 -130
  116. reconcile/test/test_vault_replication.py +0 -534
  117. reconcile/test/test_vault_utils.py +0 -47
  118. reconcile/test/test_version_bump.py +0 -18
  119. reconcile/test/test_vpc_peerings_validator.py +0 -194
  120. reconcile/test/test_wrong_region.py +0 -78
  121. release/__init__.py +0 -0
  122. release/test_version.py +0 -50
  123. release/version.py +0 -104
  124. tools/cli_commands/test/__init__.py +0 -0
  125. tools/cli_commands/test/conftest.py +0 -332
  126. tools/cli_commands/test/test_aws_cost_report.py +0 -258
  127. tools/cli_commands/test/test_cost_management_api.py +0 -326
  128. tools/cli_commands/test/test_gpg_encrypt.py +0 -235
  129. tools/cli_commands/test/test_openshift_cost_optimization_report.py +0 -255
  130. tools/cli_commands/test/test_openshift_cost_report.py +0 -295
  131. tools/cli_commands/test/test_util.py +0 -70
  132. tools/test/__init__.py +0 -0
  133. tools/test/conftest.py +0 -77
  134. tools/test/test_app_interface_metrics_exporter.py +0 -48
  135. tools/test/test_erv2.py +0 -80
  136. tools/test/test_get_container_images.py +0 -230
  137. tools/test/test_qontract_cli.py +0 -197
  138. tools/test/test_saas_promotion_state.py +0 -187
  139. tools/test/test_sd_app_sre_alert_report.py +0 -74
  140. tools/test/test_sre_checkpoints.py +0 -79
@@ -1,255 +0,0 @@
1
- from collections.abc import Callable
2
- from typing import Any
3
-
4
- import pytest
5
- from pytest_mock import MockerFixture
6
-
7
- from reconcile.typed_queries.cost_report.app_names import App
8
- from reconcile.typed_queries.cost_report.cost_namespaces import (
9
- CostNamespace,
10
- CostNamespaceLabels,
11
- )
12
- from tools.cli_commands.cost_report.model import (
13
- OptimizationReport,
14
- OptimizationReportItem,
15
- )
16
- from tools.cli_commands.cost_report.openshift_cost_optimization import (
17
- OpenShiftCostOptimizationReportCommand,
18
- )
19
- from tools.cli_commands.test.conftest import (
20
- COST_REPORT_SECRET,
21
- OPENSHIFT_COST_OPTIMIZATION_RESPONSE,
22
- OPENSHIFT_COST_OPTIMIZATION_WITH_FUZZY_MATCH_RESPONSE,
23
- )
24
-
25
-
26
- @pytest.fixture
27
- def mock_gql(mocker: MockerFixture) -> Any:
28
- return mocker.patch(
29
- "tools.cli_commands.cost_report.openshift_cost_optimization.gql"
30
- )
31
-
32
-
33
- @pytest.fixture
34
- def mock_cost_management_api(mocker: MockerFixture) -> Any:
35
- return mocker.patch(
36
- "tools.cli_commands.cost_report.openshift_cost_optimization.CostManagementApi",
37
- autospec=True,
38
- )
39
-
40
-
41
- @pytest.fixture
42
- def mock_fetch_cost_report_secret(mocker: MockerFixture) -> Any:
43
- return mocker.patch(
44
- "tools.cli_commands.cost_report.openshift_cost_optimization.fetch_cost_report_secret",
45
- return_value=COST_REPORT_SECRET,
46
- )
47
-
48
-
49
- def test_openshift_cost_optimization_report_create(
50
- mock_gql: Any,
51
- mock_cost_management_api: Any,
52
- mock_fetch_cost_report_secret: Any,
53
- ) -> None:
54
- openshift_cost_optimization_report_command = (
55
- OpenShiftCostOptimizationReportCommand.create()
56
- )
57
-
58
- assert isinstance(
59
- openshift_cost_optimization_report_command,
60
- OpenShiftCostOptimizationReportCommand,
61
- )
62
- assert (
63
- openshift_cost_optimization_report_command.gql_api
64
- == mock_gql.get_api.return_value
65
- )
66
- assert (
67
- openshift_cost_optimization_report_command.cost_management_api
68
- == mock_cost_management_api.create_from_secret.return_value
69
- )
70
- assert openshift_cost_optimization_report_command.thread_pool_size == 10
71
- mock_cost_management_api.create_from_secret.assert_called_once_with(
72
- COST_REPORT_SECRET
73
- )
74
- mock_fetch_cost_report_secret.assert_called_once_with(mock_gql.get_api.return_value)
75
-
76
-
77
- @pytest.fixture
78
- def openshift_cost_optimization_report_command(
79
- mock_gql: Any,
80
- mock_cost_management_api: Any,
81
- mock_fetch_cost_report_secret: Any,
82
- ) -> OpenShiftCostOptimizationReportCommand:
83
- return OpenShiftCostOptimizationReportCommand.create()
84
-
85
-
86
- @pytest.fixture
87
- def mock_get_app_names(mocker: MockerFixture) -> Any:
88
- return mocker.patch(
89
- "tools.cli_commands.cost_report.openshift_cost_optimization.get_app_names"
90
- )
91
-
92
-
93
- @pytest.fixture
94
- def mock_get_cost_namespaces(mocker: MockerFixture) -> Any:
95
- return mocker.patch(
96
- "tools.cli_commands.cost_report.openshift_cost_optimization.get_cost_namespaces"
97
- )
98
-
99
-
100
- APP = App(name="app", parent_app_name=None)
101
-
102
- APP_NAMESPACE = CostNamespace(
103
- name="some-project",
104
- labels=CostNamespaceLabels(insights_cost_management_optimizations="true"),
105
- app_name=APP.name,
106
- cluster_name="some-cluster",
107
- cluster_external_id="some-cluster-uuid",
108
- )
109
-
110
- APP_NAMESPACE_OPTIMIZATION_DISABLED = CostNamespace(
111
- name="some-project-disabled",
112
- labels=CostNamespaceLabels(),
113
- app_name=APP.name,
114
- cluster_name="some-cluster",
115
- cluster_external_id="some-cluster-uuid",
116
- )
117
-
118
-
119
- def test_openshift_cost_optimization_report_execute(
120
- openshift_cost_optimization_report_command: OpenShiftCostOptimizationReportCommand,
121
- mock_get_app_names: Any,
122
- mock_get_cost_namespaces: Any,
123
- fx: Callable,
124
- ) -> None:
125
- mock_get_app_names.return_value = []
126
- mock_get_cost_namespaces.return_value = []
127
- expected_output = fx("empty_openshift_cost_optimization_report.md")
128
-
129
- output = openshift_cost_optimization_report_command.execute()
130
-
131
- assert output.rstrip() == expected_output.rstrip()
132
-
133
-
134
- def test_openshift_cost_optimization_report_get_apps(
135
- openshift_cost_optimization_report_command: OpenShiftCostOptimizationReportCommand,
136
- mock_get_app_names: Any,
137
- ) -> None:
138
- expected_apps = [APP]
139
- mock_get_app_names.return_value = expected_apps
140
-
141
- apps = openshift_cost_optimization_report_command.get_apps()
142
-
143
- assert apps == expected_apps
144
-
145
-
146
- def test_openshift_cost_optimization_report_get_cost_namespaces(
147
- openshift_cost_optimization_report_command: OpenShiftCostOptimizationReportCommand,
148
- mock_get_cost_namespaces: Any,
149
- ) -> None:
150
- expected_namespaces = [APP_NAMESPACE]
151
- mock_get_cost_namespaces.return_value = [
152
- APP_NAMESPACE,
153
- APP_NAMESPACE_OPTIMIZATION_DISABLED,
154
- ]
155
-
156
- apps = openshift_cost_optimization_report_command.get_cost_namespaces()
157
-
158
- assert apps == expected_namespaces
159
-
160
-
161
- def test_openshift_cost_optimization_report_get_cost_namespaces_filter(
162
- openshift_cost_optimization_report_command: OpenShiftCostOptimizationReportCommand,
163
- mock_get_cost_namespaces: Any,
164
- ) -> None:
165
- expected_namespaces = [APP_NAMESPACE]
166
- mock_get_cost_namespaces.return_value = expected_namespaces
167
-
168
- apps = openshift_cost_optimization_report_command.get_cost_namespaces()
169
-
170
- assert apps == expected_namespaces
171
-
172
-
173
- def test_openshift_cost_optimization_report_get_reports(
174
- openshift_cost_optimization_report_command: OpenShiftCostOptimizationReportCommand,
175
- mock_cost_management_api: Any,
176
- ) -> None:
177
- mocked_api = mock_cost_management_api.create_from_secret.return_value
178
- mocked_api.get_openshift_cost_optimization_report.return_value = (
179
- OPENSHIFT_COST_OPTIMIZATION_RESPONSE
180
- )
181
-
182
- reports = openshift_cost_optimization_report_command.get_reports([APP_NAMESPACE])
183
-
184
- assert reports == {APP_NAMESPACE: OPENSHIFT_COST_OPTIMIZATION_RESPONSE}
185
- mocked_api.get_openshift_cost_optimization_report.assert_called_once_with(
186
- project=APP_NAMESPACE.name,
187
- cluster=APP_NAMESPACE.cluster_external_id,
188
- )
189
-
190
-
191
- def test_openshift_cost_optimization_report_get_reports_with_fuzzy_results(
192
- openshift_cost_optimization_report_command: OpenShiftCostOptimizationReportCommand,
193
- mock_cost_management_api: Any,
194
- ) -> None:
195
- mocked_api = mock_cost_management_api.create_from_secret.return_value
196
- mocked_api.get_openshift_cost_optimization_report.return_value = (
197
- OPENSHIFT_COST_OPTIMIZATION_WITH_FUZZY_MATCH_RESPONSE
198
- )
199
-
200
- reports = openshift_cost_optimization_report_command.get_reports([APP_NAMESPACE])
201
-
202
- assert reports == {APP_NAMESPACE: OPENSHIFT_COST_OPTIMIZATION_RESPONSE}
203
- mocked_api.get_openshift_cost_optimization_report.assert_called_once_with(
204
- project=APP_NAMESPACE.name,
205
- cluster=APP_NAMESPACE.cluster_external_id,
206
- )
207
-
208
-
209
- APP_REPORT = OptimizationReport(
210
- app_name=APP.name,
211
- items=[
212
- OptimizationReportItem(
213
- cluster=APP_NAMESPACE.cluster_name,
214
- project=APP_NAMESPACE.name,
215
- workload="test-deployment",
216
- workload_type="deployment",
217
- container="test",
218
- current_cpu_limit="4",
219
- current_cpu_request="1",
220
- current_memory_limit="5Gi",
221
- current_memory_request="400Mi",
222
- recommend_cpu_request="3",
223
- recommend_cpu_limit="5",
224
- recommend_memory_request="700Mi",
225
- recommend_memory_limit="6Gi",
226
- )
227
- ],
228
- )
229
-
230
-
231
- def test_openshift_cost_report_process_reports(
232
- openshift_cost_optimization_report_command: OpenShiftCostOptimizationReportCommand,
233
- ) -> None:
234
- expected_reports = [APP_REPORT]
235
-
236
- reports = openshift_cost_optimization_report_command.process_reports(
237
- apps=[APP],
238
- responses={
239
- APP_NAMESPACE: OPENSHIFT_COST_OPTIMIZATION_RESPONSE,
240
- },
241
- )
242
-
243
- assert reports == expected_reports
244
-
245
-
246
- def test_openshift_cost_report_render(
247
- openshift_cost_optimization_report_command: OpenShiftCostOptimizationReportCommand,
248
- fx: Callable,
249
- ) -> None:
250
- expected_output = fx("openshift_cost_optimization_report.md")
251
- reports = [APP_REPORT]
252
-
253
- output = openshift_cost_optimization_report_command.render(reports)
254
-
255
- assert output == expected_output
@@ -1,295 +0,0 @@
1
- from collections.abc import Callable
2
- from decimal import Decimal
3
- from typing import Any
4
-
5
- import pytest
6
- from pytest_mock import MockerFixture
7
-
8
- from reconcile.typed_queries.cost_report.app_names import App
9
- from reconcile.typed_queries.cost_report.cost_namespaces import (
10
- CostNamespace,
11
- CostNamespaceLabels,
12
- )
13
- from tools.cli_commands.cost_report.model import ChildAppReport, Report, ReportItem
14
- from tools.cli_commands.cost_report.openshift import OpenShiftCostReportCommand
15
- from tools.cli_commands.cost_report.response import OpenShiftReportCostResponse
16
- from tools.cli_commands.test.conftest import (
17
- COST_REPORT_SECRET,
18
- )
19
-
20
-
21
- @pytest.fixture
22
- def mock_gql(mocker: MockerFixture) -> Any:
23
- return mocker.patch("tools.cli_commands.cost_report.openshift.gql")
24
-
25
-
26
- @pytest.fixture
27
- def mock_cost_management_api(mocker: MockerFixture) -> Any:
28
- return mocker.patch(
29
- "tools.cli_commands.cost_report.openshift.CostManagementApi",
30
- autospec=True,
31
- )
32
-
33
-
34
- @pytest.fixture
35
- def mock_fetch_cost_report_secret(mocker: MockerFixture) -> Any:
36
- return mocker.patch(
37
- "tools.cli_commands.cost_report.openshift.fetch_cost_report_secret",
38
- return_value=COST_REPORT_SECRET,
39
- )
40
-
41
-
42
- def test_openshift_cost_report_create(
43
- mock_gql: Any,
44
- mock_cost_management_api: Any,
45
- mock_fetch_cost_report_secret: Any,
46
- ) -> None:
47
- openshift_cost_report_command = OpenShiftCostReportCommand.create()
48
-
49
- assert isinstance(openshift_cost_report_command, OpenShiftCostReportCommand)
50
- assert openshift_cost_report_command.gql_api == mock_gql.get_api.return_value
51
- assert (
52
- openshift_cost_report_command.cost_management_api
53
- == mock_cost_management_api.create_from_secret.return_value
54
- )
55
- assert openshift_cost_report_command.thread_pool_size == 10
56
- mock_cost_management_api.create_from_secret.assert_called_once_with(
57
- COST_REPORT_SECRET
58
- )
59
- mock_fetch_cost_report_secret.assert_called_once_with(mock_gql.get_api.return_value)
60
-
61
-
62
- @pytest.fixture
63
- def openshift_cost_report_command(
64
- mock_gql: Any,
65
- mock_cost_management_api: Any,
66
- mock_fetch_cost_report_secret: Any,
67
- ) -> OpenShiftCostReportCommand:
68
- return OpenShiftCostReportCommand.create()
69
-
70
-
71
- @pytest.fixture
72
- def mock_get_app_names(mocker: MockerFixture) -> Any:
73
- return mocker.patch("tools.cli_commands.cost_report.openshift.get_app_names")
74
-
75
-
76
- @pytest.fixture
77
- def mock_get_cost_namespaces(mocker: MockerFixture) -> Any:
78
- return mocker.patch("tools.cli_commands.cost_report.openshift.get_cost_namespaces")
79
-
80
-
81
- PARENT_APP = App(name="parent", parent_app_name=None)
82
- CHILD_APP = App(name="child", parent_app_name="parent")
83
-
84
- PARENT_APP_NAMESPACE = CostNamespace(
85
- name="parent_namespace",
86
- labels=CostNamespaceLabels(),
87
- app_name=PARENT_APP.name,
88
- cluster_name="parent_cluster",
89
- cluster_external_id="parent_cluster_external_id",
90
- )
91
- CHILD_APP_NAMESPACE = CostNamespace(
92
- name="child_namespace",
93
- labels=CostNamespaceLabels(),
94
- app_name=CHILD_APP.name,
95
- cluster_name="child_cluster",
96
- cluster_external_id="child_cluster_external_id",
97
- )
98
-
99
-
100
- def test_openshift_cost_report_execute(
101
- openshift_cost_report_command: OpenShiftCostReportCommand,
102
- mock_get_app_names: Any,
103
- mock_get_cost_namespaces: Any,
104
- fx: Callable,
105
- ) -> None:
106
- expected_output = fx("empty_openshift_cost_report.md")
107
-
108
- mock_get_app_names.return_value = []
109
- mock_get_cost_namespaces.return_value = []
110
-
111
- output = openshift_cost_report_command.execute()
112
-
113
- assert output.rstrip() == expected_output.rstrip()
114
-
115
-
116
- def test_openshift_cost_report_get_apps(
117
- openshift_cost_report_command: OpenShiftCostReportCommand,
118
- mock_get_app_names: Any,
119
- ) -> None:
120
- expected_apps = [PARENT_APP, CHILD_APP]
121
- mock_get_app_names.return_value = expected_apps
122
-
123
- apps = openshift_cost_report_command.get_apps()
124
-
125
- assert apps == expected_apps
126
-
127
-
128
- def test_openshift_cost_report_get_cost_namespaces(
129
- openshift_cost_report_command: OpenShiftCostReportCommand,
130
- mock_get_cost_namespaces: Any,
131
- ) -> None:
132
- expected_namespaces = [PARENT_APP_NAMESPACE, CHILD_APP_NAMESPACE]
133
- mock_get_cost_namespaces.return_value = expected_namespaces
134
-
135
- apps = openshift_cost_report_command.get_cost_namespaces()
136
-
137
- assert apps == expected_namespaces
138
-
139
-
140
- def openshift_report_cost_response_builder(
141
- delta_value: int,
142
- delta_percent: int,
143
- total: int,
144
- project: str,
145
- cluster: str,
146
- ) -> OpenShiftReportCostResponse:
147
- return OpenShiftReportCostResponse.parse_obj({
148
- "meta": {
149
- "delta": {
150
- "value": delta_value,
151
- "percent": delta_percent,
152
- },
153
- "total": {
154
- "cost": {
155
- "total": {
156
- "value": total,
157
- "units": "USD",
158
- }
159
- }
160
- },
161
- },
162
- "data": [
163
- {
164
- "date": "2024-02",
165
- "projects": [
166
- {
167
- "project": project,
168
- "values": [
169
- {
170
- "delta_value": delta_value,
171
- "delta_percent": delta_percent,
172
- "clusters": [cluster],
173
- "cost": {
174
- "total": {
175
- "value": total,
176
- "units": "USD",
177
- }
178
- },
179
- }
180
- ],
181
- },
182
- ],
183
- }
184
- ],
185
- })
186
-
187
-
188
- PARENT_APP_COST_RESPONSE = openshift_report_cost_response_builder(
189
- delta_value=100,
190
- delta_percent=10,
191
- total=1100,
192
- project=PARENT_APP_NAMESPACE.name,
193
- cluster=PARENT_APP_NAMESPACE.cluster_name,
194
- )
195
-
196
- CHILD_APP_COST_RESPONSE = openshift_report_cost_response_builder(
197
- delta_value=200,
198
- delta_percent=10,
199
- total=2200,
200
- project=CHILD_APP_NAMESPACE.name,
201
- cluster=CHILD_APP_NAMESPACE.cluster_name,
202
- )
203
-
204
-
205
- def test_openshift_cost_report_get_reports(
206
- openshift_cost_report_command: OpenShiftCostReportCommand,
207
- mock_cost_management_api: Any,
208
- ) -> None:
209
- mocked_api = mock_cost_management_api.create_from_secret.return_value
210
- mocked_api.get_openshift_costs_report.return_value = PARENT_APP_COST_RESPONSE
211
-
212
- reports = openshift_cost_report_command.get_reports([PARENT_APP_NAMESPACE])
213
-
214
- assert reports == {PARENT_APP_NAMESPACE: PARENT_APP_COST_RESPONSE}
215
- mocked_api.get_openshift_costs_report.assert_called_once_with(
216
- project=PARENT_APP_NAMESPACE.name,
217
- cluster=PARENT_APP_NAMESPACE.cluster_external_id,
218
- )
219
-
220
-
221
- PARENT_APP_REPORT = Report(
222
- app_name="parent",
223
- parent_app_name=None,
224
- child_apps=[
225
- ChildAppReport(name="child", total=Decimal(2200)),
226
- ],
227
- child_apps_total=Decimal(2200),
228
- date="2024-02",
229
- items=[
230
- ReportItem(
231
- name=f"{PARENT_APP_NAMESPACE.cluster_name}/{PARENT_APP_NAMESPACE.name}",
232
- delta_value=Decimal(100),
233
- delta_percent=10,
234
- total=Decimal(1100),
235
- )
236
- ],
237
- items_total=Decimal(1100),
238
- items_delta_value=Decimal(100),
239
- items_delta_percent=10,
240
- total=Decimal(3300),
241
- )
242
-
243
- CHILD_APP_REPORT = Report(
244
- app_name="child",
245
- parent_app_name="parent",
246
- child_apps=[],
247
- child_apps_total=Decimal(0),
248
- date="2024-02",
249
- items=[
250
- ReportItem(
251
- name=f"{CHILD_APP_NAMESPACE.cluster_name}/{CHILD_APP_NAMESPACE.name}",
252
- delta_value=Decimal(200),
253
- delta_percent=10,
254
- total=Decimal(2200),
255
- )
256
- ],
257
- items_total=Decimal(2200),
258
- items_delta_value=Decimal(200),
259
- items_delta_percent=10,
260
- total=Decimal(2200),
261
- )
262
-
263
-
264
- def test_openshift_cost_report_process_reports(
265
- openshift_cost_report_command: OpenShiftCostReportCommand,
266
- ) -> None:
267
- expected_reports = {
268
- "parent": PARENT_APP_REPORT,
269
- "child": CHILD_APP_REPORT,
270
- }
271
-
272
- reports = openshift_cost_report_command.process_reports(
273
- apps=[PARENT_APP, CHILD_APP],
274
- responses={
275
- PARENT_APP_NAMESPACE: PARENT_APP_COST_RESPONSE,
276
- CHILD_APP_NAMESPACE: CHILD_APP_COST_RESPONSE,
277
- },
278
- )
279
-
280
- assert reports == expected_reports
281
-
282
-
283
- def test_openshift_cost_report_render(
284
- openshift_cost_report_command: OpenShiftCostReportCommand,
285
- fx: Callable,
286
- ) -> None:
287
- expected_output = fx("openshift_cost_report.md")
288
- reports = {
289
- "parent": PARENT_APP_REPORT,
290
- "child": CHILD_APP_REPORT,
291
- }
292
-
293
- output = openshift_cost_report_command.render(reports)
294
-
295
- assert output == expected_output
@@ -1,70 +0,0 @@
1
- from typing import Any
2
- from unittest.mock import create_autospec
3
-
4
- import pytest
5
- from pytest_mock import MockerFixture
6
-
7
- from reconcile.gql_definitions.common.app_interface_vault_settings import (
8
- AppInterfaceSettingsV1,
9
- )
10
- from reconcile.gql_definitions.cost_report.settings import CostReportSettingsV1
11
- from reconcile.gql_definitions.fragments.vault_secret import VaultSecret
12
- from reconcile.utils.gql import GqlApi
13
- from tools.cli_commands.cost_report.util import fetch_cost_report_secret
14
- from tools.cli_commands.test.conftest import (
15
- COST_REPORT_SECRET,
16
- )
17
-
18
- VAULT_SETTINGS = AppInterfaceSettingsV1(vault=True)
19
- COST_REPORT_SETTINGS = CostReportSettingsV1(
20
- credentials=VaultSecret(
21
- path="some-path",
22
- field="all",
23
- version=None,
24
- format=None,
25
- )
26
- )
27
-
28
-
29
- @pytest.fixture
30
- def mock_get_app_interface_vault_settings(mocker: MockerFixture) -> Any:
31
- return mocker.patch(
32
- "tools.cli_commands.cost_report.util.get_app_interface_vault_settings",
33
- return_value=VAULT_SETTINGS,
34
- )
35
-
36
-
37
- @pytest.fixture
38
- def mock_create_secret_reader(mocker: MockerFixture) -> Any:
39
- mock = mocker.patch(
40
- "tools.cli_commands.cost_report.util.create_secret_reader",
41
- autospec=True,
42
- )
43
- mock.return_value.read_all_secret.return_value = COST_REPORT_SECRET
44
- return mock
45
-
46
-
47
- @pytest.fixture
48
- def mock_get_cost_report_settings(mocker: MockerFixture) -> Any:
49
- return mocker.patch(
50
- "tools.cli_commands.cost_report.util.get_cost_report_settings",
51
- return_value=COST_REPORT_SETTINGS,
52
- )
53
-
54
-
55
- def test_fetch_cost_report_secret(
56
- mock_get_app_interface_vault_settings: Any,
57
- mock_create_secret_reader: Any,
58
- mock_get_cost_report_settings: Any,
59
- ) -> None:
60
- mock_gql_api = create_autospec(GqlApi)
61
-
62
- secret = fetch_cost_report_secret(mock_gql_api)
63
-
64
- assert secret == COST_REPORT_SECRET
65
- mock_get_app_interface_vault_settings.assert_called_once_with(mock_gql_api.query)
66
- mock_get_cost_report_settings.assert_called_once_with(mock_gql_api)
67
- mock_create_secret_reader.assert_called_once_with(use_vault=True)
68
- mock_create_secret_reader.return_value.read_all_secret.assert_called_once_with(
69
- COST_REPORT_SETTINGS.credentials
70
- )
tools/test/__init__.py DELETED
File without changes
tools/test/conftest.py DELETED
@@ -1,77 +0,0 @@
1
- from collections.abc import (
2
- Callable,
3
- Iterable,
4
- Mapping,
5
- MutableMapping,
6
- )
7
- from pathlib import Path
8
- from typing import Any
9
-
10
- import pytest
11
- from pydantic import BaseModel
12
- from pydantic.error_wrappers import ValidationError
13
-
14
- from reconcile.typed_queries.saas_files import SaasFile
15
- from reconcile.utils.models import data_default_none
16
-
17
-
18
- class GQLClassFactoryError(Exception):
19
- pass
20
-
21
-
22
- @pytest.fixture
23
- def saas_files_builder(
24
- gql_class_factory: Callable[[type[SaasFile], Mapping], SaasFile],
25
- ) -> Callable[[Iterable[MutableMapping]], list[SaasFile]]:
26
- def builder(data: Iterable[MutableMapping]) -> list[SaasFile]:
27
- for d in data:
28
- if "app" not in d:
29
- d["app"] = {}
30
- if "pipelinesProvider" not in d:
31
- d["pipelinesProvider"] = {}
32
- if "managedResourceTypes" not in d:
33
- d["managedResourceTypes"] = []
34
- if "imagePatterns" not in d:
35
- d["imagePatterns"] = []
36
- for rt in d.get("resourceTemplates", []):
37
- for t in rt.get("targets", []):
38
- ns = t["namespace"]
39
- if "name" not in ns:
40
- ns["name"] = "some_name"
41
- if "environment" not in ns:
42
- ns["environment"] = {}
43
- if "app" not in ns:
44
- ns["app"] = {}
45
- if "cluster" not in ns:
46
- ns["cluster"] = {}
47
- return [gql_class_factory(SaasFile, d) for d in data]
48
-
49
- return builder
50
-
51
-
52
- @pytest.fixture
53
- def fx() -> Callable:
54
- def _fx(name: str) -> str:
55
- return (Path(__file__).parent / "fixtures" / name).read_text()
56
-
57
- return _fx
58
-
59
-
60
- @pytest.fixture
61
- def gql_class_factory() -> Callable[
62
- [type[BaseModel], MutableMapping[str, Any] | None],
63
- BaseModel,
64
- ]:
65
- """Create a GQL class from a fixture and set default values to None."""
66
-
67
- def _gql_class_factory(
68
- klass: type[BaseModel], data: MutableMapping[str, Any] | None = None
69
- ) -> BaseModel:
70
- try:
71
- return klass(**data_default_none(klass, data or {}))
72
- except ValidationError as e:
73
- msg = "[gql_class_factory] Your given data does not match the class ...\n"
74
- msg += "\n".join([str(m) for m in list(e.raw_errors)])
75
- raise GQLClassFactoryError(msg) from e
76
-
77
- return _gql_class_factory