Example #1
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.cli_client = cli.Client(cls.cfg)
        cls.pkg_mgr = cli.PackageManager(cls.cfg)
        cls.api_client = api.Client(cls.cfg, api.json_handler)

        api_root = utils.get_pulp_setting(cls.cli_client,
                                          "API_ROOT").lstrip("/")

        signing_services = cls.api_client.using_handler(api.page_handler).get(
            f"{api_root}api/v3/signing-services/",
            params={"name": "sign-metadata"})
        # NOTE: This is not used by the CI, only by local tests. The CI uses a separate
        # environment for API tests and Pulp, so the API tests don't have direct access
        # to run terminal commands. And cli.Client has issues with it as well.
        #
        # In the event of issues go look at post_before_script.sh.
        if not signing_services:
            init_signed_repo_configuration()

            signing_services = cls.api_client.using_handler(
                api.page_handler).get(f"{api_root}api/v3/signing-services/",
                                      params={"name": "sign-metadata"})

        cls.metadata_signing_service = signing_services[0]
Example #2
0
    def test_all(self):
        """Test whether applying an erratum will install referenced RPMs.

        It does the following:

        1. Create, sync and publish a repository with errata and RPM packages.
           Two of these RPMs have the same name and different versions. The
           newest version is referenced by one of the errata.
        2. Install the older version of the aforementioned RPM.
        3. Apply the erratum, and verify that newer version of the RPM is
           installed.

        This test targets `Pulp Smash #760
        <https://github.com/PulpQE/pulp-smash/issues/760>`_.
        """
        cfg = config.get_config()
        repo = self._create_sync_publish_repo(cfg)
        self._create_repo_file(cfg, repo)

        # Install the older version of the RPM, and verify it's been installed.
        rpm_name = 'walrus'
        rpm_versions = get_rpm_names_versions(cfg, repo)[rpm_name]
        pkg_mgr = cli.PackageManager(cfg)
        pkg_mgr.install((rpm_name + '-' + rpm_versions[0]))
        self.addCleanup(pkg_mgr.uninstall, rpm_name)
        cli_client = cli.Client(cfg)
        rpm = cli_client.run(('rpm', '-q', rpm_name)).stdout.strip()
        self.assertTrue(rpm.startswith('-'.join((rpm_name, rpm_versions[0]))))

        # Apply erratum. Verify that the newer version of the RPM is installed.
        pkg_mgr.upgrade(self._get_upgrade_targets(cfg))
        rpm = cli_client.run(('rpm', '-q', rpm_name)).stdout.strip()
        self.assertTrue(rpm.startswith('-'.join((rpm_name, rpm_versions[1]))))
Example #3
0
 def test_all(self):
     """Package manager can consume RPM with rich/weak dependencies from Pulp."""
     cfg = config.get_config()
     if cfg.pulp_version < Version('2.17'):
         raise unittest.SkipTest('This test requires Pulp 2.17 or newer.')
     if not rpm_rich_weak_dependencies(cfg):
         raise unittest.SkipTest('This test requires RPM 4.12 or newer.')
     client = api.Client(cfg, api.json_handler)
     body = gen_repo(
         importer_config={'feed': RPM_RICH_WEAK_FEED_URL},
         distributors=[gen_distributor()]
     )
     repo = client.post(REPOSITORY_PATH, body)
     self.addCleanup(client.delete, repo['_href'])
     repo = client.get(repo['_href'], params={'details': True})
     sync_repo(cfg, repo)
     publish_repo(cfg, repo)
     repo_path = gen_yum_config_file(
         cfg,
         baseurl=urljoin(cfg.get_base_url(), urljoin(
             'pulp/repos/',
             repo['distributors'][0]['config']['relative_url']
         )),
         name=repo['_href'],
         repositoryid=repo['id']
     )
     cli_client = cli.Client(cfg)
     self.addCleanup(cli_client.run, ('rm', repo_path), sudo=True)
     rpm_name = 'Cobbler'
     pkg_mgr = cli.PackageManager(cfg)
     pkg_mgr.install(rpm_name)
     self.addCleanup(pkg_mgr.uninstall, rpm_name)
     rpm = cli_client.run(('rpm', '-q', rpm_name)).stdout.strip().split('-')
     self.assertEqual(rpm_name, rpm[0])
Example #4
0
 def setUpClass(cls):
     """Verify whether dnf or yum are present."""
     cls.cfg = config.get_config()
     cls.pkg_mgr = cli.PackageManager(cls.cfg)
     cls.pkg_mgr.raise_if_unsupported(
         unittest.SkipTest,
         'This test requires dnf or yum.'
     )
