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_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_testable(1806, cfg.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():
            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
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
예제 #3
0
    def setUpClass(cls):  # pylint:disable=arguments-differ
        """Create two repositories, first is feed of second one.

        Provides server config and set of iterable to delete. Following steps
        are executed:

        1. Create repository foo with feed, sync and publish it.
        2. Create repository bar with foo as a feed with
           ``retain_old_count=0``.
        3. Run sync of repo foo.
        4. Get information on both repositories.
        """
        super(RetainOldCountTestCase, cls).setUpClass()
        client = api.Client(cls.cfg)
        cls.responses = {}
        hrefs = []  # repository hrefs

        # Create and sync the first repository.
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        hrefs.append(client.post(REPOSITORY_PATH, body).json()['_href'])
        cls.responses['first sync'] = client.post(
            urljoin(hrefs[0], 'actions/sync/'),
            {'override_config': {}}
        )

        # Add distributor and publish
        cls.responses['distribute'] = client.post(
            urljoin(hrefs[0], 'distributors/'),
            gen_distributor(),
        )
        cls.responses['publish'] = client.post(
            urljoin(hrefs[0], 'actions/publish/'),
            {'id': cls.responses['distribute'].json()['id']},
        )

        # Create and sync the second repository. Ensure it fetches content from
        # the first, and that the `retain_old_count` option is set correctly.
        # We disable SSL validation for a practical reason: each HTTPS feed
        # must have a certificate to work, which is burdensome to do here.
        body = gen_repo()
        body['importer_config']['feed'] = urljoin(
            cls.cfg.base_url,
            _PUBLISH_DIR +
            cls.responses['distribute'].json()['config']['relative_url'],
        )
        body['importer_config']['retain_old_count'] = 0  # see docstring
        body['importer_config']['ssl_validation'] = False
        hrefs.append(client.post(REPOSITORY_PATH, body).json()['_href'])
        cls.responses['second sync'] = client.post(
            urljoin(hrefs[1], 'actions/sync/'),
            {'override_config': {}}
        )

        # Read the repositories and mark them for deletion.
        cls.repos = [client.get(href).json() for href in hrefs]
        cls.resources.update(set(hrefs))
    def setUpClass(cls):  # pylint:disable=arguments-differ
        """Create two repositories, first is feed of second one.

        Provides server config and set of iterable to delete. Following steps
        are executed:

        1. Create repository foo with feed, sync and publish it.
        2. Create repository bar with foo as a feed with
           ``retain_old_count=0``.
        3. Run sync of repo foo.
        4. Get information on both repositories.
        """
        super(RetainOldCountTestCase, cls).setUpClass()
        if check_issue_2277(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        client = api.Client(cls.cfg)
        cls.responses = {}
        hrefs = []  # repository hrefs

        # Create and sync the first repository.
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        hrefs.append(client.post(REPOSITORY_PATH, body).json()['_href'])
        cls.responses['first sync'] = utils.sync_repo(cls.cfg, hrefs[0])

        # Add distributor and publish
        cls.responses['distribute'] = client.post(
            urljoin(hrefs[0], 'distributors/'),
            gen_distributor(),
        )
        cls.responses['publish'] = client.post(
            urljoin(hrefs[0], 'actions/publish/'),
            {'id': cls.responses['distribute'].json()['id']},
        )

        # Create and sync the second repository. Ensure it fetches content from
        # the first, and that the `retain_old_count` option is set correctly.
        # We disable SSL validation for a practical reason: each HTTPS feed
        # must have a certificate to work, which is burdensome to do here.
        body = gen_repo()
        body['importer_config']['feed'] = urljoin(
            cls.cfg.base_url,
            _PUBLISH_DIR +
            cls.responses['distribute'].json()['config']['relative_url'],
        )
        body['importer_config']['retain_old_count'] = 0  # see docstring
        body['importer_config']['ssl_validation'] = False
        hrefs.append(client.post(REPOSITORY_PATH, body).json()['_href'])
        cls.responses['second sync'] = utils.sync_repo(cls.cfg, hrefs[1])

        # Read the repositories and mark them for deletion.
        cls.repos = [client.get(href).json() for href in hrefs]
        cls.resources.update(set(hrefs))
예제 #5
0
    def setUpClass(cls):
        """Creates, publishes repo and fetches repomd.xml."""
        super(RepoMDTestCase, cls).setUpClass()

        cls.tasks = {}
        cls.errata = {}

        client = api.Client(cls.cfg, api.json_handler)

        # Create a repository for use by the test.
        repo = client.post(REPOSITORY_PATH, gen_repo())
        cls.resources.add(repo['_href'])

        # add yum distributor to the repo
        distribute = client.post(
            urljoin(repo['_href'], 'distributors/'),
            gen_distributor())

        # ask for it to be published
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': distribute['id']})

        # fetch the repomd.xml
        repo_url = urljoin('/pulp/repos/',
                           distribute['config']['relative_url'])
        repomd_url = urljoin(repo_url, 'repodata/repomd.xml')

        client = api.Client(cls.cfg, xml_handler)
        cls.repomd_tree = client.get(repomd_url)
예제 #6
0
    def setUpClass(cls):
        """Publish a yum repo containing some updates."""
        super(UpdateInfoTestCase, cls).setUpClass()

        cls.tasks = {}
        cls.errata = {}

        client = api.Client(cls.cfg, api.json_handler)

        # Create a repository for use by the test.
        repo = client.post(REPOSITORY_PATH, gen_repo())
        cls.resources.add(repo['_href'])

        # add yum distributor to the repo
        distribute = client.post(urljoin(repo['_href'], 'distributors/'),
                                 gen_distributor())

        # import some errata
        cls.import_updates(client, repo)

        # ask for it to be published
        client.post(urljoin(repo['_href'], 'actions/publish/'),
                    {'id': distribute['id']})

        repo_url = urljoin('/pulp/repos/',
                           distribute['config']['relative_url'])
        cls.updateinfo_tree = cls.get_repodata_xml(repo_url, 'updateinfo')
예제 #7
0
    def health_check(self):
        """Execute step three of the test plan."""
        client = api.Client(self.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        self.addCleanup(api.Client(self.cfg).delete, repo['_href'])
        client.post(
            urljoin(repo['_href'], 'actions/sync/'),
            {'override_config': {}},
        )
        distributor = client.post(
            urljoin(repo['_href'], 'distributors/'),
            gen_distributor(),
        )
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': distributor['id']},
        )
        client.response_handler = api.safe_handler
        url = urljoin('/pulp/repos/', distributor['config']['relative_url'])
        url = urljoin(url, RPM)
        pulp_rpm = client.get(url).content

        # Does this RPM match the original RPM?
        rpm = client.get(urljoin(RPM_FEED_URL, RPM)).content
        self.assertEqual(rpm, pulp_rpm)
예제 #8
0
    def test_update_checksum_type(self):
        """Check if RPM distributor can receive null checksum_type.

        See: https://pulp.plan.io/issues/2134.
        """
        if self.cfg.version < version.Version('2.9'):
            raise unittest.SkipTest('This test requires Pulp 2.9 or above.')
        client = api.Client(self.cfg, api.json_handler)
        distributor = gen_distributor()
        body = gen_repo()
        body['distributors'] = [distributor]
        repo = client.post(REPOSITORY_PATH, body)
        self.addCleanup(client.delete, repo['_href'])
        for checksum_type in (None, 'sha256', None):
            client.put(
                repo['_href'], {
                    'distributor_configs': {
                        distributor['distributor_id']: {
                            'checksum_type': checksum_type,
                        }
                    }
                })
            repo = client.get(repo['_href'], params={'details': True})
            config = repo['distributors'][0]['config']
            self.assertEqual(config.get('checksum_type'), checksum_type)
    def setUpClass(cls):
        """Create a schedule to publish the repository.

        Do the following:

        1. Create a repository with a valid feed
        2. Sync it
        3. Schedule publish to run every 30 seconds
        """
        super(CreateSuccessTestCase, cls).setUpClass()
        client = api.Client(cls.cfg)

        # Create a repo with a valid feed and sync it
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body).json()
        cls.resources.add(repo['_href'])
        utils.sync_repo(cls.cfg, repo['_href'])

        # Schedule a publish to run every 30 seconds
        distributor = gen_distributor()
        distributor_url = urljoin(repo['_href'], 'distributors/')
        client.post(
            distributor_url,
            distributor
        )
        scheduling_url = urljoin(
            distributor_url,
            '{}/schedules/publish/'.format(distributor['distributor_id']),
        )
        cls.response = client.post(
            scheduling_url,
            {'schedule': 'PT30S'}
        )
        cls.attrs = cls.response.json()
    def setUpClass(cls):
        """Create an RPM repository, sync it, and remove some units from it.

        After creating and syncing an RPM repository, we walk through the unit
        type IDs listed in
        :data:`pulp_smash.tests.rpm.api_v2.test_unassociate.RemoveUnitsTestCase.TYPE_IDS`
        and remove on unit of each kind from the repository. We verify Pulp's
        behaviour by recording repository contents pre and post removal.
        """
        super(RemoveUnitsTestCase, cls).setUpClass()
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])
        utils.sync_repo(cls.cfg, repo['_href'])

        # Remove one unit of each type.
        cls.units_before = _search_units(cls.cfg, repo['_href'], cls.TYPE_IDS)
        cls.units_removed = []
        for type_id in cls.TYPE_IDS:
            unit = random.choice(_get_units_by_type(cls.units_before, type_id))
            cls.units_removed.append(unit)
            _remove_unit(cls.cfg, repo['_href'], unit)
        cls.units_after = _search_units(cls.cfg, repo['_href'], cls.TYPE_IDS)
