def setUpModule():  # pylint:disable=invalid-name
    """Conditionally skip tests."""
    if selectors.bug_is_untestable(1991, config.get_config().version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/1991')
    if selectors.bug_is_untestable(2242, config.get_config().version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2242')
    set_up_module()
def setUpModule():  # pylint:disable=invalid-name
    """Possibly skip tests. Create and sync an RPM repository.

    Skip tests in this module if the RPM plugin is not installed on the target
    Pulp server. Then create an RPM repository with a feed and sync it. Test
    cases may copy data from this repository but should **not** change it.
    """
    set_up_module()
    cfg = config.get_config()
    client = cli.Client(config.get_config())

    # log in, then create repository
    utils.pulp_admin_login(cfg)
    client.run(
        'pulp-admin rpm repo create --repo-id {} --feed {}'
        .format(_REPO_ID, constants.RPM_SIGNED_FEED_URL).split()
    )

    # If setUpModule() fails, tearDownModule() isn't run. In addition, we can't
    # use addCleanup(), as it's an instance method. If this set-up procedure
    # grows, consider implementing a stack of tear-down steps instead.
    try:
        client.run(
            'pulp-admin rpm repo sync run --repo-id {}'
            .format(_REPO_ID).split()
        )
    except subprocess.CalledProcessError:
        client.run(
            'pulp-admin rpm repo delete --repo-id {}'.format(_REPO_ID).split()
        )
        raise
Exemplo n.º 3
0
    def test_upload(self):
        """Create a repository and upload DRPMs into it.

        Specifically, do the following:

        1. Create a yum repository.
        2. Download a DRPM file.
        3. Upload the DRPM into it. Use ``pulp-admin`` to verify its presence
           in the repository.
        4. Upload the same DRPM into the same repository, and use the
           ``--skip-existing`` flag during the upload. Verify that Pulp skips
           the upload.
        """
        if selectors.bug_is_untestable(1806, config.get_config().version):
            self.skipTest('https://pulp.plan.io/issues/1806')

        # Create a repository
        client = cli.Client(config.get_config())
        repo_id = utils.uuid4()
        client.run(
            'pulp-admin rpm repo create --repo-id {}'.format(repo_id).split()
        )
        self.addCleanup(
            client.run,
            'pulp-admin rpm repo delete --repo-id {}'.format(repo_id).split()
        )

        # Create a temporary directory, and download a DRPM file into it
        temp_dir = client.run('mktemp --directory'.split()).stdout.strip()
        self.addCleanup(client.run, 'rm -rf {}'.format(temp_dir).split())
        drpm_file = os.path.join(temp_dir, os.path.split(DRPM)[-1])
        client.run(
            'curl -o {} {}'.format(drpm_file, DRPM_UNSIGNED_URL).split()
        )

        # Upload the DRPM into the repository. Don't use subTest, as if this
        # test fails, the following one is invalid anyway.
        client.run(
            'pulp-admin rpm repo uploads drpm --repo-id {} --file {}'
            .format(repo_id, drpm_file).split()
        )
        proc = client.run(
            'pulp-admin rpm repo content drpm --repo-id {} --fields filename'
            .format(repo_id).split()
        )
        self.assertEqual(proc.stdout.split('Filename:')[1].strip(), DRPM)

        # Upload the DRPM into the repository. Pass --skip-existing.
        proc = client.run(
            ('pulp-admin rpm repo uploads drpm --repo-id {} --file {} '
             '--skip-existing')
            .format(repo_id, drpm_file).split()
        )
        self.assertIn('No files eligible for upload', proc.stdout)
Exemplo n.º 4
0
    def test_file_decriptors(self):
        """Test whether file descriptors are closed properly.

        This test targets the following issue:
        `Pulp #4073 <https://pulp.plan.io/issues/4073>`_

        Do the following:
        1. Check if 'lsof' is installed. If it is not, skip this test.
        2. Create and sync a repo.
        3. Run the 'lsof' command to verify that files in the
           path ``/var/lib/pulp/`` are closed after the sync.
        4. Assert that issued command returns `0` opened files.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)
        cli_client = cli.Client(cfg, cli.echo_handler)

        # check if 'lsof' is available
        if cli_client.run(('which', 'lsof')).returncode != 0:
            raise unittest.SkipTest('lsof package is not present')

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        remote = client.post(RPM_REMOTE_PATH, gen_rpm_remote())
        self.addCleanup(client.delete, remote['_href'])

        sync(cfg, remote, repo)

        cmd = 'lsof -t +D {}'.format(MEDIA_PATH).split()
        response = cli_client.run(cmd).stdout
        self.assertEqual(len(response), 0, response)
Exemplo n.º 5
0
    def test_force_sync(self):
        """Test whether one can force Pulp to perform a full sync."""
        cfg = config.get_config()
        if selectors.bug_is_untestable(1982, cfg.version):
            self.skipTest("https://pulp.plan.io/issues/1982")

        # Create and sync a repository.
        client = cli.Client(cfg)
        repo_id = utils.uuid4()
        client.run("pulp-admin rpm repo create --repo-id {} --feed {}".format(repo_id, RPM_SIGNED_FEED_URL).split())
        self.addCleanup(client.run, "pulp-admin rpm repo delete --repo-id {}".format(repo_id).split())
        sync_repo(cfg, repo_id)

        # Delete a random RPM
        rpms = self._list_rpms(cfg)
        client.run("{} rm -rf {}".format("sudo" if not is_root(cfg) else "", random.choice(rpms)).split())
        with self.subTest(comment="Verify the RPM was removed."):
            self.assertEqual(len(self._list_rpms(cfg)), len(rpms) - 1)

        # Sync the repository *without* force_sync.
        sync_repo(cfg, repo_id)
        with self.subTest(comment="Verify the RPM has not been restored."):
            self.assertEqual(len(self._list_rpms(cfg)), len(rpms) - 1)

        # Sync the repository again
        sync_repo(cfg, repo_id, force_sync=True)
        with self.subTest(comment="Verify the RPM has been restored."):
            self.assertEqual(len(self._list_rpms(cfg)), len(rpms))
Exemplo n.º 6
0
    def test_all(self):
        """Recursively copy a "chimpanzee" unit from one repository to another.

        "chimpanzee" depends on "walrus," and there are multiple versions of
        "walrus" in the source repository. Verify that one "walrus" unit has
        been copied to the target repository, and that the newer one has been
        copied.
        """
        cfg = config.get_config()
        repo_id = self.create_repo(cfg)
        cli.Client(cfg).run(
            'pulp-admin rpm repo copy rpm --from-repo-id {} --to-repo-id {} '
            '--str-eq name=chimpanzee --recursive'
            .format(_REPO_ID, repo_id).split()
        )

        # Verify only one "walrus" unit has been copied
        dst_rpms = _get_rpm_names_versions(cfg, repo_id)
        self.assertIn('walrus', dst_rpms)
        self.assertEqual(len(dst_rpms['walrus']), 1, dst_rpms)

        # Verify the version of the "walrus" unit
        src_rpms = _get_rpm_names_versions(cfg, _REPO_ID)
        src_rpms['walrus'].sort(key=lambda ver: Version(ver))  # noqa pylint:disable=unnecessary-lambda
        self.assertEqual(src_rpms['walrus'][-1], dst_rpms['walrus'][0])
Exemplo n.º 7
0
    def test_all(self):
        """Test whether sync/publish for content already in Pulp."""
        cfg = config.get_config()
        client = api.Client(cfg, api.page_handler)

        # step 1. delete orphans to assure that no content is present on disk,
        # or database.
        delete_orphans(cfg)

        remote = client.post(
            FILE_REMOTE_PATH,
            gen_remote(FILE_FIXTURE_MANIFEST_URL)
        )
        self.addCleanup(client.delete, remote['_href'])

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(client.delete, publisher['_href'])

        for _ in range(2):
            sync(cfg, remote, repo)
            repo = client.get(repo['_href'])
            publish(cfg, publisher, repo)
Exemplo n.º 8
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     delete_orphans(cls.cfg)
     populate_pulp(cls.cfg, url=FILE_LARGE_FIXTURE_MANIFEST_URL)
     cls.client = api.Client(cls.cfg, api.page_handler)
     cls.content = cls.client.get(FILE_CONTENT_PATH)
Exemplo n.º 9
0
    def test_all(self):
        """Verify whether the sync of a repository updates its version.

        This test explores the design choice stated in the `Pulp #3308`_ that a
        new repository version is created even if the sync does not add or
        remove any content units. Even without any changes to the remote if a
        new sync occurs, a new repository version is created.

        .. _Pulp #3308: https://pulp.plan.io/issues/3308

        Do the following:

        1. Create a repository, and a remote.
        2. Sync the repository an arbitrary number of times.
        3. Verify that the repository version is equal to the previous number
           of syncs.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        body = gen_file_remote()
        remote = client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        number_of_syncs = randint(1, 10)
        for _ in range(number_of_syncs):
            sync(cfg, remote, repo)

        repo = client.get(repo['_href'])
        path = urlsplit(repo['_latest_version_href']).path
        latest_repo_version = int(path.split('/')[-2])
        self.assertEqual(latest_repo_version, number_of_syncs)
Exemplo n.º 10
0
    def test_single_request_upload(self):
        """Test single request upload."""
        cfg = config.get_config()
        # Pulp does not support single request upload for a RPM already present
        # in Pulp.
        delete_orphans(cfg)
        file = {'file': utils.http_get(RPM_UNSIGNED_URL)}
        client = api.Client(cfg, api.page_handler)
        repo = client.post(REPO_PATH, gen_repo())

        self.addCleanup(client.delete, repo['_href'])
        client.post(
            urljoin(BASE_PATH, 'rpm/upload/'),
            files=file,
            data={'repository': repo['_href']}
        )
        repo = client.get(repo['_href'])

        # Assertion about repo version.
        self.assertIsNotNone(repo['_latest_version_href'], repo)

        # Assertions about artifcats.
        artifact = client.get(ARTIFACTS_PATH)
        self.assertEqual(len(artifact), 1, artifact)
        self.assertEqual(
            artifact[0]['sha256'],
            hashlib.sha256(file['file']).hexdigest(),
            artifact
        )

        # Assertion about content unit.
        content = client.get(RPM_CONTENT_PATH)
        self.assertEqual(len(content), 1, content)
Exemplo n.º 11
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.json_handler)
     cls.remote = {}
     cls.repo = {}
     cls.content = {}
Exemplo n.º 12
0
 def setUp(self):
     """Provide a server config and Pulp services to stop and start."""
     self.cfg = config.get_config()
     self.broker = utils.get_broker(self.cfg)
     self.services = tuple((
         cli.Service(self.cfg, service) for service in PULP_SERVICES
     ))
Exemplo n.º 13
0
    def test_all(self):
        """Create, sync and publish an OSTree repository.

        Verify that:

        * The distributor's ``last_publish`` attribute is ``None`` after the
          sync. This demonstrates that ``auto_publish`` correctly defaults to
          ``False``.
        * The distributor's ``last_publish`` attribute is not ``None`` after
          the publish.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

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

        # Sync the repository.
        utils.sync_repo(cfg, repo['_href'])
        repo = client.get(repo['_href'], params={'details': True})
        with self.subTest(comment='verify last_publish after sync'):
            self.assertIsNone(repo['distributors'][0]['last_publish'])

        # Publish the repository.
        utils.publish_repo(cfg, repo)
        repo = client.get(repo['_href'], params={'details': True})
        with self.subTest(comment='verify last_publish after publish'):
            self.assertIsNotNone(repo['distributors'][0]['last_publish'])
Exemplo n.º 14
0
    def test_all(self):
        """Publish the rpm rsync distributor before the yum distributor."""
        cfg = config.get_config()
        if selectors.bug_is_untestable(2187, cfg.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.base_url).netloc,
            '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['_href'])
        self.verify_publish_is_skip(cfg, utils.publish_repo(
            cfg,
            repo,
            {'id': distribs['rpm_rsync_distributor']['id']}
        ).json())

        # Verify that the rsync distributor hasn't placed files
        sudo = '' if utils.is_root(cfg) else 'sudo '
        cmd = (sudo + 'ls -1 /home/{}'.format(ssh_user)).split()
        dirs = set(cli.Client(cfg).run(cmd).stdout.strip().split('\n'))
        self.assertNotIn('content', dirs)
Exemplo n.º 15
0
 def setUpClass(cls):
     """Successfully log in to the server."""
     cfg = get_config()
     cls.response = requests.post(
         cfg.base_url + LOGIN_PATH,
         **cfg.get_requests_kwargs()
     )
 def setUpClass(cls):
     """Make calls to the server and save the responses."""
     client = api.Client(config.get_config(), api.echo_handler)
     cls.responses = {
         key: client.post(path, {key + '_criteriaa': {}})
         for key, path in _PATHS.items()
     }
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 selectors.bug_is_untestable(1991, cfg.version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/1991')
    set_up_module()
    try:
        _SIGNED_PACKAGES['rpm'] = utils.http_get(RPM_URL)
        _SIGNED_PACKAGES['srpm'] = utils.http_get(SRPM_URL)
        _UNSIGNED_PACKAGES['rpm'] = utils.http_get(RPM_UNSIGNED_URL)
        _UNSIGNED_PACKAGES['srpm'] = utils.http_get(SRPM_UNSIGNED_URL)
        if selectors.bug_is_testable(1806, cfg.version):
            _SIGNED_PACKAGES['drpm'] = utils.http_get(DRPM_URL)
            _UNSIGNED_PACKAGES['drpm'] = utils.http_get(DRPM_UNSIGNED_URL)
    except:
        _SIGNED_PACKAGES.clear()
        _UNSIGNED_PACKAGES.clear()
        raise
Exemplo n.º 18
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 selectors.bug_is_untestable(1937, cfg.version):
            self.skipTest('https://pulp.plan.io/issues/1937')
        utils.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, PUPPET_QUERY).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])
Exemplo n.º 19
0
def setUpModule():  # pylint:disable=invalid-name
    """Possibly skip the tests in this module. Create and sync an RPM repo.

    Skip this module of tests if Pulp is older than version 2.9. (See `Pulp
    #1724`_.) Then create an RPM repository with a feed and sync it. Test cases
    may copy data from this repository but should **not** change it.

    .. _Pulp #1724: https://pulp.plan.io/issues/1724
    """
    set_up_module()
    cfg = config.get_config()
    if cfg.version < Version('2.9'):
        raise unittest.SkipTest('This module requires Pulp 2.9 or greater.')
    if check_issue_2277(cfg):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2277')

    # Create and sync a repository.
    client = api.Client(cfg, api.json_handler)
    _CLEANUP.append((client.delete, [ORPHANS_PATH], {}))
    body = gen_repo()
    body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
    _REPO.clear()
    _REPO.update(client.post(REPOSITORY_PATH, body))
    _CLEANUP.append((client.delete, [_REPO['_href']], {}))
    try:
        utils.sync_repo(cfg, _REPO['_href'])
    except (exceptions.CallReportError, exceptions.TaskReportError,
            exceptions.TaskTimedOutError):
        tearDownModule()
        raise
def setUpModule():  # pylint:disable=invalid-name
    """Conditionally skip tests. Create repositories with fixture data."""
    cfg = config.get_config()
    if selectors.bug_is_untestable(1991, cfg.version):
        raise unittest.SkipTest('https://pulp.plan.io/issues/1991')
    set_up_module()

    # Fetch RPMs.
    _SIGNED_PACKAGES['rpm'] = utils.http_get(RPM_URL)
    _SIGNED_PACKAGES['srpm'] = utils.http_get(SRPM_URL)
    _UNSIGNED_PACKAGES['rpm'] = utils.http_get(RPM_UNSIGNED_URL)
    _UNSIGNED_PACKAGES['srpm'] = utils.http_get(SRPM_UNSIGNED_URL)
    if selectors.bug_is_testable(1806, cfg.version):
        _SIGNED_PACKAGES['drpm'] = utils.http_get(DRPM_URL)
        _UNSIGNED_PACKAGES['drpm'] = utils.http_get(DRPM_UNSIGNED_URL)

    # Create repos, and upload RPMs to them.
    client = api.Client(cfg, api.json_handler)
    try:
        repo = client.post(REPOSITORY_PATH, gen_repo())
        _REPOS['signed'] = repo
        for type_id, pkg in _SIGNED_PACKAGES.items():
            utils.upload_import_unit(cfg, pkg, type_id, repo['_href'])

        repo = client.post(REPOSITORY_PATH, gen_repo())
        _REPOS['unsigned'] = repo
        for type_id, pkg in _UNSIGNED_PACKAGES.items():
            utils.upload_import_unit(cfg, pkg, type_id, repo['_href'])
    except:
        _SIGNED_PACKAGES.clear()
        _UNSIGNED_PACKAGES.clear()
        for _ in range(len(_REPOS)):
            client.delete(_REPOS.popitem()[1]['_href'])
        raise
Exemplo n.º 21
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.json_handler)
     body = gen_distribution()
     body['base_path'] = body['base_path'].replace('-', '/')
     cls.distribution = cls.client.post(DISTRIBUTION_PATH, body)
Exemplo n.º 22
0
    def test_all(self):
        """Test whether content unit used by a repo version can be deleted.

        Do the following:

        1. Sync content to a repository.
        2. Attempt to delete a content unit present in a repository version.
           Assert that a HTTP exception was raised.
        3. Assert that number of content units present on the repository
           does not change after the attempt to delete one content unit.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        body = gen_rpm_remote()
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        sync(cfg, remote, repo)

        repo = client.get(repo['_href'])
        content = get_content(repo)
        with self.assertRaises(HTTPError):
            client.delete(choice(content)['_href'])
        self.assertEqual(len(content), len(get_content(repo)))
Exemplo n.º 23
0
    def test_all(self):
        """Verify publisher and remote can be used with different repos.

        This test explores the design choice stated in `Pulp #3341`_ that
        remove the FK from publishers and remotes to repository.
        Allowing remotes and publishers to be used with different
        repositories.

        .. _Pulp #3341: https://pulp.plan.io/issues/3341

        Do the following:

        1. Create a remote, and a publisher.
        2. Create 2 repositories.
        3. Sync both repositories using the same remote.
        4. Assert that the two repositories have the same contents.
        5. Publish both repositories using the same publisher.
        6. Assert that each generated publication has the same publisher, but
           are associated with different repositories.
        """
        cfg = config.get_config()

        # Create a remote and publisher.
        client = api.Client(cfg, api.json_handler)
        body = gen_file_remote()
        remote = client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(client.delete, publisher['_href'])

        # Create and sync repos.
        repos = []
        for _ in range(2):
            repo = client.post(REPO_PATH, gen_repo())
            self.addCleanup(client.delete, repo['_href'])
            sync(cfg, remote, repo)
            repos.append(client.get(repo['_href']))

        # Compare contents of repositories.
        contents = []
        for repo in repos:
            contents.append(get_content(repo)[FILE_CONTENT_NAME])
        self.assertEqual(
            {content['_href'] for content in contents[0]},
            {content['_href'] for content in contents[1]},
        )

        # Publish repositories.
        publications = []
        for repo in repos:
            publications.append(publish(cfg, publisher, repo))
        self.assertEqual(
            publications[0]['publisher'],
            publications[1]['publisher']
        )
        self.assertNotEqual(
            publications[0]['repository_version'],
            publications[1]['repository_version']
        )
def _get_pkglist(update):
    """Parse the "pkglist" element in an ``updateinfo.xml`` update.

    :param update: An ``xml.etree`` element corresponding to an "update"
        element in an ``updateinfo.xml`` file.
    :returns: A list of packages, each in the format used by an erratum.
    """
    src_pkglist = update.find('pkglist')
    out_pkglist = [{
        'name': src_pkglist.find('collection').find('name').text,
        'packages': [],
        'short': src_pkglist.find('collection').attrib['short'],
    }]
    for package in src_pkglist.find('collection').findall('package'):
        out_pkglist[0]['packages'].append({
            'arch': package.attrib['arch'],
            'epoch': package.attrib['epoch'],
            'filename': package.find('filename').text,
            'name': package.attrib['name'],
            'release': package.attrib['release'],
            'src': package.attrib['src'],
            'version': package.attrib['version'],
        })
        if selectors.bug_is_testable(2042, config.get_config().version):
            checksum = package.find('sum')
            out_pkglist[0]['packages'][-1]['sum'] = [
                checksum.attrib['type'], checksum.text
            ]
    return out_pkglist
Exemplo n.º 25
0
 def setUpClass(cls):
     """Create a content source."""
     super(RefreshAndDeleteContentSourcesTestCase, cls).setUpClass()
     cls.cfg = config.get_config()
     if cls.cfg.version < Version('2.8.6'):
         raise unittest.SkipTest('This test requires at least 2.8.6')
     pulp_admin_login(cls.cfg)
     cls.client = cli.Client(cls.cfg)
     cls.content_source_id = uuid4()
     content_source_path = generate_content_source(
         cls.cfg,
         cls.content_source_id,
         enabled='1',
         type='yum',
         base_url=RPM_SIGNED_FEED_URL,
     )
     sudo = '' if is_root(cls.cfg) else 'sudo '
     cls.responses = [
         cls.client.run(
             'pulp-admin content sources refresh'.split()
         ),
         _get_content_source_ids(cls.cfg),
         cls.client.run(
             'pulp-admin content sources refresh --source-id {}'
             .format(cls.content_source_id).split()
         ),
     ]
     cls.client.run(
         '{}rm -f {}'.format(sudo, content_source_path).split())
     cls.responses.append(_get_content_source_ids(cls.cfg))
 def test_all(self):
     """Execute the test case business logic."""
     cfg = config.get_config()
     self.check_issue_2363(cfg)
     repo_href = self.create_repo(cfg, RPM_MIRRORLIST_BAD, _gen_rel_url())
     with self.assertRaises(TaskReportError):
         utils.sync_repo(cfg, repo_href)
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.
    """
    if selectors.bug_is_untestable(1991, config.get_config().version):
        raise unittest2.SkipTest('https://pulp.plan.io/issues/1991')
    set_up_module()
    global _PACKAGES  # pylint:disable=global-statement
    try:
        _PACKAGES = {
            'signed drpm': utils.http_get(DRPM_URL),
            'signed rpm': utils.http_get(RPM_URL),
            'signed srpm': utils.http_get(SRPM_URL),
            'unsigned drpm': utils.http_get(DRPM_UNSIGNED_URL),
            'unsigned rpm': utils.http_get(RPM_UNSIGNED_URL),
            'unsigned srpm': utils.http_get(SRPM_UNSIGNED_URL),
        }
    except:
        _PACKAGES = None
        raise
Exemplo n.º 28
0
def setUpModule():  # pylint:disable=invalid-name
    """Possibly skip the tests in this module. Create and sync an RPM repo.

    Skip this module of tests if Pulp is older than version 2.9. (See `Pulp
    #1724`_.) Then create an RPM repository with a feed and sync it. Test cases
    may copy data from this repository but should **not** change it.

    .. _Pulp #1724: https://pulp.plan.io/issues/1724
    """
    set_up_module()
    cfg = config.get_config()
    if cfg.version < Version("2.9"):
        raise unittest2.SkipTest("This module requires Pulp 2.9 or greater.")

    # Create and sync a repository. If this set-up procedure grows, consider
    # implementing a stack of tear-down actions
    client = api.Client(cfg, api.json_handler)
    body = gen_repo()
    body["importer_config"]["feed"] = RPM_FEED_URL
    global _REPO  # pylint:disable=global-statement
    _REPO = client.post(REPOSITORY_PATH, body)
    try:
        utils.sync_repo(cfg, _REPO["_href"])
    except (exceptions.CallReportError, exceptions.TaskReportError, exceptions.TaskTimedOutError):
        client.delete(_REPO["_href"])
        raise
Exemplo n.º 29
0
    def test_all(self):
        """Test whether the content present in a repo version is immutable.

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Attempt to update the content of a repository version.
        3. Assert that an HTTP exception is raised.
        4. Assert that the repository version was not updated.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        body = gen_file_remote()
        remote = client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        sync(cfg, remote, repo)

        latest_version_href = client.get(repo['_href'])['_latest_version_href']
        with self.assertRaises(HTTPError):
            client.post(latest_version_href)
        repo = client.get(repo['_href'])
        self.assertEqual(latest_version_href, repo['_latest_version_href'])
Exemplo n.º 30
0
    def test_all(self):
        """Verify multi-resourcing locking.

        Do the following:

        1. Create a repository, and a remote.
        2. Update the remote to point to a different url.
        3. Immediately run a sync. The sync should fire after the update and
           sync from the second url.
        4. Assert that remote url was updated.
        5. Assert that the number of units present in the repository is
           according to the updated url.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        body = gen_file_remote(url=FILE_LARGE_FIXTURE_MANIFEST_URL)
        remote = client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        url = {'url': FILE_FIXTURE_MANIFEST_URL}
        client.patch(remote['_href'], url)

        sync(cfg, remote, repo)

        repo = client.get(repo['_href'])
        remote = client.get(remote['_href'])
        self.assertEqual(remote['url'], url['url'])
        self.assertDictEqual(get_content_summary(repo), FILE_FIXTURE_SUMMARY)
Exemplo n.º 31
0
    def setUpClass(cls):
        """Create class-wide variables and delete orphans.

        1. Create a repository.
        2. Create a remote pointing to external registry with policy=on_demand.
        3. Sync the repository using the remote and re-read the repo data.
        4. Create a container distribution to serve the repository
        5. Create another container distribution to the serve the repository version

        This tests targets the following issue:

        * `Pulp #4460 <https://pulp.plan.io/issues/4460>`_
        """
        cls.cfg = config.get_config()
        cls.registry_name = urlparse(cls.cfg.get_base_url()).netloc

        client_api = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(client_api)
        cls.remotes_api = RemotesContainerApi(client_api)
        cls.distributions_api = DistributionsContainerApi(client_api)

        cls.teardown_cleanups = []

        delete_orphans()

        with contextlib.ExitStack() as stack:
            # ensure tearDownClass runs if an error occurs here
            stack.callback(cls.tearDownClass)

            # Step 1
            _repo = cls.repositories_api.create(ContainerContainerRepository(**gen_repo()))
            cls.teardown_cleanups.append((cls.repositories_api.delete, _repo.pulp_href))

            # Step 2
            cls.remote = cls.remotes_api.create(gen_container_remote(policy="on_demand"))
            cls.teardown_cleanups.append((cls.remotes_api.delete, cls.remote.pulp_href))

            # Step 3
            sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
            sync_response = cls.repositories_api.sync(_repo.pulp_href, sync_data)
            monitor_task(sync_response.task)

            cls.repo = cls.repositories_api.read(_repo.pulp_href)
            cls.artifacts_api = ArtifactsApi(core_client)
            cls.artifact_count = cls.artifacts_api.list().count

            # Step 4.
            distribution_response = cls.distributions_api.create(
                ContainerContainerDistribution(**gen_distribution(repository=cls.repo.pulp_href))
            )
            created_resources = monitor_task(distribution_response.task).created_resources

            distribution = cls.distributions_api.read(created_resources[0])
            cls.distribution_with_repo = cls.distributions_api.read(distribution.pulp_href)
            cls.teardown_cleanups.append(
                (cls.distributions_api.delete, cls.distribution_with_repo.pulp_href)
            )

            # Step 5.
            distribution_response = cls.distributions_api.create(
                ContainerContainerDistribution(
                    **gen_distribution(repository_version=cls.repo.latest_version_href)
                )
            )
            created_resources = monitor_task(distribution_response.task).created_resources
            distribution = cls.distributions_api.read(created_resources[0])
            cls.distribution_with_repo_version = cls.distributions_api.read(distribution.pulp_href)
            cls.teardown_cleanups.append(
                (cls.distributions_api.delete, cls.distribution_with_repo_version.pulp_href)
            )

            # remove callback if everything goes well
            stack.pop_all()
 def setUpClass(cls):
     """Create class wide-variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.json_handler)
     cls.distribution = {}