Example #5
0
 def test_package_manager_name(self):
     """Test the property `name` returns the proper Package Manager."""
     for name in ('yum', 'dnf'):
         pkr_mgr = cli.PackageManager(self.cfg)
         with mock.patch.object(pkr_mgr, '_get_package_manager',
                                lambda *_, **__: name):
             with self.subTest(name=name):
                 # asserts .name property gets the proper value
                 self.assertEqual(pkr_mgr.name, name)
Example #6
0
 def test_raise_no_known_package_manager(self, ):
     """Test if invalid package manager throws exception."""
     with mock.patch.object(cli, 'Client') as client:
         client.return_value.run.return_value.returncode = 1
         # `fpm` is a Fake Package Manager
         client.return_value.run.return_value.stdout = 'fpm'
         pkr_mgr = cli.PackageManager(self.cfg)
         with self.assertRaises(NoKnownPackageManagerError):
             self.assertIn(pkr_mgr.name, ('yum', 'dnf'))
Example #7
0
    def test_raise_if_unsupported(self, ):
        """Test if proper exception raises on raise_if_unsupported."""
        with mock.patch.object(cli, 'Client') as client:
            client.return_value.run.return_value.returncode = 1
            # `fpm` is a Fake Package Manager
            client.return_value.run.return_value.stdout = 'fpm'

            # Should not raise error without raise_if_unsupported param
            cli.PackageManager(self.cfg)

            with self.assertRaises(RuntimeError):
                cli.PackageManager(self.cfg, (RuntimeError, 'foo'))

            with self.assertRaises(RuntimeError):
                cli.PackageManager(self.cfg, [RuntimeError])

            with self.assertRaises(RuntimeError):
                pkr_mgr = cli.PackageManager(self.cfg)
                pkr_mgr.raise_if_unsupported(RuntimeError)
Example #8
0
 def test_upgrade(self):
     """Test client is called with upgrade command."""
     with mock.patch.object(cli, 'Client') as client:
         client.return_value.run.return_value.returncode = 0
         client.return_value.run.return_value.stdout = 'updated'
         pkr_mgr = cli.PackageManager(self.cfg)
         with mock.patch.object(pkr_mgr, '_get_package_manager',
                                lambda *_, **__: 'dnf'):
             response = pkr_mgr.upgrade('fake-package-42')
             self.assertEqual(response.stdout, 'updated')
             pkr_mgr._client.run.assert_called_once_with(
                 ('dnf', '-y', 'update', 'fake-package-42'), sudo=True)
Example #9
0
 def test_upgrade(self):
     """Test client is called with upgrade command."""
     with mock.patch.object(cli, "Client") as client:
         client.return_value.run.return_value.returncode = 0
         client.return_value.run.return_value.stdout = "updated"
         pkr_mgr = cli.PackageManager(self.cfg)
         with mock.patch.object(pkr_mgr, "_get_package_manager",
                                lambda *_, **__: "dnf"):
             response = pkr_mgr.upgrade("fake-package-42")
             self.assertEqual(response.stdout, "updated")
             pkr_mgr._client.run.assert_called_once_with(
                 ("dnf", "-y", "update", "fake-package-42"), sudo=True)
Example #10
0
    def test_all(self):
        """Verify whether package manager can consume content from Pulp.

        This test targets the following issue:

        `Pulp #3204 <https://pulp.plan.io/issues/3204>`_
        """
        cfg = config.get_config()
        pkg_mgr = cli.PackageManager(cfg)
        try:
            pkg_mgr.name
        except NoKnownPackageManagerError:
            raise unittest.SkipTest('This test requires dnf or yum.')
        client = api.Client(cfg, api.json_handler)
        body = gen_rpm_remote()
        remote = client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(client.delete, remote['_href'])

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

        sync(cfg, remote, repo)

        publisher = client.post(RPM_PUBLISHER_PATH, gen_rpm_publisher())
        self.addCleanup(client.delete, publisher['_href'])

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

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

        repo_path = gen_yum_config_file(cfg,
                                        baseurl=urljoin(
                                            cfg.get_content_host_base_url(),
                                            '//' + distribution['base_url']),
                                        name=repo['name'],
                                        repositoryid=repo['name'])

        cli_client = cli.Client(cfg)
        self.addCleanup(cli_client.run, ('rm', repo_path), sudo=True)
        rpm_name = 'walrus'
        pkg_mgr.install(rpm_name)
        self.addCleanup(pkg_mgr.uninstall, rpm_name)
        rpm = cli_client.run(('rpm', '-q', rpm_name)).stdout.strip().split('-')
        self.assertEqual(rpm_name, rpm[0])