예제 #11
0
    def setUpClass(cls):
        """Publish a yum repo containing some updates."""
        super(UpdateInfoTestCase, cls).setUpClass()

        cls.tasks = {}
        cls.errata = {}

        client = api.Client(cls.cfg, api.json_handler)

        # Create a repository for use by the test.
        repo = client.post(REPOSITORY_PATH, gen_repo())
        cls.resources.add(repo['_href'])

        # add yum distributor to the repo
        distribute = client.post(
            urljoin(repo['_href'], 'distributors/'),
            gen_distributor())

        # import some errata
        cls.import_updates(client, repo)

        # ask for it to be published
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': distribute['id']})

        repo_url = urljoin('/pulp/repos/',
                           distribute['config']['relative_url'])
        cls.updateinfo_tree = cls.get_repodata_xml(repo_url, 'updateinfo')
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. 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_SIGNED_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
예제 #13
0
    def setUpClass(cls):
        """Create, sync and delete an RPM repository.

        Doing this provides orphans that the remaining test methods can make
        use of. If this method fails, it's possible that other repositories
        exist with references to the same content units.
        """
        super(OrphansTestCase, cls).setUpClass()

        # Create orphans.
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        try:
            utils.sync_repo(cls.cfg, repo['_href'])
        finally:
            client.delete(repo['_href'])

        # Verify that orphans are present. Support for langpack content units
        # was added in Pulp 2.9.
        orphans = client.get(ORPHANS_PATH)
        expected_count = 39
        if cls.cfg.version >= Version('2.9'):
            expected_count += 1
        actual_count = _count_orphans(orphans)
        if expected_count != actual_count:
            # We can't use fail(), as it's an instance method.
            raise AssertionError(
                'Test case setup failed. We attempted to create {} orphans, '
                'but actually created {}. Orphans: {}'.format(
                    expected_count, actual_count, orphans))
    def make_repo(self, cfg, dist_cfg_updates):
        """Create a repository with an importer and pair of distributors.

        Create an RPM repository with:

        * A yum importer with a valid feed.
        * A yum distributor.
        * An RPM rsync distributor referencing the yum distributor.

        In addition, schedule the repository for deletion.

        :param pulp_smash.config.ServerConfig cfg: Information about the Pulp
            server being targeted.
        :param dist_cfg_updates: A dict to be merged into the RPM rsync
            distributor's ``distributor_config`` dict. At a minimum, this
            argument should have a value of ``{'remote': {…}}``.
        :returns: The repository's href, as a string.
        """
        api_client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        body['distributors'] = [gen_distributor()]
        body['distributors'].append({
            'distributor_id': utils.uuid4(),
            'distributor_type_id': 'rpm_rsync_distributor',
            'distributor_config': {
                'predistributor_id': body['distributors'][0]['distributor_id'],
            }
        })
        body['distributors'][1]['distributor_config'].update(dist_cfg_updates)
        repo_href = api_client.post(REPOSITORY_PATH, body)['_href']
        self.addCleanup(api_client.delete, repo_href)
        return repo_href
    def setUpClass(cls):
        """Create a schedule to publish the repository.

        Do the following:

        1. Create a repository with a valid feed
        2. Sync it
        3. Schedule publish to run every 30 seconds
        """
        super(CreateSuccessTestCase, cls).setUpClass()
        client = api.Client(cls.cfg)

        # Create a repo with a valid feed and sync it
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        repo = client.post(REPOSITORY_PATH, body).json()
        cls.resources.add(repo['_href'])
        utils.sync_repo(cls.cfg, repo['_href'])

        # Schedule a publish to run every 30 seconds
        distributor = gen_distributor()
        distributor_url = urljoin(repo['_href'], 'distributors/')
        client.post(distributor_url, distributor)
        scheduling_url = urljoin(
            distributor_url,
            '{}/schedules/publish/'.format(distributor['distributor_id']),
        )
        cls.response = client.post(scheduling_url, {'schedule': 'PT30S'})
        cls.attrs = cls.response.json()
