Ejemplo n.º 1
0
    def test_all(self):
        """Upload a package group to a repository twice."""
        cfg = config.get_config()
        if check_issue_3104(cfg):
            self.skipTest('https://pulp.plan.io/issues/3104')
        client = api.Client(cfg, api.json_handler)
        self.addCleanup(client.delete, ORPHANS_PATH)

        # Create a repository.
        body = gen_repo()
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        self.addCleanup(client.delete, repo['_href'])

        # Give the repository a package group, and publish the repository.
        package_group = {'id': utils.uuid4(), 'name': utils.uuid4()}
        _upload_import_package_group(cfg, repo, package_group)
        repo = client.get(repo['_href'], params={'details': True})
        utils.publish_repo(cfg, repo)

        # Update the repository's package group, and re-publish the repository.
        package_group['name'] = utils.uuid4()
        _upload_import_package_group(cfg, repo, package_group)
        utils.publish_repo(cfg, repo)

        # Fetch the generated repodata of type 'group' (a.k.a. 'comps'). Verify
        # the package group portion.
        root_element = get_repodata(cfg, repo['distributors'][0], 'group')
        groups = root_element.findall('group')
        self.assertEqual(len(groups), 1, ElementTree.tostring(root_element))
        for key, value in package_group.items():
            with self.subTest(key=key):
                self.assertEqual(groups[0].find(key).text, value)
Ejemplo n.º 2
0
 def verify_other_xml(self, cfg, distributor, checksum_type):
     """Verify a published repo's other.xml uses the given checksum."""
     other_xml = get_repodata(cfg, distributor, 'other')
     xpath = '{{{}}}package'.format(RPM_NAMESPACES['metadata/other'])
     packages = other_xml.findall(xpath)
     pkgids_len = {len(package.get('pkgid')) for package in packages}
     self.verify_pkgid_len(pkgids_len, checksum_type)
