From beb409003d0f8a6b9128ba9b1e55b7bfeaa28e63 Mon Sep 17 00:00:00 2001 From: Matej Dujava Date: Thu, 7 Mar 2024 12:46:58 +0100 Subject: [PATCH 1/6] Search for deployments first, use dc as fallback problems with ImageStream or builds are tracked in #816 --- testsuite/dynaconf_loader.py | 10 +++- testsuite/gateways/apicast/__init__.py | 9 +++- testsuite/gateways/apicast/operator.py | 9 +++- testsuite/gateways/apicast/system.py | 8 ++- testsuite/openshift/deployments.py | 6 ++- testsuite/openshift/scaler.py | 10 +++- .../parameters/test_modular_apicast.py | 10 +++- .../parameters/test_policy_dependency.py | 10 +++- .../on_failed/test_onfailed_custom_policy.py | 10 +++- testsuite/tests/images/test_images_check.py | 51 ++++++++++++++----- .../tests/prometheus/zync/test_annotations.py | 14 +++-- 11 files changed, 115 insertions(+), 32 deletions(-) diff --git a/testsuite/dynaconf_loader.py b/testsuite/dynaconf_loader.py index 132c09b9..f2f0ac3e 100644 --- a/testsuite/dynaconf_loader.py +++ b/testsuite/dynaconf_loader.py @@ -60,6 +60,7 @@ def _guess_version(ocp, namespace): """Attempt to determine version from amp-system imagestream""" version = None + # TODO: ImageStreams are no longer used by 3scale; https://github.com/3scale-qe/3scale-tests/issues/816 try: version = ocp.image_stream_tag_from_trigger("dc/apicast-production") Version(version) @@ -99,8 +100,13 @@ def _guess_apicast_operator_version(ocp, settings): def _apicast_image(ocp): """Find source of amp-apicast image""" - lookup = ocp.do_action("get", ["dc/apicast-production", "-o", "yaml"], parse_output=True) - return lookup.model.spec.template.spec.containers[0].image + # dc are replaced with deployments in 2.15-dev + try: + lookup = ocp.do_action("get", ["deployment/apicast-production", "-o", "yaml"], parse_output=True) + return lookup.model.spec.template.spec.containers[0].image + except OpenShiftPythonException: + lookup = ocp.do_action("get", ["dc/apicast-production", "-o", "yaml"], parse_output=True) + return lookup.model.spec.template.spec.containers[0].image def _rhsso_password(tools_config, rhsso_config): diff --git a/testsuite/gateways/apicast/__init__.py b/testsuite/gateways/apicast/__init__.py index 3c9b605f..ac7d4e5d 100644 --- a/testsuite/gateways/apicast/__init__.py +++ b/testsuite/gateways/apicast/__init__.py @@ -5,6 +5,8 @@ from typing import Optional, List, Dict, Tuple import logging +from openshift_client import OpenShiftPythonException + from threescale_api.resources import Service from testsuite.capabilities import Capability @@ -82,7 +84,12 @@ def setup_tls(self, secret_name, https_port): @property def deployment(self) -> Deployment: """Gateway deployment""" - return self.openshift.deployment(f"dc/{self.name}") + # dc are replaced with deployments in 2.15-dev + try: + self.openshift.do_action("get", [f"deployment/{self.name}"]) + return self.openshift.deployment(f"deployment/{self.name}") + except OpenShiftPythonException: + return self.openshift.deployment(f"dc/{self.name}") def _routename(self, service): """name of route for given service""" diff --git a/testsuite/gateways/apicast/operator.py b/testsuite/gateways/apicast/operator.py index 8731b33a..12cac84f 100644 --- a/testsuite/gateways/apicast/operator.py +++ b/testsuite/gateways/apicast/operator.py @@ -4,6 +4,8 @@ import time from typing import Dict, Callable, Pattern, Any, Match, Union +from openshift_client import OpenShiftPythonException + from weakget import weakget from testsuite import settings @@ -153,7 +155,12 @@ def fits(openshift: OpenShiftClient): @property def deployment(self): - return self.openshift.deployment(f"deployment/apicast-{self.name}") + # dc are replaced with deployments in 2.15-dev + try: + self.openshift.do_action("get", [f"deployment/apicast-{self.name}"]) + return self.openshift.deployment(f"deployment/apicast-{self.name}") + except OpenShiftPythonException: + return self.openshift.deployment(f"dc/apicast-{self.name}") @property def environ(self) -> Properties: diff --git a/testsuite/gateways/apicast/system.py b/testsuite/gateways/apicast/system.py index 5fe0a227..039d1eb7 100644 --- a/testsuite/gateways/apicast/system.py +++ b/testsuite/gateways/apicast/system.py @@ -39,7 +39,13 @@ def __init__(self, staging: bool, openshift: "Optional[OpenShiftClient]" = None) @property def deployment(self): """Return deployment config name of this apicast""" - return self.openshift.deployment("dc/apicast-staging" if self.staging else "dc/apicast-production") + # dc are replaced with deployments in 2.15-dev + name = "apicast-staging" if self.staging else "apicast-production" + try: + self.openshift.do_action("get", [f"deployment/{name}"]) + return self.openshift.deployment(f"deployment/{name}") + except OpenShiftPythonException: + return self.openshift.deployment(f"dc/{name}") @property def environ(self) -> Properties: diff --git a/testsuite/openshift/deployments.py b/testsuite/openshift/deployments.py index 33cf231e..705427b4 100644 --- a/testsuite/openshift/deployments.py +++ b/testsuite/openshift/deployments.py @@ -184,7 +184,11 @@ def wait_for(self, timeout: int = 90): def get_pods(self): """Kubernetes Deployment doesnt have a nice universal way how to get the correct pods, so this method relies on pods having the deployment label""" - return self.openshift.select_resource("pods", labels={"deployment": self.name}) + + def select_pod(apiobject): + return apiobject.get_label("deployment") == self.name + + return self.openshift.select_resource("pods", narrow_function=select_pod) class DeploymentConfig(Deployment): diff --git a/testsuite/openshift/scaler.py b/testsuite/openshift/scaler.py index 0b4bd8c2..f5625289 100644 --- a/testsuite/openshift/scaler.py +++ b/testsuite/openshift/scaler.py @@ -3,7 +3,9 @@ import typing from contextlib import contextmanager -from testsuite.openshift.deployments import DeploymentConfig +from openshift_client import OpenShiftPythonException + +from testsuite.openshift.deployments import DeploymentConfig, KubernetesDeployment if typing.TYPE_CHECKING: from testsuite.openshift.client import OpenShiftClient @@ -34,7 +36,11 @@ def _scale_component(self, deployment_name, replicas, wait_for_replicas=None): if self.operator_deploy: apimanager_func = getattr(self.apimanager, self.DEPLOYMENT_MAPPINGS[deployment_name]) return apimanager_func(replicas, wait_for_replicas=wait_for_replicas) - deployment = DeploymentConfig(self.client, f"dc/{deployment_name}") + try: + self.client.do_action("get", [f"deployment/{deployment_name}"]) + deployment = KubernetesDeployment(self.client, f"deployment/{deployment_name}") + except OpenShiftPythonException: + deployment = DeploymentConfig(self.client, f"dc/{deployment_name}") previous_replicas = deployment.get_replicas() deployment.scale(replicas) return previous_replicas diff --git a/testsuite/tests/apicast/parameters/test_modular_apicast.py b/testsuite/tests/apicast/parameters/test_modular_apicast.py index 6f9e4df6..0bb5b975 100644 --- a/testsuite/tests/apicast/parameters/test_modular_apicast.py +++ b/testsuite/tests/apicast/parameters/test_modular_apicast.py @@ -12,11 +12,13 @@ import importlib_resources as resources import pytest +from openshift_client import OpenShiftPythonException + from testsuite import rawobj from testsuite.capabilities import Capability from testsuite.gateways.apicast.operator import OperatorApicast from testsuite.gateways.apicast.template import TemplateApicast -from testsuite.utils import blame +from testsuite.utils import blame, warn_and_skip pytestmark = [ pytest.mark.required_capabilities(Capability.STANDARD_GATEWAY, Capability.CUSTOM_ENVIRONMENT), @@ -61,7 +63,11 @@ def set_gateway_image(openshift, staging_gateway, request, testconfig): github_template = resources.files("testsuite.resources.modular_apicast").joinpath("example_policy.yml") copy_template = resources.files("testsuite.resources.modular_apicast").joinpath("example_policy_copy.yml") - amp_release = openshift().image_stream_tag_from_trigger("dc/apicast-production") + try: + amp_release = openshift().image_stream_tag_from_trigger("dc/apicast-production") + except OpenShiftPythonException: + warn_and_skip("ImageStream not found.") + project = openshift().project_name build_name_github = blame(request, "apicast-example-policy-github") build_name_copy = blame(request, "apicast-example-policy-copy") diff --git a/testsuite/tests/apicast/parameters/test_policy_dependency.py b/testsuite/tests/apicast/parameters/test_policy_dependency.py index c6f884bc..b6aff5e7 100644 --- a/testsuite/tests/apicast/parameters/test_policy_dependency.py +++ b/testsuite/tests/apicast/parameters/test_policy_dependency.py @@ -10,11 +10,13 @@ from lxml import etree from lxml.etree import XMLSyntaxError +from openshift_client import OpenShiftPythonException + from testsuite import rawobj from testsuite.capabilities import Capability from testsuite.gateways.apicast.operator import OperatorApicast from testsuite.gateways.apicast.template import TemplateApicast -from testsuite.utils import blame +from testsuite.utils import blame, warn_and_skip pytestmark = [ pytest.mark.required_capabilities(Capability.STANDARD_GATEWAY, Capability.CUSTOM_ENVIRONMENT), @@ -58,7 +60,11 @@ def set_gateway_image(openshift, staging_gateway, request, testconfig): template = resources.files("testsuite.resources.modular_apicast").joinpath("xml_policy.yml") - amp_release = openshift().image_stream_tag_from_trigger("dc/apicast-production") + try: + amp_release = openshift().image_stream_tag_from_trigger("dc/apicast-production") + except (OpenShiftPythonException, ValueError): + warn_and_skip("ImageStream not found.") + project = openshift().project_name build_name = blame(request, "apicast-xml-policy") diff --git a/testsuite/tests/apicast/policy/on_failed/test_onfailed_custom_policy.py b/testsuite/tests/apicast/policy/on_failed/test_onfailed_custom_policy.py index b088b15f..807a86fc 100644 --- a/testsuite/tests/apicast/policy/on_failed/test_onfailed_custom_policy.py +++ b/testsuite/tests/apicast/policy/on_failed/test_onfailed_custom_policy.py @@ -7,10 +7,12 @@ import importlib_resources as resources import pytest +from openshift_client import OpenShiftPythonException + from testsuite.capabilities import Capability from testsuite.gateways import gateway from testsuite.gateways.apicast.selfmanaged import SelfManagedApicast -from testsuite.utils import blame +from testsuite.utils import blame, warn_and_skip pytestmark = [ pytest.mark.required_capabilities(Capability.STANDARD_GATEWAY, Capability.CUSTOM_ENVIRONMENT), @@ -33,7 +35,11 @@ def set_gateway_image(openshift, staging_gateway, request, testconfig): github_template = resources.files("testsuite.resources.modular_apicast").joinpath("example_policy.yml") - amp_release = openshift().image_stream_tag_from_trigger("dc/apicast-production") + try: + amp_release = openshift().image_stream_tag_from_trigger("dc/apicast-production") + except (OpenShiftPythonException, ValueError): + warn_and_skip("ImageStream not found.") + project = openshift().project_name build_name_github = blame(request, "apicast-example-policy-github") diff --git a/testsuite/tests/images/test_images_check.py b/testsuite/tests/images/test_images_check.py index 0c584dba..0c16143e 100644 --- a/testsuite/tests/images/test_images_check.py +++ b/testsuite/tests/images/test_images_check.py @@ -2,25 +2,36 @@ import pytest +from packaging.version import Version # noqa # pylint: disable=unused-import + +from openshift_client import OpenShiftPythonException + from testsuite.gateways import gateway from testsuite.gateways.apicast.operator import OperatorApicast from testsuite.utils import blame +from testsuite import TESTED_VERSION # noqa # pylint: disable=unused-import + pytestmark = pytest.mark.nopersistence -@pytest.mark.parametrize( - ("image", "image_stream", "deployment_configs"), - [ - ("threescale_system", "amp-system", ["system-app"]), - ("threescale_backend", "amp-backend", ["backend-worker"]), - ("threescale_zync", "amp-zync", ["zync"]), - ("threescale_memcached", "system-memcached", ["system-memcache"]), - ("threescale_searchd", "system-searchd", ["system-searchd"]), - ("apicast", "amp-apicast", ["apicast-staging", "apicast-production"]), - ], -) -def test_deployment_image(images, openshift, image, image_stream, deployment_configs): +PARAMETERS = [ + ("threescale_system", "amp-system", ["system-app"]), + ("threescale_backend", "amp-backend", ["backend-worker"]), + ("threescale_zync", "amp-zync", ["zync"]), + ("threescale_memcached", "system-memcached", ["system-memcache"]), + ("threescale_searchd", "system-searchd", ["system-searchd"]), + ("apicast", "amp-apicast", ["apicast-staging", "apicast-production"]), +] + +IS_PARAMETERS = [(image, image_stream) for image, _, image_stream in PARAMETERS] +COMPONENTS_PARAMETERS = [(image, deployment_configs) for image, deployment_configs, _ in PARAMETERS] + + +@pytest.mark.parametrize(("image", "image_stream"), IS_PARAMETERS) +# INFO: image streams are no longer used (starting with 2.15-dev) +@pytest.mark.skipif("TESTED_VERSION > Version('2.14')") +def test_imagesource_image(images, openshift, image, image_stream): """ Test: - load expected images from settings @@ -32,8 +43,22 @@ def test_deployment_image(images, openshift, image, image_stream, deployment_con lookup = openshift.do_action("get", [f"is/{image_stream}", "-o", "yaml"], parse_output=True) digest = lookup.model.spec.tags[-1]["from"].name.split(":")[-1] assert digest == expected_image["manifest_digest"] + + +@pytest.mark.parametrize(("image", "deployment_configs"), COMPONENTS_PARAMETERS) +def test_deployment_image(images, openshift, image, deployment_configs): + """ + Test: + - load expected images from settings + - assert that expected image and image in deployment config are the same + """ + expected_image = images[image] + openshift = openshift() for deployment_config in deployment_configs: - lookup = openshift.do_action("get", [f"dc/{deployment_config}", "-o", "yaml"], parse_output=True) + try: + lookup = openshift.do_action("get", [f"dc/{deployment_config}", "-o", "yaml"], parse_output=True) + except (StopIteration, OpenShiftPythonException): + lookup = openshift.do_action("get", [f"deployment/{deployment_config}", "-o", "yaml"], parse_output=True) for container in lookup.model.spec.template.spec.containers: digest = container.image.split(":")[-1] assert digest == expected_image["resolved_images"].get(openshift.arch) diff --git a/testsuite/tests/prometheus/zync/test_annotations.py b/testsuite/tests/prometheus/zync/test_annotations.py index 29ac412c..5d4456dd 100644 --- a/testsuite/tests/prometheus/zync/test_annotations.py +++ b/testsuite/tests/prometheus/zync/test_annotations.py @@ -4,9 +4,9 @@ import pytest from packaging.version import Version # noqa # pylint: disable=unused-import +from openshift_client import OpenShiftPythonException from testsuite import TESTED_VERSION # noqa # pylint: disable=unused-import -from testsuite.configuration import openshift pytestmark = [ pytest.mark.sandbag, # requires openshift @@ -18,11 +18,15 @@ ANNOTATIONS = ["prometheus.io/port", "prometheus.io/scrape"] -@pytest.fixture(scope="module", params=["dc/zync", "dc/zync-que"]) -def pod(request): +@pytest.fixture(scope="module", params=["zync", "zync-que"]) +def pod(request, openshift): """Return zync pod object.""" - pods = openshift().deployment(request.param).get_pods().objects() - pod = next(filter(lambda x: x.model.status.phase == "Running", pods)) + try: + pods = openshift().deployment(f"deployment/{request.param}").get_pods().objects() + pod = next(filter(lambda x: x.model.status.phase == "Running", pods)) + except (StopIteration, OpenShiftPythonException): + pods = openshift().deployment(f"dc/{request.param}").get_pods().objects() + pod = next(filter(lambda x: x.model.status.phase == "Running", pods)) return pod From a278e5bfaa085b3ae511d2a18d1dc92d2c9d443d Mon Sep 17 00:00:00 2001 From: Jakub Urban Date: Mon, 26 Feb 2024 16:09:24 +0100 Subject: [PATCH 2/6] Change directory where tls certificates are stored Make prefix for tmpdirs end with _ --- Makefile | 2 ++ testsuite/certificates/persist.py | 2 +- .../test_apicast_http_proxy_cert.py | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6d9ecef3..eaf31872 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,8 @@ SHELL = /bin/bash TB ?= short LOGLEVEL ?= INFO +export resultsdir + ifdef WORKSPACE # Yes, this is for jenkins resultsdir = $(WORKSPACE) else diff --git a/testsuite/certificates/persist.py b/testsuite/certificates/persist.py index 578504bc..da544df8 100644 --- a/testsuite/certificates/persist.py +++ b/testsuite/certificates/persist.py @@ -18,7 +18,7 @@ def __init__(self) -> None: @property def _directory(self): if not self._dir: - self._dir = tempfile.mkdtemp() + self._dir = tempfile.mkdtemp(prefix="tls_certs_", dir=os.environ.get("resultsdir")) return self._dir @abstractmethod diff --git a/testsuite/tests/apicast/policy/tls/tls_upstream/mtls_apicast_cert_validation/test_apicast_http_proxy_cert.py b/testsuite/tests/apicast/policy/tls/tls_upstream/mtls_apicast_cert_validation/test_apicast_http_proxy_cert.py index cbce1f94..467b4032 100644 --- a/testsuite/tests/apicast/policy/tls/tls_upstream/mtls_apicast_cert_validation/test_apicast_http_proxy_cert.py +++ b/testsuite/tests/apicast/policy/tls/tls_upstream/mtls_apicast_cert_validation/test_apicast_http_proxy_cert.py @@ -52,6 +52,7 @@ def setup_gateway(request, mount_certificate_secret, staging_gateway, certificat staging_gateway.environ.set_many( {"APICAST_PROXY_HTTPS_CERTIFICATE_KEY": f"{path}/tls.key", "APICAST_PROXY_HTTPS_CERTIFICATE": f"{path}/tls.crt"} ) + return staging_gateway @pytest.fixture(scope="session") From 60ad4d537201e68ffe9921c79007375a3e0de629 Mon Sep 17 00:00:00 2001 From: Jakub Urban Date: Mon, 5 Jun 2023 14:14:00 +0200 Subject: [PATCH 3/6] Make apicast tests comaptible with peristence plugin Make apicast tests comaptible with peristence plugin --- .../tests/apicast/auth/test_update_staging.py | 25 +++++++++++++------ .../test_custom_policy_injection.py | 4 +-- ...t_apicast_service_configuration_version.py | 2 +- .../apicast/test_limit_exceeded_metric.py | 1 + 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/testsuite/tests/apicast/auth/test_update_staging.py b/testsuite/tests/apicast/auth/test_update_staging.py index a0afdaab..5d87ed37 100644 --- a/testsuite/tests/apicast/auth/test_update_staging.py +++ b/testsuite/tests/apicast/auth/test_update_staging.py @@ -8,21 +8,30 @@ # Test checks changes during test run hence is incompatible with persistence plugin -def test_updated_auth_param(api_client, service): +@pytest.fixture(scope="module") +def old_api_client(api_client): + """Api client with default user_key""" + return api_client() + + +@pytest.fixture(scope="module") +def new_api_client(api_client, service): + """Api client with updated user_key""" + # change of the user key + service.proxy.list().update(params={"auth_user_key": "new_key"}) + service.proxy.deploy() + + return api_client() + + +def test_updated_auth_param(old_api_client, new_api_client): """ The update of the staging configuration must be propagated immediately - Updates the user key in the staging env Request using the old key returns 403 Request using the new_key returns 200 """ - old_api_client = api_client() - # change of the user key - service.proxy.list().update(params={"auth_user_key": "new_key"}) - service.proxy.deploy() - - new_api_client = api_client() old_param_response = old_api_client.get("/anything") new_param_response = new_api_client.get("/anything") diff --git a/testsuite/tests/apicast/parameters/policies/custom_policy/test_custom_policy_injection.py b/testsuite/tests/apicast/parameters/policies/custom_policy/test_custom_policy_injection.py index bbf35d62..32848182 100644 --- a/testsuite/tests/apicast/parameters/policies/custom_policy/test_custom_policy_injection.py +++ b/testsuite/tests/apicast/parameters/policies/custom_policy/test_custom_policy_injection.py @@ -6,10 +6,10 @@ from testsuite.capabilities import Capability -# pylint: disable=unused-argument @pytest.mark.required_capabilities(Capability.OCP4) @pytest.mark.issue("https://issues.redhat.com/browse/THREESCALE-9678") -@pytest.mark.nopersistence # Don't know why this test is failing with persistence plugin, it needs more investigation +@pytest.mark.nopersistence +# pylint: disable=unused-argument def test_custom_policy(patch, application): """ Sends request to apicast and check that the custom policy header is there diff --git a/testsuite/tests/apicast/parameters/test_apicast_service_configuration_version.py b/testsuite/tests/apicast/parameters/test_apicast_service_configuration_version.py index 805bda44..41e73cbc 100644 --- a/testsuite/tests/apicast/parameters/test_apicast_service_configuration_version.py +++ b/testsuite/tests/apicast/parameters/test_apicast_service_configuration_version.py @@ -12,7 +12,7 @@ pytestmark = [ pytest.mark.required_capabilities(Capability.STANDARD_GATEWAY, Capability.CUSTOM_ENVIRONMENT), - pytest.mark.nopersistence, # Don't know why this test is failing with persistence plugin, + pytest.mark.nopersistence, # Don't know why this test is failing with persistence plugin # and it needs more investigation ] diff --git a/testsuite/tests/apicast/test_limit_exceeded_metric.py b/testsuite/tests/apicast/test_limit_exceeded_metric.py index 05416b5e..7d7e2b91 100644 --- a/testsuite/tests/apicast/test_limit_exceeded_metric.py +++ b/testsuite/tests/apicast/test_limit_exceeded_metric.py @@ -54,3 +54,4 @@ def test_anything_else_is_ok(api_client): """Call to /anything/else should return 200 OK.""" assert api_client().get("/anything/else").status_code == 200 + From f83d6b6a4ca252fb73b2a67d51581825a0fcf2cb Mon Sep 17 00:00:00 2001 From: Matej Dujava Date: Fri, 11 Oct 2024 14:01:25 +0200 Subject: [PATCH 4/6] Add rhsso.kind config option to config template Fixes: 55782d7e ("Add kind to rhsso setting to choose rhsso or rhbk") --- config/settings.yaml | 1 + config/settings.yaml.tpl | 1 + 2 files changed, 2 insertions(+) diff --git a/config/settings.yaml b/config/settings.yaml index 88a5309c..38889779 100644 --- a/config/settings.yaml +++ b/config/settings.yaml @@ -19,6 +19,7 @@ default: default: kind: "SystemApicast" rhsso: + kind: rhbk username: admin test_user: username: testUser diff --git a/config/settings.yaml.tpl b/config/settings.yaml.tpl index 8ca0664b..5dccc88d 100644 --- a/config/settings.yaml.tpl +++ b/config/settings.yaml.tpl @@ -39,6 +39,7 @@ default: threescale: name: "{DEFAULT_OPENSHIFT_THREESCALE_PROJECT}" rhsso: + kind: rhbk # rhbk is deault; other acceptable value is rhsso test_user: username: testUser password: testUser From 5442e8be27d19fb2002f103878206dca4ae186a1 Mon Sep 17 00:00:00 2001 From: Matej Dujava Date: Wed, 20 Nov 2024 11:43:29 +0100 Subject: [PATCH 5/6] Set RHSSO as default sso --- config/settings.yaml | 2 +- config/settings.yaml.tpl | 4 ++-- testsuite/dynaconf_loader.py | 2 +- testsuite/tests/conftest.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/config/settings.yaml b/config/settings.yaml index 38889779..966ed596 100644 --- a/config/settings.yaml +++ b/config/settings.yaml @@ -19,7 +19,7 @@ default: default: kind: "SystemApicast" rhsso: - kind: rhbk + kind: rhsso username: admin test_user: username: testUser diff --git a/config/settings.yaml.tpl b/config/settings.yaml.tpl index 5dccc88d..fde91a4e 100644 --- a/config/settings.yaml.tpl +++ b/config/settings.yaml.tpl @@ -39,7 +39,7 @@ default: threescale: name: "{DEFAULT_OPENSHIFT_THREESCALE_PROJECT}" rhsso: - kind: rhbk # rhbk is deault; other acceptable value is rhsso + kind: rhsso # rhsso is deault for 2.14; other acceptable value is rhbk test_user: username: testUser password: testUser @@ -207,4 +207,4 @@ development: resolved_images: # Dict of resolved images amd64: ppc64le: - s390x: \ No newline at end of file + s390x: diff --git a/testsuite/dynaconf_loader.py b/testsuite/dynaconf_loader.py index f2f0ac3e..6f52ff24 100644 --- a/testsuite/dynaconf_loader.py +++ b/testsuite/dynaconf_loader.py @@ -114,7 +114,7 @@ def _rhsso_password(tools_config, rhsso_config): server_url = tools_config.get("server") project = tools_config.get("namespace") token = tools_config.get("token") - kind = rhsso_config.get("kind", "rhbk") + kind = rhsso_config.get("kind", "rhsso") try: # is this RHOAM? tools = OpenShiftClient(project_name="redhat-rhoam-user-sso", server_url=server_url, token=token) diff --git a/testsuite/tests/conftest.py b/testsuite/tests/conftest.py index 285533be..b2c48c1d 100644 --- a/testsuite/tests/conftest.py +++ b/testsuite/tests/conftest.py @@ -565,7 +565,7 @@ def production_gateway(request, testconfig, openshift): @pytest.fixture(scope="session") def rhsso_kind(request, testconfig): """SSO kind, rhsso or rhbk""" - return testconfig["rhsso"].get("kind", "rhbk") + return testconfig["rhsso"].get("kind", "rhsso") @pytest.fixture(scope="session") From 9cd541571a767e9ca77e96c774049ecd5cf3c7e4 Mon Sep 17 00:00:00 2001 From: Matej Dujava Date: Fri, 27 Sep 2024 15:31:45 +0200 Subject: [PATCH 6/6] Fix pylint error rename (#876) * Revert "Implement podman and docker container runtimes support" This reverts commit 115c3124aaf6edc023bd7e50d4574412552813ba. * Ignore too-many-positional-arguments check --- Pipfile | 2 - doc/examples.py | 67 -------------- pylintrc | 1 + testsuite/containers/__init__.py | 0 testsuite/containers/container_runtime.py | 91 ------------------- testsuite/containers/docker_runtime.py | 46 ---------- testsuite/containers/podman_runtime.py | 55 ----------- .../apicast/test_limit_exceeded_metric.py | 1 - 8 files changed, 1 insertion(+), 262 deletions(-) delete mode 100644 testsuite/containers/__init__.py delete mode 100644 testsuite/containers/container_runtime.py delete mode 100644 testsuite/containers/docker_runtime.py delete mode 100644 testsuite/containers/podman_runtime.py diff --git a/Pipfile b/Pipfile index 870daa2f..246b4a67 100644 --- a/Pipfile +++ b/Pipfile @@ -46,8 +46,6 @@ cfssl = "==0.0.3b243" openshift-client = ">=2.0.1" hyperfoil-client="*" paramiko = "*" -docker = "*" -podman = "*" jsondiff = "*" weakget = "*" flaky = "*" diff --git a/doc/examples.py b/doc/examples.py index c9fcf9b0..3b74b5d7 100644 --- a/doc/examples.py +++ b/doc/examples.py @@ -136,70 +136,3 @@ def test_skip_apicast_retrying_on_404(application, api_client): client = api_client(disable_retry_status_list={404}) assert client.get("/status/404").status_code == 404 - - -################################################################################ -# Example usage of DockerRuntime -def example_docker(): - from testsuite.containers.docker_runtime import DockerRuntime - from testsuite.containers.container_runtime import ContainerConfig - from contextlib import closing - - with closing(DockerRuntime("tcp://10.0.145.159:2376")) as d: - cc = ContainerConfig("mysql", "latest", {"MYSQL_ROOT_PASSWORD": "root"}, {"3306": "33767"}, cmd=["ls", "-la"]) - cc.attach_volume("/root/dkr", "/mnt") - c = d.run(cc) - print(d.logs(c)) - - # d.stop(c) - d.delete_container(c) - - -############################################################################### -# Example usage of PodmanRuntime -def example_podman(): - from testsuite.containers.podman_runtime import PodmanRuntime - from testsuite.containers.container_runtime import ContainerConfig - from contextlib import closing - - with closing(PodmanRuntime("ssh://root@10.0.145.150/run/podman/io.podman")) as d: - cc = ContainerConfig("mysql", "latest", {"MYSQL_ROOT_PASSWORD": "root"}, {"3306": "33075"}, cmd=["ls"]) - cc.attach_volume("/root/blah", "/mnt") - c = d.run(cc) - print(d.logs(c)) - # d.stop(c) - d.delete_container(c) - - -############################################################################### -# Example usage of DockerRuntime -def example_docker_no_cm(): - from testsuite.containers.docker_runtime import DockerRuntime - from testsuite.containers.container_runtime import ContainerConfig - - d = DockerRuntime("tcp://10.0.145.159:2376") - cc = ContainerConfig("mysql", "latest", {"MYSQL_ROOT_PASSWORD": "root"}, {"3306": "33767"}, cmd=["ls", "-la"]) - cc.attach_volume("/root/dkr", "/mnt") - c = d.run(cc) - print(d.logs(c)) - - # d.stop(c) - d.delete_container(c) - d.close() - - -############################################################################### -# Example usage of PodmanRuntime -def example_podman_no_cm(): - from testsuite.containers.podman_runtime import PodmanRuntime - from testsuite.containers.container_runtime import ContainerConfig - - d = PodmanRuntime("ssh://root@10.0.145.150/run/podman/io.podman") - cc = ContainerConfig("mysql", "latest", {"MYSQL_ROOT_PASSWORD": "root"}, {"3306": "33076"}, cmd=["ls"]) - cc.attach_volume("/root/blah", "/mnt") - c = d.run(cc) - print(d.logs(c)) - # d.stop(c) - d.delete_container(c) - - d.close() diff --git a/pylintrc b/pylintrc index 3ea4250e..6dfd006f 100644 --- a/pylintrc +++ b/pylintrc @@ -18,6 +18,7 @@ disable=duplicate-code, # reports false alarms AND can't be disabled locally; p consider-using-f-string, # % string operator is absolutely fine redefined-outer-name, missing-timeout, # socket timeout is set globally, no need to specify it in calls + too-many-positional-arguments, [FORMAT] # Maximum number of characters on a single line. diff --git a/testsuite/containers/__init__.py b/testsuite/containers/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/testsuite/containers/container_runtime.py b/testsuite/containers/container_runtime.py deleted file mode 100644 index 9fe37f1a..00000000 --- a/testsuite/containers/container_runtime.py +++ /dev/null @@ -1,91 +0,0 @@ -""" -This module defines common interface for working with different container runtimes and provides -some helper classes for easier interaction -""" - -from abc import ABC, abstractmethod -from typing import Optional, Dict, List -from copy import deepcopy - - -class Container: # pylint: disable=too-few-public-methods - """Simple structure for holding basic information about container""" - - def __init__(self, cid: str, started: bool): - self.cid = cid - self.deleted = False - self.started = started - - -class ContainerConfig: - """Helper class for defining configuration for creating new container""" - - # pylint: disable=too-many-arguments, too-many-instance-attributes - def __init__( - self, - image: str, - tag: str = "latest", - env: Optional[Dict[str, str]] = None, - ports: Optional[Dict[str, str]] = None, - volumes: Optional[Dict[str, Dict[str, str]]] = None, - entrypoint: Optional[str] = None, - cmd: Optional[List[str]] = None, - detach: bool = True, - ): - """ports dict is in format: {container_port: host_port}""" - self.image = image - self.tag = tag - self.env = env or {} - self.ports = ports or {} - self.volumes = volumes or {} - self.entrypoint = entrypoint - self.cmd = cmd or [] - self.detach = detach - - @property - def image_repotag(self) -> str: - """Returns image id string in format 'imagename:tag'""" - return f"{self.image}:{self.tag}" - - def attach_volume(self, host_path: str, container_path: str, mode: str = None): - """Makes host_path volume accessible from container at container_path""" - self.volumes[host_path] = {"bind": container_path, "mode": mode or "Z"} - - def detach_volume(self, host_path: str): - """Removes attached volume from config""" - del self.volumes[host_path] - - def clone(self) -> "ContainerConfig": - """Makes a deep copy of this container config""" - return deepcopy(self) - - -class ContainerRuntime(ABC): - """Abstract base ContainerRuntime class defining common interface for working with containers""" - - @abstractmethod - def run(self, container_config: ContainerConfig) -> Container: - """ - Creates and runs new container defined by container_config \n - If image is not present on host it tries to automatically pull it - """ - - @abstractmethod - def start(self, container: Container): - """Starts created or stopped container""" - - @abstractmethod - def stop(self, container: Container): - """Stops running container""" - - @abstractmethod - def delete_container(self, container: Container): - """Deletes container on host""" - - @abstractmethod - def logs(self, container: Container) -> str: - """Returns container's logs as a string""" - - @abstractmethod - def close(self): - """Closes client in order to free resources""" diff --git a/testsuite/containers/docker_runtime.py b/testsuite/containers/docker_runtime.py deleted file mode 100644 index ddc46997..00000000 --- a/testsuite/containers/docker_runtime.py +++ /dev/null @@ -1,46 +0,0 @@ -""" -This module contains everything what is needed for Docker implementation of ContainerRuntime -Depends on docker library -""" - -from docker import DockerClient -from testsuite.containers.container_runtime import Container, ContainerRuntime, ContainerConfig - - -class DockerRuntime(ContainerRuntime): - """Docker implementation of ContainerRuntime""" - - def __init__(self, uri: str): - super().__init__() - self._client = DockerClient(base_url=uri, version="auto", tls=False) - - def logs(self, container: Container) -> str: - return self._client.containers.get(container.cid).logs() - - def delete_container(self, container: Container): - self._client.containers.get(container.cid).remove(force=True) - container.deleted = True - - def start(self, container: Container): - self._client.containers.get(container.cid).start() - container.started = True - - def stop(self, container: Container): - self._client.containers.get(container.cid).stop(timeout=10) - container.started = False - - def run(self, container_config: ContainerConfig) -> Container: - container = self._client.containers.run( - image=container_config.image_repotag, - command=container_config.cmd, - environment=container_config.env, - entrypoint=container_config.entrypoint, - detach=container_config.detach, - ports=container_config.ports, - volumes=container_config.volumes, - ) - - return Container(container.id, started=True) - - def close(self): - self._client.close() diff --git a/testsuite/containers/podman_runtime.py b/testsuite/containers/podman_runtime.py deleted file mode 100644 index 378afe7d..00000000 --- a/testsuite/containers/podman_runtime.py +++ /dev/null @@ -1,55 +0,0 @@ -""" -This module contains everything what is needed for Podman implementation of ContainerRuntime -Depends on podman library -""" - -from podman.errors import ImageNotFound -from podman import PodmanClient - -from testsuite.containers.container_runtime import ContainerRuntime, ContainerConfig, Container - - -class PodmanRuntime(ContainerRuntime): - """Podman implementation of ContainerRuntime""" - - def __init__(self, remote_uri: str, identity_file: str = "~/.ssh/id_master", uri: str = "unix:/tmp/podman.sock"): - super().__init__() - self._client = PodmanClient(uri=uri, remote_uri=remote_uri, identity_file=identity_file) - - def run(self, container_config: ContainerConfig) -> Container: - try: - img = self._client.images.get(container_config.image_repotag) - except ImageNotFound: - self._client.images.pull(container_config.image_repotag) - img = self._client.images.get(container_config.image_repotag) - - container = img.container( - command=container_config.cmd, - entrypoint=container_config.entrypoint, - env=[f"{k}={v}" for k, v in container_config.env.items()], - detach=True, - publish=[f"{host}:{cont}" for cont, host in container_config.ports.items()], - volume=[f"{host}:{cont['bind']}:{cont['mode']}" for host, cont in container_config.volumes.items()], - ).start() - - return Container(container.id, started=True) - - def start(self, container: Container): - self._client.containers.get(container.cid).start() - container.started = True - - def stop(self, container: Container): - self._client.containers.get(container.cid).stop(timeout=10) - container.started = False - - def delete_container(self, container: Container): - self._client.containers.get(container.cid).remove(force=True) - container.deleted = True - - def logs(self, container: Container) -> str: - return "".join(self._client.containers.get(container.cid).logs()) - - def close(self): - # should be done automatically by podman library - # but it is not, it creates for every PodmanRuntime one ssh tunnel which persists till end of the process - pass diff --git a/testsuite/tests/apicast/test_limit_exceeded_metric.py b/testsuite/tests/apicast/test_limit_exceeded_metric.py index 7d7e2b91..05416b5e 100644 --- a/testsuite/tests/apicast/test_limit_exceeded_metric.py +++ b/testsuite/tests/apicast/test_limit_exceeded_metric.py @@ -54,4 +54,3 @@ def test_anything_else_is_ok(api_client): """Call to /anything/else should return 200 OK.""" assert api_client().get("/anything/else").status_code == 200 -