def test_pull_image_from_repository_version(self): """Verify that a client can pull the image from Pulp (on-demand). 1. Using the RegistryClient pull the image from Pulp. 2. Pull the same image from remote registry. 3. Verify both images has the same checksum. 4. Ensure image is deleted after the test. """ registry = cli.RegistryClient(self.cfg) registry.raise_if_unsupported(unittest.SkipTest, "Test requires podman/docker") registry.login("-u", "admin", "-p", "password", self.registry_name) local_url = urljoin(self.cfg.get_base_url(), self.distribution_with_repo_version.base_path) registry.pull(local_url) self.teardown_cleanups.append((registry.rmi, local_url)) local_image = registry.inspect(local_url) registry.pull(REPO_UPSTREAM_NAME) remote_image = registry.inspect(REPO_UPSTREAM_NAME) self.assertEqual(local_image[0]["Id"], remote_image[0]["Id"]) registry.rmi(REPO_UPSTREAM_NAME)
def test_pull_image_from_repository_version(self): """Verify that a client can pull the image from Pulp (on-demand). 1. Using the RegistryClient pull the image from Pulp. 2. Pull the same image from remote registry. 3. Verify both images has the same checksum. 4. Ensure image is deleted after the test. """ registry = cli.RegistryClient(self.cfg) registry.raise_if_unsupported(unittest.SkipTest, 'Test requires podman/docker') local_url = urljoin(self.cfg.get_content_host_base_url(), self.distribution_with_repo_version['base_path']) registry.pull(local_url) self.teardown_cleanups.append((registry.rmi, local_url)) local_image = registry.inspect(local_url) registry.pull(DOCKER_UPSTREAM_NAME) remote_image = registry.inspect(DOCKER_UPSTREAM_NAME) self.assertEqual(local_image[0]['Id'], remote_image[0]['Id']) registry.rmi(DOCKER_UPSTREAM_NAME)
def test_pull_image_with_tag(self): """Verify that a client can pull the image from Pulp with a tag. 1. Using the RegistryClient pull the image from Pulp specifying a tag. 2. Pull the same image and same tag from remote registry. 3. Verify both images has the same checksum. 4. Ensure image is deleted after the test. """ registry = cli.RegistryClient(self.cfg) registry.raise_if_unsupported(unittest.SkipTest, "Test requires podman/docker") registry.login("-u", "admin", "-p", "password", self.registry_name) local_url = (urljoin(self.cfg.get_base_url(), self.distribution_with_repo.base_path) + REPO_UPSTREAM_TAG) registry.pull(local_url) local_image = registry.inspect(local_url) registry.pull(REPO_UPSTREAM_NAME + REPO_UPSTREAM_TAG) remote_image = registry.inspect(REPO_UPSTREAM_NAME + REPO_UPSTREAM_TAG) self.assertEqual(local_image[0]["Id"], remote_image[0]["Id"])
def setUpClass(cls): """Initialize a new manifest list that will be pushed to the registry.""" cfg = config.get_config() cls.registry = cli.RegistryClient(cfg) cls.registry.raise_if_unsupported(unittest.SkipTest, "Tests require podman/docker") cls.registry_name = urlparse(cfg.get_base_url()).netloc admin_user, admin_password = cfg.pulp_auth cls.user_admin = {"username": admin_user, "password": admin_password} api_client = gen_container_client() api_client.configuration.username = cls.user_admin["username"] api_client.configuration.password = cls.user_admin["password"] cls.pushrepository_api = RepositoriesContainerPushApi(api_client) cls.distributions_api = DistributionsContainerApi(api_client) cls.manifests_api = ContentManifestsApi(api_client) cls.tags_api = ContentTagsApi(api_client) cls.manifest_a = f"{REGISTRY_V2_REPO_PULP}:manifest_a" cls.manifest_b = f"{REGISTRY_V2_REPO_PULP}:manifest_b" cls.manifest_c = f"{REGISTRY_V2_REPO_PULP}:manifest_c" cls._pull(cls.manifest_a) cls._pull(cls.manifest_b) cls._pull(cls.manifest_c) # get default manifests' digests for the further comparison manifest_a_digest = cls.registry.inspect(cls.manifest_a)[0]["Digest"] manifest_b_digest = cls.registry.inspect(cls.manifest_b)[0]["Digest"] manifest_c_digest = cls.registry.inspect(cls.manifest_c)[0]["Digest"] cls.manifests_v2s2_digests = sorted( [manifest_a_digest, manifest_b_digest, manifest_c_digest]) # create a new manifest list composed of the pulled manifest images cls.image_v2s2_tag = "manifest_list" cls.image_v2s2_path = f"{REGISTRY_V2_REPO_PULP}:{cls.image_v2s2_tag}" cls.local_v2s2_url = f"{cls.registry_name}/foo:{cls.image_v2s2_tag}" cls.registry._dispatch_command("manifest", "create", cls.image_v2s2_path) cls.registry._dispatch_command("manifest", "add", cls.image_v2s2_path, cls.manifest_a) cls.registry._dispatch_command("manifest", "add", cls.image_v2s2_path, cls.manifest_b) cls.registry._dispatch_command("manifest", "add", cls.image_v2s2_path, cls.manifest_c) # get digests of manifests after converting images to the OCI format by reloading them cls.registry._dispatch_command("save", cls.manifest_a, "--format", "oci-dir", "-o", "manifest_a.tar") cls.registry._dispatch_command("save", cls.manifest_b, "--format", "oci-dir", "-o", "manifest_b.tar") cls.registry._dispatch_command("save", cls.manifest_c, "--format", "oci-dir", "-o", "manifest_c.tar") cls.registry._dispatch_command("load", "-q", "-i", "manifest_a.tar") cls.registry._dispatch_command("load", "-q", "-i", "manifest_b.tar") cls.registry._dispatch_command("load", "-q", "-i", "manifest_c.tar") manifest_a_digest = cls.registry.inspect("manifest_a.tar")[0]["Digest"] manifest_b_digest = cls.registry.inspect("manifest_b.tar")[0]["Digest"] manifest_c_digest = cls.registry.inspect("manifest_c.tar")[0]["Digest"] cls.manifests_oci_digests = sorted( [manifest_a_digest, manifest_b_digest, manifest_c_digest]) # create an empty manifest list cls.empty_image_tag = "empty_manifest_list" cls.empty_image_path = f"{REGISTRY_V2_REPO_PULP}:{cls.empty_image_tag}" cls.empty_image_local_url = f"{cls.registry_name}/foo:{cls.empty_image_tag}" cls.registry._dispatch_command("manifest", "create", cls.empty_image_path)
def setUpClass(cls): """ Define APIs to use and pull images needed later in tests """ api_client = gen_container_client() cfg = config.get_config() cls.repository_api = RepositoriesContainerApi(api_client) cls.pushrepository_api = RepositoriesContainerPushApi(api_client) cls.tags_api = ContentTagsApi(api_client) cls.namespace_api = PulpContainerNamespacesApi(api_client) cls.registry = cli.RegistryClient(cfg) cls.registry.raise_if_unsupported(unittest.SkipTest, "Tests require podman/docker") cls.registry_name = urlparse(cfg.get_base_url()).netloc admin_user, admin_password = cfg.pulp_auth cls.user_admin = {"username": admin_user, "password": admin_password} cls.user_creator = gen_user( [ "container.add_containerrepository", "container.add_containerremote", "container.add_containernamespace", "container.add_containerdistribution", ] ) cls.user_creator2 = gen_user( [ "container.add_containernamespace", "container.add_containerdistribution", ] ) cls.user_reader = gen_user( [ "container.view_containerrepository", "container.view_containerpushrepository", ] ) cls.user_reader2 = gen_user(["container.view_containerrepository"]) cls.user_reader3 = gen_user(["container.view_containerpushrepository"]) cls.user_helpless = gen_user([]) # create a push repo with user_creator image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_a" cls._pull(image_path) repo_name = "testcontent/perms" local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"]) cls._push(image_path, local_url, cls.user_creator) cls.push_repository = cls.pushrepository_api.list(name=repo_name).results[0] # create a second push repo with user_creator2 image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_b" cls._pull(image_path) repo_name = "testcontent2/perms" local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"]) cls._push(image_path, local_url, cls.user_creator2) cls.push_repository2 = cls.pushrepository_api.list(name=repo_name).results[0] # sync a repo with user_creator cls.repository = cls.user_creator["repository_api"].create( ContainerContainerRepository(**gen_repo()) ) cls.remote = cls.user_creator["remote_api"].create( gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1) ) sync_data = RepositorySyncURL(remote=cls.remote.pulp_href) sync_response = cls.user_creator["repository_api"].sync(cls.repository.pulp_href, sync_data) monitor_task(sync_response.task)
# coding=utf-8 """Tests that verify that images can be pushed to Pulp.""" import unittest from pulp_smash import cli, config, exceptions from pulp_container.tests.functional.utils import gen_container_client from pulpcore.client.pulp_container import RepositoriesContainerPushApi cfg = config.get_config() api_client = gen_container_client() push_repositories_api = RepositoriesContainerPushApi(api_client) registry = cli.RegistryClient(cfg) class PushContentTestCase(unittest.TestCase): """Verify whether images can be pushed to pulp.""" def test_push_using_registry_client(self): """Test push with official registry client""" registry.raise_if_unsupported(unittest.SkipTest, "Test requires podman/docker") # TODO better handling of the "http://" registry_name = cfg.get_base_url()[7:] local_url = "/".join([registry_name, "foo/bar:1.0"]) # Be sure to not being logged in registry.logout(registry_name) # Pull an image with large blobs registry.pull("centos:7")
def setUpClass(cls): """Prepare registry api.""" cfg = config.get_config() cls.registry = cli.RegistryClient(cfg)