Beispiel #1
0
    def test_different_repository(self):
        """Test ``base_version`` for different repositories.

        Do the following:

        1. Create a new repository A and sync it.
        2. Create a new repository B and a new version for this repository
           specify repository A version 1 as the ``base_version``.
        3. Check that repository A version 1 and repository B version 1 have
           the same content.
        """
        # create repo A
        repo = self.create_sync_repo()
        version_content = []
        version_content.append(
            sorted(
                [
                    self.remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['_href'],
            )
        )
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        # get repo A version 1 to be used as base_version
        base_version = get_versions(repo)[0]['_href']

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

        # create a version for repo B using repo A version 1 as base_version
        self.client.post(
            repo['_versions_href'],
            {'base_version': base_version}
        )
        repo = self.client.get(repo['_href'])

        # assert that base_version of repo B points to version 1 of repo A
        self.assertEqual(get_versions(repo)[0]['base_version'], base_version)

        # assert that content on version 1 of repo A is equal to content on
        # version 1 repo B
        version_content.append(
            sorted(
                [
                    self.remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['_href'],
            )
        )

        self.assertEqual(
            version_content[0],
            version_content[1],
            version_content
        )
Beispiel #2
0
 def test_filter_invalid_version(self):
     """Filter repository version by an invalid version number."""
     criteria = utils.uuid4()
     for params in (
             {'number': criteria},
             {'number__gt': criteria, 'number__lt': criteria},
             {'number__gte': criteria, 'number__lte': criteria},
             {'number__range': ','.join((criteria, criteria))}):
         with self.subTest(params=params):
             with self.assertRaises(HTTPError):
                 get_versions(self.repo, params)
Beispiel #3
0
    def test_04_add_content(self):
        """Add content to the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 3, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), 1, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 0, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT})
Beispiel #4
0
    def test_content(self):
        """Test pagination for repository versions."""
        # Add content to Pulp, create a repo, and add content to repo. We
        # sample 21 contents, because with page_size set to 10, this produces 3
        # pages, where the three three pages have unique combinations of values
        # for the "previous" and "next" links.
        populate_pulp(self.cfg, urljoin(FILE_MANY_FIXTURE_URL, 'PULP_MANIFEST'))
        sample_size = min(FILE_MANY_FIXTURE_COUNT, 21)
        contents = sample(self.client.get(FILE_CONTENT_PATH), sample_size)
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        def add_content():
            """Repeatedly pop an item from ``contents``, and add to repo."""
            while True:
                try:
                    content = contents.pop()
                    self.client.post(
                        repo['_versions_href'],
                        {'add_content_units': [content['_href']]}
                    )
                except IndexError:
                    break

        threads = tuple(Thread(target=add_content) for _ in range(8))
        for thread in threads:
            thread.start()
        for thread in threads:
            thread.join()

        # Verify pagination works for getting repo versions.
        repo = self.client.get(repo['_href'])
        repo_versions = get_versions(repo, {'page_size': 10})
        self.assertEqual(len(repo_versions), sample_size, repo_versions)
Beispiel #5
0
    def test_02_sync_content(self):
        """Sync content into the repository.

        Assert that:

        * The ``_versions_href`` API call is correct.
        * The ``_latest_version_href`` API call is correct.
        * The ``_latest_version_href + content/`` API call is correct.
        * The ``_latest_version_href + added_content/`` API call is correct.
        * The ``_latest_version_href + removed_content/`` API call is correct.
        * The ``content_summary`` attribute is correct.
        """
        body = gen_remote(urljoin(FILE_FIXTURE_URL, 'PULP_MANIFEST'))
        self.remote.update(self.client.post(FILE_REMOTE_PATH, body))
        sync(self.cfg, self.remote, self.repo)
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 1, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), FILE_FIXTURE_COUNT, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 0, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT})
Beispiel #6
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.content.update(choice(get_content(repo)))
        self.client.post(
            repo['_versions_href'],
            {'remove_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content = get_content(repo)
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)
        self.assertEqual(len(added_content), 0, added_content)

        removed_content = get_removed_content(repo)
        self.assertEqual(len(removed_content), 1, removed_content)

        content_summary = self.get_content_summary(repo)
        self.assertEqual(content_summary, {'file': FILE_FIXTURE_COUNT - 1})
Beispiel #7
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest
        ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        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'])

        # Step 1
        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo['_href'])
        for rpm_content in client.get(RPM_CONTENT_PATH)['results']:
            client.post(
                repo['_versions_href'],
                {'add_content_units': [rpm_content['_href']]}
            )
        version_hrefs = tuple(ver['_href'] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = publish(cfg, publisher, repo)

        # Step 3
        self.assertEqual(publication['repository_version'], version_hrefs[-1])

        # Step 4
        publication = publish(cfg, publisher, repo, non_latest)

        # Step 5
        self.assertEqual(publication['repository_version'], non_latest)

        # Step 6
        with self.assertRaises(HTTPError):
            body = {
                'repository': repo['_href'],
                'repository_version': non_latest
            }
            client.post(urljoin(publisher['_href'], 'publish/'), body)
Beispiel #8
0
    def get_repo_versions_attr(self, attr):
        """Get an ``attr`` about each version of ``self.repo``.

        Return as sorted list.
        """
        attributes = [version[attr] for version in get_versions(self.repo)]
        attributes.sort()
        return attributes
Beispiel #9
0
 def test_filter_valid_content(self):
     """Filter repository versions by valid content."""
     content = choice(self.contents)
     repo_versions = get_versions(self.repo, {'content': content['_href']})
     for repo_version in repo_versions:
         self.assertIn(
             self.client.get(content['_href']),
             get_content(self.repo, repo_version['_href'])
         )
Beispiel #10
0
 def get_content_summary(self, repo):
     """Get the ``content_summary`` for the given repository."""
     repo_versions = get_versions(repo)
     content_summaries = [
         repo_version['content_summary']
         for repo_version in repo_versions
         if repo_version['_href'] == repo['_latest_version_href']
     ]
     self.assertEqual(len(content_summaries), 1, content_summaries)
     return content_summaries[0]
Beispiel #11
0
    def test_base_version_other_parameters(self):
        """Test ``base_version`` can be used together with other parameters.

        ``add_content_units`` and ``remove_content_units``.
        """
        # create repo version 1
        repo = self.create_sync_repo()
        version_1_content = [
            self.remove_created_key(item)
            for item in get_content(repo)[FILE_CONTENT_NAME]
        ]
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        # create repo version 2 from version 1
        base_version = get_versions(repo)[0]['_href']
        added_content = self.remove_created_key(self.content.pop())
        removed_content = choice(version_1_content)
        self.client.post(
            repo['_versions_href'],
            {
                'base_version': base_version,
                'add_content_units': [added_content['_href']],
                'remove_content_units': [removed_content['_href']]
            }
        )
        repo = self.client.get(repo['_href'])
        version_2_content = [
            self.remove_created_key(item)
            for item in get_content(repo)[FILE_CONTENT_NAME]
        ]

        # assert that base_version of the version 2 points to version 1
        self.assertEqual(get_versions(repo)[1]['base_version'], base_version)

        # assert that the removed content is not present on repo version 2
        self.assertNotIn(removed_content, version_2_content)

        # assert that the added content is present on repo version 2
        self.assertIn(added_content, version_2_content)

        # assert that the same amount of units are present in both versions
        self.assertEqual(len(version_1_content), len(version_2_content))
Beispiel #12
0
 def test_filter_nonexistent_version(self):
     """Filter repository version by a nonexistent version number."""
     criteria = -1
     for params in (
             {'number': criteria},
             {'number__gt': criteria, 'number__lt': criteria},
             {'number__gte': criteria, 'number__lte': criteria},
             {'number__range': ','.join((str(criteria), str(criteria)))}):
         with self.subTest(params=params):
             versions = get_versions(self.repo, params)
             self.assertEqual(len(versions), 0, versions)
Beispiel #13
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest
           ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        body = gen_rpm_remote()
        remote = self.client.post(RPM_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

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

        sync(self.cfg, remote, repo)

        # Step 1
        repo = self.client.get(repo['_href'])
        for rpm_content in get_content(repo)[RPM_PACKAGE_CONTENT_NAME]:
            self.client.post(
                repo['_versions_href'],
                {'add_content_units': [rpm_content['_href']]}
            )
        version_hrefs = tuple(ver['_href'] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = publish(self.cfg, repo)

        # Step 3
        self.assertEqual(publication['repository_version'], version_hrefs[-1])

        # Step 4
        publication = publish(self.cfg, repo, non_latest)

        # Step 5
        self.assertEqual(publication['repository_version'], non_latest)

        # Step 6
        with self.assertRaises(HTTPError):
            body = {
                'repository': repo['_href'],
                'repository_version': non_latest
            }
            self.client.post(RPM_PUBLICATION_PATH, body)
Beispiel #14
0
    def test_01_create_repository(self):
        """Create a repository.

        Assert that:

        * The ``_versions_href`` API call is correct.
        * The ``_latest_version_href`` API call is correct.
        """
        self.repo.update(self.client.post(REPO_PATH, gen_repo()))

        repo_versions = get_versions(self.repo)
        self.assertEqual(len(repo_versions), 0, repo_versions)

        self.assertIsNone(self.repo['_latest_version_href'])
Beispiel #15
0
    def test_clean_orphan_content_unit(self):
        """Test whether orphan content units can be clean up.

        Do the following:

        1. Create, and sync a repo.
        2. Remove a content unit from the repo. This will create a second
           repository version, and create an orphan content unit.
        3. Assert that content unit that was removed from the repo and its
           artifact are present on disk.
        4. Delete orphans.
        5. Assert that the orphan content unit was cleaned up, and its artifact
           is not present on disk.
        """
        repo = self.api_client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.api_client.delete, repo['_href'])

        body = gen_file_remote()
        remote = self.api_client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(self.api_client.delete, remote['_href'])

        sync(self.cfg, remote, repo)
        repo = self.api_client.get(repo['_href'])
        content = choice(get_content(repo)[FILE_CONTENT_NAME])

        # Create an orphan content unit.
        self.api_client.post(
            repo['_versions_href'],
            {'remove_content_units': [content['_href']]}
        )

        # Verify that the artifact is present on disk.
        artifact_path = self.api_client.get(content['_artifact'])['file']
        cmd = ('ls', artifact_path)
        self.cli_client.run(cmd, sudo=True)

        # Delete first repo version. The previous removed content unit will be
        # an orphan.
        delete_version(repo, get_versions(repo)[0]['_href'])
        content_units = self.api_client.get(FILE_CONTENT_PATH)['results']
        self.assertIn(content, content_units)

        delete_orphans()
        content_units = self.api_client.get(FILE_CONTENT_PATH)['results']
        self.assertNotIn(content, content_units)

        # Verify that the artifact was removed from disk.
        with self.assertRaises(CalledProcessError):
            self.cli_client.run(cmd)
Beispiel #16
0
 def test_filter_valid_date(self):
     """Filter repository version by a valid date."""
     dates = self.get_repo_versions_attr('created')
     for params, num_results in (
             ({'created': dates[0]},
              1),
             ({'created__gt': dates[0], 'created__lt': dates[-1]},
              len(dates) - 2),
             ({'created__gte': dates[0], 'created__lte': dates[-1]},
              len(dates)),
             ({'created__range': ','.join((dates[0], dates[1]))},
              2)):
         with self.subTest(params=params):
             results = get_versions(self.repo, params)
             self.assertEqual(len(results), num_results, results)
Beispiel #17
0
 def test_filter_valid_version(self):
     """Filter repository version by a valid version number."""
     numbers = self.get_repo_versions_attr('number')
     for params, num_results in (
             ({'number': numbers[0]},
              1),
             ({'number__gt': numbers[0], 'number__lt': numbers[-1]},
              len(numbers) - 2),
             ({'number__gte': numbers[0], 'number__lte': numbers[-1]},
              len(numbers)),
             ({'number__range': '{},{}'.format(numbers[0], numbers[1])},
              2)):
         with self.subTest(params=params):
             results = get_versions(self.repo, params)
             self.assertEqual(len(results), num_results, results)
Beispiel #18
0
 def test_filter_valid_version(self):
     """Filter repository version by a valid version number."""
     numbers = self.get_repo_versions_attr('number')
     for params, num_results in (
             ({'number': numbers[0]},
              1),
             ({'number__gt': numbers[0], 'number__lt': numbers[-1]},
              len(numbers) - 2),
             ({'number__gte': numbers[0], 'number__lte': numbers[-1]},
              len(numbers)),
             ({'number__range': '{},{}'.format(numbers[0], numbers[1])},
              2)):
         with self.subTest(params=params):
             results = get_versions(self.repo, params)
             self.assertEqual(len(results), num_results, results)
Beispiel #19
0
 def test_filter_valid_date(self):
     """Filter repository version by a valid date."""
     dates = self.get_repo_versions_attr('_created')
     for params, num_results in (
             ({'_created': dates[0]},
              1),
             ({'_created__gt': dates[0], '_created__lt': dates[-1]},
              len(dates) - 2),
             ({'_created__gte': dates[0], '_created__lte': dates[-1]},
              len(dates)),
             ({'_created__range': ','.join((dates[0], dates[1]))},
              2)):
         with self.subTest(params=params):
             results = get_versions(self.repo, params)
             self.assertEqual(len(results), num_results, results)
Beispiel #20
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        client = api.Client(cfg, api.json_handler)

        body = gen_file_remote()
        remote = client.post(FILE_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)

        # Step 1
        repo = client.get(repo["_href"])
        for file_content in get_content(repo)[FILE_CONTENT_NAME]:
            client.post(repo["_versions_href"], {"add_content_units": [file_content["_href"]]})
        version_hrefs = tuple(ver["_href"] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = create_file_publication(cfg, repo)

        # Step 3
        self.assertEqual(publication["repository_version"], version_hrefs[-1])

        # Step 4
        publication = create_file_publication(cfg, repo, non_latest)

        # Step 5
        self.assertEqual(publication["repository_version"], non_latest)

        # Step 6
        with self.assertRaises(HTTPError):
            body = {"repository": repo["_href"], "repository_version": non_latest}
            client.post(FILE_PUBLICATION_PATH, body)
Beispiel #21
0
    def test_clean_orphan_content_unit(self):
        """Test whether orphan content units can be clean up.

        Do the following:

        1. Create, and sync a repo.
        2. Remove a content unit from the repo. This will create a second
           repository version, and create an orphan content unit.
        3. Assert that content unit that was removed from the repo and its
           artifact are present on disk.
        4. Delete orphans.
        5. Assert that the orphan content unit was cleaned up, and its artifact
           is not present on disk.
        """
        repo = self.api_client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.api_client.delete, repo['pulp_href'])

        body = gen_file_remote()
        remote = self.api_client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(self.api_client.delete, remote['pulp_href'])

        sync(self.cfg, remote, repo)
        repo = self.api_client.get(repo['pulp_href'])
        content = choice(get_content(repo)[FILE_CONTENT_NAME])

        # Create an orphan content unit.
        modify_repo(self.cfg, repo, remove_units=[content])

        # Verify that the artifact is present on disk.
        artifact_path = os.path.join(
            MEDIA_PATH,
            self.api_client.get(content['artifact'])['file'])
        cmd = ('ls', artifact_path)
        self.cli_client.run(cmd, sudo=True)

        # Delete first repo version. The previous removed content unit will be
        # an orphan.
        delete_version(repo, get_versions(repo)[1]['pulp_href'])
        content_units = self.api_client.get(FILE_CONTENT_PATH)['results']
        self.assertIn(content, content_units)

        delete_orphans()
        content_units = self.api_client.get(FILE_CONTENT_PATH)['results']
        self.assertNotIn(content, content_units)

        # Verify that the artifact was removed from disk.
        with self.assertRaises(CalledProcessError):
            self.cli_client.run(cmd)
Beispiel #22
0
    def setUp(self):
        """Create a repository and give it nine new versions."""
        self.repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, self.repo['_href'])

        # Don't upload the last content unit. The test case might upload it to
        # create a new repo version within the test.
        for content in self.content[:-1]:
            self.client.post(
                self.repo['_versions_href'],
                {'add_content_units': [content['_href']]}
            )
        self.repo = self.client.get(self.repo['_href'])
        self.repo_version_hrefs = tuple(
            version['_href'] for version in get_versions(self.repo)
        )
    def test_clear_all_units_using_base_version(self):
        """Test clear all units using base version."""
        for content in self.content:
            modify_repo(self.cfg, self.repo, add_units=[content])

        self.repo = self.client.get(self.repo["pulp_href"])
        base_version = get_versions(self.repo)[0]["pulp_href"]

        modify_repo(self.cfg,
                    self.repo,
                    base_version=base_version,
                    remove_units=["*"])
        self.repo = self.client.get(self.repo["pulp_href"])

        content_last_version = get_content(self.repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_last_version), 0, content_last_version)
Beispiel #24
0
    def setUp(self):
        """Create a repository and give it nine new versions."""
        self.repo = self.client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, self.repo['pulp_href'])

        # Don't upload the last content unit. The test case might upload it to
        # create a new repo version within the test.
        for content in self.content[:-1]:
            self.client.post(
                self.repo['pulp_href'] + "modify/",
                {'add_content_units': [content['pulp_href']]}
            )
        self.repo = self.client.get(self.repo['pulp_href'])
        self.repo_version_hrefs = tuple(
            version['pulp_href'] for version in get_versions(self.repo)
        )
Beispiel #25
0
    def test_clean_orphan_content_unit(self):
        """Test whether orphan content units can be clean up.

        Do the following:

        1. Create, and sync a repo.
        2. Remove a content unit from the repo. This will create a second
           repository version, and create an orphan content unit.
        3. Assert that content unit that was removed from the repo and its
           artifact are present on disk.
        4. Delete orphans.
        5. Assert that the orphan content unit was cleaned up, and its artifact
           is not present on disk.
        """
        repo = self.api_client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.api_client.delete, repo['_href'])
        body = gen_remote(urljoin(FILE_FIXTURE_URL, 'PULP_MANIFEST'))
        remote = self.api_client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(self.api_client.delete, remote['_href'])
        sync(self.cfg, remote, repo)
        repo = self.api_client.get(repo['_href'])
        content = choice(get_content(repo))

        # Create an orphan content unit.
        self.api_client.post(
            repo['_versions_href'],
            {'remove_content_units': [content['_href']]}
        )

        # Verify that the artifact is present on disk.
        artifact_path = self.api_client.get(content['artifact'])['file']
        cmd = self.sudo + ('ls', artifact_path)
        self.cli_client.run(cmd)

        # Delete first repo version. The previous removed content unit will be
        # an orphan.
        delete_version(repo, get_versions(repo)[0]['_href'])
        content_units = self.api_client.get(FILE_CONTENT_PATH)['results']
        self.assertIn(content, content_units)
        delete_orphans()
        content_units = self.api_client.get(FILE_CONTENT_PATH)['results']
        self.assertNotIn(content, content_units)

        # Verify that the artifact was removed from disk.
        with self.assertRaises(CalledProcessError):
            self.cli_client.run(cmd)
Beispiel #26
0
    def test_02_sync_content(self):
        """Sync content into the repository.

        Assert that:

        * The ``_versions_href`` API call is correct.
        * The ``_latest_version_href`` API call is correct.
        * The ``content_hrefs`` attribute is correct.
        * The ``content_added_hrefs`` attribute is correct.
        * The ``content_removed_hrefs`` attribute is correct.
        * The ``content_summary`` attribute is correct.
        * The ``content_added_summary`` attribute is correct.
        * The ``content_removed_summary`` attribute is correct.
        """
        body = gen_file_remote()
        self.remote.update(self.client.post(FILE_REMOTE_PATH, body))
        sync(self.cfg, self.remote, self.repo)
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 1, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        content_added = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_added), FILE_FIXTURE_COUNT)

        content_removed = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_removed), 0)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary, FILE_FIXTURE_SUMMARY)

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, FILE_FIXTURE_SUMMARY)

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {})
Beispiel #27
0
    def test_02_sync_content(self):
        """Sync content into the repository.

        Assert that:

        * The ``versions_href`` API call is correct.
        * The ``latest_version_href`` API call is correct.
        * The ``content_hrefs`` attribute is correct.
        * The ``content_added_hrefs`` attribute is correct.
        * The ``content_removed_hrefs`` attribute is correct.
        * The ``content_summary`` attribute is correct.
        * The ``content_added_summary`` attribute is correct.
        * The ``content_removed_summary`` attribute is correct.
        """
        body = gen_file_remote()
        self.remote.update(self.client.post(FILE_REMOTE_PATH, body))
        sync(self.cfg, self.remote, self.repo)
        repo = self.client.get(self.repo['pulp_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['latest_version_href'])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        content_added = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_added), FILE_FIXTURE_COUNT)

        content_removed = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_removed), 0)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary, FILE_FIXTURE_SUMMARY)

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, FILE_FIXTURE_SUMMARY)

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {})
Beispiel #28
0
 def test_clear_all_units_using_base_version(self):
     """Test clear all units using base version."""
     for content in self.content:
         self.client.post(self.repo['versions_href'],
                          {'add_content_units': [content['pulp_href']]})
     self.repo = self.client.get(self.repo['pulp_href'])
     base_version = get_versions(self.repo)[0]['pulp_href']
     self.client.post(
         self.repo['versions_href'],
         {
             'base_version': base_version,
             'remove_content_units': ['*']
         },
     )
     self.repo = self.client.get(self.repo['pulp_href'])
     content_last_version = get_content(self.repo)[FILE_CONTENT_NAME]
     self.assertEqual(len(content_last_version), 0, content_last_version)
Beispiel #29
0
 def test_filter_nonexistent_version(self):
     """Filter repository version by a nonexistent version number."""
     criteria = -1
     for params in ({
             'number': criteria
     }, {
             'number__gt': criteria,
             'number__lt': criteria
     }, {
             'number__gte': criteria,
             'number__lte': criteria
     }, {
             'number__range':
             ','.join((str(criteria), str(criteria)))
     }):
         with self.subTest(params=params):
             versions = get_versions(self.repo, params)
             self.assertEqual(len(versions), 0, versions)
Beispiel #30
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        # Step 1
        for file_content in get_content(
                self.repo.to_dict())[FILE_CONTENT_NAME]:
            modify_repo(self.cfg,
                        self.repo.to_dict(),
                        remove_units=[file_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(self.repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=self.repo.pulp_href)
        publication = self.create_publication(publish_data)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publication = self.create_publication(publish_data)

        # Step 5
        self.assertEqual(publication.repository_version, non_latest)

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": self.repo.pulp_href,
                "repository_version": non_latest
            }
            self.publications.create(body)
Beispiel #31
0
    def test_clean_specific_orphans(self):
        """Test whether the `content_hrefs` param removes specific orphans but not others"""
        repo_api = RepositoriesFileApi(self.api_client)
        remote_api = RemotesFileApi(self.api_client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)

        # Create two orphaned content units.
        content_a = get_content(
            repo.to_dict())[FILE_CONTENT_NAME][0]["pulp_href"]
        content_b = get_content(
            repo.to_dict())[FILE_CONTENT_NAME][1]["pulp_href"]
        content_to_remove = dict(remove_content_units=[content_a, content_b])
        repo_api.modify(repo.pulp_href, content_to_remove)

        file_contents_api = ContentFilesApi(self.api_client)
        # Delete first repo version. The previous removed content unit will be an orphan.
        delete_version(repo, get_versions(repo.to_dict())[1]["pulp_href"])
        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertIn(content_a, content_units_href)
        self.assertIn(content_b, content_units_href)

        content_hrefs_dict = {"content_hrefs": [content_a]}
        orphans_response = self.orphans_cleanup_api.cleanup(content_hrefs_dict)
        monitor_task(orphans_response.task)

        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertNotIn(content_a, content_units_href)
        self.assertIn(content_b, content_units_href)
Beispiel #32
0
    def test_file_content(self):
        """Test pagination for repository versions."""
        # Add content to Pulp, create a repo, and add content to repo. We
        # sample 21 contents, because with page_size set to 10, this produces 3
        # pages, where the three three pages have unique combinations of values
        # for the "previous" and "next" links.
        populate_pulp(self.cfg, url=FILE_MANY_FIXTURE_MANIFEST_URL)
        sample_size = min(FILE_MANY_FIXTURE_COUNT, 21)
        contents = sample(self.client.get(FILE_CONTENT_PATH), sample_size)
        repo = self.client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo["pulp_href"])

        for content in contents:
            modify_repo(self.cfg, repo, add_units=[content])

        # Verify pagination works for getting repo versions.
        repo = self.client.get(repo["pulp_href"])
        repo_versions = get_versions(repo, {"page_size": 10})
        self.assertEqual(len(repo_versions), sample_size + 1, repo_versions)
Beispiel #33
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.content.update(choice(get_content(repo)[FILE_CONTENT_NAME]))
        self.client.post(
            repo['_versions_href'],
            {'remove_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content_hrefs = get_content(repo)['pulp_file.file']
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT - 1, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [self.content], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(
            content_summary, {FILE_CONTENT_NAME: FILE_FIXTURE_COUNT - 1}
        )

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {FILE_CONTENT_NAME: 1})
Beispiel #34
0
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.content.update(choice(get_content(repo)[FILE_CONTENT_NAME]))
        self.client.post(
            repo['_versions_href'],
            {'remove_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 2, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT - 1, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [self.content], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(
            content_summary, {FILE_CONTENT_NAME: FILE_FIXTURE_COUNT - 1}
        )

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {FILE_CONTENT_NAME: 1})
Beispiel #35
0
    def test_04_add_content(self):
        """Add content to the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo['_href'])
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [self.content['_href']]}
        )
        repo = self.client.get(self.repo['_href'])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 3, repo_versions)

        self.assertIsNotNone(repo['_latest_version_href'])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(
            len(content_hrefs), FILE_FIXTURE_COUNT, content_hrefs
        )

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [self.content], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary, FILE_FIXTURE_SUMMARY)

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {FILE_CONTENT_NAME: 1})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {})
Beispiel #36
0
    def test_content(self):
        """Test pagination for repository versions."""
        # Add content to Pulp, create a repo, and add content to repo. We
        # sample 21 contents, because with page_size set to 10, this produces 3
        # pages, where the three three pages have unique combinations of values
        # for the "previous" and "next" links.
        populate_pulp(self.cfg, url=FILE_MANY_FIXTURE_MANIFEST_URL)
        sample_size = min(FILE_MANY_FIXTURE_COUNT, 21)
        contents = sample(self.client.get(FILE_CONTENT_PATH), sample_size)
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])

        for content in contents:
            self.client.post(
                repo['_versions_href'],
                {'add_content_units': [content['_href']]}
            )

        # Verify pagination works for getting repo versions.
        repo = self.client.get(repo['_href'])
        repo_versions = get_versions(repo, {'page_size': 10})
        self.assertEqual(len(repo_versions), sample_size, repo_versions)
    def test_03_remove_content(self):
        """Remove content from the repository.

        Make roughly the same assertions as :meth:`test_02_sync_content`.
        """
        repo = self.client.get(self.repo["pulp_href"])
        self.content.update(choice(get_content(repo)[FILE_CONTENT_NAME]))

        modify_repo(self.cfg, self.repo, remove_units=[self.content])
        repo = self.client.get(self.repo["pulp_href"])

        repo_versions = get_versions(repo)
        self.assertEqual(len(repo_versions), 3, repo_versions)

        self.assertIsNotNone(repo["latest_version_href"])

        content_hrefs = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content_hrefs), FILE_FIXTURE_COUNT - 1,
                         content_hrefs)

        content = get_content(repo)[FILE_CONTENT_NAME]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT - 1)

        added_content = get_added_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(added_content, [], added_content)

        removed_content = get_removed_content(repo)[FILE_CONTENT_NAME]
        self.assertListEqual(removed_content, [self.content], removed_content)

        content_summary = get_content_summary(repo)
        self.assertDictEqual(content_summary,
                             {FILE_CONTENT_NAME: FILE_FIXTURE_COUNT - 1})

        content_added_summary = get_added_content_summary(repo)
        self.assertDictEqual(content_added_summary, {})

        content_removed_summary = get_removed_content_summary(repo)
        self.assertDictEqual(content_removed_summary, {FILE_CONTENT_NAME: 1})
