def check_issue_2277(self, cfg):
        """Skip the current test method if Pulp `issue #2277`_ affects us.

        .. _issue #2277: https://pulp.plan.io/issues/2277
        """
        if cfg.version < Version('2.11') and check_issue_2277(cfg):
            self.skipTest('https://pulp.plan.io/issues/2277')
예제 #2
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)
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
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
    def check_issue_2277(self, cfg):
        """Skip the current test method if Pulp `issue #2277`_ affects us.

        .. _issue #2277: https://pulp.plan.io/issues/2277
        """
        if cfg.version < Version('2.11') and check_issue_2277(cfg):
            self.skipTest('https://pulp.plan.io/issues/2277')
예제 #6
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)
예제 #7
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
    """Possibly skip the tests in this module.

    Skip tests if `Pulp #2277 <https://pulp.plan.io/issues/2277>`_ affects us.
    """
    set_up_module()
    if check_issue_2277(config.get_config()):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
예제 #9
0
 def setUp(self):
     """Provide a server config and Pulp services to stop and start."""
     self.cfg = config.get_config()
     if check_issue_2277(self.cfg):
         self.skipTest('https://pulp.plan.io/issues/2277')
     self.broker = utils.get_broker(self.cfg)
     self.services = tuple(
         (cli.Service(self.cfg, service) for service in PULP_SERVICES))
def setUpModule():  # pylint:disable=invalid-name
    """Possibly skip the tests in this module.

    Skip tests if `Pulp #2277 <https://pulp.plan.io/issues/2277>`_ affects us.
    """
    set_up_module()
    if check_issue_2277(config.get_config()):
        raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
예제 #11
0
 def setUp(self):
     """Provide a server config and Pulp services to stop and start."""
     self.cfg = config.get_config()
     if check_issue_2277(self.cfg):
         self.skipTest('https://pulp.plan.io/issues/2277')
     if check_issue_2387(self.cfg):
         self.skipTest('https://pulp.plan.io/issues/2387')
     self.broker = utils.get_broker(self.cfg)
     self.services = tuple((
         cli.Service(self.cfg, service) for service in PULP_SERVICES
     ))
 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 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):  # 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))
예제 #15
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()
        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))
