pulp_smash.tests.docker.api_v2.test_sync_publish

Location: Pulp SmashAPI Documentationpulp_smash.tests.docker.api_v2.test_sync_publish

Tests for syncing and publishing docker repositories.

pulp_smash.tests.docker.api_v2.test_sync_publish.MANIFEST_LIST_V2 = {'type': 'object', 'description': 'Derived from: https://docs.docker.com/registry/spec/manifest-v2-2/#manifest-list', '$schema': 'http://json-schema.org/schema#', 'properties': {'schemaVersion': {'type': 'integer'}, 'manifests': {'items': {'type': 'object', 'properties': {'size': {'type': 'integer'}, 'mediaType': {'type': 'string'}, 'platform': {'type': 'object', 'properties': {'os.version': {'type': 'string'}, 'architecture': {'type': 'string'}, 'os.features': {'items': {'type': 'string'}, 'type': 'array'}, 'features': {'items': {'type': 'string'}, 'type': 'array'}, 'os': {'type': 'string'}, 'variant': {'type': 'string'}}}, 'digest': {'type': 'string'}}}, 'type': 'array'}, 'mediaType': {'type': 'string'}}, 'title': 'Image Manifest List'}

A schema for docker manifest lists.

pulp_smash.tests.docker.api_v2.test_sync_publish.MANIFEST_V1 = {'type': 'object', 'description': 'Derived from: https://docs.docker.com/registry/spec/manifest-v2-1/', '$schema': 'http://json-schema.org/schema#', 'properties': {'schemaVersion': {'type': 'integer'}, 'fsLayers': {'items': {'type': 'object', 'properties': {'blobSum': {'type': 'string'}}}, 'type': 'array'}, 'signatures': {'items': {'type': 'object', 'properties': {'signature': {'type': 'string'}, 'header': {'type': 'object', 'properties': {'jwk': {'type': 'object', 'properties': {'crv': {'type': 'string'}, 'kid': {'type': 'string'}, 'x': {'type': 'string'}, 'y': {'type': 'string'}, 'kty': {'type': 'string'}}}, 'alg': {'type': 'string'}}}, 'protected': {'type': 'string'}}}, 'type': 'array'}, 'architecture': {'type': 'string'}, 'tag': {'type': 'string'}, 'history': {'items': {'type': 'object', 'properties': {'v1Compatibility': {'type': 'string'}}}, 'type': 'array'}, 'name': {'type': 'string'}}, 'title': 'Image Manifest Version 2, Schema 1'}

A schema for docker v2 image manifests, schema 1.

pulp_smash.tests.docker.api_v2.test_sync_publish.MANIFEST_V2 = {'type': 'object', 'description': 'Derived from: https://docs.docker.com/registry/spec/manifest-v2-2/#image-manifest', '$schema': 'http://json-schema.org/schema#', 'properties': {'layers': {'items': {'type': 'object', 'properties': {'size': {'type': 'integer'}, 'urls': {'items': {'type': 'string'}, 'type': 'array'}, 'mediaType': {'type': 'string'}, 'digest': {'type': 'string'}}}, 'type': 'array'}, 'mediaType': {'type': 'string'}, 'config': {'type': 'object', 'properties': {'size': {'type': 'integer'}, 'mediaType': {'type': 'string'}, 'digest': {'type': 'string'}}}, 'schemaVersion': {'type': 'integer'}}, 'title': 'Image Manifest Version 2, Schema 2'}

A schema for docker v2 image manifests, schema 2.

class pulp_smash.tests.docker.api_v2.test_sync_publish.NoAmd64LinuxTestCase(methodName='runTest')

Sync a Docker image with no amd64/linux build.

A manifest list lets a single Docker repository contain multiple images. This is useful in the case where an image contains platform-specific code, and an image must be built for each each supported architecture, OS, etc.

When a modern Docker client fetches an image, it does the following:

  1. Get a manifest list.
  2. Look through the list of available images.
  3. Pick out an image that functions on the current host’s platform.
  4. Get a manifest for that image.
  5. Use the information in the manifest to get the image layers.

Older Docker clients aren’t aware of manifest lists, and when they go to fetch an image, they just ask for any old manifest from a repository. When a Docker registry receives such a request, it does the following:

  1. Look through the list of available images.
  2. If an image with an architecture of amd64 and an os of linux is available, return its manifest. Otherwise, return an HTTP 404.

This test case verifies Pulp’s behaviour in the case where an upstream Docker repository has content described by a manifest list.

This test case doesn’t verify Pulp’s behaviour in the case where an upstream Docker repository has content described by a v2 manifest or v1 manifest. In these cases, the correct behaviour of a Docker registry is not well defined. See the backward compatibility documentation.

classmethod setUpClass()

Create class-wide variables.

classmethod tearDownClass()

Clean up resources.

test_01_set_up()

Create, sync and publish a Docker repository.

Specifically, do the following:

  1. Create, sync and publish a Docker repository. Let the repository’s upstream name reference a repository that has an image with a manifest list and no amd64/linux build.
  2. Make Crane immediately re-read the metadata files published by Pulp. (Restart Apache.)
test_02_get_manifest_list()

Get a manifest list.

