def test_noop_resync_collections_from_pulp(self): """Test whether sync yields no-op when repo hasn't changed since last sync.""" second_body = gen_ansible_remote( url=self.distribution.client_url, requirements_file=self.requirements_file, sync_dependencies=False, ) second_remote = self.remote_collection_api.create(second_body) self.addCleanup(self.remote_collection_api.delete, second_remote.pulp_href) second_repo = self._create_repo_and_sync_with_remote(second_remote) second_content = self.cv_api.list( repository_version=f"{second_repo.pulp_href}versions/1/") self.assertGreaterEqual(len(second_content.results), 1) # Resync repository_sync_data = AnsibleRepositorySyncURL( remote=second_remote.pulp_href, optimize=True) sync_response = self.repo_api.sync(second_repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) second_repo = self.repo_api.read(second_repo.pulp_href) task = tasks.read(sync_response.task) msg = "no-op: {url} did not change since last sync".format( url=second_remote.url) messages = [r.message for r in task.progress_reports] self.assertIn(msg, str(messages))
def test_v3_sync(self): """Test syncing Pulp to Pulp over v3 api.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) body = gen_ansible_remote(url=GALAXY_ANSIBLE_BASE_URL, requirements_file=DEMO_REQUIREMENTS) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the repository. self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = self.repo_api.read(repo.pulp_href) self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/1/") # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) self.addCleanup(self.distributions_api.delete, distribution.pulp_href) # Create a second repo. mirror_repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, mirror_repo.pulp_href) body = gen_ansible_remote(url=distribution.client_url, requirements_file=DEMO_REQUIREMENTS) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the second repository. self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(mirror_repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) mirror_repo = self.repo_api.read(mirror_repo.pulp_href) self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/1/") # Check content of both repos. original_content = self.cv_api.list( repository_version=f"{repo.pulp_href}versions/1/") mirror_content = self.cv_api.list( repository_version=f"{mirror_repo.pulp_href}versions/1/") self.assertTrue( mirror_content.results) # check that we have some results self.assertEqual(sorted(original_content.results), sorted(mirror_content.results))
def test_v3_sync(self): """Test syncing Pulp to Pulp over v3 api.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) body = gen_ansible_remote(url=ANSIBLE_COLLECTION_TESTING_URL_V2) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the repository. self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = self.repo_api.read(repo.pulp_href) self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/1/") # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) self.addCleanup(self.distributions_api.delete, distribution.pulp_href) # Create a second repo. mirror_repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, mirror_repo.pulp_href) url = (distribution.client_url + "/api/v3/collections/" + ANSIBLE_DEMO_COLLECTION.replace(".", "/")) body = gen_ansible_remote(url=url) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the second repository. self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(mirror_repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) mirror_repo = self.repo_api.read(mirror_repo.pulp_href) self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/1/") # Check content of both repos. original_content = self.cv_api.list( repository_version=f"{repo.pulp_href}versions/1/") mirror_content = self.cv_api.list( repository_version=f"{mirror_repo.pulp_href}versions/1/") self.assertTrue( mirror_content.results) # check that we have some results self.assertEqual(sorted(original_content.results), sorted(mirror_content.results))
def _build_and_publish_collections(cls): """Builds and publishes the collections to be used in this test.""" cls.collections = [] cls.repo, cls.distro = cls._create_empty_repo_and_distribution( cls(), cleanup=False) upload_api = PulpAnsibleArtifactsCollectionsV3Api(cls.client) for config in TEST_COLLECTION_CONFIGS: collection = build_collection("skeleton", config=config) upload_response = upload_api.create(cls.distro.base_path, collection.filename) monitor_task("/pulp/api/v3/tasks/{}/".format( upload_response.task[-37:-1])) cls.collections.append(collection) cls.distro.client_url += "api/"
def test_update_requirements_file(self): """Test requirements_file update.""" body = gen_ansible_remote( url=self.distribution.client_url, requirements_file=self.requirements_file, ) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) repo = self._create_repo_and_sync_with_remote(remote) self.assertIsNotNone(repo.last_synced_metadata_time) response = self.remote_collection_api.partial_update( remote.pulp_href, {"requirements_file": "collections:\n - ansible.posix"}) monitor_task(response.task) repo = self.repo_api.read(repo.pulp_href) self.assertIsNone(repo.last_synced_metadata_time)
def test_install_role(self): """Test whether ansible-galaxy can install a Role hosted by Pulp.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) body = gen_ansible_remote(url=ANSIBLE_ELASTIC_FIXTURE_URL) remote = self.remote_role_api.create(body) self.addCleanup(self.remote_role_api.delete, remote.pulp_href) # Sync the repository. self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = self.repo_api.read(repo.pulp_href) # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) self.addCleanup(self.distributions_api.delete, distribution.pulp_href) with tempfile.TemporaryDirectory() as temp_dir: cmd = "ansible-galaxy role install {} -c -s {} -p {}".format( ANSIBLE_ELASTIC_ROLE_WHITELIST, distribution.client_url, temp_dir) directory = "{}/{}".format(temp_dir, ANSIBLE_ELASTIC_ROLE_NAMESPACE_NAME) self.assertTrue(not path.exists(directory), "Directory {} already exists".format(directory)) subprocess.run(cmd.split()) self.assertTrue(path.exists(directory), "Could not find directory {}".format(directory))
def create_install_scenario(self, body, collection_name): """Create Install scenario.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the repository. self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = self.repo_api.read(repo.pulp_href) # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) self.addCleanup(self.distributions_api.delete, distribution.pulp_href) with tempfile.TemporaryDirectory() as temp_dir: # FIXME Use --no-deps while https://pulp.plan.io/issues/7751 is not addressed cmd = "ansible-galaxy collection install {} -c -s {} -p {} --no-deps".format( collection_name, distribution.client_url, temp_dir) directory = "{}/ansible_collections/{}".format( temp_dir, collection_name.replace(".", "/")) self.assertTrue(not path.exists(directory), "Directory {} already exists".format(directory)) subprocess.run(cmd.split()) self.assertTrue(path.exists(directory), "Could not find directory {}".format(directory))
def test_upload_collection(self): """Test whether ansible-galaxy can upload a Collection to Pulp.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) self.addCleanup(self.distributions_api.delete, distribution.pulp_href) with tempfile.TemporaryDirectory() as temp_dir: collection_name = "".join( [random.choice(string.ascii_lowercase) for i in range(26)]) cmd = "ansible-galaxy collection init --init-path {} pulp.{}".format( temp_dir, collection_name) subprocess.run(cmd.split()) cmd = "ansible-galaxy collection build --output-path {} {}{}".format( temp_dir, temp_dir, "/pulp/" + collection_name + "/") subprocess.run(cmd.split()) repo_version = self.repo_versions_api.read( repo.latest_version_href) self.assertEqual(repo_version.number, 0) # We uploaded 1 collection cmd = "ansible-galaxy collection publish -c -s {} {}{}".format( distribution.client_url, temp_dir, "/pulp-" + collection_name + "-1.0.0.tar.gz") subprocess.run(cmd.split()) wait_tasks() repo = self.repo_api.read(repo.pulp_href) repo_version = self.repo_versions_api.read(repo.latest_version_href) self.assertEqual(repo_version.number, 1) # We uploaded 1 collection
def test_v3_sync(self): """Test syncing Pulp to Pulp over v3 api.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) requirements = 'collections:\n - source: pulp.pulp_installer\n version: "<=3.6.2"' body = gen_ansible_remote(url=GALAXY_ANSIBLE_BASE_URL, requirements_file=requirements) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the repository. self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = self.repo_api.read(repo.pulp_href) self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/1/") # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) original_path = distribution.base_path self.addCleanup(self.distributions_api.delete, distribution.pulp_href) # Create a second repo. mirror_repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, mirror_repo.pulp_href) COLLECTION_VERSION = "3.6.2" body = gen_ansible_remote(url=distribution.client_url, requirements_file=requirements) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the second repository. self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(mirror_repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) mirror_repo = self.repo_api.read(mirror_repo.pulp_href) self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/1/") # Create a distribution. body = gen_distribution() body["repository"] = mirror_repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) mirror_path = distribution.base_path self.addCleanup(self.distributions_api.delete, distribution.pulp_href) # Check content of both repos. original_content = self.collections_api.list(path=original_path) mirror_content = self.collections_api.list(path=mirror_path) self.assertEqual(mirror_content.data[0].highest_version["version"], COLLECTION_VERSION) self.assertNotEqual( original_content.data[0].highest_version["version"], COLLECTION_VERSION, )
def test_v3_sync(self): """Test syncing Pulp to Pulp over v3 api.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) body = gen_ansible_remote(url=ANSIBLE_COLLECTION_PULP_URL_V2) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the repository. self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo = self.repo_api.read(repo.pulp_href) self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/1/") # Create a distribution. body = gen_distribution() body["repository"] = repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) original_path = distribution.base_path self.addCleanup(self.distributions_api.delete, distribution.pulp_href) # Create a second repo. mirror_repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, mirror_repo.pulp_href) COLLECTION_VERSION = "3.6.2" url = (distribution.client_url + "/api/v3/collections/" + PULP_INSTALLER_COLLECTION.replace(".", "/") + "/versions/" + COLLECTION_VERSION) body = gen_ansible_remote(url=url) remote = self.remote_collection_api.create(body) self.addCleanup(self.remote_collection_api.delete, remote.pulp_href) # Sync the second repository. self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/0/") repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(mirror_repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) mirror_repo = self.repo_api.read(mirror_repo.pulp_href) self.assertEqual(mirror_repo.latest_version_href, f"{mirror_repo.pulp_href}versions/1/") # Create a distribution. body = gen_distribution() body["repository"] = mirror_repo.pulp_href distribution_create = self.distributions_api.create(body) distribution_url = monitor_task(distribution_create.task) distribution = self.distributions_api.read(distribution_url[0]) mirror_path = distribution.base_path self.addCleanup(self.distributions_api.delete, distribution.pulp_href) # Check content of both repos. original_content = self.collections_api.list(path=original_path) mirror_content = self.collections_api.list(path=mirror_path) self.assertEqual(mirror_content.data[0].highest_version["version"], COLLECTION_VERSION) self.assertNotEqual( original_content.data[0].highest_version["version"], COLLECTION_VERSION, )