Merge "Allow deferred undercloud push_destination detection"

This commit is contained in:
Zuul authored and Gerrit Code Review committed 2018-07-31 07:21:14 +00:00
commit 12ffda4e5b
2 files changed
+42 -3

No files matched your search

+12 -3
View File
@@ -91,6 +91,17 @@ class ImageUploadManager(BaseImageManager):
self.uploaders[uploader] = ImageUploader.get_uploader(uploader)
return self.uploaders[uploader]
def get_push_destination(self, item):
push_destination = item.get('push_destination')
if not push_destination:
return get_undercloud_registry()
# If set to True, use discovered undercloud registry
if isinstance(push_destination, bool):
return get_undercloud_registry()
return push_destination
def upload(self):
"""Start the upload process"""
@@ -104,9 +115,7 @@ class ImageUploadManager(BaseImageManager):
image_name = item.get('imagename')
uploader = item.get('uploader', 'docker')
pull_source = item.get('pull_source')
push_destination = item.get('push_destination')
if not push_destination:
push_destination = get_undercloud_registry()
push_destination = self.get_push_destination(item)
# This updates the parsed upload_images dict with real values
item['push_destination'] = push_destination
@@ -113,6 +113,36 @@ class TestImageUploadManager(base.TestCase):
image_uploader.get_undercloud_registry()
)
@mock.patch('netifaces.ifaddresses')
@mock.patch('netifaces.interfaces')
def test_get_push_destination(self, mock_interfaces, mock_addresses):
mock_interfaces.return_value = ['lo', 'eth0', 'br-ctlplane']
mock_addresses.return_value = {
2: [{'addr': '192.0.2.0'}]
}
manager = image_uploader.ImageUploadManager(self.filelist, debug=True)
self.assertEqual(
'192.0.2.0:8787',
manager.get_push_destination({})
)
self.assertEqual(
'192.0.2.1:8787',
manager.get_push_destination({'push_destination':
'192.0.2.1:8787'})
)
self.assertEqual(
'192.0.2.0:8787',
manager.get_push_destination({'push_destination': False})
)
self.assertEqual(
'192.0.2.0:8787',
manager.get_push_destination({'push_destination': True})
)
self.assertEqual(
'192.0.2.0:8787',
manager.get_push_destination({'push_destination': None})
)
class TestImageUploader(base.TestCase):