Beispiel #38
0
    def test_repair_repository_version_with_checksums(self):
        """Test whether corrupted files can be redownloaded.

        Do the following:

        3. Repair the RepositoryVersion.
        4. Assert that the repair task reported two corrupted and two repaired units.
        5. Repeat the RepositoryVersion repair operation.
        6. Assert that the repair task reported no missing, corrupted or repaired units.
        """
        # STEP 3
        latest_version = get_versions(self.repo)[-1]["pulp_href"]
        result = self.api_client.post(latest_version + "repair/",
                                      {"verify_checksums": True})

        # STEP 4
        self._verify_repair_results(result, missing=1, corrupted=1, repaired=2)

        # STEP 5
        result = self.api_client.post(latest_version + "repair/",
                                      {"verify_checksums": True})

        # STEP 6
        self._verify_repair_results(result)
Beispiel #39
0
    def do_publish(self, expected_values, modus):
        """Publish particular repository in flat format.

        1. Create a repository in flat repo format.
        2. Create a publication.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Assert that Release file path is equal to desired file path.
        5. Assert that the codename, suite and component are as expected.
        """
        # Create a repository:
        repo = deb_repository_api.create(gen_repo())
        self.addCleanup(deb_repository_api.delete, repo.pulp_href)

        # Create a remote:
        body = gen_deb_remote(  # DEB_FLAT_REPO_FIXTURE_URL
            url=DEB_FLAT_REPO_FIXTURE_URL,
            distributions=expected_values["distribution"])
        remote = deb_remote_api.create(body)
        self.addCleanup(deb_remote_api.delete, remote.pulp_href)

        # Sync the repository:
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = deb_repository_api.sync(repo.pulp_href,
                                                repository_sync_data)
        monitor_task(sync_response.task)
        repo = deb_repository_api.read(repo.pulp_href)
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))

        self.assertIsNotNone(repo.latest_version_href)

        # Create a publication:
        if modus == "verbatim":
            publication_api = deb_verbatim_publication_api
            Publication = DebVerbatimPublication
        else:
            publication_api = deb_apt_publication_api
            Publication = DebAptPublication

        publish_data = Publication(repository=repo.pulp_href,
                                   **self._publication_extra_args(modus))
        publish_response = publication_api.create(publish_data)
        publication_href = monitor_task(
            publish_response.task).created_resources[0]
        self.addCleanup(publication_api.delete, publication_href)
        publication = publication_api.read(publication_href)

        # Test the publication:
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        release_file = get_content(repo=publication.to_dict(),
                                   version_href=publication.repository_version
                                   )[DEB_RELEASE_FILE_NAME][0]

        release_file_path = os.path.join(
            expected_values["release_file_folder_sync"], "Release")
        self.assertEqual(release_file_path, release_file["relative_path"])
        self.assertEqual(expected_values["distribution"],
                         release_file["distribution"])
        self.assertEqual(expected_values["codename"], release_file["codename"])
        self.assertEqual(expected_values["suite"], release_file["suite"])

        release = get_content(
            repo=publication.to_dict(),
            version_href=publication.repository_version)[DEB_RELEASE_NAME][0]

        self.assertEqual(expected_values["distribution"],
                         release["distribution"])
        self.assertEqual(expected_values["codename"], release["codename"])
        self.assertEqual(expected_values["suite"], release["suite"])

        components = get_content(repo=publication.to_dict(),
                                 version_href=publication.repository_version
                                 )[DEB_RELEASE_COMPONENT_NAME]

        self.assertEqual(len(expected_values["components"]), len(components))
        for component in components:
            self.assertIn(component["component"],
                          expected_values["components"])

        package_indecies = get_content(
            repo=publication.to_dict(),
            version_href=publication.repository_version
        )[DEB_PACKAGE_INDEX_NAME]

        self.assertEqual(len(expected_values["package_index_paths_sync"]),
                         len(package_indecies))
        for package_index in package_indecies:
            self.assertIn(package_index["relative_path"],
                          expected_values["package_index_paths_sync"])

        # Create a distribution:
        body = gen_distribution()
        body["publication"] = publication_href
        distribution_response = deb_distribution_api.create(body)
        distribution_href = monitor_task(
            distribution_response.task).created_resources[0]
        distribution = deb_distribution_api.read(distribution_href)
        self.addCleanup(deb_distribution_api.delete, distribution.pulp_href)

        # Check that the expected Release files and package indecies are there:
        cfg = config.get_config()
        release_file_path = os.path.join(
            expected_values["release_file_folder_dist"], "Release")
        download_content_unit(cfg, distribution.to_dict(), release_file_path)
        for package_index_path in expected_values["package_index_paths_dist"]:
            download_content_unit(cfg, distribution.to_dict(),
                                  package_index_path)