Exemplo n.º 33
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.json_handler)
 def setUpClass(cls):
     """Provide a server config and a repository ID."""
     cls.cfg = config.get_config()
     cls.repo_id = utils.uuid4()
     utils.pulp_admin_login(cls.cfg)
Exemplo n.º 35
0
 def setUp(self):
     """Create test-wide variables."""
     self.cfg = config.get_config()
     self.client = api.Client(self.cfg, api.json_handler)
Exemplo n.º 36
0
def gen_file_client():
    """Return an OBJECT for file client."""
    configuration = config.get_config().get_bindings_config()
    return FileApiClient(configuration)
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     if cls.cfg.pulp_version < Version('2.17'):
         raise unittest.SkipTest('This test requires Pulp 2.17 or newer.')
     cls.client = api.Client(cls.cfg, api.json_handler)
Exemplo n.º 38
0
 def setUpClass(cls):
     """Create class-wide variables, and clean orphan units."""
     cls.cfg = config.get_config()
     delete_orphans(cls.cfg)
     cls.client = api.Client(cls.cfg, api.page_handler)
def tearDownModule():  # pylint:disable=invalid-name
    """Delete orphan content units."""
    api.Client(config.get_config()).delete(ORPHANS_PATH)
Exemplo n.º 40
0
 def test_cache_empty(self):
     """A config is read from disk if the cache is empty."""
     with mock.patch.object(config, '_CONFIG', None):
         with mock.patch.object(config.ServerConfig, 'read') as read:
             config.get_config()
     self.assertEqual(read.call_count, 1)
