Fix net_config_override validations

There is an issue with the _validate_no_ip_change function
where it doesn't work correctly with a custom net_config_override
file.

This patch resolves validation issue so that custom os-net-config
templates are taken into account. Additionally it makes it so
that the net_config_override can be empty, thus providing the
user a means of disabling os-net-config if they choose to do so.

Change-Id: Iada099a6bddc7927d26b19776e705b1ac231b2e5
Depends-On: I69eb812af2d653cb3eb29694ae29b57ebb2de53d
Closes-bug: #1764507
This commit is contained in:
Dan Prince 2018-04-24 08:57:34 -04:00
parent e49688be98
commit c64a1c823e
3 changed files with 20 additions and 6 deletions

View File

@ -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)

View File

@ -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

View File

@ -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