Beispiel #40
0
 def test_deleted_version_filter(self):
     """Delete a repository version and filter by its number."""
     numbers = self.get_repo_versions_attr('number')
     delete_version(self.repo)
     versions = get_versions(self.repo, {'number': numbers[-1]})
     self.assertEqual(len(versions), 0, versions)
Beispiel #41
0
    def test_publish(self):
        """Publish particular empty repository with no packages.

        1. Create a repository with given distribtuions.
        2. Create a publication.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Assert that Package Index File is not empty.
        5. Assert that there are no packages.
        """
        # Create a repository:
        repo = deb_repository_api.create(gen_repo())
        self.addCleanup(deb_repository_api.delete, repo.pulp_href)

        # Create a remote:
        body = gen_deb_remote(url=DEB_FIXTURE_URL, distributions="ginnungagap")
        remote = deb_remote_api.create(body)
        self.addCleanup(deb_remote_api.delete, remote.pulp_href)

        # Sync the repository:
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = deb_repository_api.sync(repo.pulp_href,
                                                repository_sync_data)
        monitor_task(sync_response.task)
        repo = deb_repository_api.read(repo.pulp_href)
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))

        self.assertIsNotNone(repo.latest_version_href)

        # Create a publication:
        publish_data = DebAptPublication(repository=repo.pulp_href,
                                         **self._publication_extra_args())
        publish_response = deb_apt_publication_api.create(publish_data)
        publication_href = monitor_task(
            publish_response.task).created_resources[0]
        self.addCleanup(deb_apt_publication_api.delete, publication_href)
        publication = deb_apt_publication_api.read(publication_href)

        # Test the publication:
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        release = get_content(repo=publication.to_dict(),
                              version_href=publication.repository_version)

        package_index_paths = [
            "dists/ginnungagap/asgard/binary-ppc64/Packages",
            "dists/ginnungagap/jotunheimr/binary-armeb/Packages",
            "dists/ginnungagap/asgard/binary-armeb/Packages",
            "dists/ginnungagap/jotunheimr/binary-ppc64/Packages",
            "dists/default/all/binary-all/Packages",
        ]

        self.assertFalse(release[DEB_PACKAGE_NAME])
        self.assertTrue(release[DEB_PACKAGE_INDEX_NAME])
        self.assertEqual(
            len(package_index_paths) - 1, len(release[DEB_PACKAGE_INDEX_NAME]))

        # Create a distribution:
        body = gen_distribution()
        body["publication"] = publication_href
        distribution_response = deb_distribution_api.create(body)
        distribution_href = monitor_task(
            distribution_response.task).created_resources[0]
        distribution = deb_distribution_api.read(distribution_href)
        self.addCleanup(deb_distribution_api.delete, distribution.pulp_href)

        # Check that the expected package indecies are there:
        cfg = config.get_config()
        for package_index_path in package_index_paths:
            download_content_unit(cfg, distribution.to_dict(),
                                  package_index_path)
