Przeglądaj źródła

Overwriting the udev rules file to include valid network interfaces

Overwriting network interface udev rules

Writing a file to overwrite the 70-persistent-net.rules if existing or adding if not existent

Removing the system udev rules overwrite in order to use only Coriolis specific file

Choosing to overwrite just the udev rules created by Coriolis as etc/udev/rules.d/99-coriolis-net.rules in order to keep the current network configuration when the deployment is done, through the reported network interface info

Changing path used for the udev rules test to match the changes

Changing the path used for the tests to check for changes in etc/udev/rules.d/99-coriolis-net.rules

Passing the entire object through the method that adds udev rules, so that we later retrieve its items

Fixing tests for new approach of how items are being retrieved for net_ifaces_info
Emilian Bogdan 3 miesięcy temu
rodzic
commit
b23f5feaf0

+ 5 - 6
coriolis/osmorphing/base.py

@@ -639,11 +639,10 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
             config_obj, execute_update_grub)
 
     def _add_net_udev_rules(self, net_ifaces_info):
-        udev_file = "etc/udev/rules.d/70-persistent-net.rules"
-        if not self._test_path(udev_file):
-            if net_ifaces_info:
-                content = utils.get_udev_net_rules(net_ifaces_info)
-                self._write_file_sudo(udev_file, content)
+        coriolis_udev_rules_file = "etc/udev/rules.d/99-coriolis-net.rules"
+        if net_ifaces_info:
+            content = utils.get_udev_net_rules(net_ifaces_info)
+            self._write_file_sudo(coriolis_udev_rules_file, content)
 
     def _setup_network_preservation(self, nics_info) -> None:
         net_ifaces_info = dict()
@@ -690,6 +689,6 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
                     "with MAC address '%s'", nic, nic_mac)
             net_ifaces_info.update(matching_ifaces)
 
-        self._add_net_udev_rules(net_ifaces_info.items())
+        self._add_net_udev_rules(net_ifaces_info)
 
         return

+ 5 - 5
coriolis/tests/osmorphing/test_base.py

@@ -1134,10 +1134,10 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_write_file_sudo')
     def test__add_net_udev_rules(self, mock_write_file_sudo, mock_test_path):
         mock_test_path.return_value = False
-        net_ifaces_info = [
-            ("eth0", "AA:BB:CC:DD:EE:FF"),
-            ("eth1", "FF:EE:DD:CC:BB:AA")
-        ]
+        net_ifaces_info = {
+            "eth0": "AA:BB:CC:DD:EE:FF",
+            "eth1": "FF:EE:DD:CC:BB:AA"
+        }
         content = (
             'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", '
             'ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="eth0"\n'
@@ -1148,7 +1148,7 @@ class BaseLinuxOSMorphingToolsTestBase(test_base.CoriolisBaseTestCase):
         self.os_morphing_tools._add_net_udev_rules(net_ifaces_info)
 
         mock_write_file_sudo.assert_called_once_with(
-            "etc/udev/rules.d/70-persistent-net.rules", content
+            "etc/udev/rules.d/99-coriolis-net.rules", content
         )
 
     @ddt.data(

+ 2 - 2
coriolis/tests/test_utils.py

@@ -102,8 +102,8 @@ class UtilsTestCase(test_base.CoriolisBaseTestCase):
         self.assertEqual(self.mock_func.call_count, 5)
 
     def test_get_udev_net_rules(self):
-        net_ifaces_info = [("eth0", "AA:BB:CC:DD:EE:FF"),
-                           ("eth1", "FF:EE:DD:CC:BB:AA")]
+        net_ifaces_info = {"eth0": "AA:BB:CC:DD:EE:FF",
+                           "eth1": "FF:EE:DD:CC:BB:AA"}
         expected_result = (
             'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", '
             'ATTR{address}=="aa:bb:cc:dd:ee:ff", '

+ 1 - 1
coriolis/utils.py

@@ -198,7 +198,7 @@ def retry_on_error(max_attempts=5, sleep_seconds=1,
 
 def get_udev_net_rules(net_ifaces_info):
     content = ""
-    for name, mac_address in net_ifaces_info:
+    for name, mac_address in net_ifaces_info.items():
         content += ('SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", '
                     'ATTR{address}=="%(mac_address)s", NAME="%(name)s"\n' %
                     {"name": name, "mac_address": mac_address.lower()})