Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Container Repository Tags endpoint #1032

Merged
merged 9 commits into from
Oct 25, 2021
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
67 changes: 67 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,67 @@
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 TestCaseUsingBindings


class ContainerRepositoryTagsTestCase(TestCaseUsingBindings, 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()
rochacbruno marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend to do a check before and after the update, to make sure the update was the cause of the expected result, something like:

self.assertEqual(response.meta.count, 0)
self._push(image_path, local_url, self.user_admin)
...
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume since the api does not support delete, you are using smash_client to do the delete just for cleanup?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct, I figure anyone who runs the functional tests locally will appreciate the disk space being returned.

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']}")
4 changes: 4 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