Ejemplo n.º 1
0
 def test_create_tag(self):
     """Check if a tag can be created."""
     tag_name = utils.uuid4()
     random_manifest = random.choice(
         utils.search_units(self.cfg, self.repo,
                            {'type_ids': ['docker_manifest']}))
     # Create the tag
     import_upload(
         self.cfg, self.repo, {
             'unit_type_id': 'docker_tag',
             'unit_key': {
                 'repo_id': self.repo['id'],
                 'name': tag_name,
             },
             'unit_metadata': {
                 'name': tag_name,
                 'digest': random_manifest['metadata']['digest'],
             },
         })
     # Fetch the created tag
     tag = utils.search_units(self.cfg, self.repo, {
         'type_ids': ['docker_tag'],
         'filters': {
             'unit': {
                 'name': tag_name
             }
         },
     })
     self.assertEqual(len(tag), 1)
     tag = tag.pop()
     self.assertEqual(tag['metadata']['manifest_digest'],
                      random_manifest['metadata']['digest'])
     self.assertEqual(len(self._get_tags()), len(self.tags) + 1)
Ejemplo n.º 2
0
 def test_03_compare_repos(self):
     """Verify the two repositories contain the same content unit."""
     repo_0_units = utils.search_units(self.cfg, self.repos[0])
     repo_1_units = utils.search_units(self.cfg, self.repos[1])
     self.assertEqual(
         repo_0_units[0]['unit_id'],
         repo_1_units[0]['unit_id'],
     )
Ejemplo n.º 3
0
 def test_defaults(self):
     """Verify that default parameters are correctly set."""
     with mock.patch.object(api, 'Client') as client:
         utils.search_units(mock.Mock(), {'_href': 'foo/bar/'})
     self.assertEqual(client.call_args[0][1], api.json_handler)
     self.assertEqual(
         client.return_value.post.call_args[0][1],
         {'criteria': {}},
     )
Ejemplo n.º 4
0
    def test_all(self):
        """Copy content between OSTree repositories with a filter.

        Do the following:

        1. Create a pair of repositories, and populate the first.
        2. Randomly select a unit from the first repository, and copy
           it to the second repository.
        3. Verify that the selected unit is the only one in the second
           repository.
        """
        repos = []
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        # Create and populate a source repository.
        body = gen_repo()
        body['importer_config']['feed'] = OSTREE_FEED
        body['importer_config']['branches'] = OSTREE_BRANCHES
        body['distributors'] = [gen_distributor()]
        repos.append(client.post(REPOSITORY_PATH, body))
        self.addCleanup(client.delete, repos[0]['_href'])
        utils.sync_repo(cfg, repos[0])

        # Create a destination repository.
        repos.append(client.post(REPOSITORY_PATH, gen_repo()))
        self.addCleanup(client.delete, repos[1]['_href'])

        # Copy a random unit between the repos, and verify the result.
        src_unit_id = random.choice(utils.search_units(
            cfg, repos[0]))['metadata']['_id']
        client.post(
            urljoin(repos[1]['_href'], 'actions/associate/'), {
                'source_repo_id': repos[0]['id'],
                'criteria': {
                    'filters': {
                        'unit': {
                            '_id': src_unit_id
                        }
                    },
                    'type_ids': ['ostree'],
                },
            })
        dst_unit_ids = [
            unit['metadata']['_id'] for unit in utils.search_units(
                cfg, repos[1], {'type_ids': ['ostree']})
        ]
        self.assertEqual([src_unit_id], dst_unit_ids)
Ejemplo n.º 5
0
 def test_update_tag_another_repo(self):
     """Check if tagging fail for a manifest from another repo."""
     other = create_docker_repo(self.cfg, 'library/swarm')
     self.addCleanup(api.Client(self.cfg).delete, other['_href'])
     utils.sync_repo(self.cfg, other)
     other = api.Client(self.cfg,
                        api.json_handler).get(other['_href'],
                                              params={'details': True})
     other_manifest = random.choice(
         utils.search_units(self.cfg, other,
                            {'type_ids': ['docker_manifest']}))
     tag_name = utils.uuid4()
     with self.assertRaises(TaskReportError) as context:
         import_upload(
             self.cfg, self.repo, {
                 'unit_type_id': 'docker_tag',
                 'unit_key': {
                     'repo_id': self.repo['id'],
                     'name': tag_name,
                 },
                 'unit_metadata': {
                     'name': tag_name,
                     'digest': other_manifest['metadata']['digest'],
                 },
             })
     self.assertEqual(
         'Manifest with digest {} could not be found in repository {}.'.
         format(other_manifest['metadata']['digest'], self.repo['id']),
         context.exception.task['error']['description'])
     self.assertEqual(len(self._get_tags()), len(self.tags))