예제 #16
0
    def setUpClass(cls):
        """Bind a consumer to a distributor.

        Do the following:

        1. Add a consumer.
        2. Add a repository.
        3. Add a distributor to the repository.
        4. Bind the consumer to the distributor.
        """
        super(BindConsumerTestCase, cls).setUpClass()

        # Steps 1–3
        client = api.Client(cls.cfg, api.json_handler)
        cls.consumer = client.post(CONSUMER_PATH, {'id': utils.uuid4()})
        repository = client.post(REPOSITORY_PATH, gen_repo())
        distributor = client.post(
            urljoin(repository['_href'], 'distributors/'),
            gen_distributor()
        )
        cls.resources.add(repository['_href'])

        # Step 4
        client.response_handler = api.safe_handler
        path = urljoin(CONSUMER_PATH, cls.consumer['consumer']['id'] + '/')
        path = urljoin(path, 'bindings/')
        cls.request = {
            'binding_config': {'B': 21},
            'distributor_id': distributor['id'],
            'notify_agent': False,
            'repo_id': distributor['repo_id'],
        }
        cls.response = client.post(path, cls.request)
예제 #17
0
    def setUpClass(cls):
        """Upload an erratum to a repo, publish, and download the erratum.

        Do the following:

        1. Create an RPM repository with a distributor.
        2. Upload an erratum to the repository.
        3. Publish the repository.
        4. Fetch the repository's ``updateinfo.xml`` file.
        """
        super(UploadErratumTestCase, cls).setUpClass()
        cls.erratum = gen_erratum()

        # Create an RPM repository with a feed and distributor.
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])

        # Sync content into the repository, and give it an erratum.
        utils.sync_repo(cls.cfg, repo['_href'])
        utils.upload_import_erratum(cls.cfg, cls.erratum, repo['_href'])
        repo = client.get(repo['_href'], params={'details': True})

        # Publish the repository, and fetch and parse updateinfo.xml
        distributor = repo['distributors'][0]
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': distributor['id']},
        )
        path = urljoin('/pulp/repos/', distributor['config']['relative_url'])
        cls.updateinfo = get_repomd_xml(cls.cfg, path, 'updateinfo')
예제 #18
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 make_repo(self, cfg, remote):
        """Create a repository with an importer and pair of distributors.

        Create an RPM repository with:

        * A yum importer with a valid feed.
        * A yum distributor.
        * An RPM rsync distributor referencing the yum distributor.

        In addition, schedule the repository for deletion.

        :param pulp_smash.config.ServerConfig cfg: Information about the Pulp
            server being targeted.
        :param remote: A dict for the RPM rsync distributor's ``remote``
            section.
        :returns: The repository's href, as a string.
        """
        api_client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        body['distributors'] = [gen_distributor()]
        body['distributors'].append({
            'distributor_id': utils.uuid4(),
            'distributor_type_id': 'rpm_rsync_distributor',
            'distributor_config': {
                'predistributor_id': body['distributors'][0]['distributor_id'],
                'remote': remote,
            }
        })
        repo_href = api_client.post(REPOSITORY_PATH, body)['_href']
        self.addCleanup(api_client.delete, repo_href)
        return repo_href
예제 #20
0
    def setUpClass(cls):
        """Create an RPM repository, sync it, and remove some units from it.

        After creating and syncing an RPM repository, we walk through the unit
        type IDs listed in
        :data:`pulp_smash.tests.rpm.api_v2.test_unassociate.RemoveAssociatedUnits.TYPE_IDS`
        and remove on unit of each kind from the repository. We verify Pulp's
        behaviour by recording repository contents pre and post removal.
        """
        super(RemoveAssociatedUnits, cls).setUpClass()
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])
        sync_path = urljoin(repo['_href'], 'actions/sync/')
        client.post(sync_path, {'override_config': {}})

        # List starting content
        cls.before_units = {
            type_id: _list_repo_units_of_type(client, repo['_href'], type_id)
            for type_id in cls.TYPE_IDS
        }

        # Remove one of each unit and store its id for later assertions
        cls.removed_units = {}
        for type_id, units_list in cls.before_units.items():
            cls.removed_units[type_id] = units_list[0]
            _remove_unit(client, repo['_href'], type_id, units_list[0])

        # List final content
        cls.after_units = {
            type_id: _list_repo_units_of_type(client, repo['_href'], type_id)
            for type_id in cls.TYPE_IDS
        }