Ejemplo n.º 3
0
    def setUpClass(cls):
        """Create an RPM repository, upload package groups, and publish."""
        super(UploadPackageGroupsTestCase, cls).setUpClass()
        if check_issue_3104(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')

        # Create a repository and add a distributor to it.
        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'])
        repo = client.get(repo['_href'], params={'details': True})

        # Generate several package groups, import them into the repository, and
        # publish the repository.
        cls.package_groups = {
            'minimal': _gen_minimal_group(),
            'realistic': _gen_realistic_group(),
        }
        cls.tasks = {}
        for key, package_group in cls.package_groups.items():
            report = _upload_import_package_group(cls.cfg, repo, package_group)
            cls.tasks[key] = tuple(api.poll_spawned_tasks(cls.cfg, report))
        utils.publish_repo(cls.cfg, repo)

        # Fetch the generated repodata of type 'group' (a.k.a. 'comps')
        cls.root_element = (get_repodata(cls.cfg, repo['distributors'][0],
                                         'group'))
Ejemplo n.º 4
0
 def verify_presto_delta_xml(self, cfg, distributor, checksum_type):
     """Verify a published repo's prestodelta.xml uses given checksum."""
     presto_delta_xml = get_repodata(cfg, distributor, 'prestodelta')
     checksum_types = {
         node.attrib.get('type')
         for node in presto_delta_xml.iter('checksum')
     }
     self.assertEqual(checksum_types, {checksum_type})
Ejemplo n.º 5
0
 def verify_primary_xml(self, cfg, distributor, checksum_type):
     """Verify a published repo's primary.xml uses the given checksum."""
     primary_xml = get_repodata(cfg, distributor, 'primary')
     xpath = '{{{}}}package'.format(RPM_NAMESPACES['metadata/common'])
     packages = primary_xml.findall(xpath)
     xpath = '{{{}}}checksum'.format(RPM_NAMESPACES['metadata/common'])
     checksum_types = {
         package.find(xpath).get('type') for package in packages
     }
     self.assertEqual(checksum_types, {checksum_type})
Ejemplo n.º 6
0
    def test_all(self):
        """Sync a repo whose updateinfo file has multiple pkglist sections.

        Specifically, do the following:

        1. Create, sync and publish an RPM repository whose feed is set to
           :data:`pulp_smash.constants.RPM_PKGLISTS_UPDATEINFO_FEED_URL`.
        2. Fetch and parse the published repository's ``updateinfo.xml`` file.

        Verify that the ``updateinfo.xml`` file has three packages whose
        ``<filename>`` elements have the following text:

        * penguin-0.9.1-1.noarch.rpm
        * shark-0.1-1.noarch.rpm
        * walrus-5.21-1.noarch.rpm

        Note that Pulp is free to change the structure of a source repository
        at will. For example, the source repository has three ``<collection>``
        elements, the published repository can have one, two or three
        ``<collection>`` elements. Assertions are not made about these details.
        """
        cfg = config.get_config()
        if check_issue_3104(cfg):
            self.skipTest('https://pulp.plan.io/issues/3104')
        if selectors.bug_is_untestable(2227, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/2277')

        # Create, sync and publish a repository.
        client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_PKGLISTS_UPDATEINFO_FEED_URL
        body['distributors'] = [gen_distributor()]
        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)

        # Fetch and parse ``updateinfo.xml``.
        updates_element = (get_repodata(cfg, repo['distributors'][0],
                                        'updateinfo'))

        # Verify the ``updateinfo.xml`` file.
        debug = ElementTree.tostring(updates_element)
        filename_elements = (updates_element.findall(
            'update/pkglist/collection/package/filename'))
        filenames = [
            filename_element.text for filename_element in filename_elements
        ]
        filenames.sort()
        self.assertEqual(filenames, [
            'penguin-0.9.1-1.noarch.rpm',
            'shark-0.1-1.noarch.rpm',
            'walrus-5.21-1.noarch.rpm',
        ], debug)
Ejemplo n.º 7
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(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
Ejemplo n.º 8
0
    def test_02_unassociate_publish(self):
        """Unassociate a content unit and publish the repository.

        Fetch ``updateinfo.xml``. Verify that an ``<update>`` with an ``<id>``
        of :data:`pulp_smash.constants.RPM_ERRATUM_ID` is not present.
        """
        client = api.Client(self.cfg, api.json_handler)
        client.post(urljoin(self.repo['_href'], 'actions/unassociate/'), {
            'criteria': {
                'filters': {
                    'unit': {
                        'name': RPM_ERRATUM_RPM_NAME
                    }
                }
            }
        })
        utils.publish_repo(self.cfg, self.repo)
        updates_element = (get_repodata(self.cfg, self.repo['distributors'][0],
                                        'updateinfo'))
        update_elements = _get_updates_by_id(updates_element)
        self.assertNotIn(RPM_ERRATUM_ID, update_elements)
Ejemplo n.º 9
0
    def setUpClass(cls):
        """Create, sync and publish a repository. Fetch its ``comps.xml``."""
        super(SyncRepoTestCase, cls).setUpClass()
        if check_issue_3104(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        client = api.Client(cls.cfg, api.json_handler)

        # Create a repo.
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])
        repo = client.get(repo['_href'], params={'details': True})

        # Sync and publish the repo.
        utils.sync_repo(cls.cfg, repo)
        utils.publish_repo(cls.cfg, repo)

        # Fetch and parse comps.xml.
        cls.root_element = (get_repodata(cls.cfg, repo['distributors'][0],
                                         'group'))
        cls.xml_as_str = ElementTree.tostring(cls.root_element)
Ejemplo n.º 10
0
    def test_01_sync_publish(self):
        """Sync and publish the repository.

        When executed, this test method will fetch ``updateinfo.xml`` and
        verify that:

        * An ``<update>`` with an ``<id>`` of
          :data:`pulp_smash.constants.RPM_ERRATUM_ID` is present, and
        * one of its child ``<package>`` elements has a "name" attribute equal
          to :data:`pulp_smash.constants.RPM_ERRATUM_RPM_NAME`.
        """
        utils.sync_repo(self.cfg, self.repo)
        utils.publish_repo(self.cfg, self.repo)
        updates_element = (get_repodata(self.cfg, self.repo['distributors'][0],
                                        'updateinfo'))
        update_elements = _get_updates_by_id(updates_element)
        self.assertIn(RPM_ERRATUM_ID, update_elements)

        package_elements = (update_elements[RPM_ERRATUM_ID].findall(
            'pkglist/collection/package'))
        package_names = [
            package_element.get('name') for package_element in package_elements
        ]
        self.assertIn(RPM_ERRATUM_RPM_NAME, package_names)