Merge "Make DockerImageUploader work with missing tags"

This commit is contained in:
Jenkins 2017-06-12 01:18:19 +00:00 committed by Gerrit Code Review
commit 414f94b6c1
4 changed files with 40 additions and 3 deletions

View File

@ -94,8 +94,12 @@ class DockerImageUploader(ImageUploader):
def upload_image(self, image_name, pull_source, push_destination):
dockerc = Client(base_url='unix://var/run/docker.sock')
image = image_name.rpartition(':')[0]
tag = image_name.rpartition(':')[2]
if ':' in image_name:
image = image_name.rpartition(':')[0]
tag = image_name.rpartition(':')[2]
else:
image = image_name
tag = 'latest'
repo = pull_source + '/' + image
response = [line for line in dockerc.pull(repo,

View File

@ -38,6 +38,8 @@ def create_parsed_upload_images():
{'imagename': 'tripleoupstream/centos-binary-nova-libvirt:liberty',
'push_destination': 'localhost:8787',
'pull_source': 'docker.io',
'uploader': 'docker'}
'uploader': 'docker'},
{'imagename': 'tripleoupstream/image-with-missing-tag',
'push_destination': 'localhost:8787'},
]
return uploads

View File

@ -37,6 +37,8 @@ filedata = six.u(
- imagename: tripleoupstream/centos-binary-nova-libvirt:liberty
uploader: docker
pull_source: docker.io
- imagename: tripleoupstream/image-with-missing-tag
push_destination: localhost:8787
""")
legacy_filedata = six.u(
@ -50,6 +52,8 @@ legacy_filedata = six.u(
- imagename: tripleoupstream/centos-binary-nova-libvirt:liberty
uploader: docker
pull_source: docker.io
- imagename: tripleoupstream/image-with-missing-tag
push_destination: localhost:8787
""")
@ -145,3 +149,27 @@ class TestDockerImageUploader(base.TestCase):
self.dockermock.return_value.push(
push_destination + '/' + image,
tag=tag, stream=True, insecure_registry=True)
def test_upload_image_missing_tag(self):
image = 'tripleoupstream/heat-docker-agents-centos'
expected_tag = 'latest'
pull_source = 'docker.io'
push_destination = 'localhost:8787'
self.uploader.upload_image(image,
pull_source,
push_destination)
self.dockermock.assert_called_once_with(
base_url='unix://var/run/docker.sock')
self.dockermock.return_value.pull.assert_called_once_with(
pull_source + '/' + image,
tag=expected_tag, stream=True, insecure_registry=True)
self.dockermock.return_value.tag.assert_called_once_with(
image=pull_source + '/' + image + ':' + expected_tag,
repository=push_destination + '/' + image,
tag=expected_tag, force=True)
self.dockermock.return_value.push(
push_destination + '/' + image,
tag=expected_tag, stream=True, insecure_registry=True)

View File

@ -34,6 +34,8 @@ filedata = six.u(
- imagename: tripleoupstream/centos-binary-nova-libvirt:liberty
uploader: docker
pull_source: docker.io
- imagename: tripleoupstream/image-with-missing-tag
push_destination: localhost:8787
""")
@ -76,6 +78,7 @@ class TestKollaImageBuilder(base.TestCase):
'nova-compute',
'nova-libvirt',
'heat-docker-agents-centos',
'image-with-missing-tag',
], env=env)
@mock.patch('subprocess.Popen')