From 11ec023b0309e286ed158853a19bb21d58ebc748 Mon Sep 17 00:00:00 2001 From: Brian McLaughlin Date: Mon, 25 Oct 2021 19:15:07 -0400 Subject: [PATCH] Test Container Repository Tags endpoint (#1032) * Add functional test for Container Repository Tags endpoint Issue: AAH-906 (cherry picked from commit ada466bc5dbf6759b77d4206505943106193a5cb) --- functest_requirements.txt | 1 + .../cli/test_container_repository_tags.py | 68 +++++++++++++++++++ galaxy_ng/tests/functional/utils.py | 12 ++++ 3 files changed, 81 insertions(+) create mode 100644 galaxy_ng/tests/functional/cli/test_container_repository_tags.py diff --git a/functest_requirements.txt b/functest_requirements.txt index 5d9ad3336a..2cc81c7715 100644 --- a/functest_requirements.txt +++ b/functest_requirements.txt @@ -1,3 +1,4 @@ git+https://github.com/pulp/pulp-smash.git#egg=pulp-smash +pulp-container>=2.8.0,<2.9.0 pytest orionutils diff --git a/galaxy_ng/tests/functional/cli/test_container_repository_tags.py b/galaxy_ng/tests/functional/cli/test_container_repository_tags.py new file mode 100644 index 0000000000..9b1a78d68c --- /dev/null +++ b/galaxy_ng/tests/functional/cli/test_container_repository_tags.py @@ -0,0 +1,68 @@ +import unittest + +from urllib.parse import urlparse + +from pulpcore.client.galaxy_ng.exceptions import ApiException +from pulp_container.tests.functional.api import rbac_base +from pulp_container.tests.functional.constants import DOCKERHUB_PULP_FIXTURE_1 +from pulp_smash import cli + +from galaxy_ng.tests.functional.utils import ContainerTestCaseUsingBindings + + +class ContainerRepositoryTagsTestCase(ContainerTestCaseUsingBindings, rbac_base.BaseRegistryTest): + """Test whether a container repository's tags can be listed. + + When running functional tests in dev environment please ensure that + Pulp Smash can either execute commands as root or can successfully + execute "sudo" on the localhost. + .. note:: When running against a non-https registry the client config + `insecure-registries` must be enabled. + For docker it is located in `/etc/docker/daemon.json` and content is:: + {"insecure-registries": ["0.0.0.0:5001"]} + For podman it is located in `/etc/containers/registries.conf` with:: + [registries.insecure] + registries = ['0.0.0.0:5001'] + """ + + @classmethod + def setUpClass(cls): + """ + Define APIs to use and pull images needed later in tests + """ + super().setUpClass() + + cfg = cls.cfg + cls.registry = cli.RegistryClient(cls.cfg) + cls.registry.raise_if_unsupported(unittest.SkipTest, "Tests require podman/docker") + cls.registry_name = urlparse(cls.cfg.get_base_url()).netloc + admin_user, admin_password = cls.cfg.pulp_auth + cls.user_admin = {"username": admin_user, "password": admin_password} + cls._pull(f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_a") + + def test_list_container_repository_tags(self): + image_name = "foo/bar" + image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_a" + local_url = "/".join([self.registry_name, f"{image_name}:1.0"]) + + # expect the Container Repository Tags not to exist yet + with self.assertRaises(ApiException) as context: + self.container_repo_tags_api.list(base_path=image_name) + + # Bad request + assert context.exception.status == 404 + + self._push(image_path, local_url, self.user_admin) + + response = self.container_repo_tags_api.list(base_path=image_name) + + self.assertEqual(response.meta.count, 1) + for entry in response.data: + self.assertIn(entry.name, ["1.0"]) + + # Delete created Execution Environment + # api does not currently support delete + ee_delete_response = self.smash_client.delete( + f"{self.galaxy_api_prefix}/_ui/v1/execution-environments/repositories/{image_name}/" + ) + print(f"Delete execution environment: {ee_delete_response['state']}") diff --git a/galaxy_ng/tests/functional/utils.py b/galaxy_ng/tests/functional/utils.py index ff9d319cd3..0a9008dec5 100644 --- a/galaxy_ng/tests/functional/utils.py +++ b/galaxy_ng/tests/functional/utils.py @@ -37,6 +37,8 @@ ApiContentV3SyncApi, ApiContentV3SyncConfigApi, ApiV3NamespacesApi, + ApiUiV1ExecutionEnvironmentsRepositoriesContentTagsApi as ContainerRepositoryEndpointApi, + ApiUiV1ExecutionEnvironmentsRepositoriesApi as ContainerRepositoryApi ) @@ -169,6 +171,8 @@ def setUpClass(cls): cls.collections_api = ApiContentV3CollectionsApi(cls.client) cls.sync_config_api = ApiContentV3SyncConfigApi(cls.client) cls.sync_api = ApiContentV3SyncApi(cls.client) + cls.container_repo_tags_api = ContainerRepositoryEndpointApi(cls.client) + cls.container_repo_api = ContainerRepositoryApi(cls.client) cls.get_ansible_cfg_before_test() cls.galaxy_api_prefix = os.getenv("PULP_GALAXY_API_PATH_PREFIX", "/api/galaxy").rstrip("/") @@ -220,3 +224,11 @@ def sync_repo(self, requirements_file, **kwargs): response = self.sync_api.sync(repo_name) monitor_task(f"/pulp/api/v3/tasks/{response.task}/") + + +class ContainerTestCaseUsingBindings(TestCaseUsingBindings): + @classmethod + def setUpClass(cls): + if os.getenv("TEST") == "azure": + raise SkipTest("Container Registry disabled") + super().setUpClass() \ No newline at end of file