Beispiel #42
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        repo_api = deb_repository_api
        remote_api = deb_remote_api
        publication_api = self.Meta.publication_api

        body = gen_deb_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # Step 1
        repo = repo_api.read(repo.pulp_href)
        for deb_generic_content in get_content(
                repo.to_dict())[DEB_GENERIC_CONTENT_NAME]:
            modify_repo(cfg,
                        repo.to_dict(),
                        remove_units=[deb_generic_content])
        for deb_package in get_content(repo.to_dict())[DEB_PACKAGE_NAME]:
            modify_repo(cfg, repo.to_dict(), remove_units=[deb_package])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = self.Meta.Publication(repository=repo.pulp_href,
                                             **self._publication_extra_args())
        publish_response = publication_api.create(publish_data)
        publication_href = monitor_task(
            publish_response.task).created_resources[0]
        self.addCleanup(publication_api.delete, publication_href)
        publication = publication_api.read(publication_href)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data = self.Meta.Publication(repository_version=non_latest,
                                             **self._publication_extra_args())
        publish_response = publication_api.create(publish_data)
        publication_href = monitor_task(
            publish_response.task).created_resources[0]
        publication = publication_api.read(publication_href)

        # Step 5
        self.assertEqual(publication.repository_version, non_latest)

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": repo.pulp_href,
                "repository_version": non_latest
            }
            publication_api.create(body)