예제 #21
0
    def setUpClass(cls):
        """Generate, fetch and parse a ``repomd.xml`` file.

        Do the following:

        1. Create an RPM repository, add a YUM distributor, and publish the
           repository.
        2. Fetch the ``repomd.xml`` file from the distributor, and parse it.
        """
        super(RepoMDTestCase, cls).setUpClass()

        # Create a repository. Add a yum distributor and publish it.
        client = api.Client(cls.cfg, api.json_handler)
        repo = client.post(REPOSITORY_PATH, gen_repo())
        cls.resources.add(repo['_href'])
        distributor = client.post(
            urljoin(repo['_href'], 'distributors/'),
            gen_distributor(),
        )
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': distributor['id']},
        )

        # Fetch and parse repomd.xml
        client.response_handler = xml_handler
        path = urljoin('/pulp/repos/', distributor['config']['relative_url'])
        path = urljoin(path, 'repodata/repomd.xml')
        cls.root_element = client.get(path)
예제 #22
0
    def make_repo(self, cfg, dist_cfg_updates):
        """Create a repository with an importer and pair of distributors.

        Create an RPM repository with:

        * A yum importer with a valid feed.
        * A yum distributor.
        * An RPM rsync distributor referencing the yum distributor.

        In addition, schedule the repository for deletion.

        :param pulp_smash.config.ServerConfig cfg: Information about the Pulp
            server being targeted.
        :param dist_cfg_updates: A dict to be merged into the RPM rsync
            distributor's ``distributor_config`` dict. At a minimum, this
            argument should have a value of ``{'remote': {…}}``.
        :returns: A detailed dict of information about the repo.
        """
        api_client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        body['distributors'] = [gen_distributor()]
        body['distributors'].append({
            'distributor_id': utils.uuid4(),
            'distributor_type_id': 'rpm_rsync_distributor',
            'distributor_config': {
                'predistributor_id': body['distributors'][0]['distributor_id'],
            }
        })
        body['distributors'][1]['distributor_config'].update(dist_cfg_updates)
        repo = api_client.post(REPOSITORY_PATH, body)
        self.addCleanup(api_client.delete, repo['_href'])
        return api_client.get(repo['_href'], params={'details': True})
    def setUpClass(cls):
        """Create an RPM repository, upload package groups, and publish."""
        super(UploadPackageGroupsTestCase, cls).setUpClass()

        # Create a repository and add a distributor to it.
        client = api.Client(cls.cfg, api.json_handler)
        repo = client.post(REPOSITORY_PATH, gen_repo())
        cls.resources.add(repo['_href'])
        distributor = client.post(
            urljoin(repo['_href'], 'distributors/'),
            gen_distributor(),
        )

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

        # Fetch the generated repodata of type 'group' (a.k.a. 'comps')
        cls.root_element = get_repomd_xml(
            cls.cfg,
            urljoin('/pulp/repos/', distributor['config']['relative_url']),
            'group'
        )
    def setUpClass(cls):
        """Create, sync and publish a repository. Fetch its ``comps.xml``."""
        super(SyncRepoTestCase, cls).setUpClass()
        client = api.Client(cls.cfg, api.json_handler)

        # Create a repo.
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])

        # Sync and publish the repo.
        repo = client.get(repo['_href'], params={'details': True})
        utils.sync_repo(cls.cfg, repo['_href'])
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': repo['distributors'][0]['id']},
        )
        repo = client.get(repo['_href'], params={'details': True})

        # Fetch and parse comps.xml.
        dist = repo['distributors'][0]
        dist_url = urljoin('/pulp/repos/', dist['config']['relative_url'])
        cls.root_element = get_repomd_xml(cls.cfg, dist_url, 'group')
        cls.xml_as_str = ElementTree.tostring(cls.root_element)
예제 #25
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
예제 #26
0
    def health_check(self):
        """Execute step three of the test plan."""
        client = api.Client(self.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        self.addCleanup(api.Client(self.cfg).delete, repo['_href'])
        client.post(
            urljoin(repo['_href'], 'actions/sync/'),
            {'override_config': {}},
        )
        distributor = client.post(
            urljoin(repo['_href'], 'distributors/'),
            gen_distributor(),
        )
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': distributor['id']},
        )
        client.response_handler = api.safe_handler
        url = urljoin('/pulp/repos/', distributor['config']['relative_url'])
        url = urljoin(url, RPM)
        pulp_rpm = client.get(url).content

        # Does this RPM match the original RPM?
        rpm = client.get(urljoin(RPM_FEED_URL, RPM)).content
        self.assertEqual(rpm, pulp_rpm)
예제 #27
0
    def setUpClass(cls):
        """Create an RPM repository, sync it, and remove some units from it.

        After creating and syncing an RPM repository, we walk through the unit
        type IDs listed in
        :data:`pulp_smash.tests.rpm.api_v2.test_unassociate.RemoveAssociatedUnits.TYPE_IDS`
        and remove on unit of each kind from the repository. We verify Pulp's
        behaviour by recording repository contents pre and post removal.
        """
        super(RemoveAssociatedUnits, cls).setUpClass()
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])
        sync_path = urljoin(repo['_href'], 'actions/sync/')
        client.post(sync_path, {'override_config': {}})

        # List starting content
        cls.before_units = {
            type_id: _list_repo_units_of_type(client, repo['_href'], type_id)
            for type_id in cls.TYPE_IDS
        }

        # Remove one of each unit and store its id for later assertions
        cls.removed_units = {}
        for type_id, units_list in cls.before_units.items():
            cls.removed_units[type_id] = units_list[0]
            _remove_unit(client, repo['_href'], type_id, units_list[0])

        # List final content
        cls.after_units = {
            type_id: _list_repo_units_of_type(client, repo['_href'], type_id)
            for type_id in cls.TYPE_IDS
        }
