def setUpModule(): # pylint:disable=invalid-name """Conditionally skip tests. Create repositories with fixture data.""" cfg = config.get_config() if selectors.bug_is_untestable(1991, cfg.pulp_version): raise unittest.SkipTest('https://pulp.plan.io/issues/1991') set_up_module() # Fetch RPMs. _SIGNED_PACKAGES['rpm'] = utils.http_get(RPM_SIGNED_URL) _SIGNED_PACKAGES['srpm'] = utils.http_get(SRPM_SIGNED_URL) _UNSIGNED_PACKAGES['rpm'] = utils.http_get(RPM_UNSIGNED_URL) _UNSIGNED_PACKAGES['srpm'] = utils.http_get(SRPM_UNSIGNED_URL) if selectors.bug_is_testable(1806, cfg.pulp_version): _SIGNED_PACKAGES['drpm'] = utils.http_get(DRPM_SIGNED_URL) _UNSIGNED_PACKAGES['drpm'] = utils.http_get(DRPM_UNSIGNED_URL) # Create repos, and upload RPMs to them. client = api.Client(cfg, api.json_handler) try: repo = client.post(REPOSITORY_PATH, gen_repo()) _REPOS['signed'] = repo for type_id, pkg in _SIGNED_PACKAGES.items(): utils.upload_import_unit(cfg, pkg, {'unit_type_id': type_id}, repo) repo = client.post(REPOSITORY_PATH, gen_repo()) _REPOS['unsigned'] = repo for type_id, pkg in _UNSIGNED_PACKAGES.items(): utils.upload_import_unit(cfg, pkg, {'unit_type_id': type_id}, repo) except: # noqa:E722 _SIGNED_PACKAGES.clear() _UNSIGNED_PACKAGES.clear() for _ in range(len(_REPOS)): client.delete(_REPOS.popitem()[1]['_href']) raise
def setUpModule(): # pylint:disable=invalid-name """Conditionally skip tests. Create repositories with fixture data.""" cfg = config.get_config() if selectors.bug_is_untestable(1991, cfg.version): raise unittest.SkipTest('https://pulp.plan.io/issues/1991') set_up_module() # Fetch RPMs. _SIGNED_PACKAGES['rpm'] = utils.http_get(RPM_URL) _SIGNED_PACKAGES['srpm'] = utils.http_get(SRPM_URL) _UNSIGNED_PACKAGES['rpm'] = utils.http_get(RPM_UNSIGNED_URL) _UNSIGNED_PACKAGES['srpm'] = utils.http_get(SRPM_UNSIGNED_URL) if selectors.bug_is_testable(1806, cfg.version): _SIGNED_PACKAGES['drpm'] = utils.http_get(DRPM_URL) _UNSIGNED_PACKAGES['drpm'] = utils.http_get(DRPM_UNSIGNED_URL) # Create repos, and upload RPMs to them. client = api.Client(cfg, api.json_handler) try: repo = client.post(REPOSITORY_PATH, gen_repo()) _REPOS['signed'] = repo for type_id, pkg in _SIGNED_PACKAGES.items(): utils.upload_import_unit(cfg, pkg, type_id, repo['_href']) repo = client.post(REPOSITORY_PATH, gen_repo()) _REPOS['unsigned'] = repo for type_id, pkg in _UNSIGNED_PACKAGES.items(): utils.upload_import_unit(cfg, pkg, type_id, repo['_href']) except: _SIGNED_PACKAGES.clear() _UNSIGNED_PACKAGES.clear() for _ in range(len(_REPOS)): client.delete(_REPOS.popitem()[1]['_href']) raise
def test_all(self): """Add a content unit to a repo in the middle of several publishes.""" cfg = config.get_config() if selectors.bug_is_untestable(2532, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/2532') rpms = (utils.http_get(RPM_UNSIGNED_URL), utils.http_get(RPM2_UNSIGNED_URL)) # Create a user and a repository. ssh_user, priv_key = self.make_user(cfg) ssh_identity_file = self.write_private_key(cfg, priv_key) repo = self.make_repo( cfg, { 'remote': { 'host': urlparse(cfg.get_base_url()).hostname, 'root': '/home/' + ssh_user, 'ssh_identity_file': ssh_identity_file, 'ssh_user': ssh_user, } }) # Add content, publish w/yum, add more content, publish w/rsync. dists = get_dists_by_type_id(cfg, repo) for i, key in enumerate(('yum_distributor', 'rpm_rsync_distributor')): utils.upload_import_unit(cfg, rpms[i], {'unit_type_id': 'rpm'}, repo) utils.publish_repo(cfg, repo, {'id': dists[key]['id']}) self.verify_remote_units_path(cfg, dists['rpm_rsync_distributor'], 1) # Publish with yum and rsync, respectively. for key in 'yum_distributor', 'rpm_rsync_distributor': utils.publish_repo(cfg, repo, {'id': dists[key]['id']}) self.verify_remote_units_path(cfg, dists['rpm_rsync_distributor'], 1)
def test_01_add_unit(self): """Add a content unit to the repository. Publish the repository.""" repo_before = self.get_repo() rpm = utils.http_get(RPM_UNSIGNED_URL) utils.upload_import_unit( self.cfg, rpm, {'unit_type_id': 'rpm'}, self.repo, ) utils.publish_repo(self.cfg, repo_before) repo_after = self.get_repo() with self.subTest(comment='last_unit_added'): if selectors.bug_is_untestable(1847, self.cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/1847') pre = repo_before['last_unit_added'] post = repo_after['last_unit_added'] self.assertIsNone(pre) self.assertIsNotNone(post) with self.subTest(comment='last_unit_removed'): pre = repo_before['last_unit_removed'] post = repo_after['last_unit_removed'] self.assertIsNone(pre) self.assertIsNone(post) with self.subTest(comment='last_publish'): pre = repo_before['distributors'][0]['last_publish'] post = repo_after['distributors'][0]['last_publish'] self.assertIsNone(pre) self.assertIsNotNone(post)
def test_all(self): """Test that uploading DRPM with checksumtype specified works.""" if selectors.bug_is_untestable(1806, self.cfg.pulp_version): raise unittest.SkipTest('https://pulp.plan.io/issues/1806') if selectors.bug_is_untestable(2627, self.cfg.pulp_version): raise unittest.SkipTest('https://pulp.plan.io/issues/2627') client = api.Client(self.cfg) repo = client.post(REPOSITORY_PATH, gen_repo()).json() self.addCleanup(client.delete, repo['_href']) drpm = utils.http_get(DRPM_UNSIGNED_URL) utils.upload_import_unit( self.cfg, drpm, { 'unit_type_id': 'drpm', 'unit_metadata': { 'checksumtype': 'sha256' }, }, repo, ) units = utils.search_units(self.cfg, repo, {}) self.assertEqual(len(units), 1, units) # Test if DRPM extracted correct metadata for creating filename. self.assertEqual( units[0]['metadata']['filename'], DRPM, )
def test_all(self): """Test whether one can upload an RPM with non-ascii metadata.""" cfg = config.get_config() client = api.Client(cfg, api.json_handler) repo = client.post(REPOSITORY_PATH, gen_repo()) self.addCleanup(client.delete, repo['_href']) rpm = utils.http_get(RPM_WITH_NON_ASCII_URL) utils.upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo)
def test_all(self): """Test whether one can upload an RPM with non-ascii metadata.""" cfg = config.get_config() if selectors.bug_is_untestable(1903, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/1903') client = api.Client(cfg, api.json_handler) repo = client.post(REPOSITORY_PATH, gen_repo()) self.addCleanup(client.delete, repo['_href']) rpm = utils.http_get(RPM_WITH_NON_UTF_8_URL) utils.upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo)
def upload_import_unit(url): """Upload and import the unit at ``url`` to ``repo``.""" unit = utils.http_get(url) utils.upload_import_unit( self.cfg, unit, { 'unit_key': { 'filename': basename(urlparse(url).path) }, 'unit_type_id': 'python_package', }, repo)
def test_all(self): """Test whether copied files retain their original mtime. This test targets the following issues: * `Pulp #2783 <https://pulp.plan.io/issues/2783>`_ * `Pulp Smash #720 <https://github.com/PulpQE/pulp-smash/issues/720>`_ Do the following: 1. Create, sync and publish a repository, with ``generate_sqlite`` set to true. 2. Get the ``mtime`` of the sqlite files. 3. Upload an RPM package into the repository, and sync the repository. 4. Get the ``mtime`` of the sqlite files again. Verify that the mtimes are the same. """ cfg = config.get_config() if selectors.bug_is_untestable(2783, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/2783') # Create, sync and publish a repository. client = api.Client(cfg, api.json_handler) body = gen_repo() body['importer_config']['feed'] = RPM_UNSIGNED_FEED_URL body['distributors'] = [gen_distributor()] body['distributors'][0]['distributor_config']['generate_sqlite'] = True repo = client.post(REPOSITORY_PATH, body) self.addCleanup(client.delete, repo['_href']) repo = client.get(repo['_href'], params={'details': True}) utils.sync_repo(cfg, repo) utils.publish_repo(cfg, repo) # Get the mtime of the sqlite files. cli_client = cli.Client(cfg, cli.echo_handler) cmd = '' if utils.is_root(cfg) else 'sudo ' cmd += "bash -c \"stat --format %Y '{}'/*\"".format( os.path.join( _PATH, repo['distributors'][0]['config']['relative_url'], 'repodata', )) mtimes_pre = ( cli_client.machine.session().run(cmd)[1].strip().split().sort()) # Upload to the repo, and sync it. rpm = utils.http_get(RPM_SIGNED_URL) utils.upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo) utils.sync_repo(cfg, repo) # Get the mtime of the sqlite files again. time.sleep(1) mtimes_post = ( cli_client.machine.session().run(cmd)[1].strip().split().sort()) self.assertEqual(mtimes_pre, mtimes_post)
def test_upload(self): """Test whether Pulp recognizes an uploaded RPM's vendor information. Create a repository, upload an RPM with a non-null vendor, and perform several checks. See :meth:`do_test`. """ client = api.Client(self.cfg, api.json_handler) repo = client.post(REPOSITORY_PATH, gen_repo()) self.addCleanup(client.delete, repo['_href']) rpm = utils.http_get(RPM_WITH_VENDOR_URL) utils.upload_import_unit(self.cfg, rpm, {'unit_type_id': 'rpm'}, repo) self.do_test(repo)
def test_all(self): """Publish a repository with the repoview feature on and off.""" cfg = config.get_config() if cfg.version < Version('2.9'): self.skipTest('https://pulp.plan.io/issues/189') # Create a repo, and add content client = api.Client(cfg, api.json_handler) body = gen_repo() body['distributors'] = [gen_distributor()] repo_href = client.post(constants.REPOSITORY_PATH, body)['_href'] self.addCleanup(client.delete, repo_href) rpm = utils.http_get(constants.RPM_UNSIGNED_URL) utils.upload_import_unit(cfg, rpm, 'rpm', repo_href) # Gather some facts about the repo distributor dist = client.get(urljoin(repo_href, 'distributors/'))[0] dist_url = urljoin('/pulp/repos/', dist['config']['relative_url']) # Publish the repo client.response_handler = api.safe_handler client.post(urljoin(repo_href, 'actions/publish/'), {'id': dist['id']}) response = client.get(dist_url) with self.subTest(comment='first publish'): self.assertEqual(len(response.history), 0, response.history) # Publish the repo a second time client.post( urljoin(repo_href, 'actions/publish/'), { 'id': dist['id'], 'override_config': { 'generate_sqlite': True, 'repoview': True, } }, ) response = client.get(dist_url) with self.subTest(comment='second publish'): self.assertEqual(len(response.history), 1, response.history) self.assertEqual( response.request.url, urljoin(response.history[0].request.url, 'repoview/index.html')) # Publish the repo a third time if selectors.bug_is_untestable(2349, cfg.version): self.skipTest('https://pulp.plan.io/issues/2349') client.post(urljoin(repo_href, 'actions/publish/'), {'id': dist['id']}) response = client.get(dist_url) with self.subTest(comment='third publish'): self.assertEqual(len(response.history), 0, response.history)
def test_unsigned_packages(self): """Import unsigned DRPM, RPM and SRPM packages into the repository. Verify that each import succeeds. """ for key, package in _UNSIGNED_PACKAGES.items(): with self.subTest(key=key): utils.upload_import_unit( self.cfg, package, key.split(' ')[-1], self.repo_href, )
def test_signed_packages(self): """Import signed DRPM, RPM and SRPM packages into the repo. Verify that each import succeeds. """ for key, package in _SIGNED_PACKAGES.items(): with self.subTest(key=key): utils.upload_import_unit( self.cfg, package, {'unit_type_id': key.split(' ')[-1]}, self.repo, )
def test_signed_packages(self): """Import signed DRPM, RPM and SRPM packages into the repository. Verify that each import fails. """ for key, package in _SIGNED_PACKAGES.items(): with self.subTest(key=key): with self.assertRaises(exceptions.TaskReportError): utils.upload_import_unit( self.cfg, package, key.split(' ')[-1], self.repo_href, )
def test_unsigned_packages(self): """Import unsigned DRPM, RPM and SRPM packages into the repo. Verify that each import fails. """ for key, package in _UNSIGNED_PACKAGES.items(): with self.subTest(key=key): with self.assertRaises(exceptions.TaskReportError): utils.upload_import_unit( self.cfg, package, {'unit_type_id': key.split(' ')[-1]}, self.repo, )
def test_all(self): """Publish a repository with the repoview feature on and off.""" cfg = config.get_config() if cfg.pulp_version < Version('2.9'): self.skipTest('https://pulp.plan.io/issues/189') # Create a repo, and add content client = api.Client(cfg) body = gen_repo() body['distributors'] = [gen_distributor()] repo = client.post(REPOSITORY_PATH, body).json() self.addCleanup(client.delete, repo['_href']) rpm = utils.http_get(constants.RPM_UNSIGNED_URL) utils.upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo) # Get info about the repo distributor repo = client.get(repo['_href'], params={'details': True}).json() pub_path = urljoin('/pulp/repos/', repo['distributors'][0]['config']['relative_url']) # Publish the repo utils.publish_repo(cfg, repo) response = client.get(pub_path) with self.subTest(comment='first publish'): self.assertEqual(len(response.history), 0, response.history) # Publish the repo a second time utils.publish_repo( cfg, repo, { 'id': repo['distributors'][0]['id'], 'override_config': { 'generate_sqlite': True, 'repoview': True }, }) response = client.get(pub_path) with self.subTest(comment='second publish'): self.assertEqual(len(response.history), 1, response.history) self.assertEqual( response.request.url, urljoin(response.history[0].request.url, 'repoview/index.html')) # Publish the repo a third time if selectors.bug_is_untestable(2349, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/2349') utils.publish_repo(cfg, repo) response = client.get(pub_path) with self.subTest(comment='third publish'): self.assertEqual(len(response.history), 0, response.history)
def test_all(self): """Publish a repository with the repoview feature on and off.""" cfg = config.get_config() if cfg.version < Version('2.9'): self.skipTest('https://pulp.plan.io/issues/189') # Create a repo, and add content client = api.Client(cfg, api.json_handler) body = gen_repo() body['distributors'] = [gen_distributor()] repo_href = client.post(constants.REPOSITORY_PATH, body)['_href'] self.addCleanup(client.delete, repo_href) rpm = utils.http_get(constants.RPM_UNSIGNED_URL) utils.upload_import_unit(cfg, rpm, 'rpm', repo_href) # Gather some facts about the repo distributor dist = client.get(urljoin(repo_href, 'distributors/'))[0] dist_url = urljoin('/pulp/repos/', dist['config']['relative_url']) # Publish the repo client.response_handler = api.safe_handler client.post(urljoin(repo_href, 'actions/publish/'), {'id': dist['id']}) response = client.get(dist_url) with self.subTest(comment='first publish'): self.assertEqual(len(response.history), 0, response.history) # Publish the repo a second time client.post( urljoin(repo_href, 'actions/publish/'), {'id': dist['id'], 'override_config': { 'generate_sqlite': True, 'repoview': True, }}, ) response = client.get(dist_url) with self.subTest(comment='second publish'): self.assertEqual(len(response.history), 1, response.history) self.assertEqual( response.request.url, urljoin(response.history[0].request.url, 'repoview/index.html') ) # Publish the repo a third time if selectors.bug_is_untestable(2349, cfg.version): self.skipTest('https://pulp.plan.io/issues/2349') client.post(urljoin(repo_href, 'actions/publish/'), {'id': dist['id']}) response = client.get(dist_url) with self.subTest(comment='third publish'): self.assertEqual(len(response.history), 0, response.history)
def test_all(self): """Publish with a yum and rsync distributor twice.""" cfg = config.get_config() if selectors.bug_is_untestable(2666, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/2666') if check_issue_2844(cfg): self.skipTest('https://pulp.plan.io/issues/2844') # Create a user and a repository. ssh_user, priv_key = self.make_user(cfg) ssh_identity_file = self.write_private_key(cfg, priv_key) repo = self.make_repo( cfg, { 'remote': { 'host': urlparse(cfg.get_base_url()).hostname, 'root': '/home/' + ssh_user, 'ssh_identity_file': ssh_identity_file, 'ssh_user': ssh_user, } }) # Add content. for url in (RPM_UNSIGNED_URL, RPM2_UNSIGNED_URL): utils.upload_import_unit(cfg, utils.http_get(url), {'unit_type_id': 'rpm'}, repo) dists = get_dists_by_type_id(cfg, repo) # See https://pulp.plan.io/issues/2844#note-11 time.sleep(2) # Publish with yum and rsync. for dist in 'yum_distributor', 'rpm_rsync_distributor': report = (utils.publish_repo(cfg, repo, { 'id': dists[dist]['id'] }).json()) publish_task = self.get_publish_task(cfg, report) num_processed = self.get_num_processed(publish_task) with self.subTest(comment='first rsync publish'): self.assertEqual(num_processed, 2, publish_task) # Publish with yum and rsync again. for dist in 'yum_distributor', 'rpm_rsync_distributor': report = (utils.publish_repo(cfg, repo, { 'id': dists[dist]['id'] }).json()) publish_task = self.get_publish_task(cfg, report) num_processed = self.get_num_processed(publish_task) with self.subTest(comment='second rsync publish'): self.assertEqual(num_processed, 0, publish_task)
def test_01_upload_publish(self): """Upload an RPM to the first repository, and publish it. Execute :meth:`verify_repo_search` and :meth:`verify_repo_download`. """ repo = self.repos[0] utils.upload_import_unit( self.cfg, self.rpm, {'unit_type_id': 'rpm'}, repo, ) utils.publish_repo(self.cfg, repo) self.verify_repo_search(repo) self.verify_repo_download(repo)
def test_all(self): """Publish a repository with the repoview feature on and off.""" cfg = config.get_config() if cfg.version < Version('2.9'): self.skipTest('https://pulp.plan.io/issues/189') # Create a repo, and add content client = api.Client(cfg) body = gen_repo() body['distributors'] = [gen_distributor()] repo = client.post(constants.REPOSITORY_PATH, body).json() self.addCleanup(client.delete, repo['_href']) rpm = utils.http_get(constants.RPM_UNSIGNED_URL) utils.upload_import_unit(cfg, rpm, 'rpm', repo['_href']) # Get info about the repo distributor repo = client.get(repo['_href'], params={'details': True}).json() pub_path = urljoin( '/pulp/repos/', repo['distributors'][0]['config']['relative_url'] ) # Publish the repo utils.publish_repo(cfg, repo) response = client.get(pub_path) with self.subTest(comment='first publish'): self.assertEqual(len(response.history), 0, response.history) # Publish the repo a second time utils.publish_repo(cfg, repo, { 'id': repo['distributors'][0]['id'], 'override_config': {'generate_sqlite': True, 'repoview': True}, }) response = client.get(pub_path) with self.subTest(comment='second publish'): self.assertEqual(len(response.history), 1, response.history) self.assertEqual( response.request.url, urljoin(response.history[0].request.url, 'repoview/index.html') ) # Publish the repo a third time if selectors.bug_is_untestable(2349, cfg.version): self.skipTest('https://pulp.plan.io/issues/2349') utils.publish_repo(cfg, repo) response = client.get(pub_path) with self.subTest(comment='third publish'): self.assertEqual(len(response.history), 0, response.history)
def _create_repo_import_unit(self, pkg_url): """Create a repository, and import the given package into it. Schedule the repository and all orphan content units for deletion. Return the repository's href. """ self.addCleanup(self.client.delete, ORPHANS_PATH) repo_href = self.client.post(REPOSITORY_PATH, gen_repo())['_href'] self.addCleanup(self.client.delete, repo_href) pkg = utils.http_get(pkg_url) pkg_filename = _get_pkg_filename(pkg_url) pkg_unit_type = _get_pkg_unit_type(pkg_filename) utils.upload_import_unit(self.cfg, pkg, pkg_unit_type, repo_href) return repo_href
def test_all_packages(self): """Import signed and unsigned DRPM, RPM & SRPM packages into the repo. Verify that each import succeeds. """ for key, package in _PACKAGES.items(): if (key.endswith('drpm') and selectors.bug_is_untestable(1806, self.cfg.version)): continue with self.subTest(key=key): utils.upload_import_unit( self.cfg, package, key.split(' ')[-1], self.repo_href, )
def do_test(self, feed, type_id, body, unit_key=None): """Test how well Pulp can deal with duplicate unit uploads. Do the following: 1. Create a new feed-less repository. 2. Upload content and import it into the repository. Assert the upload and import was successful. 3. Upload identical content and import it into the repository. The second upload should silently fail for all Pulp releases in the 2.x series. """ if unit_key is None: unit_key = {} client = api.Client(self.cfg, api.json_handler) unit = utils.http_get(feed) repo = client.post(REPOSITORY_PATH, body) self.addCleanup(client.delete, repo['_href']) for _ in range(2): call_report = utils.upload_import_unit(self.cfg, unit, { 'unit_type_id': type_id, 'unit_key': unit_key }, repo) self.assertIsNone(call_report['result'])
def test_all(self): """Import a DRPM into a repository and search it for content units.""" cfg = config.get_config() if selectors.bug_is_untestable(1806, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/1806') client = api.Client(cfg) repo = client.post(REPOSITORY_PATH, gen_repo()).json() self.addCleanup(client.delete, repo['_href']) drpm = utils.http_get(DRPM_UNSIGNED_URL) utils.upload_import_unit(cfg, drpm, {'unit_type_id': 'drpm'}, repo) units = utils.search_units(cfg, repo) # Test if DRPM has been uploaded successfully self.assertEqual(len(units), 1) # Test if DRPM extracted correct metadata for creating filename self.assertEqual(units[0]['metadata']['filename'], DRPM)
def test_all(self): # pylint:disable=no-self-use """Upload an ISO file into an ISO repository. Specifically, do the following: 1. Create an ISO repository. 2. Upload :data:`pulp_smash.constants.FILE_URL` to the repository. 3. Publish the repository. 4. Download the published ISO, and assert it's equal to the uploaded ISO. """ # create a repo cfg = config.get_config() client = api.Client(cfg, api.json_handler) body = { 'id': utils.uuid4(), 'importer_type_id': 'iso_importer', 'distributors': [{ 'auto_publish': False, 'distributor_id': utils.uuid4(), 'distributor_type_id': 'iso_distributor', }], } repo = client.post(REPOSITORY_PATH, body) self.addCleanup(client.delete, repo['_href']) repo = client.get(repo['_href'], params={'details': True}) # upload an ISO to the repository iso = utils.http_get(FILE_URL) iso_name = os.path.basename(urlsplit(FILE_URL).path) utils.upload_import_unit(cfg, iso, { 'unit_type_id': 'iso', 'unit_key': { 'checksum': hashlib.sha256(iso).hexdigest(), 'name': iso_name, 'size': len(iso), }, }, repo) # publish the repository, and get the published ISO utils.publish_repo(cfg, repo) client.response_handler = api.safe_handler path = urljoin(urljoin('/pulp/isos/', repo['id'] + '/'), iso_name) iso2 = client.get(path).content self.assertEqual(iso, iso2)
def test_all(self): """Test puppet_install_distributor. Do the following: 1. Create a puppet repository with a puppet_install_distributor 2. Upload a puppet module 3. Publish the repository 4. Check if the puppet_install_distributor config was properly used """ cli_client = cli.Client(self.cfg) sudo = () if utils.is_root(self.cfg) else ('sudo', ) # Create a directory and make sure Pulp can write to it. install_path = cli_client.run(('mktemp', '--directory')).stdout.strip() self.addCleanup(cli_client.run, sudo + ('rm', '-rf', install_path)) cli_client.run(sudo + ('chown', 'apache:apache', install_path)) cli_client.run(sudo + ('chcon', '-t', 'puppet_etc_t', install_path)) # Make sure the pulp_manage_puppet boolean is enabled cli_client.run(sudo + ('semanage', 'boolean', '--modify', '--on', 'pulp_manage_puppet')) self.addCleanup( cli_client.run, sudo + ('semanage', 'boolean', '--modify', '--off', 'pulp_manage_puppet')) # Create and populate a Puppet repository. distributor = gen_install_distributor() distributor['distributor_config']['install_path'] = install_path body = gen_repo() body['distributors'] = [distributor] client = api.Client(self.cfg, api.json_handler) repo = client.post(REPOSITORY_PATH, body) self.addCleanup(client.delete, repo['_href']) repo = client.get(repo['_href'], params={'details': True}) unit = utils.http_get(PUPPET_MODULE_URL_1) utils.upload_import_unit(self.cfg, unit, {'unit_type_id': 'puppet_module'}, repo) # Publish, and verify the module is present. (Dir has 700 permissions.) utils.publish_repo(self.cfg, repo) proc = cli_client.run(sudo + ('runuser', '--shell', '/bin/sh', '--command', 'ls -1 {}'.format(install_path), '-', 'apache')) self.assertIn(PUPPET_MODULE_1['name'], proc.stdout.split('\n'), proc)
def setUpClass(cls): """Import a SRPM into a repository and search it for content units. Specifically, this method does the following: 1. Create a yum repository. 2. Upload a SRPM into the repository. 3. Search for all content units in the repository. """ super(UploadSrpmTestCase, cls).setUpClass() if check_issue_2620(cls.cfg): raise unittest.SkipTest('https://pulp.plan.io/issues/2620') client = api.Client(cls.cfg) repo = client.post(REPOSITORY_PATH, gen_repo()).json() cls.resources.add(repo['_href']) srpm = utils.http_get(SRPM_UNSIGNED_URL) utils.upload_import_unit(cls.cfg, srpm, {'unit_type_id': 'srpm'}, repo) cls.units = utils.search_units(cls.cfg, repo, {}, api.safe_handler)
def setUpClass(cls): """Create a Python repo. Upload a Python package into it twice.""" super(DuplicateUploadsTestCase, cls).setUpClass() unit = utils.http_get(PYTHON_EGG_URL) unit_type_id = "python_package" client = api.Client(cls.cfg, api.json_handler) repo_href = client.post(REPOSITORY_PATH, gen_repo())["_href"] cls.resources.add(repo_href) cls.call_reports = tuple((utils.upload_import_unit(cls.cfg, unit, unit_type_id, repo_href) for _ in range(2)))
def test_signed_packages(self): """Import signed DRPM, RPM and SRPM packages into the repository. Verify that each import fails. """ for key, package in _PACKAGES.items(): if key.startswith('unsigned'): continue if (key.endswith('drpm') and selectors.bug_is_untestable(1806, self.cfg.version)): continue with self.subTest(key=key): with self.assertRaises(exceptions.TaskReportError): utils.upload_import_unit( self.cfg, package, key.split(' ')[-1], self.repo_href, )
def setUpClass(cls): """Import a SRPM into a repository and search it for content units. Specifically, this method does the following: 1. Create a yum repository. 2. Upload a SRPM into the repository. 3. Search for all content units in the repository. """ super(UploadSrpmTestCase, cls).setUpClass() client = api.Client(cls.cfg) repo = client.post(REPOSITORY_PATH, gen_repo()).json() cls.resources.add(repo['_href']) srpm = utils.http_get(SRPM_UNSIGNED_URL) upload_import_unit(cls.cfg, srpm, 'srpm', repo['_href']) cls.repo_units = client.post( urljoin(repo['_href'], 'search/units/'), {'criteria': {}}, )
def setUpClass(cls): """Create, populate and publish a repository. More specifically, do the following: 1. Create an RPM repository with a distributor. 2. Populate the repository with an RPM and two errata, where one erratum references the RPM, and the other does not. 3. Publish the repository Fetch and parse its ``updateinfo.xml`` file. """ super(UpdateInfoTestCase, cls).setUpClass() if check_issue_3104(cls.cfg): raise unittest.SkipTest('https://pulp.plan.io/issues/3104') cls.errata = {key: _gen_errata() for key in ('full', 'partial')} del cls.errata['partial']['pkglist'] cls.tasks = {} # Create a repo. client = api.Client(cls.cfg, api.json_handler) body = gen_repo() body['distributors'] = [gen_distributor()] repo = client.post(REPOSITORY_PATH, body) cls.resources.add(repo['_href']) try: # Populate and publish the repo. repo = client.get(repo['_href'], params={'details': True}) unit = utils.http_get(RPM_UNSIGNED_URL) utils.upload_import_unit(cls.cfg, unit, {'unit_type_id': 'rpm'}, repo) for key, erratum in cls.errata.items(): report = utils.upload_import_erratum(cls.cfg, erratum, repo['_href']) cls.tasks[key] = tuple(api.poll_spawned_tasks(cls.cfg, report)) utils.publish_repo(cls.cfg, repo) # Fetch and parse updateinfo.xml. cls.updates_element = (get_repodata(cls.cfg, repo['distributors'][0], 'updateinfo')) except: # noqa:E722 cls.tearDownClass() raise
def setUpClass(cls): """Import a DRPM into a repository and search it for content units. Specifically, this method does the following: 1. Create a yum repository. 2. Upload a DRPM into the repository. 3. Search for all content units in the repository. """ super(UploadDrpmTestCase, cls).setUpClass() if selectors.bug_is_untestable(1806, cls.cfg.version): raise unittest.SkipTest('https://pulp.plan.io/issues/1806') client = api.Client(cls.cfg) repo = client.post(REPOSITORY_PATH, gen_repo()).json() cls.resources.add(repo['_href']) drpm = utils.http_get(DRPM_UNSIGNED_URL) upload_import_unit(cls.cfg, drpm, 'drpm', repo['_href']) cls.repo_units = client.post( urljoin(repo['_href'], 'search/units/'), {'criteria': {}}, )
def setUpClass(cls): """Create a Puppet repository. Upload a Puppet module into it twice.""" super(DuplicateUploadsTestCase, cls).setUpClass() unit = utils.http_get(PUPPET_MODULE_URL) unit_type_id = 'puppet_module' client = api.Client(cls.cfg, api.json_handler) repo_href = client.post(REPOSITORY_PATH, gen_repo())['_href'] cls.resources.add(repo_href) cls.call_reports = tuple(( utils.upload_import_unit(cls.cfg, unit, unit_type_id, repo_href) for _ in range(2) ))
def test_all(self): """Test whether one invalid RPM upload fails and produces error details. This test targets the following issues. * `Pulp Smash #544 <https://github.com/PulpQE/pulp-smash/issues/544>`_ * `Pulp #2543 <https://pulp.plan.io/issues/2543>`_ * `Pulp #3090 <https://pulp.plan.io/issues/3090>`_ Do the following: 1. Create a RPM repository. 2. Upload an invalid RPM to repository. Assert that upload fails, and that the returned error contains a descriptive message. 3. Verify that the repository contains no RPMs. """ cfg = config.get_config() if selectors.bug_is_untestable(2543, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/2543') if selectors.bug_is_untestable(3090, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/3090') client = api.Client(cfg, api.json_handler) repo = client.post(REPOSITORY_PATH, gen_repo()) self.addCleanup(client.delete, repo['_href']) # Upload invalid RPM rpm = utils.http_get(RPM_INVALID_URL) with self.assertRaises(exceptions.TaskReportError) as context: utils.upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo) task = context.exception.task # Assert that rturned error contains a descriptive message self.assertIsNotNone(task['error']['description']) self.assertIn('upload', task['error']['description']) # Verify that the repository contains no RPMs rpm = utils.search_units(cfg, repo, {'type_ids': ('rpm', )}) self.assertEqual(len(rpm), 0)
def do_test(self, distributor_config_update): """Implement most of the test logic.""" rpms = tuple( utils.http_get(url) for url in (RPM_UNSIGNED_URL, RPM2_UNSIGNED_URL)) # Create a repository. client = api.Client(self.cfg, api.json_handler) body = gen_repo() body['distributors'] = [gen_distributor()] body['distributors'][0]['distributor_config'].update( distributor_config_update) repo = client.post(REPOSITORY_PATH, body) self.addCleanup(client.delete, repo['_href']) repo = client.get(repo['_href'], params={'details': True}) # Upload an RPM, publish the repo, and count metadata files twice. cli_client = cli.Client(self.cfg) sudo = () if utils.is_root(self.cfg) else ('sudo', ) find_repodata_cmd = sudo + ( 'find', os.path.join('/var/lib/pulp/published/yum/master/yum_distributor/', str(repo['id'])), '-type', 'd', '-name', 'repodata') found = [] for rpm in rpms: utils.upload_import_unit( self.cfg, rpm, {'unit_type_id': 'rpm'}, repo, ) utils.publish_repo(self.cfg, repo) repodata_path = cli_client.run(find_repodata_cmd).stdout.strip() found.append( cli_client.run(sudo + ('find', repodata_path, '-type', 'f')).stdout.splitlines()) return found
def test_all(self): """Verify uploaded DRPMs have checksums of the requested type. Specifically, this method does the following: 1. Create a yum repository. 2. Upload a DRPM into the repository with "checksumtype" set to "md5". 3. Assert that "checksumtype" was set to "md5". 4. Assert that checksum value was calculated according to "md5". This test targets: * `Pulp #2774 <https://pulp.plan.io/issues/2774>`_ * `Pulp Smash #663 <https://github.com/PulpQE/pulp-smash/issues/663>`_ """ cfg = config.get_config() client = api.Client(cfg, api.json_handler) repo = client.post(REPOSITORY_PATH, gen_repo()) self.addCleanup(client.delete, repo['_href']) drpm = utils.http_get(DRPM_UNSIGNED_URL) utils.upload_import_unit(cfg, drpm, { 'unit_metadata': { 'checksumtype': 'md5' }, 'unit_type_id': 'drpm', }, repo) units = utils.search_units(cfg, repo) with self.subTest(comment='verify checksumtype'): self.assertEqual(units[0]['metadata']['checksumtype'], 'md5') with self.subTest(comment='verify checksum'): if selectors.bug_is_untestable(2774, cfg.pulp_version): self.skipTest('https://pulp.plan.io/issues/2774') self.assertEqual(units[0]['metadata']['checksum'], units[0]['metadata']['checksums']['md5'])
def test_post(self): """Assert the function makes an HTTP POST request.""" with mock.patch.object(api, 'Client') as client: # post() is called twice, first to start a content upload and # second to import and upload. In both cases, a dict is returned. # Our dict mocks the first case, and just happens to work in the # second case too. client.return_value.post.return_value = { '_href': 'foo', 'upload_id': 'bar', } response = utils.upload_import_unit( mock.Mock(), # server_config b'my unit', 'my unit type id', 'http://example.com', # repo_href ) self.assertIs(response, client.return_value.post.return_value)