def setUpClass(cls): """ Define APIs to use and pull images needed later in tests """ api_client = gen_container_client() cls.pushrepository_api = RepositoriesContainerPushApi(api_client) cls.namespace_api = PulpContainerNamespacesApi(api_client) cls.repo_version_api = RepositoriesContainerVersionsApi(api_client) 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} cls.user_creator = gen_user( [ "container.add_containerdistribution", "container.add_containernamespace", ] ) cls.user_reader = gen_user(["container.view_containerpushrepository"]) cls.user_helpless = gen_user([]) # create a push repo image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_d" cls._pull(image_path) repo_name = "testrv/perms" local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"]) cls._push(image_path, local_url, cls.user_creator) cls.repository = cls.pushrepository_api.list(name=repo_name).results[0]
def setUpClass(cls): """ Define APIs to use and pull images needed later in tests """ 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} cls.user_creator = gen_user([ "container.add_containernamespace", "container.add_containerdistribution" ]) cls.user_dist_collaborator = gen_user([]) cls.user_dist_consumer = gen_user([]) cls.user_namespace_collaborator = gen_user([]) cls.user_reader = gen_user([]) cls.user_helpless = gen_user([]) # View push repositories, distributions, and namespaces using user_creator. 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.namespace_api = PulpContainerNamespacesApi(api_client) cls._pull(f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_a") cls._pull(f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_b") cls._pull(f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_c") cls._pull(f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_d")
def setUpClass(cls): """ Define APIs to use. """ api_client = gen_container_client() cls.pushrepository_api = RepositoriesContainerPushApi(api_client) cls.namespace_api = PulpContainerNamespacesApi(api_client) 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 cls.user_creator = gen_user( model_roles=[ "container.containerdistribution_creator", "container.containernamespace_creator", ] ) cls.user_reader = gen_user(model_roles=["container.containerdistribution_consumer"]) cls.user_helpless = gen_user() # create a push repo image_path = f"{REGISTRY_V2_REPO_PULP}:manifest_d" cls._pull(image_path) repo_name = "test_push_repo/perms" local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"]) cls._push(image_path, local_url, cls.user_creator) cls.repository = cls.pushrepository_api.list(name=repo_name).results[0]
def setUpClass(cls): """Create class wide-variables.""" api_client = gen_container_client() cls.repositories_api = RepositoriesContainerApi(api_client) cls.remotes_api = RemotesContainerApi(api_client) cls.distributions_api = DistributionsContainerApi(api_client) cls.namespaces_api = PulpContainerNamespacesApi(api_client) cls.cfg = config.get_config() cls.client = api.Client(cls.cfg, api.json_handler) cls.repository = cls.repositories_api.create(ContainerContainerRepository(**gen_repo())) remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1) cls.remote = cls.remotes_api.create(ContainerContainerRemote(**remote_data)) sync_data = RepositorySyncURL(remote=cls.remote.pulp_href) sync_response = cls.repositories_api.sync(cls.repository.pulp_href, sync_data) monitor_task(sync_response.task)
def setUpClass(cls): """Define class-wide variables and initialize a repository needed later in the tests.""" 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.repositories_api = RepositoriesContainerPushApi(api_client) cls.versions_api = RepositoriesContainerVersionsApi(api_client) cls.namespaces_api = PulpContainerNamespacesApi(api_client) cls.manifests_api = ContentManifestsApi(api_client) cls.distributions_api = DistributionsContainerApi(api_client) # the image tagged as 'manifest_a' consists of 3 blobs, 1 manifest, and 1 tag manifest_a_path = f"{REGISTRY_V2_REPO_PULP}:manifest_a" cls._pull(manifest_a_path) local_url = "/".join([cls.registry_name, "foo/bar:tag"]) cls._push(manifest_a_path, local_url, cls.user_admin) cls.repo = cls.repositories_api.list(name="foo/bar").results[0] cls.distribution = cls.distributions_api.list( name="foo/bar").results[0] cls.namespace = cls.namespaces_api.list(name="foo").results[0] # create a new tag to test if all tags pointing to the same manifest will be removed cls.manifest_a = cls.manifests_api.list().results[0] tag_data = TagImage(tag="new_tag", digest=cls.manifest_a.digest) tag_response = cls.repositories_api.tag(cls.repo.pulp_href, tag_data) monitor_task(tag_response.task) latest_version_href = cls.repositories_api.read( cls.repo.pulp_href).latest_version_href cls.content_to_remove = cls.versions_api.read( latest_version_href).content_summary.present
def gen_user(model_roles=None, object_roles=None): """Create a user with a set of permissions in the pulp database.""" if model_roles is None: model_roles = [] if object_roles is None: object_roles = [] user = { "username": utils.uuid4(), "password": utils.uuid4(), } new_user = users_api.create(user) user["pulp_href"] = new_user.pulp_href for role in model_roles: assign_role_to_user(user, role) for role, content_object in object_roles: assign_role_to_user(user, role, content_object) api_config = cfg.get_bindings_config() api_config.username = user["username"] api_config.password = user["password"] user["core_api_client"] = CoreApiClient(api_config) user["groups_api"] = GroupsApi(user["core_api_client"]) user["group_users_api"] = GroupsUsersApi(user["core_api_client"]) user["container_api_client"] = ContainerApiClient(api_config) user["namespace_api"] = PulpContainerNamespacesApi( user["container_api_client"]) user["distribution_api"] = DistributionsContainerApi( user["container_api_client"]) user["remote_api"] = RemotesContainerApi(user["container_api_client"]) user["repository_api"] = RepositoriesContainerApi( user["container_api_client"]) user["pushrepository_api"] = RepositoriesContainerPushApi( user["container_api_client"]) user["repo_version_api"] = RepositoriesContainerVersionsApi( user["container_api_client"]) user["tags_api"] = ContentTagsApi(user["container_api_client"]) user["manifests_api"] = ContentManifestsApi(user["container_api_client"]) user["blobs_api"] = ContentBlobsApi(user["container_api_client"]) return user
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)