예제 #28
0
    def setUpClass(cls):
        """Create, sync and delete an RPM repository.

        Doing this provides orphans that the remaining test methods can make
        use of. If this method fails, it's possible that other repositories
        exist with references to the same content units.
        """
        super(OrphansTestCase, cls).setUpClass()

        # Create orphans.
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        try:
            utils.sync_repo(cls.cfg, repo['_href'])
        finally:
            client.delete(repo['_href'])

        # Verify that orphans are present. Support for langpack content units
        # was added in Pulp 2.9.
        orphans = client.get(ORPHANS_PATH)
        expected_count = 39
        if cls.cfg.version >= Version('2.9'):
            expected_count += 1
        actual_count = _count_orphans(orphans)
        if expected_count != actual_count:
            # We can't use fail(), as it's an instance method.
            raise AssertionError(
                'Test case setup failed. We attempted to create {} orphans, '
                'but actually created {}. Orphans: {}'
                .format(expected_count, actual_count, orphans)
            )
    def setUpClass(cls):
        """Create, sync and publish a repository. Fetch its ``comps.xml``."""
        super(SyncRepoTestCase, cls).setUpClass()
        client = api.Client(cls.cfg, api.json_handler)

        # Create a repo.
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])

        # Sync and publish the repo.
        repo = client.get(repo['_href'], params={'details': True})
        utils.sync_repo(cls.cfg, repo['_href'])
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': repo['distributors'][0]['id']},
        )
        repo = client.get(repo['_href'], params={'details': True})

        # Fetch and parse comps.xml.
        dist = repo['distributors'][0]
        dist_url = urljoin('/pulp/repos/', dist['config']['relative_url'])
        cls.root_element = get_repomd_xml(cls.cfg, dist_url, 'group')
        cls.xml_as_str = ElementTree.tostring(cls.root_element)
예제 #30
0
    def setUpClass(cls):
        """Create a schedule to publish a repo, verify the ``total_run_count``.

        Do the following:

        1. Create a repository with a valid feed
        2. Sync it
        3. Schedule publish to run every 2 minutes
        4. Wait for 130 seconds and read the schedule to get the number of
           "publish" runs
        """
        super(ScheduledPublishTestCase, cls).setUpClass()
        client = api.Client(cls.cfg, api.json_handler)

        # Create a repo with a valid feed and sync it
        body = gen_repo()
        body["importer_config"]["feed"] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo["_href"])
        utils.sync_repo(cls.cfg, repo["_href"])

        # Schedule a publish to run every 2 minutes
        distributor = gen_distributor()
        client.post(urljoin(repo["_href"], "distributors/"), distributor)
        scheduling_url = "/".join(["distributors", distributor["distributor_id"], "schedules/publish/"])
        schedule_path = urljoin(repo["_href"], scheduling_url)
        schedule = client.post(schedule_path, {"schedule": "PT2M"})

        # Wait for publish to run
        time.sleep(130)

        # Read the schedule
        cls.response = client.get(schedule["_href"])
    def setUpClass(cls):
        """Bind a consumer to a distributor.

        Do the following:

        1. Add a consumer.
        2. Add a repository.
        3. Add a distributor to the repository.
        4. Bind the consumer to the distributor.
        """
        super(BindConsumerTestCase, cls).setUpClass()

        # Steps 1–3
        client = api.Client(cls.cfg, api.json_handler)
        cls.consumer = client.post(CONSUMER_PATH, {'id': utils.uuid4()})
        repository = client.post(REPOSITORY_PATH, gen_repo())
        distributor = client.post(
            urljoin(repository['_href'], 'distributors/'), gen_distributor())
        cls.resources.add(repository['_href'])

        # Step 4
        client.response_handler = api.safe_handler
        path = urljoin(CONSUMER_PATH, cls.consumer['consumer']['id'] + '/')
        path = urljoin(path, 'bindings/')
        cls.request = {
            'binding_config': {
                'B': 21
            },
            'distributor_id': distributor['id'],
            'notify_agent': False,
            'repo_id': distributor['repo_id'],
        }
        cls.response = client.post(path, cls.request)
예제 #32
0
    def setUpClass(cls):
        """Create an RPM repository, sync it, and remove some units from it.

        After creating and syncing an RPM repository, we walk through the unit
        type IDs listed in
        :data:`pulp_smash.tests.rpm.api_v2.test_unassociate.RemoveUnitsTestCase.TYPE_IDS`
        and remove on unit of each kind from the repository. We verify Pulp's
        behaviour by recording repository contents pre and post removal.
        """
        super(RemoveUnitsTestCase, cls).setUpClass()
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])
        utils.sync_repo(cls.cfg, repo['_href'])

        # Remove one unit of each type.
        cls.units_before = _search_units(cls.cfg, repo['_href'], cls.TYPE_IDS)
        cls.units_removed = []
        for type_id in cls.TYPE_IDS:
            unit = random.choice(_get_units_by_type(cls.units_before, type_id))
            cls.units_removed.append(unit)
            _remove_unit(cls.cfg, repo['_href'], unit)
        cls.units_after = _search_units(cls.cfg, repo['_href'], cls.TYPE_IDS)
    def setUpClass(cls):
        """Create an RPM repository, upload package groups, and publish."""
        super(UploadPackageGroupsTestCase, cls).setUpClass()

        # Create a repository and add a distributor to it.
        client = api.Client(cls.cfg, api.json_handler)
        repo = client.post(REPOSITORY_PATH, gen_repo())
        cls.resources.add(repo['_href'])
        distributor = client.post(
            urljoin(repo['_href'], 'distributors/'),
            gen_distributor(),
        )

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

        # Fetch the generated repodata of type 'group' (a.k.a. 'comps')
        cls.root_element = get_repomd_xml(
            cls.cfg,
            urljoin('/pulp/repos/', distributor['config']['relative_url']),
            'group')
    def setUpClass(cls):
        """Create a schedule to publish a repo, verify the ``total_run_count``.

        Do the following:

        1. Create a repository with a valid feed
        2. Sync it
        3. Schedule publish to run every 2 minutes
        4. Wait for 130 seconds and read the schedule to get the number of
           "publish" runs
        """
        super(ScheduledPublishTestCase, cls).setUpClass()
        client = api.Client(cls.cfg, api.json_handler)

        # Create a repo with a valid feed and sync it
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        repo = client.post(REPOSITORY_PATH, body)
        cls.resources.add(repo['_href'])
        utils.sync_repo(cls.cfg, repo['_href'])

        # Schedule a publish to run every 2 minutes
        distributor = gen_distributor()
        client.post(urljoin(repo['_href'], 'distributors/'), distributor)
        scheduling_url = '/'.join([
            'distributors', distributor['distributor_id'], 'schedules/publish/'
        ])
        schedule_path = urljoin(repo['_href'], scheduling_url)
        schedule = client.post(schedule_path, {'schedule': 'PT2M'})

        # Wait for publish to run
        time.sleep(130)

        # Read the schedule
        cls.response = client.get(schedule['_href'])
