Skip to content

Commit

Permalink
Test Container Repository Tags endpoint (ansible#1032)
Browse files Browse the repository at this point in the history
* Add functional test for Container Repository Tags endpoint
Issue: AAH-906
  • Loading branch information
bmclaughlin authored and jctanner committed Dec 1, 2021
1 parent 9c04144 commit 9cfb9e6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions functest_requirements.txt
Original file line number Diff line number Diff line change
@@ -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
68 changes: 68 additions & 0 deletions galaxy_ng/tests/functional/cli/test_container_repository_tags.py
Original file line number Diff line number Diff line change
@@ -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']}")
12 changes: 12 additions & 0 deletions galaxy_ng/tests/functional/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
ApiContentV3SyncApi,
ApiContentV3SyncConfigApi,
ApiV3NamespacesApi,
ApiUiV1ExecutionEnvironmentsRepositoriesContentTagsApi as ContainerRepositoryEndpointApi,
ApiUiV1ExecutionEnvironmentsRepositoriesApi as ContainerRepositoryApi
)


Expand Down Expand Up @@ -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("/")

Expand Down Expand Up @@ -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()

0 comments on commit 9cfb9e6

Please sign in to comment.