From 79b1d0b2494de10f140993cf422b9d8efd100a28 Mon Sep 17 00:00:00 2001 From: Harald Jensas Date: Fri, 16 Feb 2018 14:21:25 +0100 Subject: [PATCH] Add validation for rotued networks disabled Add a validation, if the config have multiple subnets specified but routed networks is disabled we raise validation error. Change-Id: Ic7ca1fb76e73da70f6a72100a9cbff42d8f34b0d --- instack_undercloud/tests/test_validator.py | 34 ++++++++++++++++++++++ instack_undercloud/undercloud.py | 5 ++++ 2 files changed, 39 insertions(+) diff --git a/instack_undercloud/tests/test_validator.py b/instack_undercloud/tests/test_validator.py index bd1340f84..4702e3f74 100644 --- a/instack_undercloud/tests/test_validator.py +++ b/instack_undercloud/tests/test_validator.py @@ -36,6 +36,7 @@ class TestValidator(base.BaseTestCase): cfg.StrOpt('gateway'), cfg.BoolOpt('masquerade')] self.conf.register_opts(self.opts, group=self.grp0) + self.grp1 = cfg.OptGroup(name='subnet1', title='subnet1') self.conf.config(cidr='192.168.24.0/24', dhcp_start='192.168.24.5', dhcp_end='192.168.24.24', inspection_iprange='192.168.24.100,192.168.24.120', @@ -238,3 +239,36 @@ class TestValidator(base.BaseTestCase): ipxe_enabled=True) self.assertRaises(validator.FailedValidation, undercloud._validate_architecure_options) + + @mock.patch('netifaces.interfaces') + def test_validate_routed_networks_not_enabled_pass(self, ifaces_mock): + ifaces_mock.return_value = ['eth0', 'eth1'] + self.conf.config(enable_routed_networks=False) + self.conf.config(subnets=['ctlplane-subnet']) + undercloud._validate_network() + + @mock.patch('netifaces.interfaces') + def test_validate_routed_networks_not_enabled_fail(self, ifaces_mock): + ifaces_mock.return_value = ['eth0', 'eth1'] + self.conf.config(enable_routed_networks=False) + self.conf.config(subnets=['ctlplane-subnet', 'subnet1']) + self.assertRaises(validator.FailedValidation, + undercloud._validate_network) + + @mock.patch('netifaces.interfaces') + def test_validate_routed_networks_enabled_pass(self, ifaces_mock): + ifaces_mock.return_value = ['eth0', 'eth1'] + self.conf.config(enable_routed_networks=True) + self.conf.config(subnets=['ctlplane-subnet', 'subnet1']) + self.conf.register_opts(self.opts, group=self.grp1) + self.conf.config(cidr='192.168.24.0/24', + dhcp_start='192.168.24.5', dhcp_end='192.168.24.24', + inspection_iprange='192.168.24.100,192.168.24.120', + gateway='192.168.24.1', masquerade=True, + group='ctlplane-subnet') + self.conf.config(cidr='192.168.10.0/24', dhcp_start='192.168.10.10', + dhcp_end='192.168.10.99', + inspection_iprange='192.168.10.100,192.168.10.189', + gateway='192.168.10.254', masquerade=True, + group='subnet1') + undercloud._validate_network() diff --git a/instack_undercloud/undercloud.py b/instack_undercloud/undercloud.py index d0aa8e57d..07749a959 100644 --- a/instack_undercloud/undercloud.py +++ b/instack_undercloud/undercloud.py @@ -791,6 +791,11 @@ def _validate_network(): LOG.error('Undercloud configuration validation failed: %s', message) raise validator.FailedValidation(message) + if (len(CONF.subnets) > 1 and not CONF.enable_routed_networks): + message = ('Multiple subnets specified: %s but routed networks are ' + 'not enabled.' % CONF.subnets) + error_handler(message) + params = {opt.name: CONF[opt.name] for opt in _opts} # Get parameters of "local_subnet", pass to validator to ensure parameters # such as "local_ip", "undercloud_public_host" and "undercloud_admin_host"