Ensure no duplicate IPs are used in undercloud.conf

If duplicate IPs are used in undercloud.conf it will cause
issues with haproxy.

Closes-Bug: #1832168
Change-Id: I35547080aee943438d34b2d62632795af32f8462
This commit is contained in:
Brendan 2019-06-10 16:52:25 +10:00 committed by Takashi Kajinami
parent 880cdbf9f9
commit 2600260be5
2 changed files with 53 additions and 0 deletions

View File

@ -230,6 +230,44 @@ class TestNetworkSettings(base.TestCase):
undercloud_config._process_network_args,
env)
def test_undercloud_ips_duplicated_fail(self):
env = {}
# local_ip == undercloud_admin_host
self.conf.config(local_ip='192.168.24.1/24',
undercloud_admin_host='192.168.24.1',
undercloud_public_host='192.168.24.2',
generate_service_certificate=True)
self.assertRaises(exceptions.InvalidConfiguration,
undercloud_config._process_network_args,
env)
# local_ip == undercloud_public_host
self.conf.config(local_ip='192.168.24.1/24',
undercloud_admin_host='192.168.24.3',
undercloud_public_host='192.168.24.1',
generate_service_certificate=True)
self.assertRaises(exceptions.InvalidConfiguration,
undercloud_config._process_network_args,
env)
# undercloud_admin_host == undercloud_public_host
self.conf.config(local_ip='192.168.24.1/24',
undercloud_admin_host='192.168.24.2',
undercloud_public_host='192.168.24.2',
generate_service_certificate=True)
self.assertRaises(exceptions.InvalidConfiguration,
undercloud_config._process_network_args,
env)
# We do not care about ip duplication when ssl is disabled
self.conf.config(local_ip='192.168.24.1/24',
undercloud_admin_host='192.168.24.1',
undercloud_public_host='192.168.24.2',
generate_service_certificate=False,
undercloud_service_certificate='')
undercloud_config._process_network_args(env)
def test_start_end_all_addresses(self):
self.conf.config(dhcp_start='192.168.24.0',
dhcp_end='192.168.24.255',

View File

@ -359,6 +359,21 @@ def _process_network_args(env):
env['RedisIPv6'] = True
env['MysqlIPv6'] = True
# We do not use undercloud ips for env, but just validate the configured
# value here.
if (CONF.get('generate_service_certificate') or
CONF.get('undercloud_service_certificate')):
undercloud_ips = [
CONF.local_ip.split('/')[0],
CONF.undercloud_admin_host,
CONF.undercloud_public_host
]
if len(undercloud_ips) != len(set(undercloud_ips)):
msg = ("The same IP is used for multiple endpoints. Please use "
"unique ips for local_ip, undercloud_admin_host and "
"undercloud_public_host")
raise exceptions.InvalidConfiguration(msg)
def prepare_undercloud_deploy(upgrade=False, no_validations=False,
verbose_level=1, yes=False,