From 3c7c10098c9aee4aa9cfa3f971621f014cfa0658 Mon Sep 17 00:00:00 2001 From: Emilian Bogdan Date: Tue, 27 Jan 2026 02:58:21 +0200 Subject: [PATCH] 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 --- coriolis/osmorphing/base.py | 11 +++++------ coriolis/tests/osmorphing/test_base.py | 10 +++++----- coriolis/tests/test_utils.py | 4 ++-- coriolis/utils.py | 2 +- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/coriolis/osmorphing/base.py b/coriolis/osmorphing/base.py index 775646809..4c3e43398 100644 --- a/coriolis/osmorphing/base.py +++ b/coriolis/osmorphing/base.py @@ -639,11 +639,10 @@ def _set_grub2_console_settings(self, consoles=None, speed=None, 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 @@ def _setup_network_preservation(self, nics_info) -> None: "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 diff --git a/coriolis/tests/osmorphing/test_base.py b/coriolis/tests/osmorphing/test_base.py index af4dd1f09..c32fa3fcf 100644 --- a/coriolis/tests/osmorphing/test_base.py +++ b/coriolis/tests/osmorphing/test_base.py @@ -1134,10 +1134,10 @@ def test__set_grub2_console_settings_default_params( @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 @@ def test__add_net_udev_rules(self, mock_write_file_sudo, mock_test_path): 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( diff --git a/coriolis/tests/test_utils.py b/coriolis/tests/test_utils.py index 26a319782..5576ad259 100644 --- a/coriolis/tests/test_utils.py +++ b/coriolis/tests/test_utils.py @@ -102,8 +102,8 @@ def test_retry_on_error_exception_retry_max_attempts(self): 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", ' diff --git a/coriolis/utils.py b/coriolis/utils.py index 097ce52e4..4f82aaf3e 100644 --- a/coriolis/utils.py +++ b/coriolis/utils.py @@ -198,7 +198,7 @@ def _exec_retry(*args, **kwargs): 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()})