Break out function get_undercloud_registry
This is useful outside doing actual image uploads, so get_undercloud_registry is now a standalone function with some unit testing. Change-Id: Ida47d14530d3ed86c30929d62f29e3c13b040178 Blueprint: container-prepare-workflow
This commit is contained in:
parent
3651884d8b
commit
ca06bedb41
@ -45,6 +45,15 @@ SECURE_REGISTRIES = (
|
||||
)
|
||||
|
||||
|
||||
def get_undercloud_registry():
|
||||
addr = 'localhost'
|
||||
if 'br-ctlplane' in netifaces.interfaces():
|
||||
addrs = netifaces.ifaddresses('br-ctlplane')
|
||||
if netifaces.AF_INET in addrs and addrs[netifaces.AF_INET]:
|
||||
addr = addrs[netifaces.AF_INET][0].get('addr', 'localhost')
|
||||
return '%s:%s' % (addr, '8787')
|
||||
|
||||
|
||||
class ImageUploadManager(BaseImageManager):
|
||||
"""Manage the uploading of image files
|
||||
|
||||
@ -76,14 +85,14 @@ class ImageUploadManager(BaseImageManager):
|
||||
uploads = self.load_config_files(self.UPLOADS) or []
|
||||
container_images = self.load_config_files(self.CONTAINER_IMAGES) or []
|
||||
upload_images = uploads + container_images
|
||||
default_push_destination = self.get_ctrl_plane_ip() + ':8787'
|
||||
|
||||
for item in upload_images:
|
||||
image_name = item.get('imagename')
|
||||
uploader = item.get('uploader', 'docker')
|
||||
pull_source = item.get('pull_source')
|
||||
push_destination = item.get('push_destination',
|
||||
default_push_destination)
|
||||
push_destination = item.get('push_destination')
|
||||
if not push_destination:
|
||||
push_destination = get_undercloud_registry()
|
||||
|
||||
# This updates the parsed upload_images dict with real values
|
||||
item['push_destination'] = push_destination
|
||||
@ -96,14 +105,6 @@ class ImageUploadManager(BaseImageManager):
|
||||
|
||||
return upload_images # simply to make test validation easier
|
||||
|
||||
def get_ctrl_plane_ip(self):
|
||||
addr = 'localhost'
|
||||
if 'br-ctlplane' in netifaces.interfaces():
|
||||
addrs = netifaces.ifaddresses('br-ctlplane')
|
||||
if netifaces.AF_INET in addrs and addrs[netifaces.AF_INET]:
|
||||
addr = addrs[netifaces.AF_INET][0].get('addr', 'localhost')
|
||||
return addr
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ImageUploader(object):
|
||||
|
@ -37,7 +37,7 @@ def create_parsed_upload_images():
|
||||
'push_destination': 'localhost:8787'},
|
||||
{'imagename': 'docker.io/tripleomaster/'
|
||||
'centos-binary-nova-libvirt:liberty',
|
||||
'push_destination': 'localhost:8787'},
|
||||
'push_destination': '192.0.2.0:8787'},
|
||||
{'imagename': 'docker.io/tripleomaster/'
|
||||
'image-with-missing-tag',
|
||||
'push_destination': 'localhost:8787'},
|
||||
|
@ -56,8 +56,11 @@ class TestImageUploadManager(base.TestCase):
|
||||
@mock.patch('os.path.isfile', return_value=True)
|
||||
@mock.patch('fcntl.ioctl', side_effect=Exception)
|
||||
@mock.patch('tripleo_common.image.image_uploader.Client')
|
||||
def test_file_parsing(self, mockdocker, mockioctl, mockpath,
|
||||
@mock.patch('tripleo_common.image.image_uploader.'
|
||||
'get_undercloud_registry', return_value='192.0.2.0:8787')
|
||||
def test_file_parsing(self, mock_gur, mockdocker, mockioctl, mockpath,
|
||||
mock_images_match, mock_is_insecure):
|
||||
|
||||
manager = image_uploader.ImageUploadManager(self.filelist, debug=True)
|
||||
parsed_data = manager.upload()
|
||||
mockpath(self.filelist[0])
|
||||
@ -71,6 +74,8 @@ class TestImageUploadManager(base.TestCase):
|
||||
|
||||
dockerc = mockdocker.return_value
|
||||
dockerc.remove_image.assert_has_calls([
|
||||
mock.call('192.0.2.0:8787/tripleomaster'
|
||||
'/centos-binary-nova-libvirt:liberty'),
|
||||
mock.call('docker.io/tripleomaster'
|
||||
'/centos-binary-nova-compute:liberty'),
|
||||
mock.call('docker.io/tripleomaster'
|
||||
@ -82,14 +87,30 @@ class TestImageUploadManager(base.TestCase):
|
||||
|
||||
mock.call('localhost:8787/tripleomaster'
|
||||
'/centos-binary-nova-compute:liberty'),
|
||||
mock.call('localhost:8787/tripleomaster'
|
||||
'/centos-binary-nova-libvirt:liberty'),
|
||||
mock.call('localhost:8787/tripleomaster'
|
||||
'/heat-docker-agents-centos:latest'),
|
||||
mock.call('localhost:8787/tripleomaster/'
|
||||
'image-with-missing-tag:latest'),
|
||||
])
|
||||
|
||||
@mock.patch('netifaces.ifaddresses')
|
||||
@mock.patch('netifaces.interfaces')
|
||||
def test_get_undercloud_registry(self, mock_interfaces, mock_addresses):
|
||||
mock_interfaces.return_value = ['lo', 'eth0']
|
||||
self.assertEqual(
|
||||
'localhost:8787',
|
||||
image_uploader.get_undercloud_registry()
|
||||
)
|
||||
|
||||
mock_interfaces.return_value = ['lo', 'eth0', 'br-ctlplane']
|
||||
mock_addresses.return_value = {
|
||||
2: [{'addr': '192.0.2.0'}]
|
||||
}
|
||||
self.assertEqual(
|
||||
'192.0.2.0:8787',
|
||||
image_uploader.get_undercloud_registry()
|
||||
)
|
||||
|
||||
|
||||
class TestImageUploader(base.TestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user