瀏覽代碼

Get nmconnection name by interface-name first

Cristian Matiut 1 月之前
父節點
當前提交
b7098ed67e

+ 2 - 1
coriolis/osmorphing/netpreserver/nmconnection.py

@@ -33,10 +33,11 @@ class NmconnectionNetPreserver(base.BaseNetPreserver):
             "ethernet", self.nmconnection_file)
         if nmconnection_ethernet:
             for nmconn_file, nmconn in nmconnection_ethernet:
-                name = nmconn.get("connection", {}).get("id")
+                name = nmconn.get("interface-name", nmconn.get("id"))
                 if not name:
                     name = re.match(r"^.*/(.*)\.nmconnection$",
                                     nmconn_file).groups()[0]
+                name = name.replace(" ", "_")
                 mac_address = nmconn.get("mac-address")
                 self.interface_info[name] = {
                     "mac_address": mac_address,

+ 29 - 7
coriolis/tests/osmorphing/netpreserver/test_nmconnection.py

@@ -101,7 +101,7 @@ class NmconnectionNetPreserverTestCase(test_base.CoriolisBaseTestCase):
             self.netpreserver.nmconnection_file + "/eth0.nmconnection"
         )
         nmconn_with_id = {
-            "connection": {"id": "eth0"},
+            "id": "eth0",
             "mac-address": "00:11:22:33:44:55",
             "address1": "192.168.1.10/24"
         }
@@ -116,21 +116,35 @@ class NmconnectionNetPreserverTestCase(test_base.CoriolisBaseTestCase):
             self.netpreserver.nmconnection_file + "/eth2.nmconnection"
         )
         nmconn_without_mac_address = {
-            "connection": {"id": "eth2"},
+            "id": "eth2",
             "address1": "192.168.1.30/24",
         }
         nmconn_file_without_mac_address_ip_address = (
             self.netpreserver.nmconnection_file + "/eth3.nmconnection"
         )
         nmconn_without_mac_address_ip_address = {
-            "connection": {"id": "eth3"},
+            "id": "id_eth3",
+            "address": "192.168.1.40/24",
+        }
+        nmconn_file_with_space = (
+            self.netpreserver.nmconnection_file + "/System ethx.nmconnection"
+        )
+        nmconn_without_mac_address_and_id = {
+            "address1": "192.168.1.50/24",
+        }
+        nmconn_with_interface_name = {
+            "interface-name": "eth4",
+            "id": "id_eth4",
+            "address": "192.168.1.60/24",
         }
         mock_get_keyfiles_by_type.return_value = [
             (nmconn_file_with_id, nmconn_with_id),
             (nmconn_file_without_id, nmconn_without_id),
             (nmconn_file_without_mac_address, nmconn_without_mac_address),
             (nmconn_file_without_mac_address_ip_address,
-             nmconn_without_mac_address_ip_address)
+             nmconn_without_mac_address_ip_address),
+            (nmconn_file_with_space, nmconn_without_mac_address_and_id),
+            (nmconn_file_with_space, nmconn_with_interface_name)
         ]
 
         self.netpreserver.interface_info = {}
@@ -150,10 +164,18 @@ class NmconnectionNetPreserverTestCase(test_base.CoriolisBaseTestCase):
                 "mac_address": None,
                 "ip_addresses": ["192.168.1.30"]
             },
-            "eth3": {
+            "id_eth3": {
+                "mac_address": None,
+                "ip_addresses": ["192.168.1.40"]
+            },
+            "System_ethx": {
+                "mac_address": None,
+                "ip_addresses": ["192.168.1.50"]
+            },
+            "eth4": {
                 "mac_address": None,
-                "ip_addresses": []
+                "ip_addresses": ["192.168.1.60"]
             }
         }
 
-        self.assertEqual(self.netpreserver.interface_info, expected_info)
+        self.assertEqual(expected_info, self.netpreserver.interface_info)