Browse Source

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
Dan Prince 1 year ago
parent
commit
c64a1c823e

+ 9
- 0
instack_undercloud/tests/test_undercloud.py View File

@@ -379,6 +379,15 @@ class TestNoIPChange(BaseTestCase):
379 379
         mock_loads.return_value = mock_config
380 380
         undercloud._validate_no_ip_change()
381 381
 
382
+    @mock.patch('instack_undercloud.undercloud.open')
383
+    @mock.patch('os.path.isfile', return_value=True)
384
+    def test_update_empty(self, mock_isfile, mock_open):
385
+        # This would be a way to disable os-net-config from running
386
+        mock_open.side_effect = [
387
+            mock.mock_open(read_data='').return_value,
388
+        ]
389
+        undercloud._validate_no_ip_change()
390
+
382 391
     @mock.patch('instack_undercloud.undercloud.open')
383 392
     @mock.patch('json.loads')
384 393
     @mock.patch('os.path.isfile', return_value=True)

+ 9
- 3
instack_undercloud/undercloud.py View File

@@ -818,16 +818,22 @@ def _validate_no_ip_change():
818 818
     need to disallow it early in the install before configurations start to
819 819
     be changed.
820 820
     """
821
-    os_net_config_file = '/etc/os-net-config/config.json'
821
+    if CONF.net_config_override:
822
+        os_net_config_file = CONF.net_config_override
823
+    else:
824
+        os_net_config_file = '/etc/os-net-config/config.json'
822 825
     # Nothing to do if we haven't already installed
823 826
     if not os.path.isfile(
824 827
             os.path.expanduser(os_net_config_file)):
825 828
         return
826
-    with open(os_net_config_file) as f:
827
-        network_config = json.loads(f.read())
828 829
     try:
830
+        with open(os_net_config_file) as f:
831
+            network_config = json.loads(f.read())
829 832
         ctlplane = [i for i in network_config.get('network_config', [])
830 833
                     if i['name'] == 'br-ctlplane'][0]
834
+    except ValueError:
835
+        # File was empty
836
+        return
831 837
     except IndexError:
832 838
         # Nothing to check if br-ctlplane wasn't configured
833 839
         return

+ 2
- 3
undercloud.conf.sample View File

@@ -120,9 +120,8 @@
120 120
 
121 121
 # Path to network config override template. If set, this template will
122 122
 # be used to configure the networking via os-net-config. Must be in
123
-# json format. Templated tags can be used within the template, see
124
-# instack-undercloud/elements/undercloud-stack-config/net-
125
-# config.json.template for example tags (string value)
123
+# json format. If you wish to disable os-net-config you can use an
124
+# set this location to point to an empty file.
126 125
 #net_config_override =
127 126
 
128 127
 # Network interface on which inspection dnsmasq will listen.  If in

Loading…
Cancel
Save