def test_all(self): """Delete an artifact, it is removed from the filesystem. Do the following: 1. Create an artifact, and verify it is present on the filesystem. 2. Delete the artifact, and verify it is absent on the filesystem. """ cfg = config.get_config() cli_client = cli.Client(cfg) storage = utils.get_pulp_setting(cli_client, "DEFAULT_FILE_STORAGE") if storage != "pulpcore.app.models.storage.FileSystem": self.skipTest("this test only works for filesystem storage") media_root = utils.get_pulp_setting(cli_client, "MEDIA_ROOT") api_client = api.Client(cfg, api.json_handler) # create files = {"file": utils.http_get(FILE_URL)} artifact = api_client.post(ARTIFACTS_PATH, files=files) self.addCleanup(api_client.delete, artifact["pulp_href"]) cmd = ("ls", os.path.join(media_root, artifact["file"])) cli_client.run(cmd, sudo=True) # delete self.doCleanups() with self.assertRaises(CalledProcessError): cli_client.run(cmd, sudo=True)
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.api_client = ApiClient(configuration) cls.cli_client = cli.Client(cls.cfg) cls.storage = utils.get_pulp_setting(cls.cli_client, "DEFAULT_FILE_STORAGE") cls.media_root = utils.get_pulp_setting(cls.cli_client, "MEDIA_ROOT")
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.api_client = ApiClient(configuration) cls.cli_client = cli.Client(cls.cfg) cls.orphans_cleanup_api = OrphansCleanupApi(core_client) cls.storage = utils.get_pulp_setting(cls.cli_client, "DEFAULT_FILE_STORAGE") cls.media_root = utils.get_pulp_setting(cls.cli_client, "MEDIA_ROOT") orphans_response = cls.orphans_cleanup_api.cleanup({"orphan_protection_time": 0}) monitor_task(orphans_response.task)
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.cli_client = cli.Client(cls.cfg) cls.pkg_mgr = cli.PackageManager(cls.cfg) cls.api_client = api.Client(cls.cfg, api.json_handler) api_root = utils.get_pulp_setting(cls.cli_client, "API_ROOT").lstrip("/") signing_services = cls.api_client.using_handler(api.page_handler).get( f"{api_root}api/v3/signing-services/", params={"name": "sign-metadata"}) # NOTE: This is not used by the CI, only by local tests. The CI uses a separate # environment for API tests and Pulp, so the API tests don't have direct access # to run terminal commands. And cli.Client has issues with it as well. # # In the event of issues go look at post_before_script.sh. if not signing_services: init_signed_repo_configuration() signing_services = cls.api_client.using_handler( api.page_handler).get(f"{api_root}api/v3/signing-services/", params={"name": "sign-metadata"}) cls.metadata_signing_service = signing_services[0]
def set_pulp2_snapshot(name): """ Roll out a specific pulp 2 snapshot Args: name(str): directory name of the pulp 2 snapshot """ smash_cfg = smash_config.get_config() smash_cli_client = cli.Client(smash_cfg) pulp2_mongodb_conf = utils.get_pulp_setting(smash_cli_client, "PULP2_MONGODB") mongodb_host = pulp2_mongodb_conf['seeds'].split(':')[0] pulp2_fs_setup_script_path = '/tmp/set_pulp2.sh' # for running tests locally if smash_cfg.hosts[0].hostname == 'localhost': basepath = os.path.dirname(os.path.realpath(__file__)) pulp2_fs_setup_script_path = os.path.join(basepath, 'scripts/set_pulp2.sh') cmd = ('bash', pulp2_fs_setup_script_path, mongodb_host, name) smash_cli_client.run(cmd, sudo=True) # needs to be done locally otherwise auth is required because password is provided in the # cleartext. cmd = ('mongo', 'pulp_database', '--eval', 'db.createUser({user:"******",pwd:"ci_cd", ' 'roles:["readWrite"]});') subprocess.run(cmd)
def setUp(self): """Initialize Pulp with some content for our repair tests. 1. Create and sync a repo. 2. Select two content units from the repo, delete one artifact and corrupt another. """ # STEP 1 delete_orphans() repo = self.api_client.post(FILE_REPO_PATH, gen_repo()) self.addCleanup(self.api_client.delete, repo["pulp_href"]) body = gen_file_remote() remote = self.api_client.post(FILE_REMOTE_PATH, body) self.addCleanup(self.api_client.delete, remote["pulp_href"]) sync(self.cfg, remote, repo) repo = self.api_client.get(repo["pulp_href"]) # STEP 2 media_root = utils.get_pulp_setting(self.cli_client, "MEDIA_ROOT") content1, content2 = sample(get_content(repo)[FILE_CONTENT_NAME], 2) # Muddify one artifact on disk. artifact1_path = os.path.join( media_root, self.api_client.get(content1["artifact"])["file"]) cmd1 = ("sed", "-i", "-e", r"$a bit rot", artifact1_path) self.cli_client.run(cmd1, sudo=True) # Delete another one from disk. artifact2_path = os.path.join( media_root, self.api_client.get(content2["artifact"])["file"]) cmd2 = ("rm", artifact2_path) self.cli_client.run(cmd2, sudo=True) self.repo = repo
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.cli_client = cli.Client(cls.cfg) allowed_imports = get_pulp_setting(cls.cli_client, "ALLOWED_IMPORT_PATHS") if not allowed_imports or "/tmp" not in allowed_imports: raise unittest.SkipTest( "Cannot run import-tests unless /tmp is in ALLOWED_IMPORT_PATHS ({})." .format(allowed_imports), ) cls.client = api.Client(cls.cfg, api.json_handler) cls.core_client = CoreApiClient( configuration=cls.cfg.get_bindings_config()) cls.file_client = gen_file_client() cls.repo_api = RepositoriesFileApi(cls.file_client) cls.remote_api = RemotesFileApi(cls.file_client) cls.versions_api = RepositoriesFileVersionsApi(cls.file_client) cls.content_api = ContentFilesApi(cls.file_client) cls.exporter_api = ExportersPulpApi(cls.core_client) cls.exports_api = ExportersCoreExportsApi(cls.core_client) cls.importer_api = ImportersPulpApi(cls.core_client) cls.imports_api = ImportersCoreImportsApi(cls.core_client) cls.import_check_api = ImportersCoreImportCheckApi(cls.core_client) (cls.import_repos, cls.export_repos, cls.remotes) = cls._setup_repositories() cls.exporter = cls._create_exporter() cls.export = cls._create_export() cls.chunked_export = cls._create_chunked_export() cls._setup_import_check_directories()
def setUp(self): """Make an API client.""" self.client = api.Client(config.get_config(), api.json_handler) self.status_response = STATUS cli_client = cli.Client(config.get_config()) self.storage = utils.get_pulp_setting(cli_client, "DEFAULT_FILE_STORAGE") if self.storage != "pulpcore.app.models.storage.FileSystem": self.status_response["properties"].pop("storage", None)
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.client = gen_rpm_client() cls.cli_client = cli.Client(cls.cfg) cls.repo_api = RepositoriesRpmApi(cls.client) cls.remote_api = RemotesRpmApi(cls.client) delete_orphans(cls.cfg) cls.md5_allowed = "md5" in get_pulp_setting( cls.cli_client, "ALLOWED_CONTENT_CHECKSUMS")
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.api_client = api.Client(cls.cfg, api.smart_handler) cls.cli_client = cli.Client(cls.cfg) storage = utils.get_pulp_setting(cls.cli_client, "DEFAULT_FILE_STORAGE") if storage not in SUPPORTED_STORAGE_FRAMEWORKS: raise unittest.SkipTest( "Cannot simulate bit-rot on this storage platform ({}).". format(storage), )
def test_content_served_immediate_with_range_request_invalid_start_value(self): """Assert that range requests with a negative start value errors as expected.""" cfg = config.get_config() cli_client = cli.Client(cfg) storage = utils.get_pulp_setting(cli_client, "DEFAULT_FILE_STORAGE") if storage != "pulpcore.app.models.storage.FileSystem": self.skipTest("The S3 test API project doesn't handle invalid Range values correctly") self.setup_download_test("immediate", url=FILE_CHUNKED_FIXTURE_MANIFEST_URL) with self.assertRaises(HTTPError) as cm: download_content_unit_return_requests_response( self.cfg, self.distribution.to_dict(), "1.iso", headers={"Range": "bytes=-1-11"} ) self.assertEqual(cm.exception.response.status_code, 416)
def set_pulp2_snapshot(name): """ Roll out a specific pulp 2 snapshot Args: name(str): directory name of the pulp 2 snapshot """ smash_cfg = smash_config.get_config() smash_cli_client = cli.Client(smash_cfg) pulp2_mongodb_conf = utils.get_pulp_setting(smash_cli_client, "PULP2_MONGODB") mongodb_host = pulp2_mongodb_conf["seeds"].split(":")[0] pulp2_fs_setup_script_path = "/tmp/set_pulp2.sh" # for running tests locally if smash_cfg.hosts[0].hostname == "localhost": basepath = os.path.dirname(os.path.realpath(__file__)) pulp2_fs_setup_script_path = os.path.join(basepath, "scripts/set_pulp2.sh") cmd = ("bash", pulp2_fs_setup_script_path, mongodb_host, name) smash_cli_client.run(cmd, sudo=True) # needs to be done locally otherwise auth is required because password is provided in the # cleartext. cmd = ( "mongo", "pulp_database", "--eval", 'db.createUser({user:"******",pwd:"ci_cd",roles:["readWrite"],passwordDigestor:"server"});', "--host", mongodb_host, ) subprocess.run(cmd)
DistributionsContainerApi, PulpContainerNamespacesApi, RepositoriesContainerApi, RepositoriesContainerPushApi, RepositoriesContainerVersionsApi, ) cfg = config.get_config() cli_client = cli.Client(cfg) configuration = cfg.get_bindings_config() core_client = CoreApiClient(configuration) users_api = UsersApi(core_client) users_roles_api = UsersRolesApi(core_client) TOKEN_AUTH_DISABLED = utils.get_pulp_setting(cli_client, "TOKEN_AUTH_DISABLED") 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)
UnTagImage, ) from pulp_container.tests.functional.utils import ( gen_container_client, gen_container_remote, get_auth_for_url, ) STANDARD_FILE_STORAGE_FRAMEWORKS = [ "django.core.files.storage.FileSystemStorage", "pulpcore.app.models.storage.FileSystem", ] cli_client = cli.Client(config.get_config()) DEFAULT_FILE_STORAGE = utils.get_pulp_setting(cli_client, "DEFAULT_FILE_STORAGE") CACHE_ENABLED = utils.get_pulp_setting(cli_client, "CACHE_ENABLED") PULP_CONTENT_HOST_BASE_URL = config.get_config().get_base_url() @unittest.skipUnless(CACHE_ENABLED, "The caching machinery was not enabled") class ContentCacheTestCache(unittest.TestCase): """A test case that verifies the functionality of the Redis caching machinery.""" @classmethod def setUpClass(cls): """Sync a remote repository and create a new distribution pointing to the repository.""" client_api = gen_container_client() cls.blobs_api = ContentBlobsApi(client_api) cls.manifests_api = ContentManifestsApi(client_api) cls.tags_api = ContentTagsApi(client_api)