Пример #1
0
 def test_connection_error(self):
     """Make the dependent function raise a connection error."""
     ver = Version('0')
     with mock.patch.object(selectors, '_get_bug') as get_bug:
         get_bug.side_effect = requests.exceptions.ConnectionError
         with self.assertWarns(RuntimeWarning):
             selectors.bug_is_fixed(None, ver)
Пример #2
0
 def test_unknown_status(self):
     """Assert the method correctly handles an unknown bug status."""
     ver = Version('0')
     bug = selectors._Bug('foo', ver)
     with mock.patch.object(selectors, '_get_bug', return_value=bug):
         with self.assertRaises(exceptions.BugStatusUnknownError):
             selectors.bug_is_fixed(None, ver)
    def test_all(self):
        """Publish the rpm rsync distributor before the yum distributor."""
        cfg = config.get_config()
        if not selectors.bug_is_fixed(2187, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/2187')

        # 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,
                }
            })

        # Publish with the rsync distributor.
        distribs = get_dists_by_type_id(cfg, repo)
        args = (cfg, repo, {'id': distribs['rpm_rsync_distributor']['id']})
        self.verify_publish_is_skip(cfg, publish_repo(*args).json())

        # Verify that the rsync distributor hasn't placed files.
        dirs = self.remote_root_files(cfg, distribs['rpm_rsync_distributor'])
        self.assertNotIn('content', dirs)

        # Publish with the rsync distributor again, and verify again.
        if selectors.bug_is_fixed(2722, cfg.pulp_version):
            self.verify_publish_is_skip(cfg, publish_repo(*args).json())
            dirs = self.remote_root_files(cfg,
                                          distribs['rpm_rsync_distributor'])
            self.assertNotIn('content', dirs)
Пример #4
0
def setUpModule():  # pylint:disable=invalid-name
    """Conditionally skip tests. Cache packages to be uploaded to repos.

    Skip the tests in this module if:

    * The RPM plugin is unsupported.
    * `Pulp #1991 <https://pulp.plan.io/issues/1991>`_ is untestable for the
      version of Pulp under test.
    """
    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()
    try:
        _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)
    except:  # noqa:E722
        _SIGNED_PACKAGES.clear()
        _UNSIGNED_PACKAGES.clear()
        raise
Пример #5
0
    def test_broker_reconnect(self):
        """Test Pulp's support for reconnecting to a broker that goes missing.

        Do the following:

        1. Start both the broker and several other services.
        2. Stop the broker, wait, and start it again.
        3. Test Pulp's health. Create an RPM repository, sync it, add a
           distributor, publish it, and download an RPM.

        This test targets:

        * `Pulp #1635 <https://pulp.plan.io/issues/1635>`_
        * `Pulp #2613 <https://pulp.plan.io/issues/2613>`_
        """
        if not selectors.bug_is_fixed(1635, self.cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/1635')
        if (self.cfg.pulp_version >= Version('2.13') and
                not selectors.bug_is_fixed(2613, self.cfg.pulp_version)):
            self.skipTest('https://pulp.plan.io/issues/2613')
        # We assume that the broker and other services are already running. As
        # a result, we skip step 1 and go straight to step 2.
        self.svc_mgr.stop(self.broker)
        time.sleep(30)
        self.svc_mgr.start(self.broker)
        self.health_check()  # Step 3.
Пример #6
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,
     )