Beispiel #43
0
    def test_same_repository(self):
        """Test ``base_version`` for the same repository.

        Do the following:

        1. Create a repository.
        2. Sync the repository (this creates repository version 1).
        3. Add a new content unit a new repository version (this create
           repository version 2).
        4. Create a new repository version using version 1 as ``base_version``
           (this creates version 3).
        5. Check that version 1 and version 3 have the same content.
        """
        # create repo version 1
        repo = self.create_sync_repo()
        version_content = []
        version_content.append(
            sorted(
                [
                    self.remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['_href'],
            )
        )
        self.assertIsNone(get_versions(repo)[0]['base_version'])

        content = self.content.pop()

        # create repo version 2
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [content['_href']]}
        )
        repo = self.client.get(repo['_href'])

        # create repo version 3 from version 1
        base_version = get_versions(repo)[0]['_href']
        self.client.post(
            repo['_versions_href'],
            {'base_version': base_version}
        )
        repo = self.client.get(repo['_href'])

        # assert that base_version of the version 3 points to version 1
        self.assertEqual(get_versions(repo)[2]['base_version'], base_version)

        # assert that content on version 1 is equal to content on version 3
        version_content.append(
            sorted(
                [
                    self.remove_created_key(item)
                    for item in get_content(repo)[FILE_CONTENT_NAME]
                ],
                key=lambda item: item['_href'],
            )
        )
        self.assertEqual(
            version_content[0],
            version_content[1],
            version_content
        )
 def test_filter_invalid_content(self):
     """Filter repository version by invalid content."""
     with self.assertRaises(HTTPError):
         get_versions(self.repo, {"content": utils.uuid4()})