Assert that:

  • The response headers include a content-type of accept:application/vnd.docker.distribution.manifest.list.v2+json. (See test_02_get_manifest_list().
  • The response body matches MANIFEST_LIST_V2.
  • The returned manifest list doesn’t include any entry where architecture of amd64 and os is linux.
test_02_get_manifest_v1()

Get a v1 manifest. Assert that an HTTP 404 is returned.

test_02_get_manifest_v2()

Get a v2 manifest. Assert that an HTTP 404 is returned.

class pulp_smash.tests.docker.api_v2.test_sync_publish.NonNamespacedImageTestCase(methodName='runTest')

Work with an image whose name has no namespace.

test_all()

Work with an image whose name has no namespace.

Create, sync and publish a Docker repository whose UPSTREAM_NAME doesn’t include a namespace. A typical Docker image has a name like “library/busybox.” When a non-namespaced image name like “busybox” is given, a prefix of “library” is assumed.

class pulp_smash.tests.docker.api_v2.test_sync_publish.RepoRegistryIdTestCase(methodName='runTest')

Show Pulp can publish repos with varying repo_registry_id values.

do_test(cfg, repo_registry_id)

Execute the test with the given repo_registry_id.

test_all()

Show Pulp can publish repos with varying repo_registry_id values.

The repo_registry_id setting defines a Docker repository’s name as seen by clients such as the Docker CLI. It’s traditionally a two-part name such as docker/busybox, but according to Pulp #2368, it can contain an arbitrary number of slashes. This test case verifies that the repo_registry_id can be set to values containing one, two and three slashes.

Also see: Pulp #2723.

class pulp_smash.tests.docker.api_v2.test_sync_publish.SyncPublishMixin

Tools for test cases that sync and publish Docker repositories.

This class must be mixed in to a class that inherits from unittest.TestCase.

static adjust_url(url)

Return a URL that can be used for talking with Crane.

The URL returned is the same as url, except that the scheme is set to HTTP, and the port is set to (or replaced by) 5000.

Parameters:url – A string, such as https://pulp.example.com/foo.
Returns:A string, such as http://pulp.example.com:5000/foo.
static make_crane_client(cfg)

Make an API client for talking with Crane.

Create an API client for talking to Crane. The client returned by this method is similar to the following client:

>>> client = api.Client(cfg, api.json_handler)

However:

  • The client’s base URL is adjusted as described by adjust_url().
  • The client will send an accept:application/json header with each request.
Parameters:cfg (pulp_smash.config.PulpSmashConfig) – Information about a Pulp deployment.
Returns:An API client for talking with Crane.
Return type:pulp_smash.api.Client
class pulp_smash.tests.docker.api_v2.test_sync_publish.V1RegistryTestCase(methodName='runTest')

Create, sync, publish and interact with a v1 Docker registry.

classmethod setUpClass()

Create class-wide variables.

classmethod tearDownClass()

Clean up resources.

test_01_set_up()

Create, sync and publish a repository.

Specifically, do the following:

  1. Create, sync and publish a Docker repository. Let the repository’s feed reference a v1 Docker registry.
  2. Make Crane immediately re-read the metadata files published by Pulp. (Restart Apache.)
test_02_get_crane_repositories()

Issue an HTTP GET request to /crane/repositories.

Assert that the response is as described by Crane Admin.

test_02_get_crane_repositories_v1()

Issue an HTTP GET request to /crane/repositories/v1.

Assert that the response is as described by Crane Admin.

verify_v1_repo(repo)

Implement the assertions for the test_02* methods.

class pulp_smash.tests.docker.api_v2.test_sync_publish.V2RegistryTestCase(methodName='runTest')

Create, sync, publish and interact with a v2 Docker registry.

classmethod setUpClass()

Create class-wide variables.

classmethod tearDownClass()

Clean up resources.

test_01_set_up()

Create, sync and publish a Docker repository.

Specifically, do the following:

  1. Create, sync and publish a Docker repository. Let the repository’s feed reference a v2 Docker registry, and let the repository’s upstream name reference an image with a manifest list.
  2. Make Crane immediately re-read the metadata files published by Pulp. (Restart Apache.)
test_02_get_crane_repositories_v2()

Issue an HTTP GET request to /crane/repositories/v2.

Assert that the response is as described by Crane Admin.

test_02_get_manifest_list()

Issue an HTTP GET request to /v2/{repo_id}/manifests/latest.

Pass a header of accept:application/vnd.docker.distribution.manifest.list.v2+json Assert that:

  • The response body matches MANIFEST_LIST_V2.
  • The response has a content-type equal to what was requested. (According to Docker’s backward compatiblity specification, if a registry is asked for a manifest list but doesn’t have a manifest list, it may return a manifest instead. But this test targets manifest lists, and it will fail if that happens.)
test_02_get_manifest_v1()

Issue an HTTP GET request to /v2/{repo_id}/manifests/latest.

Pass each of the followng headers in turn:

  • (none)
  • accept:application/json
  • accept:application/vnd.docker.distribution.manifest.v1+json

Assert the response matches MANIFEST_V1.

This test targets Pulp #2336.

test_02_get_manifest_v2()

Issue an HTTP GET request to /v2/{repo_id}/manifests/latest.

Pass a header of accept:application/vnd.docker.distribution.manifest.v2+json. Assert that the response body matches MANIFEST_V2.

This test targets Pulp #2336.