def test_all(self):
        """Add a content unit to a repo in the middle of several publishes."""
        cfg = config.get_config()
        if not selectors.bug_is_fixed(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')):
            upload_import_unit(cfg, rpms[i], {'unit_type_id': 'rpm'}, repo)
            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':
            publish_repo(cfg, repo, {'id': dists[key]['id']})
        self.verify_remote_units_path(cfg, dists['rpm_rsync_distributor'], 1)
예제 #2
0
    def test_all(self):
        """Verify whether uploaded module.yaml is reflected in the pulp repo."""
        cfg = config.get_config()
        if cfg.pulp_version < Version('2.17'):
            raise unittest.SkipTest(
                'This test requires at least Pulp 2.17 or newer.')
        client = api.Client(cfg, api.json_handler)
        # Create a normal Repo without any data.
        body = gen_repo(importer_config={'feed': RPM_UNSIGNED_FEED_URL},
                        distributors=[gen_distributor()])
        repo = client.post(REPOSITORY_PATH, body)
        repo = client.get(repo['_href'], params={'details': True})
        self.addCleanup(client.delete, repo['_href'])
        sync_repo(cfg, repo)

        # download modules.yaml and upload it to pulp_repo
        unit = self._get_module_yaml_file(RPM_WITH_MODULES_FEED_URL)
        upload_import_unit(cfg, unit, {
            'unit_key': {},
            'unit_type_id': 'modulemd',
        }, repo)
        repo = client.get(repo['_href'], params={'details': True})
        # Assert that `modulemd` and `modulemd_defaults` are present on the
        # repository.
        self.assertIsNotNone(repo['content_unit_counts']['modulemd'])
        self.assertIsNotNone(repo['content_unit_counts']['modulemd_defaults'])
예제 #3
0
def setUpModule():  # pylint:disable=invalid-name
    """Conditionally skip tests. Create repositories with fixture data."""
    cfg = config.get_config()
    if not selectors.bug_is_fixed(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_fixed(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():
            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():
            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
예제 #4
0
 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)
     upload_import_unit(
         self.cfg,
         rpm,
         {'unit_type_id': 'rpm'},
         self.repo,
     )
     publish_repo(self.cfg, repo_before)
     repo_after = self.get_repo()
     with self.subTest(comment='last_unit_added'):
         if not selectors.bug_is_fixed(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)
예제 #5
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 cli.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:
            upload_import_unit(self.cfg, rpm, {'unit_type_id': 'rpm'}, repo)
            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
예제 #6
0
    def test_all(self):
        """Verify ``RPM_LARGE_METADATA`` RPM file can be uploaded.

        Specifically, this method does the following:

        1. Create an RPM repo.
        2. Verify whether the file ``RPM_LARGE_METADATA`` can be uploaded
           into the repo without errors.

        This test targets:

        * `Pulp #723 <https://pulp.plan.io/issues/723>`_
        * `Pulp-2-Tests #88 <https://github.com/PulpQE/Pulp-2-Tests/issues/88>`_
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)
        body = gen_repo(distributors=[gen_distributor()])
        repo = client.post(REPOSITORY_PATH, body)
        self.addCleanup(client.delete, repo['_href'])
        rpm = utils.http_get(RPM_LARGE_METADATA_FEED)
        upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo)
        repo = client.get(repo['_href'], params={'details': True})
        publish_repo(cfg, repo)
        rpm_path = get_rpm_published_path(cfg, repo, RPM_LARGE_METADATA)

        # Check whether the RPM is uploaded published.
        self.assertIn(RPM_LARGE_METADATA, rpm_path, rpm_path)
예제 #7
0
 def test_all(self):
     """Test that uploading DRPM with checksumtype specified works."""
     if not selectors.bug_is_fixed(1806, self.cfg.pulp_version):
         raise unittest.SkipTest('https://pulp.plan.io/issues/1806')
     if not selectors.bug_is_fixed(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)
     upload_import_unit(
         self.cfg,
         drpm,
         {
             'unit_type_id': 'drpm',
             'unit_metadata': {
                 'checksumtype': 'sha256'
             },
         },
         repo,
     )
     units = 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,
     )
예제 #8
0
 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)
     upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo)
예제 #9
0
    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 not selectors.bug_is_fixed(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})
        sync_repo(cfg, repo)
        publish_repo(cfg, repo)

        # Get the mtime of the sqlite files.
        cli_client = cli.Client(cfg, cli.echo_handler)
        cmd = '' if cli.is_root(cfg) else 'sudo '
        cmd += "bash -c \"stat --format %Y '{}'/*\"".format(
            os.path.join(
                _PATH,
                repo['distributors'][0]['config']['relative_url'],
                'repodata',
            ))
        # machine.session is used here to keep SSH session open
        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)
        upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo)
        sync_repo(cfg, repo)

        # Get the mtime of the sqlite files again.
        time.sleep(1)
        # machine.session is used here to keep SSH session open
        mtimes_post = (
            cli_client.machine.session().run(cmd)[1].strip().split().sort())
        self.assertEqual(mtimes_pre, mtimes_post)
예제 #10
0
    def test_all(self):
        """Upload a V2 manifest list.

        Do the following:

        1. Create, sync and publish a repository. Read the repository and the
           repository's manifest list.
        2. Upload a modified version of the manifest list to the repository.
           Re-read the repository and the repository's manifest list.
        3. Assert that:

           * The repository's manifest list hasn't been changed. (After all,
             the repository hasn't been published since the new manifest list
             was uploaded.)
           * The repository's ``docker_manifest_list`` attribute has increased
             by the approprate number.

        This test targets the following issues:

        * `Pulp #2993 <https://pulp.plan.io/issues/2993>`_
        * `Pulp Smash #829 <https://github.com/PulpQE/pulp-smash/issues/829>`_
        """
        repo = self.create_sync_publish_repo(self.cfg, {
            'enable_v1': False,
            'enable_v2': True,
            'feed': DOCKER_V2_FEED_URL,
            'upstream_name': get_upstream_name(self.cfg),
        })
        crane_client = self.make_crane_client(self.cfg)
        crane_client.request_kwargs['headers']['accept'] = (
            'application/vnd.docker.distribution.manifest.list.v2+json'
        )
        manifest_list_path = '/v2/{}/manifests/latest'.format(repo['id'])
        manifest_list = crane_client.get(manifest_list_path)

        # Upload a modified manifest list.
        modified_manifest_list = copy.deepcopy(manifest_list)
        modified_manifest_list['manifests'].pop()
        upload_import_unit(
            self.cfg,
            json.dumps(modified_manifest_list).encode('utf-8'),
            {'unit_type_id': 'docker_manifest_list'},
            repo,
        )

        # Verify outcomes.
        with self.subTest(comment='verify manifest list is same'):
            new_manifest_list = crane_client.get(manifest_list_path)
            self.assertEqual(manifest_list, new_manifest_list)
        with self.subTest(comment='verify docker_manifest_list repo attr'):
            new_repo = api.Client(self.cfg).get(repo['_href']).json()
            self.assertEqual(
                repo['content_unit_counts']['docker_manifest_list'] +
                len(modified_manifest_list['manifests']),
                new_repo['content_unit_counts']['docker_manifest_list'],
            )
예제 #11
0
 def test_all(self):
     """Test whether one can upload an RPM with non-ascii metadata."""
     cfg = config.get_config()
     if not selectors.bug_is_fixed(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)
     upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo)
예제 #12
0
 def _upload_import_unit(url):
     """Upload and import the unit at ``url`` to ``repo``."""
     unit = utils.http_get(url)
     upload_import_unit(
         self.cfg, unit, {
             'unit_key': {
                 'filename': basename(urlparse(url).path)
             },
             'unit_type_id': 'python_package',
         }, repo)
예제 #13
0
    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)
        upload_import_unit(self.cfg, rpm, {'unit_type_id': 'rpm'}, repo)
        self.do_test(repo)
예제 #14
0
    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')
        if utils.fips_is_supported(cfg) and utils.fips_is_enabled(cfg):
            self.skipTest('https://pulp.plan.io/issues/3775')

        # 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(RPM_UNSIGNED_URL)
        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
        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
        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 not selectors.bug_is_fixed(2349, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/2349')
        publish_repo(cfg, repo)
        response = client.get(pub_path)
        with self.subTest(comment='third publish'):
            self.assertEqual(len(response.history), 0, response.history)
예제 #15
0
    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):
                upload_import_unit(
                    self.cfg,
                    package,
                    {'unit_type_id': key.split(' ')[-1]},
                    self.repo,
                )
예제 #16
0
    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):
                    upload_import_unit(
                        self.cfg,
                        package,
                        {'unit_type_id': key.split(' ')[-1]},
                        self.repo,
                    )
예제 #17
0
    def test_all(self):
        """Publish with a yum and rsync distributor twice."""
        cfg = config.get_config()
        if not selectors.bug_is_fixed(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):
            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 = (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 = (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)
예제 #18
0
    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]
        upload_import_unit(
            self.cfg,
            self.rpm,
            {'unit_type_id': 'rpm'},
            repo,
        )
        publish_repo(self.cfg, repo)
        self.verify_repo_search(repo)
        self.verify_repo_download(repo)
예제 #19
0
    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
        """
        cfg = config.get_config()
        if (not selectors.bug_is_fixed(3314, cfg.pulp_version)
                and os_is_f27(cfg)):
            self.skipTest('https://pulp.plan.io/issues/3314')
        cli_client = cli.Client(cfg)

        # 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, ('rm', '-rf', install_path), sudo=True)
        cli_client.run(('chown', 'apache:apache', install_path), sudo=True)
        cli_client.run(('chcon', '-t', 'puppet_etc_t', install_path),
                       sudo=True)

        # Make sure the pulp_manage_puppet boolean is enabled
        cli_client.run(('setsebool', 'pulp_manage_puppet', 'on'), sudo=True)

        self.addCleanup(cli_client.run,
                        ('setsebool', 'pulp_manage_puppet', 'off'),
                        sudo=True)

        # 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(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)
        upload_import_unit(cfg, unit, {'unit_type_id': 'puppet_module'}, repo)

        # Publish, and verify the module is present. (Dir has 700 permissions.)
        publish_repo(cfg, repo)
        proc = cli_client.run(('runuser', '--shell', '/bin/sh', '--command',
                               'ls -1 {}'.format(install_path), '-', 'apache'),
                              sudo=True)
        self.assertIn(PUPPET_MODULE_1['name'], proc.stdout.split('\n'), proc)
예제 #20
0
    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 = upload_import_unit(self.cfg, unit, {
                'unit_type_id': type_id,
                'unit_key': unit_key
            }, repo)
            self.assertIsNone(call_report['result'])
예제 #21
0
    def test_all(self):
        """Import a DRPM into a repository and search it for content units."""
        cfg = config.get_config()
        if not selectors.bug_is_fixed(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)
        upload_import_unit(cfg, drpm, {'unit_type_id': 'drpm'}, repo)
        units = 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)
예제 #22
0
    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.
        """
        cfg = config.get_config()
        if check_issue_2620(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2620')
        cls.client = api.Client(cfg, api.json_handler)
        cls.repo = cls.client.post(REPOSITORY_PATH, gen_repo())
        srpm = utils.http_get(SRPM_UNSIGNED_URL)
        upload_import_unit(cfg, srpm, {'unit_type_id': 'srpm'}, cls.repo)
        cls.units = search_units(cfg, cls.repo, {}, api.safe_handler)
예제 #23
0
    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 ``pulp_2_tests.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)
        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
        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)
예제 #24
0
    def test_all(self):
        """Import a RPM with rich/weak dependencies into a repository.

        Search it for content units.
        """
        cfg = config.get_config()
        if cfg.pulp_version < Version('2.17'):
            raise unittest.SkipTest('This test requires Pulp 2.17 or newer.')
        client = api.Client(cfg, api.json_handler)
        repo = client.post(REPOSITORY_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])
        rpm = utils.http_get(urljoin(RPM_RICH_WEAK_FEED_URL + '/', RPM_RICH_WEAK))
        upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo)
        units = search_units(cfg, repo)

        # Test if RPM has been uploaded successfully
        self.assertEqual(len(units), 1)

        # Test if RPM extracted correct metadata for creating filename
        self.assertEqual(units[0]['metadata']['filename'], RPM_RICH_WEAK)
예제 #25
0
    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().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)
            upload_import_unit(cls.cfg, unit, {'unit_type_id': 'rpm'}, repo)
            for key, erratum in cls.errata.items():
                report = upload_import_erratum(cls.cfg, erratum, repo)
                cls.tasks[key] = tuple(api.poll_spawned_tasks(cls.cfg, report))
            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
예제 #26
0
    def copy_units(self, recursive, recursive_conservative, old_dependency):
        """Copy units using ``recursive`` and  ``recursive_conservative``."""
        repos = []
        body = gen_repo(
            importer_config={'feed': RPM_UNSIGNED_FEED_URL},
            distributors=[gen_distributor()],
        )
        repos.append(self.client.post(REPOSITORY_PATH, body))
        self.addCleanup(self.client.delete, repos[0]['_href'])
        sync_repo(self.cfg, repos[0])
        repos.append(self.client.post(REPOSITORY_PATH, gen_repo()))
        self.addCleanup(self.client.delete, repos[1]['_href'])

        # `old_dependency` will import an older version, `0.71` of walrus to
        # the destiny repository.
        if old_dependency:
            rpm = utils.http_get(RPM_WITH_OLD_VERSION_URL)
            upload_import_unit(self.cfg, rpm, {'unit_type_id': 'rpm'},
                               repos[1])
            units = search_units(self.cfg, repos[1], {'type_ids': ['rpm']})
            self.assertEqual(len(units), 1, units)

        self.client.post(
            urljoin(repos[1]['_href'], 'actions/associate/'),
            {
                'source_repo_id': repos[0]['id'],
                'override_config': {
                    'recursive': recursive,
                    'recursive_conservative': recursive_conservative,
                },
                'criteria': {
                    'filters': {
                        'unit': {
                            'name': 'chimpanzee'
                        }
                    },
                    'type_ids': ['rpm'],
                },
            },
        )
        return self.client.get(repos[1]['_href'], params={'details': True})
예제 #27
0
    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 = self.client.post(REPOSITORY_PATH, gen_repo())
        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)
        upload_import_unit(
            self.cfg,
            pkg,
            {'unit_type_id': pkg_unit_type},
            repo,
        )

        return repo['_href']
예제 #28
0
    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 not selectors.bug_is_fixed(2543, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/2543')
        if not selectors.bug_is_fixed(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:
            upload_import_unit(cfg, rpm, {'unit_type_id': 'rpm'}, repo)
        task = context.exception.task

        # Assert that returned error contains a descriptive message
        self.assertIsNotNone(task['error']['description'])
        self.assertIn('upload', task['error']['description'].lower())

        # Verify that the repository contains no RPMs
        rpm = search_units(cfg, repo, {'type_ids': ('rpm', )})
        self.assertEqual(len(rpm), 0)
예제 #29
0
    def test_all(self):
        """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 with "checksumtype" set to
            "sha256"
        3. Search for all content units in the repository.
        """
        cfg = config.get_config()
        if not selectors.bug_is_fixed(1806, cfg.pulp_version):
            raise unittest.SkipTest('https://pulp.plan.io/issues/1806')
        if not selectors.bug_is_fixed(2627, cfg.pulp_version):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2627')
        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)
        upload_import_unit(
            cfg,
            drpm,
            {
                'unit_type_id': 'drpm',
                'unit_metadata': {
                    'checksumtype': 'sha256'
                },
            },
            repo,
        )
        units = search_units(cfg, repo, {})
        self.assertEqual(len(units), 1, units)
        # Test if DRPM extracted correct metadata for creating filename.
        self.assertEqual(
            units[0]['metadata']['filename'],
            DRPM,
        )
예제 #30
0
    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)
        upload_import_unit(cfg, drpm, {
            'unit_metadata': {
                'checksumtype': 'md5'
            },
            'unit_type_id': 'drpm',
        }, repo)
        units = search_units(cfg, repo)

        with self.subTest(comment='verify checksumtype'):
            self.assertEqual(units[0]['metadata']['checksumtype'], 'md5')
        with self.subTest(comment='verify checksum'):
            if not selectors.bug_is_fixed(2774, cfg.pulp_version):
                self.skipTest('https://pulp.plan.io/issues/2774')
            self.assertEqual(units[0]['metadata']['checksum'],
                             units[0]['metadata']['checksums']['md5'])
예제 #31
0
 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 = upload_import_unit(
             mock.Mock(),  # cfg
             b'my unit',  # unit
             {},  # import_params
             {'_href': 'http://example.com'},  # repo
         )
     self.assertIs(response, client.return_value.post.return_value)