From 7d3f274a3c660655072f11a2b6aedd63405df5f9 Mon Sep 17 00:00:00 2001 From: Alex Schultz Date: Mon, 17 Feb 2020 15:44:07 -0700 Subject: [PATCH] Fix default image registry address lookup By using a function as the default for the registry url variables, the function is actually executed on every invocation of openstack client which is less than ideal. This change moves the default registry lookup to only occur if the option is not passed in by the user. This limits the lookup of the local registry to only occur when the correct openstack tripleo container iamge commands are run. Change-Id: Iace7be9dbdcf681c5f2f25f5810aa11e9da1853c Closes-Bug: #1863679 --- .../tests/v1/test_container_image.py | 8 +++--- tripleoclient/v1/container_image.py | 28 +++++++++++++------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/tripleoclient/tests/v1/test_container_image.py b/tripleoclient/tests/v1/test_container_image.py index 593874257..3af649669 100644 --- a/tripleoclient/tests/v1/test_container_image.py +++ b/tripleoclient/tests/v1/test_container_image.py @@ -144,7 +144,7 @@ class TestContainerImagePush(TestPluginV1): mock_task.assert_called_once_with( image_name='namespace/foo', pull_source='docker.io', - push_destination=parsed_args.registry_url, + push_destination='uc.ctlplane.somedomain', append_tag=parsed_args.append_tag, modify_role=None, modify_vars=None, @@ -197,7 +197,7 @@ class TestContainerImagePush(TestPluginV1): mock_task.assert_called_once_with( image_name='containers-storage:docker.io/namespace/foo', pull_source=None, - push_destination=parsed_args.registry_url, + push_destination='uc.ctlplane.somedomain', append_tag=parsed_args.append_tag, modify_role=None, modify_vars=None, @@ -250,7 +250,7 @@ class TestContainerImagePush(TestPluginV1): mock_task.assert_called_once_with( image_name='containers-storage:docker.io/namespace/foo', pull_source=None, - push_destination=parsed_args.registry_url, + push_destination='uc.ctlplane.somedomain', append_tag=parsed_args.append_tag, modify_role=None, modify_vars=None, @@ -361,7 +361,7 @@ class TestContainerImagePush(TestPluginV1): mock_task.assert_called_once_with( image_name='namespace/foo:tag', pull_source='docker.io', - push_destination=parsed_args.registry_url, + push_destination='127.0.0.1:8787', append_tag=parsed_args.append_tag, modify_role=None, modify_vars=None, diff --git a/tripleoclient/v1/container_image.py b/tripleoclient/v1/container_image.py index a69c0d771..920927765 100644 --- a/tripleoclient/v1/container_image.py +++ b/tripleoclient/v1/container_image.py @@ -545,7 +545,7 @@ class TripleOContainerImagePush(command.Command): "--registry-url", dest="registry_url", metavar='', - default=image_uploader.get_undercloud_registry(), + default=None, help=_("URL of the destination registry in the form " ":.") ) @@ -630,9 +630,13 @@ class TripleOContainerImagePush(command.Command): '//:' '') - registry_url = parsed_args.registry_url - if not registry_url.startswith('docker://'): - registry_url = 'docker://%s' % registry_url + registry_url_arg = parsed_args.registry_url + if registry_url_arg is None: + registry_url_arg = image_uploader.get_undercloud_registry() + if not registry_url_arg.startswith('docker://'): + registry_url = 'docker://%s' % registry_url_arg + else: + registry_url = registry_url_arg reg_url = parse.urlparse(registry_url) uploader.authenticate(reg_url, @@ -642,7 +646,7 @@ class TripleOContainerImagePush(command.Command): task = image_uploader.UploadTask( image_name=image_name, pull_source=image_source, - push_destination=parsed_args.registry_url, + push_destination=registry_url_arg, append_tag=parsed_args.append_tag, modify_role=None, modify_vars=None, @@ -670,7 +674,7 @@ class TripleOContainerImageDelete(command.Command): "--registry-url", dest="registry_url", metavar='', - default=image_uploader.get_undercloud_registry(), + default=None, help=_("URL of registry images are to be listed from in the " "form :.") ) @@ -713,7 +717,10 @@ class TripleOContainerImageDelete(command.Command): lock = processlock.ProcessLock() manager = image_uploader.ImageUploadManager(lock=lock) uploader = manager.uploader('python') - url = uploader._image_to_url(parsed_args.registry_url) + registry_url_arg = parsed_args.registry_url + if registry_url_arg is None: + registry_url_arg = image_uploader.get_undercloud_registry() + url = uploader._image_to_url(registry_url_arg) session = uploader.authenticate(url, parsed_args.username, parsed_args.password) @@ -737,7 +744,7 @@ class TripleOContainerImageList(command.Lister): "--registry-url", dest="registry_url", metavar='', - default=image_uploader.get_undercloud_registry(), + default=None, help=_("URL of registry images are to be listed from in the " "form :.") ) @@ -761,7 +768,10 @@ class TripleOContainerImageList(command.Lister): lock = processlock.ProcessLock() manager = image_uploader.ImageUploadManager(lock=lock) uploader = manager.uploader('python') - url = uploader._image_to_url(parsed_args.registry_url) + registry_url_arg = parsed_args.registry_url + if registry_url_arg is None: + registry_url_arg = image_uploader.get_undercloud_registry() + url = uploader._image_to_url(registry_url_arg) session = uploader.authenticate(url, parsed_args.username, parsed_args.password) results = uploader.list(url.geturl(), session=session)