Skip to content

Commit

Permalink
Merge branch 'main' into COST-tweak-polling-batch
Browse files Browse the repository at this point in the history
  • Loading branch information
lcouzens committed Jun 28, 2024
2 parents 86e0b93 + 1810fa1 commit a655b3d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 36 deletions.
14 changes: 5 additions & 9 deletions build_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ function job_cleanup() {

trap job_cleanup EXIT ERR SIGINT SIGTERM

DOCKER_CONF="$TMP_JOB_DIR/.docker"
mkdir -p "$DOCKER_CONF"
docker --config="$DOCKER_CONF" login -u="$QUAY_USER" -p="$QUAY_TOKEN" quay.io
docker --config="$DOCKER_CONF" build --build-arg GIT_COMMIT="$GIT_COMMIT" -t "${IMAGE}:${IMAGE_TAG}" .
docker --config="$DOCKER_CONF" push "${IMAGE}:${IMAGE_TAG}"
podman login -u="$QUAY_USER" -p="$QUAY_TOKEN" quay.io
podman build --build-arg GIT_COMMIT="$GIT_COMMIT" -t "${IMAGE}:${IMAGE_TAG}" .
podman push "${IMAGE}:${IMAGE_TAG}"

docker --config="$DOCKER_CONF" tag "${IMAGE}:${IMAGE_TAG}" "${IMAGE}:latest"
docker --config="$DOCKER_CONF" push "${IMAGE}:latest"

docker --config="$DOCKER_CONF" logout
podman tag "${IMAGE}:${IMAGE_TAG}" "${IMAGE}:latest"
podman push "${IMAGE}:latest"
18 changes: 13 additions & 5 deletions koku/api/report/ocp/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@
DISTRIBUTED_COST_INTERNAL = {"distributed_cost": "cost_total_distributed"}


def order_by_field_requires_group_by(data, order_name, group_by_key):
def order_by_field_requires_group_by(data, order_name, group_by_keys):
error = {}
if order_name in data.get("order_by", {}) and group_by_key not in data.get("group_by", {}):
error["order_by"] = gettext(f"Cannot order by field {order_name} without grouping by {group_by_key}.")
raise serializers.ValidationError(error)
if order_name in data.get("order_by", {}):
# Ensure group_by_keys is a list of keys to check
if not isinstance(group_by_keys, list):
group_by_keys = [group_by_keys]

# Check if none of the required group_by keys are present
if not any(key in data.get("group_by", {}) for key in group_by_keys):
error["order_by"] = gettext(
f"Cannot order by field {order_name} without grouping by one of {', '.join(group_by_keys)}."
)
raise serializers.ValidationError(error)


class OCPGroupBySerializer(GroupSerializer):
Expand Down Expand Up @@ -165,7 +173,7 @@ def validate(self, data):
error["order_by"] = gettext("Cannot order by delta without a delta param")
raise serializers.ValidationError(error)
order_by_field_requires_group_by(data, DISTRIBUTED_COST_INTERNAL["distributed_cost"], "project")
order_by_field_requires_group_by(data, "storage_class", "persistentvolumeclaim")
order_by_field_requires_group_by(data, "storage_class", ["persistentvolumeclaim", "storageclass"])
order_by_field_requires_group_by(data, "persistentvolumeclaim", "persistentvolumeclaim")
if data.get("delta") == DISTRIBUTED_COST_INTERNAL["distributed_cost"] and "project" not in data.get(
"group_by", {}
Expand Down
47 changes: 25 additions & 22 deletions koku/api/report/test/ocp/test_ocp_query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,31 @@ def test_cpu_memory_order_bys(self):

def test_storage_class_order_bys(self):
"""Test that we can order by the pvc values."""
url = "?group_by[project]=*&group_by[persistentvolumeclaim]=*&order_by[storage_class]=desc"
query_params = self.mocked_query_params(url, OCPVolumeView)
handler = OCPReportQueryHandler(query_params)
query_data = handler.execute_query()
self.assertIsNotNone(query_data.get("data"))
self.assertIsNotNone(query_data.get("total"))
self.assertIsNotNone(query_data["total"].get("storage_class"))
first_date = query_data["data"][0]
tested = False
for cluster in first_date.get("projects", []):
pvc_list = cluster.get("persistentvolumeclaims")
storage_class_order_result = []
expected = None
for pvc in pvc_list:
for pvc_value in pvc.get("values", []):
storage_class_order_result.append(pvc_value.get("storage_class"))
if not expected:
expected = deepcopy(storage_class_order_result)
expected.sort(reverse=True)
self.assertEqual(storage_class_order_result, expected)
tested = True
self.assertTrue(tested)
group_bys = ["persistentvolumeclaim", "storageclass"]
for group_by in group_bys:
with self.subTest(group_by=group_by):
url = f"?group_by[project]=*&group_by[{group_by}]=*&order_by[storage_class]=desc"
query_params = self.mocked_query_params(url, OCPVolumeView)
handler = OCPReportQueryHandler(query_params)
query_data = handler.execute_query()
self.assertIsNotNone(query_data.get("data"))
self.assertIsNotNone(query_data.get("total"))
self.assertIsNotNone(query_data["total"].get("storage_class"))
first_date = query_data["data"][0]
tested = False
for project in first_date.get("projects", []):
group_list = project.get(f"{group_by}s")
storage_class_order_result = []
expected = None
for element in group_list:
for element_value in element.get("values", []):
storage_class_order_result.append(element_value.get("storage_class"))
if not expected:
expected = deepcopy(storage_class_order_result)
expected.sort(reverse=True)
self.assertEqual(storage_class_order_result, expected)
tested = True
self.assertTrue(tested)

def test_persistentvolumeclaim_order_by(self):
"""Test that we can order by the pvc values."""
Expand Down

0 comments on commit a655b3d

Please sign in to comment.