Allow pushing docker images to host's ctl plane IP
This commit allows image uploader config file with missing 'push_destination' attributes. In which case, the host's control plane (br-ctlplane) IP address with port 8787 is used or localhost if there is no such interface. Change-Id: Idfe18f25ddee944ef96ab14f8edeb056656a06bc
This commit is contained in:
parent
80859a9349
commit
f2b1950c52
|
@ -17,3 +17,4 @@ python-ironic-inspector-client>=1.5.0 # Apache-2.0
|
|||
Jinja2!=2.9.0,!=2.9.1,!=2.9.2,!=2.9.3,!=2.9.4,>=2.8 # BSD License (3 clause)
|
||||
python-novaclient!=7.0.0,>=6.0.0 # Apache-2.0
|
||||
passlib>=1.7.0 # BSD
|
||||
netifaces>=0.10.4 # MIT
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
import abc
|
||||
import logging
|
||||
import netifaces
|
||||
import six
|
||||
|
||||
from docker import Client
|
||||
|
@ -40,12 +41,17 @@ class ImageUploadManager(BaseImageManager):
|
|||
self.logger.info('Using config files: %s' % self.config_files)
|
||||
|
||||
upload_images = self.load_config_files(self.CONFIG_SECTIONS[1])
|
||||
default_push_destination = self.get_ctrl_plane_ip() + ':8787'
|
||||
|
||||
for item in upload_images:
|
||||
image_name = item.get('imagename')
|
||||
uploader = item.get('uploader')
|
||||
pull_source = item.get('pull_source')
|
||||
push_destination = item.get('push_destination')
|
||||
push_destination = item.get('push_destination',
|
||||
default_push_destination)
|
||||
|
||||
# This updates the parsed upload_images dict with real values
|
||||
item['push_destination'] = push_destination
|
||||
|
||||
self.logger.info('imagename: %s' % image_name)
|
||||
|
||||
|
@ -54,6 +60,14 @@ 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):
|
||||
|
|
|
@ -39,7 +39,6 @@ filedata = six.u(
|
|||
- imagename: tripleoupstream/centos-binary-nova-libvirt:liberty
|
||||
uploader: docker
|
||||
pull_source: docker.io
|
||||
push_destination: localhost:8787
|
||||
""")
|
||||
|
||||
|
||||
|
@ -53,8 +52,9 @@ class TestImageUploadManager(base.TestCase):
|
|||
@mock.patch('tripleo_common.image.base.open',
|
||||
mock.mock_open(read_data=filedata), create=True)
|
||||
@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, mockpath, mockdocker):
|
||||
def test_file_parsing(self, mockpath, mockioctl, mockdocker):
|
||||
print(filedata)
|
||||
manager = ImageUploadManager(self.filelist, debug=True)
|
||||
parsed_data = manager.upload()
|
||||
|
@ -65,7 +65,7 @@ class TestImageUploadManager(base.TestCase):
|
|||
key=operator.itemgetter('imagename'))
|
||||
sorted_parsed_data = sorted(parsed_data,
|
||||
key=operator.itemgetter('imagename'))
|
||||
self.assertEqual(sorted_parsed_data, sorted_expected_data)
|
||||
self.assertEqual(sorted_expected_data, sorted_parsed_data)
|
||||
|
||||
|
||||
class TestImageUploader(base.TestCase):
|
||||
|
|
Loading…
Reference in New Issue