Example #11
0
 def setUpClass(cls):
     """Verify whether dnf or yum are present."""
     cls.cfg = config.get_config()
     configuration = cls.cfg.get_bindings_config()
     core_client = CoreApiClient(configuration)
     cls.artifacts_api = ArtifactsApi(core_client)
     cls.client = gen_rpm_client()
     cls.repo_api = RepositoriesRpmApi(cls.client)
     cls.remote_api = RemotesRpmApi(cls.client)
     cls.publications = PublicationsRpmApi(cls.client)
     cls.distributions = DistributionsRpmApi(cls.client)
     cls.before_consumption_artifact_count = 0
     cls.pkg_mgr = cli.PackageManager(cls.cfg)
     cls.pkg_mgr.raise_if_unsupported(unittest.SkipTest,
                                      "This test requires dnf or yum.")
Example #12
0
    def test_all(self):
        """Update an RPM in a repository and on a host."""
        cfg = config.get_config()
        if check_issue_3876(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3876')
        if check_issue_3104(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        if check_issue_2277(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        if check_issue_2620(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2620')
        client = cli.Client(cfg)
        pkg_mgr = cli.PackageManager(cfg)
        sudo = () if cli.is_root(cfg) else ('sudo', )
        verify = cfg.get_hosts('api')[0].roles['api'].get('verify')

        # 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.get_base_url(), 'pulp/repos/' + repo_id),
            enabled=1,
            gpgcheck=0,
            metadata_expire=0,  # force metadata to load every time
            name=repo_id,
            repositoryid=repo_id,
            sslverify='yes' if verify else 'no',
        )
        self.addCleanup(client.run, sudo + ('rm', repo_path))
        pkg_mgr.install(rpm_name)
        self.addCleanup(pkg_mgr.uninstall, rpm_name)
        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 = pkg_mgr.upgrade(rpm_name)
        self.assertNotIn('Nothing to do.', proc.stdout)
Example #13
0
 def test_apply_erratum(self):
     """Test apply erratum is called for supported package managers."""
     with mock.patch.object(cli, 'Client') as client:
         client.return_value.run.return_value.returncode = 0
         for name in ('yum', 'dnf'):
             pkr_mgr = cli.PackageManager(self.cfg)
             with mock.patch.object(
                     pkr_mgr, '_get_package_manager',
                     lambda *_, **__: name), mock.patch.object(
                         pkr_mgr, '_client'), mock.patch.object(
                             pkr_mgr,
                             '_dnf_apply_erratum'), mock.patch.object(
                                 pkr_mgr, '_yum_apply_erratum'):
                 pkr_mgr.apply_erratum('1234:4567')
                 method = getattr(pkr_mgr,
                                  '_{0}_apply_erratum'.format(pkr_mgr.name))
                 method.assert_called_once_with('1234:4567')
Example #14
0
 def test_apply_erratum(self):
     """Test apply erratum is called for supported package managers."""
     with mock.patch.object(cli, "Client") as client:
         client.return_value.run.return_value.returncode = 0
         for name in ("yum", "dnf"):
             pkr_mgr = cli.PackageManager(self.cfg)
             with mock.patch.object(
                     pkr_mgr, "_get_package_manager",
                     lambda *_, **__: name), mock.patch.object(
                         pkr_mgr, "_client"), mock.patch.object(
                             pkr_mgr,
                             "_dnf_apply_erratum"), mock.patch.object(
                                 pkr_mgr, "_yum_apply_erratum"):
                 pkr_mgr.apply_erratum("1234:4567")
                 method = getattr(pkr_mgr,
                                  "_{0}_apply_erratum".format(pkr_mgr.name))
                 method.assert_called_once_with("1234:4567")
Example #15
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.cli_client = cli.Client(cls.cfg)
        cls.pkg_mgr = cli.PackageManager(cls.cfg)
        cls.api_client = api.Client(cls.cfg, api.json_handler)

        signing_services = cls.api_client.using_handler(api.page_handler).get(
            'pulp/api/v3/signing-services/', params={'name': 'sign-metadata'})
        if not signing_services:
            init_signed_repo_configuration()

            signing_services = cls.api_client.using_handler(
                api.page_handler).get('pulp/api/v3/signing-services/',
                                      params={'name': 'sign-metadata'})

        cls.metadata_signing_service = signing_services[0]
Example #16
0
    def test_all(self):
        """Update an RPM in a repository and on a host."""
        cfg = config.get_config()
        if check_issue_3876(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3876')
        if check_issue_3104(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        if check_issue_2277(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2277')
        if check_issue_2620(cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/2620')
        client = cli.Client(cfg)
        pkg_mgr = cli.PackageManager(cfg)

        # 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.get_base_url(),
                                            'pulp/repos/' + repo_id),
                                        name=repo_id,
                                        repositoryid=repo_id)
        self.addCleanup(client.run, ('rm', repo_path), sudo=True)
        pkg_mgr.install(rpm_name)
        self.addCleanup(pkg_mgr.uninstall, rpm_name)
        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 = pkg_mgr.upgrade(rpm_name)
        self.assertNotIn('Nothing to do.', proc.stdout)