Example #1
0
 def _do_test_valid_upstream_name(self, repo):
     """Sync a v1 Docker repository with a valid ``upstream_name``."""
     self.client.post(urljoin(repo['_href'], 'actions/sync/'), {
         'override_config': {
             'upstream_name': get_upstream_name(self.cfg)
         }
     })
Example #2
0
 def setUp(self):
     """Create docker repository."""
     self.repo = self.create_sync_publish_repo(self.cfg, {
         'enable_v1': False,
         'enable_v2': True,
         'feed': DOCKER_V2_FEED_URL,
         'upstream_name': get_upstream_name(self.cfg),
     })
Example #3
0
 def setUp(self):
     """Create and sync a docker repository."""
     super().setUp()
     self.repo = create_docker_repo(self.cfg, get_upstream_name(self.cfg))
     self.addCleanup(api.Client(self.cfg).delete, self.repo['_href'])
     sync_repo(self.cfg, self.repo)
     self.repo = api.Client(self.cfg, api.json_handler).get(
         self.repo['_href'], params={'details': True})
     self.tags = self._get_tags()
Example #4
0
    def test_all(self):
        """Upload a V2 manifest list.

        Do the following:

        1. Create, sync and publish a repository. Read the repository and the
           repository's manifest list.
        2. Upload a modified version of the manifest list to the repository.
           Re-read the repository and the repository's manifest list.
        3. Assert that:

           * The repository's manifest list hasn't been changed. (After all,
             the repository hasn't been published since the new manifest list
             was uploaded.)
           * The repository's ``docker_manifest_list`` attribute has increased
             by the approprate number.

        This test targets the following issues:

        * `Pulp #2993 <https://pulp.plan.io/issues/2993>`_
        * `Pulp Smash #829 <https://github.com/PulpQE/pulp-smash/issues/829>`_
        """
        repo = self.create_sync_publish_repo(self.cfg, {
            'enable_v1': False,
            'enable_v2': True,
            'feed': DOCKER_V2_FEED_URL,
            'upstream_name': get_upstream_name(self.cfg),
        })
        crane_client = self.make_crane_client(self.cfg)
        crane_client.request_kwargs['headers']['accept'] = (
            'application/vnd.docker.distribution.manifest.list.v2+json'
        )
        manifest_list_path = '/v2/{}/manifests/latest'.format(repo['id'])
        manifest_list = crane_client.get(manifest_list_path)

        # Upload a modified manifest list.
        modified_manifest_list = copy.deepcopy(manifest_list)
        modified_manifest_list['manifests'].pop()
        upload_import_unit(
            self.cfg,
            json.dumps(modified_manifest_list).encode('utf-8'),
            {'unit_type_id': 'docker_manifest_list'},
            repo,
        )

        # Verify outcomes.
        with self.subTest(comment='verify manifest list is same'):
            new_manifest_list = crane_client.get(manifest_list_path)
            self.assertEqual(manifest_list, new_manifest_list)
        with self.subTest(comment='verify docker_manifest_list repo attr'):
            new_repo = api.Client(self.cfg).get(repo['_href']).json()
            self.assertEqual(
                repo['content_unit_counts']['docker_manifest_list'] +
                len(modified_manifest_list['manifests']),
                new_repo['content_unit_counts']['docker_manifest_list'],
            )
Example #5
0
 def test_01_set_up(self):
     """Create a repository and populate with with schema v2 content."""
     body = gen_repo()
     body['importer_config'].update({
         'enable_v1': False,
         'enable_v2': True,
         'feed': DOCKER_V2_FEED_URL,
         'upstream_name': get_upstream_name(self.cfg),
     })
     type(self).repo = self.client.post(REPOSITORY_PATH, body)
     sync_repo(self.cfg, self.repo)
     type(self).repo = self.client.get(
         self.repo['_href'],
         params={'details': True}
     )
Example #6
0
    def do_test(self, cfg, repo_registry_id):
        """Execute the test with the given ``repo_registry_id``."""
        # Create, sync and publish.
        importer_config = {
            'enable_v1': False,
            'enable_v2': True,
            'feed': DOCKER_V2_FEED_URL,
            'upstream_name': get_upstream_name(cfg),
        }
        distrib = gen_distributor()
        distrib['distributor_config']['repo-registry-id'] = repo_registry_id
        self.create_sync_publish_repo(cfg, importer_config, [distrib])

        # Get and inspect /crane/repositories/v2.
        client = self.make_crane_client(cfg)
        repos = client.get('/crane/repositories/v2')
        self.assertIn(repo_registry_id, repos.keys())
        self.assertFalse(repos[repo_registry_id]['protected'])
Example #7
0
    def test_validate_content_type(self):
        """Validates content_type contains correct content."""
        cfg = config.get_config()
        if cfg.pulp_version < Version('2.19'):
            raise unittest.SkipTest('This test requires Pulp 2.19 or newer.')

        # Create, sync and publish docker repo
        repo = self.create_sync_publish_repo(
            cfg, {
                'enable_v1': False,
                'enable_v2': True,
                'feed': DOCKER_V2_FEED_URL,
                'upstream_name': get_upstream_name(cfg),
            })

        # Get all tags from docker repo
        # Chose a random tag to check
        random_tag = random.choice(
            search_units(
                cfg,
                repo,
                {'type_ids': ['docker_tag']},
            ))

        # Get the Header URL of the random tag
        url = '/pulp/docker/v2/{}/manifests/1/{}'.format(
            repo['display_name'],
            random_tag['metadata']['name'],
        )

        # Get the Content-Type of that tag
        header = api.Client(cfg, api.code_handler).get(url).headers

        # Verify the header
        # application/vnd.docker.distribution.manifest.v1+prettyjws
        self.assertTrue(
            all([
                strings in header['Content-Type'] for strings in [
                    'application',
                    'vnd.docker',
                    'distribution',
                    'manifest',
                ]
            ]), header['Content-Type'])
Example #8
0
 def test_all(self):
     """Create a docker repo with an invalid feed and sync it."""
     repo_id = utils.uuid4()
     self.assertNotIn(
         'Task Failed',
         repo_create(
             self.cfg,
             feed='https://docker.example.com',
             repo_id=repo_id,
             upstream_name=get_upstream_name(self.cfg),
         ).stdout)
     self.addCleanup(repo_delete, self.cfg, repo_id)
     client = cli.Client(self.cfg, cli.echo_handler)
     proc = client.run(('pulp-admin', 'docker', 'repo', 'sync', 'run',
                        '--repo-id', repo_id))
     if selectors.bug_is_fixed(427, self.cfg.pulp_version):
         with self.subTest():
             self.assertNotEqual(proc.returncode, 0)
     with self.subTest():
         self.assertNotIn('Task Succeeded', proc.stdout)
     with self.subTest():
         self.assertIn('Task Failed', proc.stdout)