예제 #35
0
    def setUpClass(cls):
        """Generate, fetch and parse a ``repomd.xml`` file.

        Do the following:

        1. Create an RPM repository with a YUM distributor and publish it.
        2. Fetch the ``repomd.xml`` file from the distributor, and parse it.
        """
        super(RepoMDTestCase, cls).setUpClass()
        if check_issue_2277(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')

        # Create a repository with a yum distributor and publish it.
        client = api.Client(cls.cfg, api.json_handler)
        body = gen_repo()
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        repo = client.get(repo['_href'], params={'details': True})
        cls.resources.add(repo['_href'])
        utils.publish_repo(cls.cfg, repo)

        # Fetch and parse repomd.xml
        client.response_handler = xml_handler
        path = urljoin(
            '/pulp/repos/',
            repo['distributors'][0]['config']['relative_url'],
        )
        path = urljoin(path, 'repodata/repomd.xml')
        cls.root_element = client.get(path)
예제 #36
0
    def setUpClass(cls):
        """Generate, fetch and parse a ``repomd.xml`` file.

        Do the following:

        1. Create an RPM repository, add a YUM distributor, and publish the
           repository.
        2. Fetch the ``repomd.xml`` file from the distributor, and parse it.
        """
        super(RepoMDTestCase, cls).setUpClass()
        if check_issue_2277(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')

        # Create a repository. Add a yum distributor and publish it.
        client = api.Client(cls.cfg, api.json_handler)
        repo = client.post(REPOSITORY_PATH, gen_repo())
        cls.resources.add(repo['_href'])
        distributor = client.post(
            urljoin(repo['_href'], 'distributors/'),
            gen_distributor(),
        )
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': distributor['id']},
        )

        # Fetch and parse repomd.xml
        client.response_handler = xml_handler
        path = urljoin('/pulp/repos/', distributor['config']['relative_url'])
        path = urljoin(path, 'repodata/repomd.xml')
        cls.root_element = client.get(path)
def _create_repository(cfg, importer_config):
    """Create an RPM repository with the given importer configuration.

    Return the repository's href.
    """
    body = gen_repo()
    body['importer_config'] = importer_config
    return api.Client(cfg).post(REPOSITORY_PATH, body).json()['_href']
def _create_repository(cfg, importer_config):
    """Create an RPM repository with the given importer configuration.

    Return the repository's href.
    """
    body = gen_repo()
    body['importer_config'] = importer_config
    return api.Client(cfg).post(REPOSITORY_PATH, body).json()['_href']
예제 #39
0
    def test_all(self):
        """Sync a repo whose updateinfo file has multiple pkglist sections.

        Do the following:

        1. Create and sync a repository with an importer and distributor.
           Ensure the importer's feed is set to
           :data:`pulp_smash.constants.RPM_PKGLISTS_UPDATEINFO_FEED_URL`.
        2. Publish the repository, and fetch and parse its updateinfo file.
        3. Verify the updateinfo contains the correct number of ``<pkglists>``
           sections, with the correct contents in each.
        """
        cfg = config.get_config()
        if selectors.bug_is_untestable(2227, cfg.version):
            self.skipTest('https://pulp.plan.io/issues/2277')

        # Create and sync a repository.
        client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_PKGLISTS_UPDATEINFO_FEED_URL
        body['distributors'] = [gen_distributor()]
        repo = client.post(REPOSITORY_PATH, body)
        self.addCleanup(client.delete, repo['_href'])
        utils.sync_repo(cfg, repo['_href'])

        # Publish the repository, and fetch and parse its updateinfo file.
        repo = client.get(repo['_href'], params={'details': True})
        self.assertEqual(len(repo['distributors']), 1, repo['distributors'])
        distributor = repo['distributors'][0]
        client.post(
            urljoin(repo['_href'], 'actions/publish/'),
            {'id': distributor['id']},
        )
        root_element = get_repomd_xml(
            cfg,
            urljoin('/pulp/repos/', distributor['config']['relative_url']),
            'updateinfo'
        )

        # Verify the contents of the updateinfo file.
        debug = ElementTree.tostring(root_element)
        pkglists = root_element.find('update').findall('pkglist')
        self.assertEqual(len(pkglists), 3, debug)

        collections = [pkglist.find('collection') for pkglist in pkglists]
        names = {collection.find('name').text for collection in collections}
        self.assertEqual(names, {'1', '2', '3'}, debug)

        packages = {
            collection.find('package').find('filename').text
            for collection in collections
        }
        self.assertEqual(packages, {
            'penguin-0.9.1-1.noarch.rpm',
            'shark-0.1-1.noarch.rpm',
            'walrus-5.21-1.noarch.rpm',
        }, debug)
 def setUpClass(cls):
     """Create a repository with a feed and sync it."""
     super(PackagesDirectoryTestCase, cls).setUpClass()
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body['importer_config']['feed'] = RPM_FEED_URL
     cls.repo_href = client.post(REPOSITORY_PATH, body)['_href']
     cls.resources.add(cls.repo_href)
     utils.sync_repo(cls.cfg, cls.repo_href)
    def setUpClass(cls):
        """Create several schedules.

        Each schedule is created to test a different failure scenario.
        """
        super(CreateFailureTestCase, cls).setUpClass()
        client = api.Client(cls.cfg)

        # Create a repo with a valid feed and sync it
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        repo = client.post(REPOSITORY_PATH, body).json()
        cls.resources.add(repo['_href'])
        utils.sync_repo(cls.cfg, repo['_href'])

        # Add a distibutor
        distributor = gen_distributor()
        client.post(urljoin(repo['_href'], 'distributors/'), distributor)
        client.response_handler = api.echo_handler
        cls.bodies = (
            {
                'schedule': None
            },  # 400
            {
                'unknown': 'parameter',
                'schedule': 'PT30S'
            },  # 400
            ['Incorrect data type'],  # 400
            {
                'missing_required_keys': 'schedule'
            },  # 400
            {
                'schedule': 'PT30S'
            },  # tests incorrect distributor in url, 404
            {
                'schedule': 'PT30S'
            },  # tests incorrect repo in url, 404
        )
        scheduling_url = '/'.join([
            'distributors', distributor['distributor_id'], 'schedules/publish/'
        ])
        bad_distributor_url = '/'.join(
            ['distributors',
             utils.uuid4(), 'schedules/publish/'])
        bad_repo_path = '/'.join([REPOSITORY_PATH, utils.uuid4()])
        cls.paths = (urljoin(repo['_href'], scheduling_url),
                     urljoin(repo['_href'], scheduling_url),
                     urljoin(repo['_href'], scheduling_url),
                     urljoin(repo['_href'], scheduling_url),
                     urljoin(repo['_href'], bad_distributor_url),
                     urljoin(bad_repo_path, scheduling_url))
        cls.status_codes = (400, 400, 400, 400, 404, 404)
        cls.responses = [
            client.post(path, req_body)
            for path, req_body in zip(cls.paths, cls.bodies)
        ]
 def setUpClass(cls):
     """Create an RPM repository. Upload an RPM into it twice."""
     super(DuplicateUploadsTestCase, cls).setUpClass()
     utils.reset_pulp(cls.cfg)
     unit = utils.http_get(RPM_URL)
     unit_type_id = 'rpm'
     client = api.Client(cls.cfg, api.json_handler)
     repo_href = client.post(REPOSITORY_PATH, gen_repo())['_href']
     cls.resources.add(repo_href)
     cls.upload_import_unit_args = (cls.cfg, unit, unit_type_id, repo_href)
 def setUpClass(cls):
     """Create an RPM repository. Upload an RPM into it twice."""
     super(DuplicateUploadsTestCase, cls).setUpClass()
     utils.reset_pulp(cls.cfg)
     unit = utils.http_get(RPM_SIGNED_URL)
     unit_type_id = 'rpm'
     client = api.Client(cls.cfg, api.json_handler)
     repo_href = client.post(REPOSITORY_PATH, gen_repo())['_href']
     cls.resources.add(repo_href)
     cls.upload_import_unit_args = (cls.cfg, unit, unit_type_id, repo_href)
예제 #44
0
 def setUpClass(cls):
     """Create and sync a repository."""
     if inspect.getmro(cls)[0] == BaseSearchTestCase:
         raise unittest.SkipTest('Abstract base class.')
     super(BaseSearchTestCase, cls).setUpClass()
     body = gen_repo()
     body['importer_config']['feed'] = cls.get_feed_url()
     cls.repo = api.Client(cls.cfg).post(REPOSITORY_PATH, body).json()
     cls.resources.add(cls.repo['_href'])
     utils.sync_repo(cls.cfg, cls.repo['_href'])
예제 #45
0
 def setUpClass(cls):
     """Create and sync a repository."""
     if inspect.getmro(cls)[0] == BaseSearchTestCase:
         raise unittest.SkipTest("Abstract base class.")
     super(BaseSearchTestCase, cls).setUpClass()
     body = gen_repo()
     body["importer_config"]["feed"] = cls.get_feed_url()
     cls.repo = api.Client(cls.cfg).post(REPOSITORY_PATH, body).json()
     cls.resources.add(cls.repo["_href"])
     utils.sync_repo(cls.cfg, cls.repo["_href"])
 def setUpClass(cls):
     """Create a repository with a feed and sync it."""
     super(PackagesDirectoryTestCase, cls).setUpClass()
     if check_issue_2277(cls.cfg):
         raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
     cls.repo_href = client.post(REPOSITORY_PATH, body)['_href']
     cls.resources.add(cls.repo_href)
     utils.sync_repo(cls.cfg, cls.repo_href)
예제 #47
0
 def setUpClass(cls):
     """Create an RPM repository with an invalid feed and sync it."""
     super(SyncInvalidFeedTestCase, cls).setUpClass()
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body["importer_config"]["feed"] = utils.uuid4()
     repo = client.post(REPOSITORY_PATH, body)
     client.response_handler = api.echo_handler
     cls.report = client.post(urljoin(repo["_href"], "actions/sync/"))
     cls.tasks = tuple(api.poll_spawned_tasks(cls.cfg, cls.report.json()))
     cls.resources.add(repo["_href"])
예제 #48
0
 def setUpClass(cls):
     """Create an RPM repository with a valid feed and sync it."""
     if inspect.getmro(cls)[0] == SyncRepoBaseTestCase:
         raise unittest2.SkipTest("Abstract base class.")
     super(SyncRepoBaseTestCase, cls).setUpClass()
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body["importer_config"]["feed"] = cls.get_feed_url()
     cls.repo_href = client.post(REPOSITORY_PATH, body)["_href"]
     cls.resources.add(cls.repo_href)
     cls.report = utils.sync_repo(cls.cfg, cls.repo_href)
 def setUpClass(cls):
     """Create a repository with a feed and sync it."""
     super(PackagesDirectoryTestCase, cls).setUpClass()
     if check_issue_2277(cls.cfg):
         raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
     cls.repo_href = client.post(REPOSITORY_PATH, body)['_href']
     cls.resources.add(cls.repo_href)
     utils.sync_repo(cls.cfg, cls.repo_href)
 def setUpClass(cls):
     """Create and sync a repository."""
     super(ForceFullTestCase, cls).setUpClass()
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
     body['distributors'] = [gen_distributor()]
     repo = client.post(REPOSITORY_PATH, body)
     cls.resources.add(repo['_href'])
     utils.sync_repo(cls.cfg, repo['_href'])
     cls.repo = client.get(repo['_href'], params={'details': True})
예제 #51
0
 def setUpClass(cls):
     """Create an RPM repository with an invalid feed and sync it."""
     super(SyncInvalidFeedTestCase, cls).setUpClass()
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body['importer_config']['feed'] = utils.uuid4()
     repo = client.post(REPOSITORY_PATH, body)
     client.response_handler = api.echo_handler
     cls.report = client.post(urljoin(repo['_href'], 'actions/sync/'))
     cls.tasks = tuple(api.poll_spawned_tasks(cls.cfg, cls.report.json()))
     cls.resources.add(repo['_href'])
예제 #52
0
 def setUpClass(cls):
     """Create an RPM repository with a valid feed and sync it."""
     if inspect.getmro(cls)[0] == SyncRepoBaseTestCase:
         raise unittest.SkipTest('Abstract base class.')
     super(SyncRepoBaseTestCase, cls).setUpClass()
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body['importer_config']['feed'] = cls.get_feed_url()
     cls.repo_href = client.post(REPOSITORY_PATH, body)['_href']
     cls.resources.add(cls.repo_href)
     cls.report = utils.sync_repo(cls.cfg, cls.repo_href)
예제 #53
0
 def setUpClass(cls):
     """Create and sync a repository."""
     super(ForceFullTestCase, cls).setUpClass()
     client = api.Client(cls.cfg, api.json_handler)
     body = gen_repo()
     body['importer_config']['feed'] = RPM_FEED_URL
     body['distributors'] = [gen_distributor()]
     repo = client.post(REPOSITORY_PATH, body)
     cls.resources.add(repo['_href'])
     utils.sync_repo(cls.cfg, repo['_href'])
     cls.repo = client.get(repo['_href'], params={'details': True})
예제 #54
0
    def create_repo(cls):
        """Create a semi-random RPM repository with a valid RPM feed URL.

        Add this repository's href to ``cls.resources``. Return a two-tuple of
        ``(href, importer_type_id)``. This method requires a server config,
        ``cls.cfg``, and a set, ``cls.resources``.
        """
        body = gen_repo()
        body["importer_config"]["feed"] = RPM_FEED_URL
        href = api.Client(cls.cfg).post(REPOSITORY_PATH, body).json()["_href"]
        cls.resources.add(href)
        return (href, body["importer_type_id"])
    def _create_sync_repo(self, feed_url):
        """Create a repository with the given feed and sync it.

        Return the repository's href.
        """
        self.addCleanup(self.client.delete, ORPHANS_PATH)
        body = gen_repo()
        body['importer_config']['feed'] = feed_url
        repo_href = self.client.post(REPOSITORY_PATH, body)['_href']
        self.addCleanup(self.client.delete, repo_href)
        utils.sync_repo(self.cfg, repo_href)
        return repo_href
예제 #56
0
    def create_repo(cls):
        """Create a semi-random RPM repository with a valid RPM feed URL.

        Add this repository's href to ``cls.resources``. Return a two-tuple of
        ``(href, importer_type_id)``. This method requires a server config,
        ``cls.cfg``, and a set, ``cls.resources``.
        """
        body = gen_repo()
        body['importer_config']['feed'] = RPM_FEED_URL
        href = api.Client(cls.cfg).post(REPOSITORY_PATH, body).json()['_href']
        cls.resources.add(href)
        return (href, body['importer_type_id'])
예제 #57
0
    def test_all(self):
        """Publish a repository with the repoview feature on and off."""
        cfg = config.get_config()
        if cfg.version < Version('2.9'):
            self.skipTest('https://pulp.plan.io/issues/189')

        # Create a repo, and add content
        client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['distributors'] = [gen_distributor()]
        repo_href = client.post(constants.REPOSITORY_PATH, body)['_href']
        self.addCleanup(client.delete, repo_href)
        rpm = utils.http_get(constants.RPM_UNSIGNED_URL)
        utils.upload_import_unit(cfg, rpm, 'rpm', repo_href)

        # Gather some facts about the repo distributor
        dist = client.get(urljoin(repo_href, 'distributors/'))[0]
        dist_url = urljoin('/pulp/repos/', dist['config']['relative_url'])

        # Publish the repo
        client.response_handler = api.safe_handler
        client.post(urljoin(repo_href, 'actions/publish/'), {'id': dist['id']})
        response = client.get(dist_url)
        with self.subTest(comment='first publish'):
            self.assertEqual(len(response.history), 0, response.history)

        # Publish the repo a second time
        client.post(
            urljoin(repo_href, 'actions/publish/'),
            {
                'id': dist['id'],
                'override_config': {
                    'generate_sqlite': True,
                    'repoview': True,
                }
            },
        )
        response = client.get(dist_url)
        with self.subTest(comment='second publish'):
            self.assertEqual(len(response.history), 1, response.history)
            self.assertEqual(
                response.request.url,
                urljoin(response.history[0].request.url,
                        'repoview/index.html'))

        # Publish the repo a third time
        if selectors.bug_is_untestable(2349, cfg.version):
            self.skipTest('https://pulp.plan.io/issues/2349')
        client.post(urljoin(repo_href, 'actions/publish/'), {'id': dist['id']})
        response = client.get(dist_url)
        with self.subTest(comment='third publish'):
            self.assertEqual(len(response.history), 0, response.history)
예제 #58
0
 def setUpClass(cls):
     """Create two RPM repositories, with and without feed URLs."""
     super(CreateTestCase, cls).setUpClass()
     client = api.Client(cls.cfg, api.json_handler)
     cls.bodies = tuple((gen_repo() for _ in range(2)))
     cls.bodies[1]['importer_config'] = {'feed': utils.uuid4()}
     cls.repos = [client.post(REPOSITORY_PATH, body) for body in cls.bodies]
     cls.importers_iter = [
         client.get(urljoin(repo['_href'], 'importers/'))
         for repo in cls.repos
     ]
     for repo in cls.repos:
         cls.resources.add(repo['_href'])  # mark for deletion