Example #1
0
def setUpModule():  # pylint:disable=invalid-name
    """Possibly skip tests. Create and sync an RPM repository.

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

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

    # If setUpModule() fails, tearDownModule() isn't run. In addition, we can't
    # use addCleanup(), as it's an instance method. If this set-up procedure
    # grows, consider implementing a stack of tear-down steps instead.
    try:
        client.run('pulp-admin rpm repo sync run --repo-id {}'.format(
            _REPO_ID).split())
    except subprocess.CalledProcessError:
        client.run(
            'pulp-admin rpm repo delete --repo-id {}'.format(_REPO_ID).split())
        raise
Example #2
0
    def test_sync_downloaded_content(self):
        """Create two repositories with the same feed, and sync them serially.

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

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

        # Verify the number of puppet modules in each repository.
        unit_counts = [
            get_num_units_in_repo(cfg, repo_id) for repo_id in repo_ids
        ]
        for i, unit_count in enumerate(unit_counts):
            with self.subTest(i=i):
                self.assertGreater(unit_count, 0)
        self.assertEqual(unit_counts[0], unit_counts[1])
Example #3
0
    def setUpClass(cls):
        """Create, populate and publish a repository.

        Ensure at least two versions of an RPM are present in the repository.
        """
        cls.cfg = config.get_config()
        if check_issue_3104(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        cls.repo_id = None
        cls.relative_url = utils.uuid4() + '/'
        pulp_admin_login(cls.cfg)
        client = cli.Client(cls.cfg)
        repo_id = utils.uuid4()
        client.run(('pulp-admin', 'rpm', 'repo', 'create', '--repo-id',
                    repo_id, '--feed', RPM_UNSIGNED_FEED_URL, '--relative-url',
                    cls.relative_url))
        cls.repo_id = repo_id
        del repo_id
        try:
            client.run(('pulp-admin', 'rpm', 'repo', 'sync', 'run',
                        '--repo-id', cls.repo_id))
            cls.content = client.run(('pulp-admin', 'rpm', 'repo', 'content',
                                      'rpm', '--repo-id', cls.repo_id)).stdout
        except:  # noqa:E722
            cls.tearDownClass()
            raise
Example #4
0
    def test_all(self):
        """Search contents of a richnweak repository matching package name.

        This test targets `Pulp #3929`_ and `Pulp Smash #901`_. The
        `repository content`_ documentation describes the CLI content syntax.

        .. _Pulp #3929:  https://pulp.plan.io/issues/3929
        .. _Pulp Smash #901: https://github.com/PulpQE/pulp-smash/issues/901
        .. _repository content:
            https://docs.pulpproject.org/en/latest/user-guide/admin-client/repositories.html#content-search

        Asserts the required fields are present.
        """
        cfg = config.get_config()
        if cfg.pulp_version < Version('2.17.1'):
            raise unittest.SkipTest('This test requires Pulp 2.17.1 or newer.')
        pulp_admin_login(cfg)
        api_client = api.Client(cfg, api.json_handler)
        body = gen_repo(importer_config={'feed': RPM_RICH_WEAK_FEED_URL}, )
        repo = api_client.post(REPOSITORY_PATH, body)
        self.addCleanup(api_client.delete, repo['_href'])
        sync_repo(cfg, repo)
        repo = api_client.get(repo['_href'], params={'details': True})

        result = cli.Client(cfg).run(
            'pulp-admin rpm repo content rpm --repo-id {} '
            '--match name=Cobbler'.format(repo['id']).split())
        required_fields = ('Recommends:', 'Requires:', 'Provides:')
        for field in required_fields:
            with self.subTest(field=field):
                self.assertEqual(result.stdout.count(field), 1, result)
Example #5
0
 def setUpClass(cls):
     """Create a repository."""
     cfg = config.get_config()
     pulp_admin_login(cfg)
     cls.client = cli.Client(cfg)
     cls.repo_id = utils.uuid4()
     cls.client.run(
         'pulp-admin rpm repo create --repo-id {}'
         .format(cls.repo_id).split()
     )
Example #6
0
def setUpModule():  # pylint:disable=invalid-name
    """Execute ``pulp-admin login`` and reset Pulp.

    For :class:`RemovedContentTestCase` to function correctly, we require that
    all of the content units on Pulp's filesystem belong to the repository
    created by that test case. Resetting Pulp guarantees that this is so.
    Ideally, all test cases would clean up after themselves so that no resets
    are necessary.
    """
    cfg = config.get_config()
    set_up_module()
    reset_pulp(cfg)
    pulp_admin_login(cfg)
Example #7
0
    def setUpClass(cls):
        """Provide a server config and a repository ID."""
        cls.cfg = config.get_config()

        if cls.cfg.pulp_version < version.Version('2.8'):
            raise unittest.SkipTest('These tests require Pulp 2.8 or above.')

        pulp_admin_login(cls.cfg)

        cls.repo_id = utils.uuid4()
        docker_utils.repo_create(
            cls.cfg,
            enable_v2='true',
            repo_id=cls.repo_id,
        )
        docker_utils.repo_sync(cls.cfg, repo_id=cls.repo_id)
        cls.delete_cmd = docker_utils.repo_delete(cls.cfg, cls.repo_id)
Example #8
0
 def setUpClass(cls):
     """Create and sync a repository."""
     cls.cfg = config.get_config()
     if cls.cfg.pulp_version < Version('2.9'):
         raise unittest.SkipTest('These tests require Pulp 2.9 or above.')
     pulp_admin_login(cls.cfg)
     cls.repo_id = utils.uuid4()
     cls.client = cli.Client(cls.cfg)
     cls.client.run(
         'pulp-admin rpm repo create --repo-id {} --feed {}'.format(
             cls.repo_id, RPM_SIGNED_FEED_URL).split())
     try:
         cls.client.run('pulp-admin rpm repo sync run --repo-id {}'.format(
             cls.repo_id).split())
     except subprocess.CalledProcessError:
         cls.client.run('pulp-admin rpm repo delete --repo-id {}'.format(
             cls.repo_id).split())
         raise
Example #9
0
    def setUpClass(cls):
        """Provide a server config and a repository ID."""
        cls.cfg = config.get_config()
        if cls.cfg.pulp_version < version.Version('2.8'):
            raise unittest.SkipTest('These tests require Pulp 2.8 or above.')
        if not selectors.bug_is_fixed(1710, cls.cfg.pulp_version):
            raise unittest.SkipTest('https://pulp.plan.io/issues/1710')

        pulp_admin_login(cls.cfg)

        # Create a repository and update its distributor.
        cls.repo_id = utils.uuid4()
        cls.repo_registry_id = 'test/' + utils.uuid4()
        docker_utils.repo_create(cls.cfg, repo_id=cls.repo_id)
        cls.update_response = docker_utils.repo_update(
            cls.cfg,
            repo_id=cls.repo_id,
            repo_registry_id=cls.repo_registry_id,
        )
Example #10
0
 def test_run(self):
     """Assert the function executes ``cli.Client.run``."""
     with mock.patch.object(cli, "Client") as client:
         cfg = config.PulpSmashConfig(
             pulp_auth=["admin", "admin"],
             pulp_version="1!0",
             pulp_selinux_enabled=True,
             timeout=1800,
             hosts=[
                 config.PulpHost(hostname="example.com",
                                 roles={"pulp cli": {}})
             ],
         )
         response = pulp_admin_login(cfg)
         self.assertIs(response, client.return_value.run.return_value)
Example #11
0
    def test_sync_puppet_forge(self):
        """Create a Puppet repository and trigger a sync."""
        cfg = config.get_config()
        pulp_admin_login(cfg)

        # Create a repository and schedule it for deletion.
        repo_id = utils.uuid4()
        client = cli.Client(cfg)
        cmd = (
            'pulp-admin puppet repo create --repo-id {} --feed {} --queries {}'
        ).format(repo_id, PUPPET_FEED_2, PUPPET_QUERY_2)
        client.run(cmd.split())
        cmd = 'pulp-admin puppet repo delete --repo-id {}'.format(repo_id)
        self.addCleanup(client.run, cmd.split())

        # Sync the repository.
        cmd = 'pulp-admin puppet repo sync run --repo-id {}'.format(repo_id)
        completed_proc = client.run(cmd.split())

        # Verify no errors were reported.
        phrase = 'Invalid properties:'
        for stream in ('stdout', 'stderr'):
            with self.subTest(stream=stream):
                self.assertNotIn(phrase, getattr(completed_proc, stream))
Example #12
0
 def test_run(self):
     """Assert the function executes ``cli.Client.run``."""
     with mock.patch.object(cli, 'Client') as client:
         cfg = config.PulpSmashConfig(
             pulp_auth=['admin', 'admin'],
             pulp_version='1!0',
             pulp_selinux_enabled=True,
             hosts=[
                 config.PulpHost(
                     hostname='example.com',
                     roles={'pulp cli': {}},
                 )
             ]
         )
         response = pulp_admin_login(cfg)
         self.assertIs(response, client.return_value.run.return_value)
Example #13
0
def setUpModule():  # pylint:disable=invalid-name
    """Execute ``pulp-admin login``."""
    set_up_module()
    pulp_admin_login(config.get_config())
Example #14
0
 def setUp(self):
     """Provide a server config and a repository ID."""
     self.cfg = config.get_config()
     self.repo_id = utils.uuid4()
     pulp_admin_login(self.cfg)
Example #15
0
def setUpModule():  # pylint:disable=invalid-name
    """Conditionally skip this module, and execute ``pulp-admin login``."""
    set_up_module()
    pulp_admin_login(config.get_config())
def setUpModule():  # pylint:disable=invalid-name
    """Log in."""
    set_up_module()
    pulp_admin_login(config.get_config())