Ejemplo n.º 6
0
 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,
     )
Ejemplo n.º 7
0
    def do_test(self, feed, type_ids):
        """Remove units from a repo and make assertions about it.

        Do the following:

        1. Create and sync a repository with the given ``feed``.
        2. For each type ID in ``type_ids``, remove a content unit of that type
           from the repository. See :meth:`do_remove_unit`.
        3. Assert the correct units are still in the repository. The repository
           should have all the units that were originally synced into the
           repository, minus those that have been removed.
        4. Remove a non-existent unit from the repository. Assert that the
           ``last_unit_removed`` timestamp was not updated.
        """
        body = gen_repo()
        body['importer_config']['feed'] = feed
        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})
        utils.sync_repo(self.cfg, repo)
        self.initial_units = utils.search_units(self.cfg, repo)

        for type_id in type_ids:
            with self.subTest(type_id=type_id):
                self.do_remove_unit(type_id, repo)

        with self.subTest('remaining units'):
            removed_ids = {_get_unit_id(unit) for unit in self.removed_units}
            remaining_ids = {
                _get_unit_id(unit)
                for unit in utils.search_units(self.cfg, repo)
            }
            self.assertEqual(removed_ids & remaining_ids, set())

        if selectors.bug_is_testable(2630, self.cfg.pulp_version):
            with self.subTest('last removed unit'):
                lur_before = self.get_repo_last_unit_removed(repo)
                time.sleep(1)  # ensure last_unit_removed increments
                # Select an unit and mess it up
                unit = random.choice(self.initial_units).copy()
                unit_id_name, _ = _get_unit_id(unit)
                unit['metadata'][unit_id_name] = utils.uuid4()
                # Remove the non-existent unit
                _remove_unit(self.cfg, repo, unit)
                lur_after = self.get_repo_last_unit_removed(repo)
                self.assertEqual(lur_before, lur_after)
Ejemplo n.º 8
0
    def verify_package_types(self, cfg, repo):
        """Assert sdist and bdist_wheel shelf-reader packages were synced.

        This test targets `Pulp #1883 <https://pulp.plan.io/issues/1883>`_.
        """
        units = utils.search_units(cfg, repo)
        unit_types = {unit['metadata']['packagetype'] for unit in units}
        self.assertEqual(unit_types, {'sdist', 'bdist_wheel'})
Ejemplo n.º 9
0
 def test_v2(self):
     """Test that repo is present, sync-able, and has content."""
     repo_path = '{}/'.format(DOCKER_V2_REPO)
     repo = {'_href': urljoin(REPOSITORY_PATH, repo_path)}
     sync_report = utils.sync_repo(self.cfg, repo)
     api.poll_spawned_tasks(self.cfg, sync_report.json())
     units = utils.search_units(self.cfg, repo)
     self.assertGreater(len(units), 0, 'No units found in repo')
Ejemplo n.º 10
0
 def test_all(self):
     """Test that repo is present, sync-able, and has content."""
     repo_path = '{}/'.format(RPM_REPO)
     repo = {'_href': urljoin(REPOSITORY_PATH, repo_path)}
     repo = self.client.get(repo['_href'], params={'details': True})
     sync_report = utils.sync_repo(self.cfg, repo)
     api.poll_spawned_tasks(self.cfg, sync_report.json())
     units = utils.search_units(self.cfg, repo)
     self.assertGreater(len(units), 0, 'No units found in repo')
     download_rpm(self.cfg, repo['distributors'][0], RPM)
