diff --git a/instack_undercloud/tests/test_undercloud.py b/instack_undercloud/tests/test_undercloud.py index 652f31116..f163c41f6 100644 --- a/instack_undercloud/tests/test_undercloud.py +++ b/instack_undercloud/tests/test_undercloud.py @@ -379,6 +379,15 @@ class TestNoIPChange(BaseTestCase): mock_loads.return_value = mock_config undercloud._validate_no_ip_change() + @mock.patch('instack_undercloud.undercloud.open') + @mock.patch('os.path.isfile', return_value=True) + def test_update_empty(self, mock_isfile, mock_open): + # This would be a way to disable os-net-config from running + mock_open.side_effect = [ + mock.mock_open(read_data='').return_value, + ] + undercloud._validate_no_ip_change() + @mock.patch('instack_undercloud.undercloud.open') @mock.patch('json.loads') @mock.patch('os.path.isfile', return_value=True) diff --git a/instack_undercloud/undercloud.py b/instack_undercloud/undercloud.py index 44da8606a..aad700661 100644 --- a/instack_undercloud/undercloud.py +++ b/instack_undercloud/undercloud.py @@ -818,16 +818,22 @@ def _validate_no_ip_change(): need to disallow it early in the install before configurations start to be changed. """ - os_net_config_file = '/etc/os-net-config/config.json' + if CONF.net_config_override: + os_net_config_file = CONF.net_config_override + else: + os_net_config_file = '/etc/os-net-config/config.json' # Nothing to do if we haven't already installed if not os.path.isfile( os.path.expanduser(os_net_config_file)): return - with open(os_net_config_file) as f: - network_config = json.loads(f.read()) try: + with open(os_net_config_file) as f: + network_config = json.loads(f.read()) ctlplane = [i for i in network_config.get('network_config', []) if i['name'] == 'br-ctlplane'][0] + except ValueError: + # File was empty + return except IndexError: # Nothing to check if br-ctlplane wasn't configured return diff --git a/undercloud.conf.sample b/undercloud.conf.sample index 78a3aae72..969674610 100644 --- a/undercloud.conf.sample +++ b/undercloud.conf.sample @@ -120,9 +120,8 @@ # Path to network config override template. If set, this template will # be used to configure the networking via os-net-config. Must be in -# json format. Templated tags can be used within the template, see -# instack-undercloud/elements/undercloud-stack-config/net- -# config.json.template for example tags (string value) +# json format. If you wish to disable os-net-config you can use an +# set this location to point to an empty file. #net_config_override = # Network interface on which inspection dnsmasq will listen. If in