Beispiel #45
0
 def test_filter_invalid_content(self):
     """Filter repository version by invalid content."""
     with self.assertRaises(HTTPError):
         get_versions(self.repo, {'content': utils.uuid4()})
Beispiel #46
0
    def test_clean_orphan_content_unit(self):
        """Test whether orphan content units can be clean up.

        Do the following:

        1. Create, and sync a repo.
        2. Remove a content unit from the repo. This will create a second
           repository version, and create an orphan content unit.
        3. Assert that content unit that was removed from the repo and its
           artifact are present on disk.
        4. Delete orphans.
        5. Assert that the orphan content unit was cleaned up, and its artifact
           is not present on disk.
        """
        repo_api = RepositoriesFileApi(self.api_client)
        remote_api = RemotesFileApi(self.api_client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)
        content = choice(get_content(repo.to_dict())[FILE_CONTENT_NAME])

        # Create an orphan content unit.
        repo_api.modify(repo.pulp_href,
                        dict(remove_content_units=[content["pulp_href"]]))

        artifacts_api = ArtifactsApi(core_client)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact is present on disk.
            artifact_path = os.path.join(
                MEDIA_PATH,
                artifacts_api.read(content["artifact"]).file)
            cmd = ("ls", artifact_path)
            self.cli_client.run(cmd, sudo=True)

        file_contents_api = ContentFilesApi(self.api_client)
        # Delete first repo version. The previous removed content unit will be
        # an orphan.
        delete_version(repo, get_versions(repo.to_dict())[1]["pulp_href"])
        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertIn(content["pulp_href"], content_units_href)

        delete_orphans()
        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertNotIn(content["pulp_href"], content_units_href)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact was removed from disk.
            with self.assertRaises(CalledProcessError):
                self.cli_client.run(cmd)
Beispiel #47
0
    def test_01_all(self):
        """
        TODO: This needs to be broken up!

        Publication creation causes a publish task, which must also tested here.

            1. Create a repository with at least 2 repository versions.
            2. Create a publication by supplying the latest ``repository_version``.
            3. Assert that the publication ``repository_version`` attribute points
               to the latest repository version.
            4. Create a publication by supplying the non-latest
               ``repository_version``.
            5. Assert that the publication ``repository_version`` attribute points
               to the supplied repository version.
            6. Assert that an exception is raised when providing two different
               repository versions to be published at same time.
        """
        body = gen_python_remote(PYTHON_FIXTURES_URL)
        remote = self.client.post(PYTHON_REMOTE_PATH, body)
        self.addCleanup(self.client.delete, remote['_href'])

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

        sync(self.cfg, remote, repo)

        # Step 1
        repo = self.client.get(repo['_href'])
        for python_content in get_content(repo)[PYTHON_CONTENT_NAME]:
            self.client.post(repo['_versions_href'],
                             {'add_content_units': [python_content['_href']]})
        versions = get_versions(repo)
        non_latest = choice(versions[:-1])

        # Step 2
        publication1 = gen_python_publication(self.cfg, repository=repo)

        # Step 3
        self.assertEqual(publication1['repository_version'],
                         versions[-1]['_href'])

        # Step 4
        publication2 = gen_python_publication(self.cfg,
                                              repository_version=non_latest)

        # Step 5
        self.assertEqual(publication2['repository_version'],
                         non_latest['_href'])

        # Step 6
        with self.assertRaises(HTTPError):
            gen_python_publication(
                self.cfg,
                repository_version=non_latest,
                repository=repo,
            )

        # TEST RETRIEVE
        """
        Read a publisher by its href.
        """
        publication_retrieved = self.client.get(publication1['_href'])
        for key, val in publication1.items():
            with self.subTest(key=key):
                self.assertEqual(publication_retrieved[key], val)

        # TODO TEST LIST
        # TODO TEST PARTIAL AND FULL UPDATE

        # TEST DELETE
        """
        Delete a publisher.
        """
        self.client.delete(publication1['_href'])
        with self.assertRaises(HTTPError):
            self.client.get(publication1['_href'])