Ejemplo n.º 11
0
    def get_manifests(self):
        """Return all manifests in this test's repo.

        If the Pulp system under test is version 2.13 or newer, only return
        schema v1 manifests. See :meth:`get_latest_tags`.
        """
        criteria = {'type_ids': ['docker_manifest']}
        if self.cfg.pulp_version >= Version('2.13'):
            criteria['filters'] = {'unit': {'schema_version': 1}}
        return utils.search_units(self.cfg, self.repo, criteria)
Ejemplo n.º 12
0
    def test_all(self):
        """Test that recursive copy of erratas copies RPM packages.

        This test targets the following issues:

        * `Pulp Smash #769 <https://github.com/PulpQE/pulp-smash/issues/769>`_
        * `Pulp #3004 <https://pulp.plan.io/issues/3004>`_

        Do the following:

        1. Create and sync a repository with errata, and RPM packages.
        2. Create second repository.
        3. Copy units from from first repository to second repository
           using ``recursive`` as true, and filter  ``type_id`` as
           ``erratum``.
        4. Assert that RPM packages were copied.
        """
        cfg = config.get_config()
        if selectors.bug_is_untestable(3004, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/3004')

        repos = []
        client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_UPDATED_INFO_FEED_URL
        body['distributors'] = [gen_distributor()]
        repos.append(client.post(REPOSITORY_PATH, body))
        self.addCleanup(client.delete, repos[0]['_href'])
        utils.sync_repo(cfg, repos[0])

        # Create a second repository.
        repos.append(client.post(REPOSITORY_PATH, gen_repo()))
        self.addCleanup(client.delete, repos[1]['_href'])

        # Copy data to second repository.
        client.post(
            urljoin(repos[1]['_href'], 'actions/associate/'), {
                'source_repo_id': repos[0]['id'],
                'override_config': {
                    'recursive': True
                },
                'criteria': {
                    'filters': {},
                    'type_ids': ['erratum']
                },
            })

        # Assert that RPM packages were copied.
        units = utils.search_units(cfg, repos[1], {'type_ids': ['rpm']})
        self.assertGreater(len(units), 0)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
def get_rpm_names_versions(cfg, repo):
    """Get a dict of a repository's RPMs and their versions.

    :param pulp_smash.config.PulpSmashConfig cfg: Information about a Pulp app.
    :param repo: A dict of information about a repository.
    :returns: The name and versions of each package in the repository, with the
        versions sorted in ascending order. For example: ``{'walrus': ['0.71',
        '5.21']}``.
    """
    rpms = utils.search_units(cfg, repo, {'type_ids': ['rpm']})
    names_versions = {}
    for rpm in rpms:
        rpm_name = rpm['metadata']['name']
        names_versions.setdefault(rpm_name, [])
        names_versions[rpm_name].append(rpm['metadata']['version'])
    for versions in names_versions.values():
        versions.sort(key=Version)
    return names_versions
Ejemplo n.º 15
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.
        """
        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)
Ejemplo n.º 16
0
    def test_02_second_publish(self):
        """Add an additional content unit and publish the repository again."""
        utils.sync_repo(self.cfg, self.repo)
        utils.publish_repo(self.cfg, self.repo)
        self.updateinfo_xml_hrefs.append(self.get_updateinfo_xml_href())

        client = api.Client(self.cfg)
        with self.subTest(comment='check number of RPMs in repo'):
            units = (utils.search_units(self.cfg, self.repo,
                                        {'type_ids': ('rpm', )}))
            self.assertEqual(len(units), 32)
        with self.subTest(comment='check updateinfo.xml has a new path'):
            # pylint:disable=no-value-for-parameter
            self.assertNotEqual(*self.updateinfo_xml_hrefs)
        with self.subTest(comment='check old updateinfo.xml is unavailable'):
            with self.assertRaises(HTTPError):
                client.get(self.updateinfo_xml_hrefs[0])
        with self.subTest(comment='check new updateinfo.xml is available'):
            client.get(self.updateinfo_xml_hrefs[1])
Ejemplo n.º 17
0
    def do_test(self, feed, type_id):
        """Publish a repository with an invalid checksum.

        Do the following:

        1. Create and sync repository of type ``type_id`` and with the given
           feed. Ensure the repository's importer has a deferred/lazy download
           policy.
        2. Determine which checksum type the units in the repository use. (As
           of this writing, Pulp can handle md5, sha1 and sha256 checksum
           types.)
        3. Publish the repository with checksum types different from what the
           units in the repository use. Assert the publish fails.

        This test targets `Pulp Smash #287
        <https://github.com/PulpQE/pulp-smash/issues/287>`_.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        # Create and sync a repository.
        body = gen_repo()
        body['importer_config']['download_policy'] = 'on_demand'
        body['importer_config']['feed'] = feed
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        self.addCleanup(client.delete, repo['_href'])
        utils.sync_repo(cfg, repo)
        repo = client.get(repo['_href'], params={'details': True})

        # Figure out which checksum type the units in the repository use.
        units = utils.search_units(cfg, repo, {'type_ids': type_id})
        checksums = {'md5', 'sha1', 'sha256'}

        # Publish this repo with checksums that aren't available.
        checksums -= {units[0]['metadata']['checksumtype']}
        for checksum in checksums:
            client.put(repo['distributors'][0]['_href'], {
                'distributor_config': {'checksum_type': checksum}
            })
            with self.assertRaises(TaskReportError):
                utils.publish_repo(cfg, repo)
Ejemplo n.º 18
0
    def test_03_update_root_repo(self):
        """Remove a content unit from the root repository and republish it."""
        unit = random.choice(_get_rpms(self.cfg, self.repos['root']))
        criteria = {
            'filters': {
                'unit': {
                    'name': unit['metadata']['name']
                }
            },
            'type_ids': [unit['unit_type_id']],
        }
        api.Client(self.cfg).post(
            urljoin(self.repos['root']['_href'], 'actions/unassociate/'), {
                'criteria': criteria
            }).json()
        utils.publish_repo(self.cfg, self.repos['root'])

        # Verify the removed unit cannot be found via a search.
        units = utils.search_units(self.cfg, self.repos['root'], criteria)
        self.assertEqual(len(units), 0, units)
Ejemplo n.º 19
0
    def test_all(self):
        """Republish a repository after removing content."""
        cfg = config.get_config()
        if check_issue_3104(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        if check_issue_2277(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        if check_issue_2620(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2620')

        # 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()]
        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)

        # Pick a random content unit and verify it's accessible.
        unit = random.choice(
            utils.search_units(cfg, repo, {'type_ids': ('rpm', )}))
        filename = unit['metadata']['filename']
        get_unit(cfg, repo['distributors'][0], filename)

        # Remove the content unit and verify it's inaccessible.
        client.post(
            urljoin(repo['_href'], 'actions/unassociate/'),
            {'criteria': {
                'filters': {
                    'unit': {
                        'filename': filename
                    }
                }
            }},
        )
        utils.publish_repo(cfg, repo)
        with self.assertRaises(KeyError):
            get_unit(cfg, repo['distributors'][0], filename)
Ejemplo n.º 20
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 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 _find_unit(self, repo_href, pkg_url):
        """Search the given repository for a package.

        Search the repository for content units having the same filename as
        ``pkg_url``, verify only one result is found, and return it.
        """
        pkg_filename = _get_pkg_filename(pkg_url)
        pkg_unit_type = _get_pkg_unit_type(pkg_filename)
        if pkg_unit_type == 'drpm':
            # This is the location of the package relative to the repo root.
            pkg_filename = 'drpms/' + pkg_filename
        units = utils.search_units(self.cfg, {'_href': repo_href}, {
            'filters': {
                'unit': {
                    'filename': {
                        '$in': [pkg_filename]
                    }
                }
            },
            'type_ids': [pkg_unit_type],
        })
        self.assertEqual(len(units), 1)
        return units[0]
Ejemplo n.º 22
0
    def get_latest_tags(self):
        """Return all tags in this test's repo with a name of "latest".

        Starting with Pulp 2.13, docker schema v2 is supported. As a result, a
        tag or manifest may be included in search results twice, with a
        differing schema_version. For convenience, if the Pulp system under
        test is version 2.13 or newer, only schema v1 is targeted. (The choice
        of schema version 1 is arbitrary.) See `Pulp #2099
        <https://pulp.plan.io/issues/2099>`_.

        :returns: A list of docker tags.
        """
        criteria = {
            'filters': {
                'unit': {
                    'name': 'latest'
                }
            },
            'type_ids': ['docker_tag'],
        }
        if self.cfg.pulp_version >= Version('2.13'):
            criteria['filters']['unit']['schema_version'] = 1
        return utils.search_units(self.cfg, self.repo, criteria)
Ejemplo n.º 23
0
 def test_03_unassociate_unit(self):
     """Unassociate the unit from the repository. Publish the repository."""
     repo_before = self.get_repo()
     units = utils.search_units(self.cfg, self.repo)
     self.assertEqual(len(units), 1, units)
     _remove_unit(self.cfg, self.repo, units[0])
     time.sleep(1)  # ensure last_publish increments
     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 = parse(repo_before['last_unit_added'])
         post = parse(repo_after['last_unit_added'])
         self.assertEqual(pre, post)
     with self.subTest(comment='last_unit_removed'):
         pre = repo_before['last_unit_removed']
         post = repo_after['last_unit_removed']
         self.assertIsNone(pre)
         self.assertIsNotNone(post)
     with self.subTest(comment='last_publish'):
         pre = parse(repo_before['distributors'][0]['last_publish'])
         post = parse(repo_after['distributors'][0]['last_publish'])
         self.assertGreater(post, pre)
Ejemplo n.º 24
0
    def test_01_first_publish(self):
        """Populate and publish the repository."""
        utils.sync_repo(self.cfg, self.repo)
        client = api.Client(self.cfg)
        client.post(
            urljoin(self.repo['_href'], 'actions/unassociate/'), {
                'criteria': {
                    'filters': {
                        'unit': {
                            'filename': RPM
                        }
                    },
                    'type_ids': ('rpm', ),
                }
            })
        utils.publish_repo(self.cfg, self.repo)
        self.updateinfo_xml_hrefs.append(self.get_updateinfo_xml_href())

        with self.subTest(comment='check number of RPMs in repo'):
            units = (utils.search_units(self.cfg, self.repo,
                                        {'type_ids': ('rpm', )}))
            self.assertEqual(len(units), 31)
        with self.subTest(comment='check updateinfo.xml is available'):
            client.get(self.updateinfo_xml_hrefs[0])
Ejemplo n.º 25
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)
        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'])
Ejemplo n.º 26
0
 def test_all(self):
     """Check if Pulp only associate missing repo content."""
     if self.cfg.pulp_version < Version('2.11'):
         self.skipTest(
             'Selective association is available on Pulp 2.11+ see Pulp '
             '#2457 for more information')
     client = api.Client(self.cfg, api.json_handler)
     body = gen_repo()
     body['importer_config']['feed'] = RPM_UNSIGNED_FEED_URL
     repo = client.post(REPOSITORY_PATH, body)
     self.addCleanup(client.delete, repo['_href'])
     utils.sync_repo(self.cfg, repo)
     rpm_units = (_get_units_by_type(utils.search_units(self.cfg, repo),
                                     'rpm'))
     # Let's select up to 1/5 of the available units to remove
     to_remove = random.sample(
         rpm_units, random.randrange(int(RPM_UNSIGNED_FEED_COUNT / 4)))
     for unit in to_remove:
         _remove_unit(self.cfg, repo, unit)
     report = client.post(urljoin(repo['_href'], 'actions/sync/'))
     tasks = tuple(api.poll_spawned_tasks(self.cfg, report))
     self.assertEqual(len(tasks), 1, tasks)
     self.assertEqual(tasks[0]['result']['added_count'], len(to_remove),
                      to_remove)
Ejemplo n.º 27
0
    def do_test(self, repo):
        """Verify that the given ``repo`` has an RPM with vendor data.

        Perform the following checks:

        * Search ``repo`` for RPMs and filter with a valid unit license. Assert
          that one search result is returned, and that it has vendor metadata.
        * Search ``repo`` for RPMs and filter with a valid unit vendor. Assert
          that one search result is returned, and that it has vendor metadata.
        * Search ``repo`` for RPMs and filter with an invalid unit license.
          Assert that no search results are returned.
        * Search ``repo`` for RPMs and filter with an invalid unit vendor.
          Assert that no search results are returned.

        The license-based searches serve as a sanity check. They show that the
        search syntax is correct.
        """
        with self.subTest(comment='filter with a valid unit license'):
            units = utils.search_units(
                self.cfg, repo, {
                    'filters': {
                        'unit': {
                            'license':
                            RPM_WITH_VENDOR_DATA['metadata']['license']
                        }
                    },
                    'type_ids': ['rpm'],
                })
            self._verify_search_results(units)

        with self.subTest(comment='filter with a valid unit vendor'):
            units = utils.search_units(
                self.cfg, repo, {
                    'filters': {
                        'unit': {
                            'vendor':
                            RPM_WITH_VENDOR_DATA['metadata']['vendor']
                        }
                    },
                    'type_ids': ['rpm'],
                })
            self._verify_search_results(units)

        with self.subTest(comment='filter with an invalid unit license'):
            units = utils.search_units(
                self.cfg, repo, {
                    'filters': {
                        'unit': {
                            'license': utils.uuid4()
                        }
                    },
                    'type_ids': ['rpm'],
                })
            self.assertEqual(len(units), 0, units)

        with self.subTest(comment='filter with an invalid unit vendor'):
            units = utils.search_units(
                self.cfg, repo, {
                    'filters': {
                        'unit': {
                            'vendor': utils.uuid4()
                        }
                    },
                    'type_ids': ['rpm'],
                })
            self.assertEqual(len(units), 0, units)
Ejemplo n.º 28
0
    def verify_repo_search(self, repo):
        """Search for units in the given ``repo``.

        Verify that only one content unit is in ``repo``, and that several of
        its metadata attributes are correct. This test targets `Pulp #2365
        <https://pulp.plan.io/issues/2365>`_ and `Pulp #2754
        <https://pulp.plan.io/issues/2754>`_
        """
        units = utils.search_units(self.cfg, repo)
        self.assertEqual(len(units), 1)

        # filename and derived attributes
        with self.subTest():
            self.assertEqual(units[0]['metadata']['filename'], RPM)
        with self.subTest():
            self.assertEqual(units[0]['metadata']['epoch'], RPM_DATA['epoch'])
        with self.subTest():
            self.assertEqual(units[0]['metadata']['name'], RPM_DATA['name'])
        with self.subTest():
            self.assertEqual(units[0]['metadata']['version'],
                             RPM_DATA['version'])
        with self.subTest():
            self.assertEqual(units[0]['metadata']['release'],
                             RPM_DATA['release'])

        # other attributes
        with self.subTest():
            self.assertEqual(units[0]['metadata']['license'],
                             RPM_DATA['metadata']['license'])
        with self.subTest():
            self.assertEqual(
                units[0]['metadata']['description'],
                RPM_DATA['metadata']['description'],
            )
        with self.subTest():
            self.assertEqual(
                units[0]['metadata']['files'],
                RPM_DATA['metadata']['files'],
            )

        if selectors.bug_is_testable(2754, self.cfg.pulp_version):
            # Test that additional fields are available.
            # Affected by Pulp issue #2754

            with self.subTest():
                self.assertEqual(
                    units[0]['metadata']['group'],
                    RPM_DATA['metadata']['group'],
                )
            with self.subTest():
                self.assertEqual(
                    units[0]['metadata']['summary'],
                    RPM_DATA['metadata']['summary'],
                )
            with self.subTest():
                self.assertEqual(
                    units[0]['metadata']['size'],
                    RPM_DATA['metadata']['size']['package'],
                )
            with self.subTest():
                self.assertEqual(
                    units[0]['metadata']['sourcerpm'],
                    RPM_DATA['metadata']['sourcerpm'],
                )
Ejemplo n.º 29
0
def _get_rpms(cfg, repo):
    """Return RPM content units in the given repository."""
    return utils.search_units(cfg, repo, {'type_ids': ('rpm', )})
Ejemplo n.º 30
0
 def test_04_find_unit(self):
     """Search for the content unit. Assert it isn't available."""
     units = utils.search_units(self.cfg, self.repo,
                                {'type_ids': ('rpm', )})
     self.assertEqual(len(units), 0, units)