Merge "Ensure we get a value for manifest digest"
This commit is contained in:
commit
609e527ed2
|
@ -406,9 +406,18 @@ class BaseImageUploader(object):
|
|||
manifest_r.raise_for_status()
|
||||
tags_r.raise_for_status()
|
||||
|
||||
manifest = manifest_r.json()
|
||||
manifest_str = manifest_r.text
|
||||
|
||||
if 'Docker-Content-Digest' in manifest_r.headers:
|
||||
digest = manifest_r.headers['Docker-Content-Digest']
|
||||
else:
|
||||
# The registry didn't supply the manifest digest, so calculate it
|
||||
calc_digest = hashlib.sha256()
|
||||
calc_digest.update(manifest_str.encode('utf-8'))
|
||||
digest = 'sha256:%s' % calc_digest.hexdigest()
|
||||
|
||||
manifest = json.loads(manifest_str)
|
||||
|
||||
digest = manifest_r.headers['Docker-Content-Digest']
|
||||
if manifest.get('schemaVersion', 2) == 1:
|
||||
config = json.loads(manifest['history'][0]['v1Compatibility'])
|
||||
layers = list(reversed([l['blobSum']
|
||||
|
|
|
@ -489,6 +489,7 @@ class TestBaseImageUploader(base.TestCase):
|
|||
{'digest': 'ccc'},
|
||||
]
|
||||
}
|
||||
manifest_str = json.dumps(manifest_resp, indent=3)
|
||||
manifest_headers = {'Docker-Content-Digest': 'eeeeee'}
|
||||
tags_resp = {'tags': ['one', 'two', 'latest']}
|
||||
config_resp = {
|
||||
|
@ -518,7 +519,7 @@ class TestBaseImageUploader(base.TestCase):
|
|||
|
||||
# test full response
|
||||
req.get('https://registry-1.docker.io/v2/t/nova-api/manifests/latest',
|
||||
json=manifest_resp, headers=manifest_headers)
|
||||
text=manifest_str, headers=manifest_headers)
|
||||
|
||||
self.assertEqual(
|
||||
{
|
||||
|
@ -576,6 +577,7 @@ class TestBaseImageUploader(base.TestCase):
|
|||
{'blobSum': 'aaa'},
|
||||
]
|
||||
}
|
||||
manifest_str = json.dumps(manifest_resp, indent=3)
|
||||
manifest_headers = {'Docker-Content-Digest': 'eeeeee'}
|
||||
tags_resp = {'tags': ['one', 'two', 'latest']}
|
||||
|
||||
|
@ -590,7 +592,7 @@ class TestBaseImageUploader(base.TestCase):
|
|||
|
||||
# test full response
|
||||
req.get('https://registry-1.docker.io/v2/t/nova-api/manifests/latest',
|
||||
json=manifest_resp, headers=manifest_headers)
|
||||
text=manifest_str, headers=manifest_headers)
|
||||
|
||||
self.assertDictEqual(
|
||||
{
|
||||
|
@ -612,6 +614,82 @@ class TestBaseImageUploader(base.TestCase):
|
|||
inspect(url1, session=session)
|
||||
)
|
||||
|
||||
def test_inspect_no_digest_header(self):
|
||||
req = self.requests
|
||||
session = requests.Session()
|
||||
session.headers['Authorization'] = 'Bearer asdf1234'
|
||||
inspect = image_uploader.BaseImageUploader._inspect
|
||||
|
||||
url1 = urlparse('docker://docker.io/t/nova-api:latest')
|
||||
|
||||
manifest_resp = {
|
||||
'schemaVersion': 2,
|
||||
'config': {
|
||||
'mediaType': 'text/html',
|
||||
'digest': 'abcdef'
|
||||
},
|
||||
'layers': [
|
||||
{'digest': 'aaa'},
|
||||
{'digest': 'bbb'},
|
||||
{'digest': 'ccc'},
|
||||
]
|
||||
}
|
||||
manifest_str = json.dumps(manifest_resp, indent=3)
|
||||
manifest_headers = {}
|
||||
tags_resp = {'tags': ['one', 'two', 'latest']}
|
||||
config_resp = {
|
||||
'created': '2018-10-02T11:13:45.567533229Z',
|
||||
'docker_version': '1.13.1',
|
||||
'config': {
|
||||
'Labels': {
|
||||
'build-date': '20181002',
|
||||
'build_id': '1538477701',
|
||||
'kolla_version': '7.0.0'
|
||||
}
|
||||
},
|
||||
'architecture': 'amd64',
|
||||
'os': 'linux',
|
||||
}
|
||||
|
||||
req.get('https://registry-1.docker.io/v2/t/nova-api/tags/list',
|
||||
json=tags_resp)
|
||||
req.get('https://registry-1.docker.io/v2/t/nova-api/blobs/abcdef',
|
||||
json=config_resp)
|
||||
|
||||
# test 404 response
|
||||
req.get('https://registry-1.docker.io/v2/t/nova-api/manifests/latest',
|
||||
status_code=404)
|
||||
self.assertRaises(ImageNotFoundException, inspect, url1,
|
||||
session=session)
|
||||
|
||||
# test full response
|
||||
req.get('https://registry-1.docker.io/v2/t/nova-api/manifests/latest',
|
||||
text=manifest_str, headers=manifest_headers)
|
||||
|
||||
calc_digest = hashlib.sha256()
|
||||
calc_digest.update(manifest_str.encode('utf-8'))
|
||||
digest = 'sha256:%s' % calc_digest.hexdigest()
|
||||
|
||||
self.assertEqual(
|
||||
{
|
||||
'Architecture': 'amd64',
|
||||
'Created': '2018-10-02T11:13:45.567533229Z',
|
||||
'Digest': digest,
|
||||
'DockerVersion': '1.13.1',
|
||||
'Labels': {
|
||||
'build-date': '20181002',
|
||||
'build_id': '1538477701',
|
||||
'kolla_version': '7.0.0'
|
||||
},
|
||||
'Layers': ['aaa', 'bbb', 'ccc'],
|
||||
'Name': 'docker.io/t/nova-api',
|
||||
'Os': 'linux',
|
||||
'RepoTags': ['one', 'two', 'latest'],
|
||||
'Tag': 'latest'
|
||||
},
|
||||
inspect(url1, session=session)
|
||||
)
|
||||
|
||||
@mock.patch('concurrent.futures.ThreadPoolExecutor')
|
||||
def test_list(self, mock_pool):
|
||||
mock_pool.return_value.map.return_value = (
|
||||
|
|
Loading…
Reference in New Issue