Beispiel #48
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest
           ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()

        delete_orphans(cfg)

        client = api.Client(cfg, api.json_handler)
        body = gen_remote(fixture_u1.url,
                          cookbooks={fixture_u1.example1_name: ""})
        remote = client.post(COOKBOOK_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, mirror=True)
        repo = client.get(repo["_href"])
        repo_content = get_cookbook_content(repo)
        self.assertTrue(repo_content)

        publisher = client.post(COOKBOOK_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(client.delete, publisher["_href"])

        # Step 1
        repo = client.post(REPO_PATH, gen_repo())
        self.addCleanup(client.delete, repo["_href"])
        for cookbook in repo_content:
            client.post(repo["_versions_href"],
                        {"add_content_units": [cookbook["_href"]]})
        version_hrefs = tuple(ver["_href"] for ver in get_versions(repo))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publication = publish(cfg, publisher, repo)

        # Step 3
        self.assertEqual(publication["repository_version"], version_hrefs[-1])

        # Step 4
        publication = publish(cfg, publisher, repo, non_latest)

        # Step 5
        self.assertEqual(publication["repository_version"], non_latest)

        # Step 6
        with self.assertRaises(HTTPError):
            body = {
                "repository": repo["_href"],
                "repository_version": non_latest
            }
            client.post(urljoin(publisher["_href"], "publish/"), body)
Beispiel #49
0
    def test_repo_auto_distribution(self):
        """Test auto distribution of a repository.

        This test targets the following issue:

        * `Pulp Smash #947 <https://github.com/PulpQE/pulp-smash/issues/947>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publisher.
        3. Create a distribution and set the repository and publishera to the
           previous created ones.
        4. Create a publication using the latest repository version.
        5. Assert that the previous distribution has a  ``publication`` set as
           the one created in step 4.
        6. Create a new repository version by adding content to the repository.
        7. Create another publication using the just created repository
           version.
        8. Assert that distribution now has the ``publication`` set to the
           publication created in the step 7.
        9. Verify that content added in the step 7 is now available to download
           from distribution, and verify that the content unit has the same
           checksum when fetched directly from Pulp-Fixtures.
        """
        self.assertGreaterEqual(len(self.contents), 2, self.contents)

        # Create a repository.
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [self.contents[0]['_href']]}
        )
        repo = self.client.get(repo['_href'])

        # Create publisher.
        publisher = self.client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(self.client.delete, publisher['_href'])

        # Create a distribution
        body = gen_distribution()
        body['repository'] = repo['_href']
        body['publisher'] = publisher['_href']
        distribution = self.client.post(DISTRIBUTION_PATH, body)
        self.addCleanup(self.client.delete, distribution['_href'])
        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)
        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Assert that distribution was updated as per step 5.
        self.assertEqual(distribution['publication'], publication['_href'])

        # Create a new repository version.
        self.client.post(
            repo['_versions_href'],
            {'add_content_units': [self.contents[1]['_href']]}
        )
        repo = self.client.get(repo['_href'])
        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)
        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Assert that distribution was updated as per step 8.
        self.assertEqual(distribution['publication'], publication['_href'])
        unit_path = get_added_content(repo, last_version_href)[0]['relative_path']
        unit_url = self.cfg.get_hosts('api')[0].roles['api']['scheme']
        unit_url += '://' + distribution['base_url'] + '/'
        unit_url = urljoin(unit_url, unit_path)

        self.client.response_handler = api.safe_handler
        pulp_hash = hashlib.sha256(
            self.client.get(unit_url).content
        ).hexdigest()
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(FILE_URL, unit_path))
        ).hexdigest()

        # Verify checksum. Step 9.
        self.assertEqual(fixtures_hash, pulp_hash)
Beispiel #50
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Create distribution.
        6. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        7. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        # Step 1
        for file_content in get_content(
                self.repo.to_dict())[FILE_CONTENT_NAME]:
            repository_modify_data = RepositoryAddRemoveContent(
                remove_content_units=[file_content["pulp_href"]])
            modify_response = self.repo_api.modify(self.repo.pulp_href,
                                                   repository_modify_data)
            monitor_task(modify_response.task)
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(self.repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=self.repo.pulp_href)
        publication = self.create_publication(publish_data)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publication = self.create_publication(publish_data)

        # Step 5
        body = gen_distribution()
        body["base_path"] = "pulp_post_upgrade_test"
        body["publication"] = publication.pulp_href

        distribution_response = self.distributions.create(body)
        created_resources = monitor_task(
            distribution_response.task).created_resources
        distribution = self.distributions.read(created_resources[0])

        # Step 6
        self.assertEqual(publication.repository_version, non_latest)

        # Step 7
        with self.assertRaises(ApiException):
            body = {
                "repository": self.repo.pulp_href,
                "repository_version": non_latest
            }
            self.publications.create(body)

        # Step 8
        url = self.cfg.get_content_host_base_url(
        ) + "/pulp/content/pulp_post_upgrade_test/"
        self.assertEqual(url, distribution.base_url, url)
Beispiel #51
0
    def test_content_app_returns_404(self):
        """Test that content app returns 404 on wrong url.

        This test targets the following issue: 4278

        * `<https://pulp.plan.io/issues/4278>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publisher.
        3. Create a distribution and set the repository and publisher to the
           previous created ones.
        4. Create a publication using the latest repository version.
        5. Verify that the content app serves 404 responses.
        """
        self.assertGreaterEqual(len(self.contents), 2, self.contents)

        # Create a repository.
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])
        self.client.post(repo['_versions_href'],
                         {'add_content_units': [self.contents[0]['_href']]})
        repo = self.client.get(repo['_href'])

        # Create publisher.
        publisher = self.client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(self.client.delete, publisher['_href'])

        # Create a distribution
        body = gen_distribution()
        body['repository'] = repo['_href']
        body['publisher'] = publisher['_href']

        distribution = self.client.post(DISTRIBUTION_PATH, body)
        self.addCleanup(self.client.delete, distribution['_href'])

        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)

        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Verify 404 response for wrong url of the distribution
        unit_path = 'i-do-not-exist'
        unit_url = self.cfg.get_hosts('api')[0].roles['api']['scheme']
        unit_url += '://' + distribution['base_url'] + '-WRONG/'
        unit_url = urljoin(unit_url, unit_path)

        self.client.response_handler = api.safe_handler
        with self.assertRaisesRegex(HTTPError, r'^404'):
            self.client.get(unit_url).content

        # Verify 404 response for wrong url inside the distribution
        unit_path = 'i-do-not-exist'
        unit_url = self.cfg.get_hosts('api')[0].roles['api']['scheme']
        unit_url += '://' + distribution['base_url'] + '/'
        unit_url = urljoin(unit_url, unit_path)

        self.client.response_handler = api.safe_handler
        with self.assertRaisesRegex(HTTPError, r'^404'):
            self.client.get(unit_url).content
