Tolerate ports in tag discover

The tag parsing assumed there would only be one colon in the path,
which does not hold when there is a port in the registry path.

Once again we're bitten by image names not being real URLs.

Change-Id: Ia2d0efeaa269d61f6669b141d745ab2c1bb306da
Closes-Bug: #1735565
This commit is contained in:
Steve Baker 2017-12-01 12:05:20 +13:00
parent 55cfcefeb4
commit 451ba333ea
2 changed files with 21 additions and 1 deletions

View File

@ -159,7 +159,10 @@ class DockerImageUploader(ImageUploader):
def discover_image_tag(self, image, tag_from_label=None):
dockerc = Client(base_url='unix://var/run/docker.sock', version='auto')
image_name, colon, tag = image.partition(':')
image_name, colon, tag = image.rpartition(':')
if not image_name:
image_name = tag
tag = None
if not tag:
tag = 'latest'
image = '%s:%s' % (image_name, tag)

View File

@ -196,6 +196,23 @@ class TestDockerImageUploader(base.TestCase):
self.assertRaises(ImageUploaderException,
self.uploader.discover_image_tag, image, 'foo')
def test_discover_image_tag_with_port(self):
image = 'foo:5000/t/heat-docker-agents-centos:latest'
vimage = 'foo:5000/t/heat-docker-agents-centos:1.2.3'
dockerc = self.dockermock.return_value
dockerc.pull.return_value = ['{"status": "done"}']
dockerc.inspect_image.return_value = {
'Config': {'Labels': {'image-version': '1.2.3'}}
}
result = self.uploader.discover_image_tag(image, 'image-version')
self.assertEqual('1.2.3', result)
dockerc.pull.assert_has_calls([
mock.call(image, tag=None, stream=True),
mock.call(vimage, tag=None, stream=True),
])
@mock.patch('time.sleep')
def test_pull_retry(self, sleep_mock):
image = 'docker.io/tripleoupstream/heat-docker-agents-centos'