def tearDownModule():  # pylint:disable=invalid-name
    """Delete the repository created by ``setUpModule``."""
    cli.Client(config.get_config()).run(
        'pulp-admin rpm repo delete --repo-id {}'.format(_REPO_ID).split()
    )
Exemplo n.º 42
0
def before_all(context):
    context.cfg = config.get_config()
    context.matcher = SelectorTagMatcher(context.cfg)
Exemplo n.º 43
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = gen_file_client()
Exemplo n.º 44
0
 def test_cache_full(self):
     """No config is read from disk if the cache is populated."""
     with mock.patch.object(config, '_CONFIG'):
         with mock.patch.object(config.ServerConfig, 'read') as read:
             config.get_config()
     self.assertEqual(read.call_count, 0)
Exemplo n.º 45
0
 def setUp(self):
     """Set common variables."""
     self.cfg = config.get_config()
Exemplo n.º 46
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.json_handler)
     cls.remote = {}
     cls.body = _gen_verbose_remote()
Exemplo n.º 47
0
    def do_test(self, policy):
        """Verify whether content served by pulp can be downloaded.

        The process of publishing content is more involved in Pulp 3 than it
        was under Pulp 2. Given a repository, the process is as follows:

        1. Create a publication from the repository. (The latest repository
           version is selected if no version is specified.) A publication is a
           repository version plus metadata.
        2. Create a distribution from the publication. The distribution defines
           at which URLs a publication is available, e.g.
           ``http://example.com/content/foo/`` and
           ``http://example.com/content/bar/``.

        Do the following:

        1. Create, populate, publish, and distribute a repository.
        2. Select a random content unit in the distribution. Download that
           content unit from Pulp, and verify that the content unit has the
           same checksum when fetched directly from Pulp-Fixtures.

        This test targets the following issues:

        * `Pulp #2895 <https://pulp.plan.io/issues/2895>`_
        * `Pulp Smash #872 <https://github.com/pulp/pulp-smash/issues/872>`_
        """
        repo_api = deb_repository_api
        remote_api = deb_remote_api
        publication_api = self.Meta.publication_api
        distribution_api = deb_distribution_api

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_deb_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync a Repository
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)

        # Create a publication.
        publish_data = self.Meta.Publication(repository=repo.pulp_href)
        publish_response = publication_api.create(publish_data)
        publication_href = monitor_task(publish_response.task)[0]
        self.addCleanup(publication_api.delete, publication_href)

        # Create a distribution.
        body = gen_distribution()
        body["publication"] = publication_href
        distribution_response = distribution_api.create(body)
        distribution_href = monitor_task(distribution_response.task)[0]
        distribution = distribution_api.read(distribution_href)
        self.addCleanup(distribution_api.delete, distribution.pulp_href)

        # Pick a content unit (of each type), and download it from both Pulp Fixtures…
        unit_paths = [
            choice(paths)
            for paths in self.Meta.get_content_unit_paths(repo).values()
            if paths
        ]
        fixtures_hashes = [
            hashlib.sha256(
                utils.http_get(urljoin(DEB_FIXTURE_URL,
                                       unit_path[0]))).hexdigest()
            for unit_path in unit_paths
        ]

        # …and Pulp.
        pulp_hashes = []
        cfg = config.get_config()
        for unit_path in unit_paths:
            content = download_content_unit(cfg, distribution.to_dict(),
                                            unit_path[1])
            pulp_hashes.append(hashlib.sha256(content).hexdigest())

        self.assertEqual(fixtures_hashes, pulp_hashes)