예제 #16
0
 def test_unit_integrity(self):
     """Download and verify an RPM from each Pulp distributor."""
     if check_issue_2277(self.cfg):
         self.skipTest('https://pulp.plan.io/issues/2277')
     for response in self.responses['distribute']:
         distributor = response.json()
         with self.subTest(distributor=distributor):
             url = urljoin('/pulp/repos/',
                           response.json()['config']['relative_url'])
             url = urljoin(url, RPM)
             rpm = api.Client(self.cfg).get(url).content
             self.assertEqual(rpm, self.rpm)
 def test_unit_integrity(self):
     """Download and verify an RPM from each Pulp distributor."""
     if check_issue_2277(self.cfg):
         self.skipTest('https://pulp.plan.io/issues/2277')
     for response in self.responses['distribute']:
         distributor = response.json()
         with self.subTest(distributor=distributor):
             url = urljoin(
                 '/pulp/repos/',
                 response.json()['config']['relative_url']
             )
             url = urljoin(url, RPM)
             rpm = api.Client(self.cfg).get(url).content
             self.assertEqual(rpm, self.rpm)
    def test_all(self):
        """Update an RPM in a repository and on a host."""
        cfg = config.get_config()
        if check_issue_2277(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        client = cli.Client(cfg)
        sudo = '' if is_root(cfg) else 'sudo '

        # Create the second repository.
        repo_id = self.create_repo(cfg)

        # Pick an RPM with two versions.
        rpm_name = 'walrus'
        rpm_versions = _get_rpm_names_versions(cfg, _REPO_ID)[rpm_name]

        # Copy the older RPM to the second repository, and publish it.
        self._copy_and_publish(cfg, rpm_name, rpm_versions[0], repo_id)

        # Install the RPM on a host.
        repo_path = gen_yum_config_file(
            cfg,
            baseurl=urljoin(cfg.base_url, 'pulp/repos/' + repo_id),
            enabled=1,
            gpgcheck=0,
            metadata_expire=0,  # force metadata to load every time
            repositoryid=repo_id,
            sslverify='yes' if cfg.verify else 'no',
        )
        self.addCleanup(
            client.run,
            '{}rm {}'.format(sudo, repo_path).split()
        )
        client.run('{}yum install -y {}'.format(sudo, rpm_name).split())
        self.addCleanup(
            client.run,
            '{}yum remove -y {}'.format(sudo, rpm_name).split()
        )
        client.run(['rpm', '-q', rpm_name])

        # Copy the newer RPM to the second repository, and publish it.
        self._copy_and_publish(cfg, rpm_name, rpm_versions[1], repo_id)

        # Update the installed RPM on the host.
        proc = client.run('{}yum -y update {}'.format(sudo, rpm_name).split())
        self.assertNotIn('Nothing to do.', proc.stdout)
예제 #19
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()
        if check_issue_2387(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2387')
        if check_issue_2277(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        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_SIGNED_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
        utils.publish_repo(cls.cfg, repo)
        path = urljoin(
            '/pulp/repos/',
            repo['distributors'][0]['config']['relative_url']
        )
        cls.updateinfo = get_repomd_xml(cls.cfg, path, 'updateinfo')
예제 #20
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()
        if check_issue_2277(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        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_SIGNED_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')
예제 #21
0
    def setUpClass(cls):
        """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 and run sync.
        3. Get content of both repositories.
        4. Remove random unit from repository foo and publish foo.
        5. Sync repository bar.
        6. Get content of both repositories.
        """
        super(RemoveMissingTestCase, cls).setUpClass()
        if check_issue_2277(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        cls.responses = {}
        hrefs = []  # repository hrefs

        # Create and sync a repository.
        client = api.Client(cls.cfg)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        hrefs.append(client.post(REPOSITORY_PATH, body).json()['_href'])
        cls.resources.add(hrefs[0])  # mark for deletion
        cls.responses['first sync'] = utils.sync_repo(cls.cfg, hrefs[0])

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

        # Create and sync a second repository. 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']['remove_missing'] = True  # see docstring
        body['importer_config']['ssl_validation'] = False
        hrefs.append(client.post(REPOSITORY_PATH, body).json()['_href'])
        cls.resources.add(hrefs[1])  # mark for deletion
        cls.responses['second sync'] = utils.sync_repo(cls.cfg, hrefs[1])

        # Get contents of both repositories
        for i, href in enumerate(hrefs):
            cls.responses['repo {} units, pre'.format(i)] = client.post(
                urljoin(href, 'search/units/'),
                {'criteria': {}},
            )

        # Get random unit from first repository to remove
        cls.removed_unit = random.choice([
            unit['metadata']['name']
            for unit in cls.responses['repo 0 units, pre'].json()
            if unit['unit_type_id'] == 'rpm'
        ])

        # Remove unit from first repo and publish again
        cls.responses['remove unit'] = client.post(
            urljoin(hrefs[0], 'actions/unassociate/'),
            {
                'criteria': get_unit_unassociate_criteria(cls.removed_unit),
            },
        )

        # Publish the first repo again, and sync the second repo again.
        cls.responses['second publish'] = client.post(
            urljoin(hrefs[0], 'actions/publish/'),
            {'id': cls.responses['distribute'].json()['id']},
        )
        cls.responses['third sync'] = utils.sync_repo(cls.cfg, hrefs[1])

        # Search for units in both repositories again
        for i, href in enumerate(hrefs):
            cls.responses['repo {} units, post'.format(i)] = client.post(
                urljoin(href, 'search/units/'),
                {'criteria': {}},
            )
예제 #22
0
    def setUpClass(cls):
        """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 and run sync.
        3. Get content of both repositories.
        4. Remove random unit from repository foo and publish foo.
        5. Sync repository bar.
        6. Get content of both repositories.
        """
        super(RemoveMissingTestCase, cls).setUpClass()
        if check_issue_2277(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        cls.responses = {}
        hrefs = []  # repository hrefs

        # Create and sync a repository.
        client = api.Client(cls.cfg)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        hrefs.append(client.post(REPOSITORY_PATH, body).json()['_href'])
        cls.resources.add(hrefs[0])  # mark for deletion
        cls.responses['first sync'] = utils.sync_repo(cls.cfg, hrefs[0])

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

        # Create and sync a second repository. 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']['remove_missing'] = True  # see docstring
        body['importer_config']['ssl_validation'] = False
        hrefs.append(client.post(REPOSITORY_PATH, body).json()['_href'])
        cls.resources.add(hrefs[1])  # mark for deletion
        cls.responses['second sync'] = utils.sync_repo(cls.cfg, hrefs[1])

        # Get contents of both repositories
        for i, href in enumerate(hrefs):
            cls.responses['repo {} units, pre'.format(i)] = client.post(
                urljoin(href, 'search/units/'),
                {'criteria': {}},
            )

        # Get random unit from first repository to remove
        cls.removed_unit = random.choice([
            unit['metadata']['name']
            for unit in cls.responses['repo 0 units, pre'].json()
            if unit['unit_type_id'] == 'rpm'
        ])

        # Remove unit from first repo and publish again
        cls.responses['remove unit'] = client.post(
            urljoin(hrefs[0], 'actions/unassociate/'),
            {
                'criteria': get_unit_unassociate_criteria(cls.removed_unit),
            },
        )

        # Publish the first repo again, and sync the second repo again.
        cls.responses['second publish'] = client.post(
            urljoin(hrefs[0], 'actions/publish/'),
            {'id': cls.responses['distribute'].json()['id']},
        )
        cls.responses['third sync'] = utils.sync_repo(cls.cfg, hrefs[1])

        # Search for units in both repositories again
        for i, href in enumerate(hrefs):
            cls.responses['repo {} units, post'.format(i)] = client.post(
                urljoin(href, 'search/units/'),
                {'criteria': {}},
            )
예제 #23
0
    def setUpClass(cls):
        """Create one repository with feed, unassociate unit and re-publish.

        Following steps are executed:

        1. Create repository foo with feed, sync and publish it.
        2. Get an unit X and assert it is accessible.
        3. Remove unit X from repository foo and re-publish foo.
        4. Get same unit X and assert it is not accessible.
        """
        super(RepublishTestCase, cls).setUpClass()
        if check_issue_2277(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        cls.responses = {}

        # Create and sync a repository.
        client = api.Client(cls.cfg)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_SIGNED_FEED_URL
        repo_href = client.post(REPOSITORY_PATH, body).json()['_href']
        cls.resources.add(repo_href)  # mark for deletion
        cls.responses['sync'] = utils.sync_repo(cls.cfg, repo_href)

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

        # Get contents of repository
        cls.responses['repo units'] = client.post(
            urljoin(repo_href, 'search/units/'),
            {'criteria': {}},
        )

        # Get random unit from repository to remove
        removed_unit = random.choice([
            unit['metadata']['filename']
            for unit in cls.responses['repo units'].json()
            if unit['unit_type_id'] == 'rpm'
        ])

        # Download the RPM from repository.
        url = urljoin(
            '/pulp/repos/',
            cls.responses['distribute'].json()['config']['relative_url']
        )
        url = urljoin(url, removed_unit)
        cls.responses['first get'] = client.get(url)

        # Remove unit from the repo
        cls.responses['remove unit'] = client.post(
            urljoin(repo_href, 'actions/unassociate/'),
            {
                'criteria': {
                    'fields': {
                        'unit': [
                            'arch',
                            'checksum',
                            'checksumtype',
                            'epoch',
                            'name',
                            'release',
                            'version',
                        ]
                    },
                    'type_ids': ['rpm'],
                    'filters': {
                        'unit': {'filename': removed_unit}
                    }
                }
            },
        )

        # Publish the repo again
        cls.responses['second publish'] = client.post(
            urljoin(repo_href, 'actions/publish/'),
            {'id': cls.responses['distribute'].json()['id']},
        )

        # Download the RPM from repository.
        url = urljoin(
            '/pulp/repos/',
            cls.responses['distribute'].json()['config']['relative_url']
        )
        url = urljoin(url, removed_unit)
        client.response_handler = api.echo_handler
        cls.responses['second get'] = client.get(url)