Example #1
0
    def setUpClass(cls):
        """Create an RPM repository with a valid feed and sync it.

        Do the following:

        1. Reset Pulp, including the Squid cache.
        2. Create a repository with the "on demand" download policy.
        3. Sync and publish the repository.
        4. Download an RPM from the published repository.
        5. Download the same RPM to ensure it is served by the cache.
        """
        super().setUpClass()
        if check_issue_3104(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        if not selectors.bug_is_fixed(4120, cls.cfg.pulp_version):
            raise unittest.SkipTest('https://pulp.plan.io/issues/4120')

        # Ensure `locally_stored_units` is 0 before we start.
        reset_squid(cls.cfg)
        reset_pulp(cls.cfg)

        # Create, sync and publish a repository.
        repo = _create_repo(cls.cfg, 'on_demand')
        cls.resources.add(repo['_href'])
        sync_repo(cls.cfg, repo)

        # Read the repository.
        client = api.Client(cls.cfg)
        cls.repo = client.get(repo['_href'], params={'details': True}).json()

        # Download the same RPM twice.
        cls.rpm = get_unit(cls.cfg, cls.repo['distributors'][0], RPM)
        cls.same_rpm = get_unit(cls.cfg, cls.repo['distributors'][0], RPM)
    def setUpClass(cls):
        """Create an RPM repository with a valid feed and sync it.

        Do the following:

        1. Reset Pulp, including the Squid cache.
        2. Create a repository with the "background" download policy.
        3. Sync and publish the repository.
        4. Download an RPM from the repository.
        """
        super().setUpClass()
        if check_issue_3104(cls.cfg):
            raise unittest.SkipTest('https://pulp.plan.io/issues/3104')
        if (not selectors.bug_is_fixed(1905, cls.cfg.pulp_version)
                and os_is_rhel6(cls.cfg)):
            raise unittest.SkipTest('https://pulp.plan.io/issues/1905')

        # Required to ensure content is actually downloaded.
        reset_squid(cls.cfg)
        reset_pulp(cls.cfg)

        # Create, sync and publish a repository.
        repo = _create_repo(cls.cfg, 'background')
        cls.resources.add(repo['_href'])
        report = sync_repo(cls.cfg, repo).json()

        # Record the tasks spawned when syncing the repository, and the state
        # of the repository itself after the sync.
        client = api.Client(cls.cfg)
        cls.repo = client.get(repo['_href'], params={'details': True}).json()
        cls.tasks = tuple(api.poll_spawned_tasks(cls.cfg, report))

        # Download an RPM.
        cls.rpm = get_unit(cls.cfg, cls.repo['distributors'][0], RPM)
Example #3
0
 def test_all(self):
     """Sync two repositories w/identical content but differing layouts."""
     cfg = config.get_config()
     if check_issue_3104(cfg):
         self.skipTest('https://pulp.plan.io/issues/3104')
     if check_issue_2798(cfg):
         self.skipTest('https://pulp.plan.io/issues/2798')
     if check_issue_2354(cfg):
         self.skipTest('https://pulp.plan.io/issues/2354')
     if (os_is_f26(cfg)
             and not selectors.bug_is_fixed(3036, cfg.pulp_version)):
         # Here, the calls to get_unit() cause pulp_streamer.service to die
         # without logging out anything. In Pulp #3036, certain actions
         # cause pulp_streamer.service to die while logging out a core dump.
         # Thus, this test failure might be unrelated to Pulp #3036.
         self.skipTest('https://pulp.plan.io/issues/3036')
     repos = [
         self.create_repo(cfg, feed, 'on_demand')
         for feed in (RPM_ALT_LAYOUT_FEED_URL, RPM_UNSIGNED_FEED_URL)
     ]
     for repo in repos:
         sync_repo(cfg, repo)
     for repo in repos:
         publish_repo(cfg, repo)
     rpms = []
     for repo in repos:
         with self.subTest(repo=repo):
             rpms.append(
                 get_unit(cfg, repo['distributors'][0], RPM).content)
     self.assertEqual(len(rpms), len(repos))
     self.assertEqual(rpms[0], rpms[1], repos)
Example #4
0
    def verify_repo_download(self, repo):
        """Download ``pulp_2_tests.constants.RPM` from the given ``repo``.

        Verify that it is exactly equal to the one uploaded earlier.
        """
        response = get_unit(self.cfg, repo['distributors'][0], RPM)
        with self.subTest():
            self.assertIn(response.headers['content-type'],
                          ('application/octet-stream', 'application/x-rpm'))
        with self.subTest():
            self.assertEqual(self.rpm, response.content)
Example #5
0
    def test_all(self):
        """Republish a repository after removing content."""
        cfg = config.get_config()
        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')

        # Create, sync and publish a repository.
        client = api.Client(cfg, api.json_handler)
        body = gen_repo()
        body['importer_config']['feed'] = RPM_UNSIGNED_FEED_URL
        body['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)

        # Pick a random content unit and verify it's accessible.
        unit = random.choice(search_units(cfg, repo, {'type_ids': ('rpm', )}))
        filename = unit['metadata']['filename']
        get_unit(cfg, repo['distributors'][0], filename)

        # Remove the content unit and verify it's inaccessible.
        client.post(
            urljoin(repo['_href'], 'actions/unassociate/'),
            {'criteria': {
                'filters': {
                    'unit': {
                        'filename': filename
                    }
                }
            }},
        )
        publish_repo(cfg, repo)
        with self.assertRaises(KeyError):
            get_unit(cfg, repo['distributors'][0], filename)
Example #6
0
    def assert_on_demand(self, repo):
        """Assert that on_demand download policy is properly working."""
        # Assert no content units were downloaded besides metadata.
        metadata_unit_count = sum([
            count for name, count in repo['content_unit_counts'].items()
            if name not in ('rpm', 'drpm', 'srpm')
        ])
        self.assertEqual(repo['locally_stored_units'], metadata_unit_count)

        # Assert there is at least one content unit in the repository.
        total_units = sum(repo['content_unit_counts'].values())
        self.assertEqual(repo['total_repository_units'], total_units)

        # Download the same RPM twice.
        rpm = get_unit(self.cfg, repo['distributors'][0], RPM)
        same_rpm = get_unit(self.cfg, repo['distributors'][0], RPM)

        # Assert the initial request received a 302 Redirect.
        self.assertTrue(rpm.history[0].is_redirect)

        # Assert the checksum of the downloaded RPM matches the metadata.
        actual = hashlib.sha256(rpm.content).hexdigest()
        expect = utils.get_sha256_checksum(RPM_UNSIGNED_URL)
        self.assertEqual(actual, expect)

        # Assert the first request resulted in a cache miss from Squid.
        self.assertIn('MISS', rpm.headers['X-Cache-Lookup'], rpm.headers)

        # Assert the checksum of the second RPM matches the metadata.
        actual = hashlib.sha256(same_rpm.content).hexdigest()
        expect = utils.get_sha256_checksum(RPM_UNSIGNED_URL)
        self.assertEqual(actual, expect)

        # Assert the second request resulted in a cache hit from Squid."""
        self.assertIn(
            'HIT',
            same_rpm.headers['X-Cache-Lookup'],
            same_rpm.headers,
        )
Example #7
0
 def test_all(self):
     """Execute the test case business logic."""
     cfg = config.get_config()
     if check_issue_3104(cfg):
         self.skipTest('https://pulp.plan.io/issues/3104')
     self.check_issue_2277(cfg)
     self.check_issue_2321(cfg)
     repo = self.create_repo(cfg, RPM_MIRRORLIST_MIXED, _gen_rel_url())
     sync_repo(cfg, repo)
     publish_repo(cfg, repo)
     actual_rpm = get_unit(cfg, repo['distributors'][0], RPM).content
     target_rpm = utils.http_get(RPM_UNSIGNED_URL)
     self.assertEqual(actual_rpm, target_rpm)
Example #8
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_SIGNED_FEED_URL
        body['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(self.cfg, repo)
        publish_repo(self.cfg, repo)
        pulp_rpm = get_unit(self.cfg, repo['distributors'][0], RPM).content

        # Does this RPM match the original RPM?
        rpm = utils.http_get(RPM_SIGNED_URL)
        self.assertEqual(rpm, pulp_rpm)
    def test_all(self):
        """Sync a repository, change its feed, and sync it again."""
        if check_issue_3104(self.cfg):
            self.skipTest('https://pulp.plan.io/issues/3104')

        # Create, sync and publish repositories A and B.
        repos = []
        for _ in range(2):
            body = gen_repo()
            body['importer_config']['feed'] = RPM_UNSIGNED_FEED_URL
            body['distributors'] = [gen_distributor()]
            repos.append(self.create_sync_publish_repo(body))

        # Create repository C, let it sync from repository A, and publish it.
        body = gen_repo()
        body['importer_config']['feed'] = self.get_feed(repos[0])
        body['importer_config']['ssl_validation'] = False
        body['distributors'] = [gen_distributor()]
        repo = self.create_sync_publish_repo(body)

        # Update repository C.
        client = api.Client(self.cfg, api.json_handler)
        feed = self.get_feed(repos[1])
        client.put(repo['importers'][0]['_href'],
                   {'importer_config': {
                       'feed': feed
                   }})
        repo = client.get(repo['_href'], params={'details': True})
        self.assertEqual(repo['importers'][0]['config']['feed'], feed)

        # Sync and publish repository C.
        sync_repo(self.cfg, repo)
        publish_repo(self.cfg, repo)

        rpm = utils.http_get(RPM_UNSIGNED_URL)
        response = get_unit(self.cfg, repo['distributors'][0], RPM)
        with self.subTest():
            self.assertIn(response.headers['content-type'],
                          ('application/octet-stream', 'application/x-rpm'))
        with self.subTest():
            self.assertEqual(rpm, response.content)
Example #10
0
    def _assert_background_immediate(self, repo):
        """Make assertions about background and immediate download policies."""
        # Download an RPM.
        rpm = get_unit(self.cfg, repo['distributors'][0], RPM)

        # Assert that all content is downloaded for the repository.
        self.assertEqual(
            repo['locally_stored_units'],
            sum(repo['content_unit_counts'].values()),
            repo['content_unit_counts'],
        )

        # Assert that the request was serviced directly by Pulp.
        # HTTP 302 responses should have a "Location" header.
        history_headers = [response.headers for response in rpm.history]
        self.assertEqual(0, len(rpm.history), history_headers)

        # Assert the checksum of the downloaded RPM matches the metadata.
        actual = hashlib.sha256(rpm.content).hexdigest()
        expect = utils.get_sha256_checksum(RPM_UNSIGNED_URL)
        self.assertEqual(actual, expect)