Exemplo n.º 48
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.user = {}
Exemplo n.º 49
0
    def test_all(self):
        """Verify whether content served by pulp can be downloaded.

        The process of publishing content is more involved in Pulp 3 than it
        was under Pulp 2. Given a repository, the process is as follows:

        1. Create a publication from the repository. (The latest repository
           version is selected if no version is specified.) A publication is a
           repository version plus metadata.
        2. Create a distribution from the publication. The distribution defines
           at which URLs a publication is available, e.g.
           ``http://example.com/content/foo/`` and
           ``http://example.com/content/bar/``.

        Do the following:

        1. Create, populate, publish, and distribute a repository.
        2. Select a random content unit in the distribution. Download that
           content unit from Pulp, and verify that the content unit has the
           same checksum when fetched directly from Pulp-Fixtures.

        This test targets the following issues:

        * `Pulp #2895 <https://pulp.plan.io/issues/2895>`_
        * `Pulp Smash #872 <https://github.com/PulpQE/pulp-smash/issues/872>`_
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        body = gen_rpm_remote()
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

        sync(cfg, remote, repo)
        repo = client.get(repo['_href'])

        # Create a publication.
        publication = publish(cfg, repo)
        self.addCleanup(client.delete, publication['_href'])

        # Create a distribution.
        body = gen_distribution()
        body['publication'] = publication['_href']
        distribution = client.using_handler(api.task_handler).post(
            RPM_DISTRIBUTION_PATH, body)
        self.addCleanup(client.delete, distribution['_href'])

        # Pick a content unit, and download it from both Pulp Fixtures…
        unit_path = choice(get_rpm_package_paths(repo))
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(RPM_UNSIGNED_FIXTURE_URL,
                                   unit_path))).hexdigest()

        # …and Pulp.
        content = download_content_unit(cfg, distribution, unit_path)
        pulp_hash = hashlib.sha256(content).hexdigest()

        self.assertEqual(fixtures_hash, pulp_hash)
Exemplo n.º 50
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        client = gen_rpm_client()
        repo_api = RepositoriesRpmApi(client)
        remote_api = RemotesRpmApi(client)
        publications = PublicationsRpmApi(client)

        body = gen_rpm_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # Step 1
        repo = repo_api.read(repo.pulp_href)
        for rpm_content in get_content(
                repo.to_dict())[RPM_PACKAGE_CONTENT_NAME]:
            modify_repo(cfg, repo.to_dict(), add_units=[rpm_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = RpmRpmPublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        self.addCleanup(publications.delete, publication_href)
        publication = publications.read(publication_href)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data.repository_version = non_latest
        publish_data.repository = None
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        publication = publications.read(publication_href)

        # Step 5
        self.assertEqual(publication.repository_version, non_latest)

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": repo.pulp_href,
                "repository_version": non_latest
            }
            publications.create(body)
Exemplo n.º 51
0
    def test_all(self):
        """Test content promotion for a distribution.

        This test targets the following issue:

        * `Pulp #4186 <https://pulp.plan.io/issues/4186>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publisher, and publication.
        3. Create 2 distributions - using the same publication. Those
           distributions will have different ``base_path``.
        4. Assert that distributions have the same publication.
        5. Select a content unit. Download that content unit from Pulp using
           the two different distributions.
           Assert that content unit has the same checksum when fetched from
           different distributions.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])

        remote = client.post(FILE_REMOTE_PATH,
                             gen_remote(FILE_FIXTURE_MANIFEST_URL))
        self.addCleanup(client.delete, remote['_href'])

        sync(cfg, remote, repo)
        repo = client.get(repo['_href'])

        publisher = client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(client.delete, publisher['_href'])

        publication = publish(cfg, publisher, repo)
        self.addCleanup(client.delete, publication['_href'])

        distributions = []
        for _ in range(2):
            body = gen_distribution()
            body['publication'] = publication['_href']
            response_dict = client.post(DISTRIBUTION_PATH, body)
            dist_task = client.get(response_dict['task'])
            distribution_href = dist_task['created_resources'][0]
            distribution = client.get(distribution_href)
            distributions.append(distribution)
            self.addCleanup(client.delete, distribution['_href'])

        self.assertEqual(distributions[0]['publication'],
                         distributions[1]['publication'], distributions)

        unit_urls = []
        unit_path = get_added_content(
            repo)[FILE_CONTENT_NAME][0]['relative_path']
        for distribution in distributions:
            unit_url = cfg.get_hosts('api')[0].roles['api']['scheme']
            unit_url += '://' + distribution['base_url'] + '/'
            unit_urls.append(urljoin(unit_url, unit_path))

        client.response_handler = api.safe_handler
        self.assertEqual(
            hashlib.sha256(client.get(unit_urls[0]).content).hexdigest(),
            hashlib.sha256(client.get(unit_urls[1]).content).hexdigest(),
            unit_urls,
        )
Exemplo n.º 52
0
 def setUp(self):
     """Make an API client."""
     self.client = api.Client(config.get_config(), api.json_handler)
Exemplo n.º 53
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.api_client = api.Client(cls.cfg, api.smart_handler)
     cls.cli_client = cli.Client(cls.cfg)
Exemplo n.º 54
0
    def setUpClass(cls):
        """
        Define APIs to use and pull images needed later in tests
        """
        api_client = gen_container_client()
        cfg = config.get_config()

        cls.repository_api = RepositoriesContainerApi(api_client)
        cls.pushrepository_api = RepositoriesContainerPushApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)

        cls.namespace_api = PulpContainerNamespacesApi(api_client)
        cls.registry = cli.RegistryClient(cfg)
        cls.registry.raise_if_unsupported(unittest.SkipTest,
                                          "Tests require podman/docker")
        cls.registry_name = urlparse(cfg.get_base_url()).netloc

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}
        cls.user_creator = gen_user([
            "container.add_containerrepository",
            "container.add_containerremote",
            "container.add_containernamespace",
            "container.add_containerdistribution",
        ])
        cls.user_creator2 = gen_user([
            "container.add_containernamespace",
            "container.add_containerdistribution",
        ])
        cls.user_reader = gen_user([
            "container.view_containerrepository",
            "container.view_containerpushrepository",
        ])
        cls.user_reader2 = gen_user(["container.view_containerrepository"])
        cls.user_reader3 = gen_user(["container.view_containerpushrepository"])
        cls.user_helpless = gen_user([])

        # create a push repo with user_creator
        image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_a"
        cls._pull(image_path)
        repo_name = "testcontent/perms"
        local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"])
        cls._push(image_path, local_url, cls.user_creator)
        cls.push_repository = cls.pushrepository_api.list(
            name=repo_name).results[0]

        # create a second push repo with user_creator2
        image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_b"
        cls._pull(image_path)
        repo_name = "testcontent2/perms"
        local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"])
        cls._push(image_path, local_url, cls.user_creator2)
        cls.push_repository2 = cls.pushrepository_api.list(
            name=repo_name).results[0]

        # sync a repo with user_creator
        cls.repository = cls.user_creator["repository_api"].create(
            ContainerContainerRepository(**gen_repo()))
        cls.remote = cls.user_creator["remote_api"].create(
            gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1))
        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.user_creator["repository_api"].sync(
            cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Exemplo n.º 55
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        client = gen_rpm_client()
        repo_api = RepositoriesRpmApi(client)
        remote_api = RemotesRpmApi(client)
        publications = PublicationsRpmApi(client)
        distributions = DistributionsRpmApi(client)

        body = gen_rpm_remote()
        remote = remote_api.create(body)

        repo = repo_api.create(gen_repo())

        repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # Step 1
        repo = repo_api.read(repo.pulp_href)
        repo_content = get_content(
            repo.to_dict())[RPM_PACKAGE_CONTENT_NAME][:-1]
        for rpm_content in repo_content:
            modify_repo(cfg, repo.to_dict(), remove_units=[rpm_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))
        non_latest = choice(version_hrefs[1:-1])

        # Step 2
        publish_data = RpmRpmPublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(
            publish_response.task).created_resources
        publication_href = created_resources[0]
        publication = publications.read(publication_href)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data.repository_version = non_latest
        publish_data.repository = None
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(
            publish_response.task).created_resources
        publication_href = created_resources[0]
        publication = publications.read(publication_href)

        # Step 5
        body = gen_distribution()
        body["base_path"] = "pulp_pre_upgrade_test"
        body["publication"] = publication.pulp_href

        distribution_response = distributions.create(body)
        created_resources = monitor_task(
            distribution_response.task).created_resources
        distribution = distributions.read(created_resources[0])

        # Step 6
        self.assertEqual(publication.repository_version, non_latest)

        # Step 7
        with self.assertRaises(ApiException):
            body = {
                "repository": repo.pulp_href,
                "repository_version": non_latest
            }
            publications.create(body)

        # Step 8
        url = cfg.get_content_host_base_url(
        ) + "/pulp/content/pulp_pre_upgrade_test/"
        self.assertEqual(url, distribution.base_url, url)
def tearDownModule():  # pylint:disable=invalid-name
    """Delete the repository created by :meth:`setUpModule`."""
    api.Client(config.get_config()).delete(_REPO['_href'])
Exemplo n.º 57
0
class BaseTestRpm:
    """
    Test RPM migration re-runs.
    """
    smash_cfg = smash_config.get_config()
    smash_cli_client = cli.Client(smash_cfg)
    plan_initial = None
    plan_rerun = None

    @classmethod
    def setUpClass(cls):
        """
        Create all the client instances needed to communicate with Pulp.
        """
        configuration = Configuration(**BINDINGS_CONFIGURATION)

        rpm_client = RpmApiClient(configuration)
        migration_client = MigrationApiClient(configuration)

        # Create api clients for all resource types
        cls.rpm_repo_api = RepositoriesRpmApi(rpm_client)
        cls.rpm_repo_versions_api = RepositoriesRpmVersionsApi(rpm_client)
        cls.rpm_remote_api = RemotesRpmApi(rpm_client)
        cls.rpm_distribution_api = DistributionsRpmApi(rpm_client)
        cls.rpm_publication_api = PublicationsRpmApi(rpm_client)
        cls.rpm_content_apis = {
            'advisory': ContentAdvisoriesApi(rpm_client),
            'disttree': ContentDistributionTreesApi(rpm_client),
            'modulemd': ContentModulemdsApi(rpm_client),
            'modulemd-defaults': ContentModulemdDefaultsApi(rpm_client),
            'category': ContentPackagecategoriesApi(rpm_client),
            'environment': ContentPackageenvironmentsApi(rpm_client),
            'group': ContentPackagegroupsApi(rpm_client),
            'langpack': ContentPackagelangpacksApi(rpm_client),
            'package': ContentPackagesApi(rpm_client),
        }
        cls.migration_plans_api = MigrationPlansApi(migration_client)
        cls.pulp2content_api = Pulp2ContentApi(migration_client)
        cls.pulp2repositories_api = Pulp2RepositoriesApi(migration_client)

    @classmethod
    def run_migration(cls, plan, run_params={}):
        """
        Run a migration plan.

        Args:
            plan(str): A migration plan to run, in JSON format.
            run_params(dict): parameters for the `run` call. Optional.

        Returns:
            task(pulpcore.app.models.Task): a migration task created for this plan

        """
        mp = cls.migration_plans_api.create({'plan': plan})
        mp_run_response = cls.migration_plans_api.run(mp.pulp_href, run_params)
        task = monitor_task(mp_run_response.task)
        monitor_task_group(task.task_group)
        return task

    @classmethod
    def tearDownClass(cls):
        """
        Clean up the database after the set of tests is run.
        """
        cmd = get_psql_smash_cmd(TRUNCATE_TABLES_QUERY_BASH)
        cls.smash_cli_client.run(cmd, sudo=True)
        time.sleep(0.5)
Exemplo n.º 58
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = api.Client(cls.cfg, api.page_handler)
     raise unittest.SkipTest('Skipping until we resolve https://pulp.plan.io/issues/5507')
Exemplo n.º 59
0
def gen_pulpcore_client():
    """Return an OBJECT for pulpcore client."""
    configuration = config.get_config().get_bindings_config()
    return CoreApiClient(configuration)
Exemplo n.º 60
0
from urllib.parse import urljoin

from pulp_smash import config
from pulp_smash.pulp3.constants import (
    BASE_CONTENT_PATH,
    BASE_DISTRIBUTION_PATH,
    BASE_REPO_PATH,
    BASE_PATH,
    BASE_PUBLICATION_PATH,
    BASE_REMOTE_PATH,
)

RPM_COPY_PATH = urljoin(BASE_PATH, 'rpm/copy/')
"""The URL used for copying RPM content between repos."""

PULP_FIXTURES_BASE_URL = config.get_config().get_fixtures_url()

DOWNLOAD_POLICIES = ["immediate", "on_demand", "streamed"]

DRPM_UNSIGNED_FIXTURE_URL = urljoin(PULP_FIXTURES_BASE_URL, 'drpm-unsigned/')
"""The URL to a repository with unsigned DRPM packages."""

RPM_PACKAGE_CONTENT_NAME = 'rpm.package'

RPM_PACKAGECATEGORY_CONTENT_NAME = 'rpm.packagecategory'

RPM_PACKAGEGROUP_CONTENT_NAME = 'rpm.packagegroup'

RPM_PACKAGELANGPACKS_CONTENT_NAME = 'rpm.packagelangpacks'

RPM_ADVISORY_CONTENT_NAME = 'rpm.advisory'