From 00fe507ed61a664ba5d2d8bc7275221d8a66ec68 Mon Sep 17 00:00:00 2001 From: Brendan Date: Mon, 10 Jun 2019 16:52:25 +1000 Subject: [PATCH] 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 (cherry picked from commit 2600260be5ad99da36775e470758591d8fcd2ca9) --- .../tests/v1/undercloud/test_config.py | 38 +++++++++++++++++++ tripleoclient/v1/undercloud_config.py | 15 ++++++++ 2 files changed, 53 insertions(+) diff --git a/tripleoclient/tests/v1/undercloud/test_config.py b/tripleoclient/tests/v1/undercloud/test_config.py index b4d1f9d1f..8f994db1c 100644 --- a/tripleoclient/tests/v1/undercloud/test_config.py +++ b/tripleoclient/tests/v1/undercloud/test_config.py @@ -189,6 +189,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', diff --git a/tripleoclient/v1/undercloud_config.py b/tripleoclient/v1/undercloud_config.py index dfb2468b8..8cdb37085 100644 --- a/tripleoclient/v1/undercloud_config.py +++ b/tripleoclient/v1/undercloud_config.py @@ -349,6 +349,21 @@ def _process_network_args(env): 'nameservers.') env['DnsServers'] = ','.join(CONF['undercloud_nameservers']) + # 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,