Beispiel #52
0
    def test_repair_repository_version(self):
        """Test whether corrupted files can be redownloaded.

        Do the following:

        1. Create, and sync a repo.
        2. Select a content unit from the repo and change its appearance on disk.
        3. Repair the RepositoryVersion.
        4. Assert that the repair task reported one corrupted and one repaired unit.
        5. Repair the RepositoryVersion.
        6. Assert that the repair task reported none corrupted and none repaired unit.
        """
        if settings.DEFAULT_FILE_STORAGE not in self.SUPPORTED_STORAGE_FRAMEWORKS:
            self.skipTest(
                "Cannot simulate bit-rot on this storage platform ({}).".
                format(settings.DEFAULT_FILE_STORAGE), )

        # STEP 1
        delete_orphans()
        repo = self.api_client.post(FILE_REPO_PATH, gen_repo())
        self.addCleanup(self.api_client.delete, repo['pulp_href'])

        body = gen_file_remote()
        remote = self.api_client.post(FILE_REMOTE_PATH, body)
        self.addCleanup(self.api_client.delete, remote['pulp_href'])

        sync(self.cfg, remote, repo)
        repo = self.api_client.get(repo['pulp_href'])

        # STEP 2
        content1, content2 = sample(get_content(repo)[FILE_CONTENT_NAME], 2)
        if settings.DEFAULT_FILE_STORAGE in self.SUPPORTED_STORAGE_FRAMEWORKS:
            # Muddify one artifact on disk.
            artifact1_path = os.path.join(
                MEDIA_PATH,
                self.api_client.get(content1['artifact'])['file'])
            cmd1 = ('sed', '-i', '-e', r'$a bit rot', artifact1_path)
            self.cli_client.run(cmd1, sudo=True)
            # Delete another one from disk.
            artifact2_path = os.path.join(
                MEDIA_PATH,
                self.api_client.get(content2['artifact'])['file'])
            cmd2 = ('rm', artifact2_path)
            self.cli_client.run(cmd2, sudo=True)
        else:
            self.fail(
                "Corrupting files on this storage platform is not supported.")

        # STEP 3
        latest_version = get_versions(repo)[-1]['pulp_href']
        result = self.api_client.post(latest_version + 'repair/')

        # STEP 4
        corrupted_units_report = next(
            (report for report in result['progress_reports']
             if report['code'] == 'repair.corrupted'), None)
        self.assertEqual(corrupted_units_report['done'], 2,
                         corrupted_units_report)
        repaired_units_report = next(
            (report for report in result['progress_reports']
             if report['code'] == 'repair.repaired'), None)
        self.assertEqual(repaired_units_report['done'], 2,
                         repaired_units_report)

        # STEP 5
        result = self.api_client.post(latest_version + 'repair/')

        # STEP 6
        corrupted_units_report = next(
            (report for report in result['progress_reports']
             if report['code'] == 'repair.corrupted'), None)
        self.assertEqual(corrupted_units_report['done'], 0,
                         corrupted_units_report)
        repaired_units_report = next(
            (report for report in result['progress_reports']
             if report['code'] == 'repair.repaired'), None)
        self.assertEqual(repaired_units_report['done'], 0,
                         repaired_units_report)
    def test_repo_auto_distribution(self):
        """Test auto distribution of a repository.

        This test targets the following issue:

        * `Pulp Smash #947 <https://github.com/PulpQE/pulp-smash/issues/947>`_

        Do the following:

        1. Create a repository that has at least one repository version.
        2. Create a publisher.
        3. Create a distribution and set the repository and publishera to the
           previous created ones.
        4. Create a publication using the latest repository version.
        5. Assert that the previous distribution has a  ``publication`` set as
           the one created in step 4.
        6. Create a new repository version by adding content to the repository.
        7. Create another publication using the just created repository
           version.
        8. Assert that distribution now has the ``publication`` set to the
           publication created in the step 7.
        9. Verify that content added in the step 7 is now available to download
           from distribution, and verify that the content unit has the same
           checksum when fetched directly from Pulp-Fixtures.
        """
        self.assertGreaterEqual(len(self.contents), 2, self.contents)

        # Create a repository.
        repo = self.client.post(REPO_PATH, gen_repo())
        self.addCleanup(self.client.delete, repo['_href'])
        self.client.post(repo['_versions_href'],
                         {'add_content_units': [self.contents[0]['_href']]})
        repo = self.client.get(repo['_href'])

        # Create publisher.
        publisher = self.client.post(FILE_PUBLISHER_PATH, gen_publisher())
        self.addCleanup(self.client.delete, publisher['_href'])

        # Create a distribution
        body = gen_distribution()
        body['repository'] = repo['_href']
        body['publisher'] = publisher['_href']
        distribution = self.client.post(DISTRIBUTION_PATH, body)
        self.addCleanup(self.client.delete, distribution['_href'])
        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)
        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Assert that distribution was updated as per step 5.
        self.assertEqual(distribution['publication'], publication['_href'])

        # Create a new repository version.
        self.client.post(repo['_versions_href'],
                         {'add_content_units': [self.contents[1]['_href']]})
        repo = self.client.get(repo['_href'])
        last_version_href = get_versions(repo)[-1]['_href']
        publication = publish(self.cfg, publisher, repo, last_version_href)
        self.addCleanup(self.client.delete, publication['_href'])
        distribution = self.client.get(distribution['_href'])

        # Assert that distribution was updated as per step 8.
        self.assertEqual(distribution['publication'], publication['_href'])
        unit_path = get_added_content(repo,
                                      last_version_href)[0]['relative_path']
        unit_url = self.cfg.get_hosts('api')[0].roles['api']['scheme']
        unit_url += '://' + distribution['base_url'] + '/'
        unit_url = urljoin(unit_url, unit_path)

        self.client.response_handler = api.safe_handler
        pulp_hash = hashlib.sha256(
            self.client.get(unit_url).content).hexdigest()
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(FILE_URL, unit_path))).hexdigest()

        # Verify checksum. Step 9.
        self.assertEqual(fixtures_hash, pulp_hash)
 def test_deleted_version_filter(self):
     """Delete a repository version and filter by its number."""
     numbers = self.get_repo_versions_attr("number")
     delete_version(self.repo)
     versions = get_versions(self.repo, {"number": numbers[-1]})
     self.assertEqual(len(versions), 0, versions)
Beispiel #55
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        client = gen_file_client()
        repo_api = RepositoriesFileApi(client)
        remote_api = RemotesFileApi(client)
        publications = PublicationsFileApi(client)

        body = gen_file_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # Step 1
        repo = repo_api.read(repo.pulp_href)
        for file_content in get_content(repo.to_dict())[FILE_CONTENT_NAME]:
            modify_repo(cfg, repo.to_dict(), remove_units=[file_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        self.addCleanup(publications.delete, publication_href)
        publication = publications.read(publication_href)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        publication = publications.read(publication_href)

        # Step 5
        self.assertEqual(publication.repository_version, non_latest)

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": repo.pulp_href,
                "repository_version": non_latest
            }
            publications.create(body)