Пример #7
0
    def test_01_first_repo(self):
        """Create, sync content into and publish a Python repository.

        See:

        * `Pulp #135 <https://pulp.plan.io/issues/135>`_
        * `Pulp #3578 <https://pulp.plan.io/issues/3578>`_
        * `Pulp #3769 <https://pulp.plan.io/issues/3769>`_
        * `Pulp Smash #494 <https://github.com/PulpQE/pulp-smash/issues/494>`_
        """
        if (self.cfg.pulp_version < Version('2.17')
                or not selectors.bug_is_fixed(3578, self.cfg.pulp_version)):
            self.skipTest('https://pulp.plan.io/issues/3578')
        if not selectors.bug_is_fixed(135, self.cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/135')
        if (utils.fips_is_supported(self.cfg)
                and utils.fips_is_enabled(self.cfg)
                and not selectors.bug_is_fixed(3769, self.cfg.pulp_version)):
            self.skipTest('https://pulp.plan.io/issues/3769')
        client = api.Client(self.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config'] = {
            'feed': PYTHON_PYPI_FEED_URL,
            'package_names': 'shelf-reader',
        }
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        self.repos.append(repo)
        call_report = sync_repo(self.cfg, repo)
        with self.subTest(comment='verify the sync succeeded'):
            self.verify_sync(self.cfg, call_report)
        with self.subTest(comment='verify content units are present'):
            self.verify_package_types(self.cfg, repo)
        repo = get_details(self.cfg, repo)
        publish_repo(self.cfg, repo)
Пример #8
0
def setUpModule():  # pylint:disable=invalid-name
    """Conditionally skip tests."""
    if not selectors.bug_is_fixed(1991, config.get_config().pulp_version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/1991')
    if not selectors.bug_is_fixed(2242, config.get_config().pulp_version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2242')
    set_up_module()
Пример #9
0
 def test_unknown_status(self):
     """Assert the method correctly handles an unknown bug status."""
     ver = Version('0')
     bug = selectors._Bug('foo', ver)
     with mock.patch.object(selectors, '_get_bug', return_value=bug):
         with self.assertRaises(exceptions.BugStatusUnknownError):
             selectors.bug_is_fixed(None, ver)
Пример #10
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
Пример #11
0
 def test_connection_error(self):
     """Make the dependent function raise a connection error."""
     ver = Version('0')
     with mock.patch.object(selectors, '_get_bug') as get_bug:
         get_bug.side_effect = requests.exceptions.ConnectionError
         with self.assertWarns(RuntimeWarning):
             selectors.bug_is_fixed(None, ver)
Пример #12
0
 def setUpClass(cls):
     """Create class-wide variables."""
     super().setUpClass()
     cls.cfg = config.get_config()
     cls.repo = {}
     if (os_is_f26(cls.cfg)
             and not selectors.bug_is_fixed(3036, cls.cfg.pulp_version)):
         raise unittest.SkipTest('https://pulp.plan.io/issues/3036')
     if not selectors.bug_is_fixed(2384, cls.cfg.pulp_version):
         raise unittest.SkipTest('https://pulp.plan.io/issues/2384')
Пример #13
0
 def setUpClass(cls):
     """Create class-wide variables."""
     super().setUpClass()
     cls.cfg = config.get_config()
     if (os_is_f26(cls.cfg)
             and not selectors.bug_is_fixed(3036, cls.cfg.pulp_version)):
         raise unittest.SkipTest('https://pulp.plan.io/issues/3036')
     for issue_id in (2287, 2384):
         if not selectors.bug_is_fixed(issue_id, cls.cfg.pulp_version):
             raise unittest.SkipTest(
                 'https://pulp.plan.io/issues/{}'.format(issue_id))
Пример #14
0
    def test_all(self):
        """Test Pulp's handling of its ``PULP_MAX_TASKS_PER_CHILD`` setting."""
        cfg = config.get_config()
        if not selectors.bug_is_fixed(2172, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/2172')
        pulp_3540_testable = selectors.bug_is_fixed(3540, cfg.pulp_version)
        if os_is_f27(cfg) and not pulp_3540_testable:
            self.skipTest('https://pulp.plan.io/issues/3540')
        svc_mgr = cli.GlobalServiceManager(cfg)
        sudo = () if cli.is_root(cfg) else ('sudo', )
        set_cmd = sudo + (
            'sed', '-i', '-e',
            's/.*PULP_MAX_TASKS_PER_CHILD=[0-9]*$/PULP_MAX_TASKS_PER_CHILD=2/',
            '/etc/default/pulp_workers')
        unset_cmd = sudo + (
            'sed', '-i', '-e',
            's/^PULP_MAX_TASKS_PER_CHILD=2$/# PULP_MAX_TASKS_PER_CHILD=2/',
            '/etc/default/pulp_workers')
        procs_over_time = []

        # Step 1
        procs_over_time.append(get_pulp_worker_procs(cfg))
        for proc in procs_over_time[-1]:
            self.assertNotIn('--maxtasksperchild=2', proc, procs_over_time)

        # Step 2
        client = cli.Client(cfg)
        client.run(set_cmd)
        self.addCleanup(svc_mgr.restart, PULP_SERVICES)
        if not pulp_3540_testable:
            self.addCleanup(time.sleep, 30)
        self.addCleanup(client.run, unset_cmd)
        svc_mgr.restart(PULP_SERVICES)
        procs_over_time.append(get_pulp_worker_procs(cfg))
        for proc in procs_over_time[-1]:
            self.assertIn('--maxtasksperchild=2', proc, procs_over_time)

        # Step 3
        repo_id = utils.uuid4()
        proc = client.run(('pulp-admin', 'rpm', 'repo', 'create', '--repo-id',
                           repo_id, '--feed', RPM_UNSIGNED_FEED_URL))
        self.addCleanup(
            client.run,
            ('pulp-admin', 'rpm', 'repo', 'delete', '--repo-id', repo_id))
        self.assertNotIn('Task Failed', proc.stdout)
        proc = client.run(
            ('pulp-admin', 'rpm', 'repo', 'sync', 'run', '--repo-id', repo_id))
        self.assertNotIn('Task Failed', proc.stdout)

        # Step 4
        self.doCleanups()
        procs_over_time.append(get_pulp_worker_procs(cfg))
        for proc in procs_over_time[-1]:
            self.assertNotIn('--maxtasksperchild=2', proc, procs_over_time)
Пример #15
0
    def test_invalid_v3(self):
        """Update a distributor's relative path with an invalid value.

        Prepend a slash to an existing relative path. For example, if an
        existing relative path is ``foo/bar``, then this relative path would be
        ``/foo/bar``.
        """
        if (self.cfg.pulp_version >= Version('2.14')
                and not selectors.bug_is_fixed(2769, self.cfg.pulp_version)):
            self.skipTest('https://pulp.plan.io/issues/2769')

        # update
        client = api.Client(self.cfg, api.json_handler)
        old_path = self.repos[1]['distributors'][0]['config']['relative_path']
        new_path = (
            '/' + self.repos[0]['distributors'][0]['config']['relative_path'])
        with self.assertRaises(exceptions.TaskReportError):
            client.put(self.repos[1]['distributors'][0]['_href'],
                       {'distributor_config': {
                           'relative_path': new_path
                       }})

        # verify
        repo = client.get(self.repos[1]['_href'], params={'details': True})
        self.assertEqual(repo['distributors'][0]['config']['relative_path'],
                         old_path)
Пример #16
0
    def test_invalid_file_feed(self):
        """Create and sync a ISO repo from an invalid file feed.

        Assert that the sync fails with the information that some units were
        not available.
        """
        if self.cfg.pulp_version < Version('2.11'):
            self.skipTest(
                'Pulp reports 404 for ISO repos only on 2.11 or greater.')
        if not selectors.bug_is_fixed(3899, self.cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/3899')
        pulp_manifest = self.parse_pulp_manifest(FILE_MIXED_FEED_URL)
        missing = [
            row['name'] for row in pulp_manifest
            if row['name'].startswith('missing')
        ]
        client = api.Client(self.cfg, api.json_handler)
        repo = client.post(REPOSITORY_PATH, _gen_iso_repo(FILE_MIXED_FEED_URL))
        self.addCleanup(client.delete, repo['_href'])
        with self.assertRaises(exceptions.TaskReportError) as context:
            sync_repo(self.cfg, repo)
        task = context.exception.task
        self.assertIsNotNone(task['error'])
        # Description is a string generated after a Python's list of dicts
        # object. Adjust the string so we can parse it as JSON instead of using
        # eval. Having this as a Python object helps inspecting the message
        description = json.loads(task['error']['description'].replace(
            'u\'', '\'')  # noqa
                                 .replace('\'', '"')  # noqa
                                 )
        for info in description:
            with self.subTest(name=info['name']):
                self.assertEqual(info['error']['response_code'], 404)
                self.assertEqual(info['error']['response_msg'], 'Not Found')
                self.assertIn(info['name'], missing)
Пример #17
0
    def test_02_copy_tags(self):
        """Copy tags from one repository to another.

        Assert the same number of tags are present in both repositories.

        This test targets `Pulp #3892 <https://pulp.plan.io/issues/3892>`_.
        """
        if not selectors.bug_is_fixed(3892, self.cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/3892')
        client = api.Client(self.cfg, api.json_handler)
        repo = client.post(REPOSITORY_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])
        client.post(
            urljoin(repo['_href'], 'actions/associate/'), {
                'source_repo_id': self.repo['id'],
                'criteria': {
                    'filters': {},
                    'type_ids': ['docker_tag']
                },
            })
        repo = client.get(repo['_href'], params={'details': True})
        self.assertEqual(
            self.repo['content_unit_counts']['docker_tag'],
            repo['content_unit_counts'].get('docker_tag', 0),
        )
    def setUpClass(cls):
        """Create an RPM repository with a valid feed and sync it.

        Do the following:

        1. Reset Pulp, including the Squid cache.
        2. Create a repository with the "background" download policy.
        3. Sync and publish the repository.
        4. Download an RPM from the repository.
        """
        super().setUpClass()
        if check_issue_3104(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        if (not selectors.bug_is_fixed(1905, cls.cfg.pulp_version)
                and os_is_rhel6(cls.cfg)):
            raise unittest.SkipTest('https://pulp.plan.io/issues/1905')

        # Required to ensure content is actually downloaded.
        reset_squid(cls.cfg)
        reset_pulp(cls.cfg)

        # Create, sync and publish a repository.
        repo = _create_repo(cls.cfg, 'background')
        cls.resources.add(repo['_href'])
        report = sync_repo(cls.cfg, repo).json()

        # Record the tasks spawned when syncing the repository, and the state
        # of the repository itself after the sync.
        client = api.Client(cls.cfg)
        cls.repo = client.get(repo['_href'], params={'details': True}).json()
        cls.tasks = tuple(api.poll_spawned_tasks(cls.cfg, report))

        # Download an RPM.
        cls.rpm = get_unit(cls.cfg, cls.repo['distributors'][0], RPM)
Пример #19
0
 def test_display_order_occurences(self):
     """Assert ``display_order`` occurs once if omitted from the unit."""
     if not selectors.bug_is_fixed(1787, self.cfg.pulp_version):
         self.skipTest('https://pulp.plan.io/issues/1787')
     input_id = self.package_groups['minimal']['id']
     output = _get_groups_by_id(self.root_element)[input_id]
     self.assertEqual(len(output.findall('display_order')), 1)
Пример #20
0
 def test_signed_drpm(self):
     """Import a signed DRPM into Pulp. Verify its signature."""
     if not selectors.bug_is_fixed(1806, self.cfg.pulp_version):
         self.skipTest('https://pulp.plan.io/issues/1806')
     repo_href = self._create_repo_import_unit(DRPM_SIGNED_URL)
     unit = self._find_unit(repo_href, DRPM_SIGNED_URL)
     self._verify_pkg_key(unit, PULP_FIXTURES_KEY_ID)
Пример #21
0
 def test_unsigned_drpm(self):
     """Import an unsigned DRPM into Pulp. Verify it has no signature."""
     if not selectors.bug_is_fixed(1806, self.cfg.pulp_version):
         self.skipTest('https://pulp.plan.io/issues/1806')
     repo_href = self._create_repo_import_unit(DRPM_UNSIGNED_URL)
     unit = self._find_unit(repo_href, DRPM_UNSIGNED_URL)
     self.assertNotIn('signing_key', unit['metadata'])
Пример #22
0
def setUpModule():  # pylint:disable=invalid-name
    """Maybe skip this module of tests."""
    set_up_module()
    cfg = config.get_config()
    if (cfg.pulp_version >= Version('2.15.1')
            and not selectors.bug_is_fixed(3310, cfg.pulp_version)):
        raise unittest.SkipTest('https://pulp.plan.io/issues/3310')
Пример #23
0
    def test_all(self):
        """Test the update of ostree importers.

        Do the following:

        1. Create a repository.
        2. Update the ``importer`` associated with the repository.
        3. Perform assertions about the just updated ``importer``.
        """
        cfg = config.get_config()
        if not selectors.bug_is_fixed(3210, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/3210')
        client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = OSTREE_FEED
        body['importer_config']['branches'] = OSTREE_BRANCHES
        repo = client.post(REPOSITORY_PATH, body)
        self.addCleanup(client.delete, repo['_href'])
        repo = client.get(repo['_href'], params={'details': True})
        importer_config = {
            'basic_auth_username': None,
            'depth': randrange(-1, 10),
            'feed': utils.uuid4(),
            'ssl_validation': choice((False, True)),
        }
        client.put(repo['importers'][0]['_href'],
                   {'importer_config': importer_config})
        repo = client.get(repo['_href'], params={'details': True})
        for key, val in importer_config.items():
            with self.subTest(key=key):
                if val is None:
                    self.assertNotIn(key, repo['importers'][0]['config'])
                else:
                    self.assertEqual(val, repo['importers'][0]['config'][key])
Пример #24
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)
    def setUpClass(cls):
        """Create an RPM repository and issue a task to download the repo.

        Do the following:

        1. Reset Pulp.
        2. Create a repository with the "on demand" download policy.
        3. Sync the repository.
        4. Trigger a repository download.
        5. Corrupt a file in the repository.
        6. Trigger a repository download, without unit verification.
        7. Trigger a repository download, with unit verification.
        """
        cls.cfg = config.get_config()
        if (not selectors.bug_is_fixed(1905, cls.cfg.pulp_version)
                and os_is_rhel6(cls.cfg)):
            raise unittest.SkipTest('https://pulp.plan.io/issues/1905')

        # Ensure Pulp is empty of units otherwise we might just associate pre-
        # existing units.
        reset_pulp(cls.cfg)

        # Create and sync a repository.
        api_client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo(importer_config={
            'feed': RPM_UNSIGNED_FEED_URL,
            'download_policy': 'on_demand'
        })
        cls.repo = api_client.post(REPOSITORY_PATH, body)
        sync_repo(cls.cfg, cls.repo)

        # Trigger a repository download. Read the repo before and after.
        download_path = urljoin(cls.repo['_href'], 'actions/download/')
        params = {'details': True}
        cls.repo_pre_download = api_client.get(cls.repo['_href'],
                                               params=params)
        api_client.post(download_path, {'verify_all_units': False})
        cls.repo_post_download = api_client.get(cls.repo['_href'],
                                                params=params)

        # Corrupt an RPM. The file is there, but the checksum isn't right.
        rpm_abs_path = cls.get_rpm_abs_path()
        cli_client = cli.Client(cls.cfg)
        checksum_cmd = ('sha256sum ' + rpm_abs_path).split()
        cls.sha_pre_corruption = cli_client.run(checksum_cmd,
                                                sudo=True).stdout.strip()
        cli_client.run(('rm ' + rpm_abs_path).split(), sudo=True)
        cli_client.run(('touch ' + rpm_abs_path).split(), sudo=True)
        cli_client.run(('chown apache:apache ' + rpm_abs_path).split(),
                       sudo=True)
        cls.sha_post_corruption = cli_client.run(checksum_cmd,
                                                 sudo=True).stdout.strip()

        # Trigger repository downloads that don't and do checksum files, resp.
        api_client.post(download_path, {'verify_all_units': False})
        cls.unverified_file_sha = cli_client.run(checksum_cmd,
                                                 sudo=True).stdout.strip()
        api_client.post(download_path, {'verify_all_units': True})
        cls.verified_file_sha = cli_client.run(checksum_cmd,
                                               sudo=True).stdout.strip()
Пример #26
0
    def test_all(self):
        """Create and sync a puppet repository with no feed."""
        cfg = config.get_config()
        if not selectors.bug_is_fixed(2628, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/2628')

        # Create a repository.
        client = api.Client(cfg, api.json_handler)
        repo = client.post(REPOSITORY_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        # Sync the repository. An error *should* occur. We just want the error
        # to be sane.
        with self.assertRaises(exceptions.TaskReportError) as err:
            sync_repo(cfg, repo)
        with self.subTest(comment='check task "error" field'):
            self.assertIsNotNone(err.exception.task['error'])
            self.assertNotEqual(
                err.exception.task['error']['description'],
                "'NoneType' object has no attribute 'endswith'"
            )
            self.assertNotEqual(err.exception.task['error']['code'], 'PLP0000')
        with self.subTest(comment='check task "exception" field'):
            self.assertIsNone(err.exception.task['exception'])
        with self.subTest(comment='check task "traceback" field'):
            self.assertIsNone(err.exception.task['traceback'])
Пример #27
0
    def test_iso(self):
        """Upload duplicate ISO content. See :meth:`do_test`.

        This test targets the following issues:

        * `Pulp Smash #582 <https://github.com/PulpQE/pulp-smash/issues/582>`_
        * `Pulp #2274 <https://pulp.plan.io/issues/2274>`_
        """
        if not selectors.bug_is_fixed(2274, self.cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/2274')
        body = {
            'id':
            utils.uuid4(),
            'importer_type_id':
            'iso_importer',
            'distributors': [{
                'auto_publish': False,
                'distributor_id': utils.uuid4(),
                'distributor_type_id': 'iso_distributor',
            }],
        }
        iso = utils.http_get(FILE_URL)
        unit_key = {
            'checksum': hashlib.sha256(iso).hexdigest(),
            'name': os.path.basename(urlsplit(FILE_URL).path),
            'size': len(iso),
        }
        self.do_test(FILE_URL, 'iso', body, unit_key)
Пример #28
0
def setUpModule():  # pylint:disable=invalid-name
    """Skip tests if the RPM plugin is not installed."""
    set_up_module()
    cfg = config.get_config()
    if cfg.pulp_version < Version('2.8'):
        raise unittest.SkipTest('This module requires Pulp 2.8 or greater.')
    if os_is_f26(cfg) and not selectors.bug_is_fixed(3036, cfg.pulp_version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/3036')
    if check_issue_2798(cfg):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2798')
    if check_issue_2387(cfg):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2387')
    if not selectors.bug_is_fixed(2272, cfg.pulp_version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2272')
    if not selectors.bug_is_fixed(2144, cfg.pulp_version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2144')
Пример #29
0
    def test_sync_downloaded_content(self):
        """Create two repositories with the same feed, and sync them serially.

        More specifically, this test creates two puppet repositories with
        identical feeds, syncs them serially, and verifies that both have equal
        non-zero content unit counts.
        """
        cfg = config.get_config()
        if not selectors.bug_is_fixed(1937, cfg.pulp_version):
            self.skipTest('https://pulp.plan.io/issues/1937')
        pulp_admin_login(cfg)

        # Create two repos, schedule them for deletion, and sync them.
        client = cli.Client(cfg)
        repo_ids = [utils.uuid4() for _ in range(2)]
        for repo_id in repo_ids:
            client.run(('pulp-admin puppet repo create '
                        '--repo-id {} --feed {} --queries {}').format(
                            repo_id, PUPPET_FEED_2, PUPPET_QUERY_2).split())
            self.addCleanup(client.run,
                            ('pulp-admin puppet repo delete --repo-id {}'
                             ).format(repo_id).split())
            client.run(('pulp-admin puppet repo sync run --repo-id {}'
                        ).format(repo_id).split())

        # Verify the number of puppet modules in each repository.
        unit_counts = [
            get_num_units_in_repo(cfg, repo_id) for repo_id in repo_ids
        ]
        for i, unit_count in enumerate(unit_counts):
            with self.subTest(i=i):
                self.assertGreater(unit_count, 0)
        self.assertEqual(unit_counts[0], unit_counts[1])
Пример #30
0
    def setUpClass(cls):
        """Create an RPM repository with a valid feed and sync it.

        Do the following:

        1. Reset Pulp, including the Squid cache.
        2. Create a repository with the "on demand" download policy.
        3. Sync and publish the repository.
        4. Download an RPM from the published repository.
        5. Download the same RPM to ensure it is served by the cache.
        """
        super().setUpClass()
        if check_issue_3104(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        if not selectors.bug_is_fixed(4120, cls.cfg.pulp_version):
            raise unittest.SkipTest('https://pulp.plan.io/issues/4120')

        # Ensure `locally_stored_units` is 0 before we start.
        reset_squid(cls.cfg)
        reset_pulp(cls.cfg)

        # Create, sync and publish a repository.
        repo = _create_repo(cls.cfg, 'on_demand')
        cls.resources.add(repo['_href'])
        sync_repo(cls.cfg, repo)

        # Read the repository.
        client = api.Client(cls.cfg)
        cls.repo = client.get(repo['_href'], params={'details': True}).json()

        # Download the same RPM twice.
        cls.rpm = get_unit(cls.cfg, cls.repo['distributors'][0], RPM)
        cls.same_rpm = get_unit(cls.cfg, cls.repo['distributors'][0], RPM)
Пример #31
0
    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)
Пример #32
0
    def test_02_copy_manifest_lists(self):
        """Copy manifest lists from one repository to another.

        Assert the same number of manifest lists are present in both
        repositories. This test targets:

        * `Pulp #2384 <https://pulp.plan.io/issues/2384>`_
        * `Pulp #2385 <https://pulp.plan.io/issues/2385>`_
        * `Pulp #3892 <https://pulp.plan.io/issues/3892>`_
        """
        for issue_id in (2384, 2385, 3892):
            if not selectors.bug_is_fixed(issue_id, self.cfg.pulp_version):
                self.skipTest(
                    'https://pulp.plan.io/issues/{}'.format(issue_id)
                )
        repo = self.client.post(REPOSITORY_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])
        self.client.post(urljoin(repo['_href'], 'actions/associate/'), {
            'criteria': {'filters': {}, 'type_ids': ['docker_manifest_list']},
            'source_repo_id': self.repo['id'],
        })
        repo = self.client.get(repo['_href'], params={'details': True})
        self.assertEqual(
            self.repo['content_unit_counts']['docker_manifest_list'],
            repo['content_unit_counts'].get('docker_manifest_list', 0),
        )
Пример #33
0
 def test_untestable_status(self):
     """Assert the method correctly handles "untestable" bug statuses."""
     ver = Version('0')
     for bug_status in selectors._UNTESTABLE_BUGS:
         bug = selectors._Bug(bug_status, ver)
         with mock.patch.object(selectors, '_get_bug', return_value=bug):
             with self.subTest(bug_status=bug_status):
                 self.assertFalse(selectors.bug_is_fixed(None, ver))
Пример #34
0
 def test_02_read_distribution_without_specific_fields(self):
     """Read a distribution by its href excluding specific fields."""
     if not selectors.bug_is_fixed(4599, self.cfg.pulp_version):
         raise unittest.SkipTest('Issue 4599 is not resolved')
     # requests doesn't allow the use of != in parameters.
     url = '{}?fields!=base_path,name'.format(
         self.distribution['_href']
     )
     distribution = self.client.get(url)
     response_fields = distribution.keys()
     self.assertNotIn('base_path', response_fields)
     self.assertNotIn('name', response_fields)
Пример #35
0
def require_issue_3687(exc):
    """Skip tests if Fedora 27 is under test and `Pulp #3687`_ is open.

    :param exc: A class to instantiate and raise as an exception. Its
        constructor must accept one string argument.

    .. _Pulp #3687: https://pulp.plan.io/issues/3687
    """
    cfg = config.get_config()
    if (not selectors.bug_is_fixed(3687, cfg.pulp_version) and
            _os_is_f27(cfg)):
        raise exc('https://pulp.plan.io/issues/3687')
Пример #36
0
    def test_02_read_distribution_with_specific_fields(self):
        """Read a distribution by its href providing specific field list.

        Permutate field list to ensure different combinations on result.
        """
        if not selectors.bug_is_fixed(4599, self.cfg.pulp_version):
            raise unittest.SkipTest('Issue 4599 is not resolved')
        fields = ('base_path', 'name')
        for field_pair in permutations(fields, 2):
            # ex: field_pair = ('_href', 'base_url)
            with self.subTest(field_pair=field_pair):
                distribution = self.client.get(
                    self.distribution['_href'],
                    params={'fields': ','.join(field_pair)}
                )
                self.assertEqual(
                    sorted(field_pair), sorted(distribution.keys())
                )