Image Uploader - get_undercloud_registry IPv6

Adds support for IPv6 undercloud in the image uploader.
The get_undercloud_registry will look for an IPv4 address
first, then look for an IPv6 address.

If the address is an IPv6 address brackets are added.

Closes-Bug: #1836057
Change-Id: Ibc90e46ffba2b6385a4d49171761023e15e4d471
This commit is contained in:
Harald Jensås 2019-07-10 14:39:53 +02:00
parent 05460a6657
commit 460b99aefb
4 changed files with 48 additions and 16 deletions

View File

@ -37,6 +37,7 @@ from tripleo_common.image.base import BaseImageManager
from tripleo_common.image.exception import ImageNotFoundException
from tripleo_common.image.exception import ImageUploaderException
from tripleo_common.image import image_export
from tripleo_common.utils import common as common_utils
LOG = logging.getLogger(__name__)
@ -99,7 +100,10 @@ def get_undercloud_registry():
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')
elif netifaces.AF_INET6 in addrs and addrs[netifaces.AF_INET6]:
addr = addrs[netifaces.AF_INET6][0].get('addr', 'localhost')
return '%s:%s' % (common_utils.bracket_ipv6(addr), '8787')
class ImageUploadManager(BaseImageManager):

View File

@ -108,6 +108,20 @@ class TestImageUploadManager(base.TestCase):
image_uploader.get_undercloud_registry()
)
@mock.patch('netifaces.ifaddresses')
@mock.patch('netifaces.interfaces')
def test_get_undercloud_registry_ipv6(self, mock_interfaces,
mock_addresses):
mock_interfaces.return_value = ['lo', 'eth0', 'br-ctlplane']
mock_addresses.return_value = {
10: [{'addr': 'fd12:3456:789a:1::1'}]
}
self.assertEqual(
'[fd12:3456:789a:1::1]:8787',
image_uploader.get_undercloud_registry()
)
@mock.patch('netifaces.ifaddresses')
@mock.patch('netifaces.interfaces')
def test_get_push_destination(self, mock_interfaces, mock_addresses):

View File

@ -0,0 +1,27 @@
# Copyright 2019 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import socket
def bracket_ipv6(address):
"""Put a bracket around address if it is valid IPv6
Return it unchanged if it is a hostname or IPv4 address.
"""
try:
socket.inet_pton(socket.AF_INET6, address)
return "[%s]" % address
except socket.error:
return address

View File

@ -12,11 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import socket
from six.moves import urllib
from tripleo_common import constants
from tripleo_common.utils import common as common_utils
def get_service_ips(stack):
@ -49,18 +48,6 @@ def get_overcloud_endpoint(stack):
return output['output_value']
def bracket_ipv6(address):
"""Put a bracket around address if it is valid IPv6
Return it unchanged if it is a hostname or IPv4 address.
"""
try:
socket.inet_pton(socket.AF_INET6, address)
return "[%s]" % address
except socket.error:
return address
CLEAR_ENV = """# Clear any old environment that may conflict.
for key in $( set | awk '{FS=\"=\"} /^OS_/ {print $1}' ); do unset $key ; done
"""
@ -84,7 +71,7 @@ def create_overcloudrc(stack, no_proxy, admin_password, region_name):
overcloud_host = urllib.parse.urlparse(overcloud_endpoint).hostname
overcloud_admin_vip = get_endpoint('KeystoneAdmin', stack)
no_proxy_list = map(bracket_ipv6,
no_proxy_list = map(common_utils.bracket_ipv6,
[no_proxy, overcloud_host, overcloud_admin_vip])
rc_params = {