def test_clean_orphan_artifact(self): """Test whether orphan artifacts units can be clean up.""" repo_api = RepositoriesFileApi(self.api_client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) artifacts_api = ArtifactsApi(core_client) artifact = artifacts_api.create(file=__file__) if self.storage == "pulpcore.app.models.storage.FileSystem": cmd = ("ls", os.path.join(self.media_root, artifact.file)) self.cli_client.run(cmd, sudo=True) orphans_response = self.orphans_cleanup_api.cleanup({"orphan_protection_time": 10}) monitor_task(orphans_response.task) # assert artifact was not removed artifacts = artifacts_api.list().count self.assertEqual(artifacts, 1) orphans_response = self.orphans_cleanup_api.cleanup({"orphan_protection_time": 0}) monitor_task(orphans_response.task) with self.assertRaises(ApiException): artifacts_api.read(artifact.pulp_href) if self.storage == "pulpcore.app.models.storage.FileSystem": with self.assertRaises(CalledProcessError): self.cli_client.run(cmd)
def test_all(self): """Perform a lazy sync and change to immeditae to force download.""" # delete orphans to assure that no content units are present on the # file system delete_orphans() client = gen_file_client() artifacts_api = ArtifactsApi(core_client) repo_api = RepositoriesFileApi(client) remote_api = RemotesFileApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_file_remote(policy=choice(ON_DEMAND_DOWNLOAD_POLICIES)) remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) # Sync the repository using a lazy download policy repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) artifacts = artifacts_api.list().to_dict()["results"] self.assertEqual(len(artifacts), 0, artifacts) # Update the policy to immediate response = remote_api.partial_update(remote.pulp_href, {"policy": "immediate"}) monitor_task(response.task) remote = remote_api.read(remote.pulp_href) self.assertEqual(remote.policy, "immediate") # Sync using immediate download policy repository_sync_data = RepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) # Assert that missing artifacts are downloaded artifacts = artifacts_api.list().to_dict()["results"] self.assertEqual(len(artifacts), FILE_FIXTURE_COUNT, artifacts)