Skip to content

Commit

Permalink
[COST-5919] Update OCP VMs provider map (#5512)
Browse files Browse the repository at this point in the history
* Update OCP VMs provider map.

* add simple unit test

---------

Co-authored-by: maskarb <[email protected]>
  • Loading branch information
bacciotti and maskarb authored Feb 26, 2025
1 parent 5976aaa commit 7fb214e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
22 changes: 22 additions & 0 deletions koku/api/report/ocp/provider_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,17 @@ def __init__(self, provider, report_type, schema_name):
"request_memory": Sum("pod_request_memory_gigabyte_hours") / 24,
"request_cpu_units": Max(Value("Core", output_field=CharField())),
"request_memory_units": Max(Value("GiB", output_field=CharField())),
"cost_total_distributed": self.cloud_infrastructure_cost
+ self.markup_cost
+ self.cost_model_cost
+ self.distributed_platform_cost
+ self.distributed_worker_cost
+ self.distributed_unattributed_network_cost
+ self.distributed_unattributed_storage_cost,
"cost_platform_distributed": self.distributed_platform_cost,
"cost_worker_unallocated_distributed": self.distributed_worker_cost,
"cost_network_unattributed_distributed": self.distributed_unattributed_network_cost,
"cost_storage_unattributed_distributed": self.distributed_unattributed_storage_cost,
},
"capacity_aggregate": {},
"annotations": {
Expand All @@ -819,6 +830,17 @@ def __init__(self, provider, report_type, schema_name):
"request_memory": Max("pod_request_memory_gigabyte_hours") / 24,
"request_cpu_units": Value("Core", output_field=CharField()),
"request_memory_units": Value("GiB", output_field=CharField()),
"cost_total_distributed": self.cloud_infrastructure_cost
+ self.markup_cost
+ self.cost_model_cost
+ self.distributed_platform_cost
+ self.distributed_worker_cost
+ self.distributed_unattributed_network_cost
+ self.distributed_unattributed_storage_cost,
"cost_platform_distributed": self.distributed_platform_cost,
"cost_worker_unallocated_distributed": self.distributed_worker_cost,
"cost_network_unattributed_distributed": self.distributed_unattributed_network_cost,
"cost_storage_unattributed_distributed": self.distributed_unattributed_storage_cost,
"cluster": Max(Coalesce("cluster_alias", "cluster_id")),
"node": Max(F("node")),
"project": Max("namespace"),
Expand Down
27 changes: 24 additions & 3 deletions koku/api/report/test/ocp/view/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,27 @@ def test_execute_query_ocp_costs_group_by_project__distributed_costs(self):
self.assertNotEqual(distributed_cost, Decimal(0))
self.assertAlmostEqual(distributed_cost, expected_total, 6)

def test_virtual_machines_distributed_costs(self):
"""Test that the virtual machines endpoint returns distributed costs."""
url = reverse("reports-openshift-virtual-machines")
client = APIClient()
response = client.get(url, **self.headers)
self.assertEqual(response.status_code, status.HTTP_200_OK)

data = response.data

meta_total_cost = data.get("meta", {}).get("total", {}).get("cost", {})
expected_dist_cost_keys = {
"platform_distributed",
"worker_unallocated_distributed",
"network_unattributed_distributed",
"storage_unattributed_distributed",
}
self.assertTrue(
expected_dist_cost_keys.issubset(meta_total_cost),
f"Missing {expected_dist_cost_keys.difference(meta_total_cost)}",
)

def test_execute_query_ocp_costs_with_delta(self):
"""Test that deltas work for costs."""
url = reverse("reports-openshift-costs")
Expand Down Expand Up @@ -1335,7 +1356,7 @@ def test_execute_query_with_group_by_order_by_and_limit(self):
"filter[limit]": 5,
}

url = f'{reverse("reports-openshift-cpu")}?' + urlencode(params, quote_via=quote_plus)
url = f"{reverse('reports-openshift-cpu')}?" + urlencode(params, quote_via=quote_plus)
response = client.get(url, **self.headers)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -1385,7 +1406,7 @@ def test_order_by_distributed_cost_ranked_list(self):
"filter[limit]": limit_size,
"filter[offset]": 0,
}
url = f'{reverse("reports-openshift-costs")}?' + urlencode(params, quote_via=quote_plus)
url = f"{reverse('reports-openshift-costs')}?" + urlencode(params, quote_via=quote_plus)
response = client.get(url, **self.headers)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down Expand Up @@ -1427,7 +1448,7 @@ def test_execute_query_with_group_by_project_order_by_distributed_cost(self):
"filter[limit]": 5,
}

url = f'{reverse("reports-openshift-costs")}?' + urlencode(params, quote_via=quote_plus)
url = f"{reverse('reports-openshift-costs')}?" + urlencode(params, quote_via=quote_plus)
response = client.get(url, **self.headers)
self.assertEqual(response.status_code, status.HTTP_200_OK)

Expand Down

0 comments on commit 7fb214e

Please sign in to comment.