From 83a7764ec955b48f0270d657ea11624f41e07610 Mon Sep 17 00:00:00 2001 From: Jakub Smolar Date: Thu, 20 Jun 2024 16:01:28 +0200 Subject: [PATCH] Update KuadrantCR sub-component deployment reference --- testsuite/openshift/__init__.py | 1 + testsuite/openshift/authorino.py | 3 ++- testsuite/openshift/kuadrant.py | 14 ++++++-------- testsuite/openshift/limitador.py | 16 ++++++++++++++++ .../cr_configuration/test_reconcile_limitador.py | 8 ++++---- 5 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 testsuite/openshift/limitador.py diff --git a/testsuite/openshift/__init__.py b/testsuite/openshift/__init__.py index e00ce42e..0589be97 100644 --- a/testsuite/openshift/__init__.py +++ b/testsuite/openshift/__init__.py @@ -58,6 +58,7 @@ def safe_apply(self): """ result, status = self.modify_and_apply(lambda _: True, retries=2) assert status, f"Unable to apply changes for APIObject with result: {result}" + self.refresh() return result def wait_for_ready(self): diff --git a/testsuite/openshift/authorino.py b/testsuite/openshift/authorino.py index 85a43e9f..4f46ffcb 100644 --- a/testsuite/openshift/authorino.py +++ b/testsuite/openshift/authorino.py @@ -9,6 +9,7 @@ from testsuite.lifecycle import LifecycleObject from testsuite.openshift import CustomResource from testsuite.openshift.client import OpenShiftClient +from testsuite.openshift.deployment import Deployment from testsuite.utils import asdict @@ -90,7 +91,7 @@ def create_instance( def deployment(self): """Returns Deployment object for this Authorino""" with self.context: - return selector(f"deployment/{self.name()}").object() + return selector(f"deployment/{self.name()}").object(cls=Deployment) @property def metrics_service(self): diff --git a/testsuite/openshift/kuadrant.py b/testsuite/openshift/kuadrant.py index 693b102f..93a4c28d 100644 --- a/testsuite/openshift/kuadrant.py +++ b/testsuite/openshift/kuadrant.py @@ -21,6 +21,12 @@ def __init__(self, kuadrant_cr, spec_name): self.kuadrant_cr = kuadrant_cr self.spec_name = spec_name + @property + def deployment(self): + """Returns Deployment object for CR""" + with self.context: + return selector("deployment", labels={"app": self.spec_name}).object(cls=Deployment) + def __getitem__(self, name): return self.kuadrant_cr.model.spec[self.spec_name][name] @@ -40,8 +46,6 @@ def __getattr__(self, item): class KuadrantCR(CustomResource): """Represents Kuadrant CR objects""" - LIMITADOR = "limitador-limitador" - @property def authorino(self) -> KuadrantSection: """Returns spec.authorino from Kuadrant object""" @@ -53,9 +57,3 @@ def limitador(self) -> KuadrantSection: """Returns spec.limitador from Kuadrant object""" self.model.spec.setdefault("limitador", {}) return KuadrantSection(self, "limitador") - - @property - def limitador_deployment(self): - """Returns Deployment object for this Authorino""" - with self.context: - return selector(f"deployment/{self.LIMITADOR}").object(cls=Deployment) diff --git a/testsuite/openshift/limitador.py b/testsuite/openshift/limitador.py new file mode 100644 index 00000000..c18584d1 --- /dev/null +++ b/testsuite/openshift/limitador.py @@ -0,0 +1,16 @@ +"""Limitador CR object""" + +from openshift_client import selector + +from testsuite.openshift import CustomResource +from testsuite.openshift.deployment import Deployment + + +class LimitadorCR(CustomResource): + """Represents Limitador CR objects""" + + @property + def deployment(self) -> Deployment: + """Returns Deployment object for this Limitador""" + with self.context: + return selector(f"deployment/{self.name()}").object(cls=Deployment) diff --git a/testsuite/tests/kuadrant/reconciliation/cr_configuration/test_reconcile_limitador.py b/testsuite/tests/kuadrant/reconciliation/cr_configuration/test_reconcile_limitador.py index 153fccfe..26ff8303 100644 --- a/testsuite/tests/kuadrant/reconciliation/cr_configuration/test_reconcile_limitador.py +++ b/testsuite/tests/kuadrant/reconciliation/cr_configuration/test_reconcile_limitador.py @@ -40,7 +40,7 @@ def test_replicas_field_to_reconcile(kuadrant): kuadrant.wait_for_ready() assert kuadrant.limitador["replicas"] == 2 - assert kuadrant.limitador_deployment.model.spec["replicas"] == 2 + assert kuadrant.limitador.deployment.model.spec["replicas"] == 2 def test_resource_requirements_field_to_reconcile(kuadrant): @@ -57,7 +57,7 @@ def test_resource_requirements_field_to_reconcile(kuadrant): kuadrant.wait_for_ready() assert kuadrant.limitador["resourceRequirements"] == asdict(value) - assert kuadrant.limitador_deployment.model.spec.template.spec.containers[0]["resources"] == asdict(value) + assert kuadrant.limitador.deployment.model.spec.template.spec.containers[0]["resources"] == asdict(value) @pytest.mark.xfail @@ -79,7 +79,7 @@ def test_blank_fields_wont_reconcile(kuadrant): kuadrant.safe_apply() kuadrant.wait_for_ready() - assert kuadrant.limitador_deployment.model.spec.replicas == 3 - assert kuadrant.limitador_deployment.model.spec.template.spec.containers[0]["resources"] == asdict( + assert kuadrant.limitador.deployment.model.spec.replicas == 3 + assert kuadrant.limitador.deployment.model.spec.template.spec.containers[0]["resources"] == asdict( ContainerResources(requests_cpu="250m", requests_memory="32Mi") )