Skip to content

Commit 232fe9e

Browse files
committed
Get nmconnection name by interface-name first
1 parent dae596f commit 232fe9e

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

coriolis/osmorphing/netpreserver/nmconnection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ def parse_network(self):
3333
"ethernet", self.nmconnection_file)
3434
if nmconnection_ethernet:
3535
for nmconn_file, nmconn in nmconnection_ethernet:
36-
name = nmconn.get("connection", {}).get("id")
36+
name = nmconn.get("interface-name", nmconn.get("id"))
3737
if not name:
3838
name = re.match(r"^.*/(.*)\.nmconnection$",
3939
nmconn_file).groups()[0]
40+
name = name.replace(" ", "_")
4041
mac_address = nmconn.get("mac-address")
4142
self.interface_info[name] = {
4243
"mac_address": mac_address,

coriolis/tests/osmorphing/netpreserver/test_nmconnection.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_parse_network(self, mock_get_keyfiles_by_type):
101101
self.netpreserver.nmconnection_file + "/eth0.nmconnection"
102102
)
103103
nmconn_with_id = {
104-
"connection": {"id": "eth0"},
104+
"id": "eth0",
105105
"mac-address": "00:11:22:33:44:55",
106106
"address1": "192.168.1.10/24"
107107
}
@@ -116,21 +116,35 @@ def test_parse_network(self, mock_get_keyfiles_by_type):
116116
self.netpreserver.nmconnection_file + "/eth2.nmconnection"
117117
)
118118
nmconn_without_mac_address = {
119-
"connection": {"id": "eth2"},
119+
"id": "eth2",
120120
"address1": "192.168.1.30/24",
121121
}
122122
nmconn_file_without_mac_address_ip_address = (
123123
self.netpreserver.nmconnection_file + "/eth3.nmconnection"
124124
)
125125
nmconn_without_mac_address_ip_address = {
126-
"connection": {"id": "eth3"},
126+
"id": "id_eth3",
127+
"address": "192.168.1.40/24",
128+
}
129+
nmconn_file_with_space = (
130+
self.netpreserver.nmconnection_file + "/System ethx.nmconnection"
131+
)
132+
nmconn_without_mac_address_and_id = {
133+
"address1": "192.168.1.50/24",
134+
}
135+
nmconn_with_interface_name = {
136+
"interface-name": "eth4",
137+
"id": "id_eth4",
138+
"address": "192.168.1.60/24",
127139
}
128140
mock_get_keyfiles_by_type.return_value = [
129141
(nmconn_file_with_id, nmconn_with_id),
130142
(nmconn_file_without_id, nmconn_without_id),
131143
(nmconn_file_without_mac_address, nmconn_without_mac_address),
132144
(nmconn_file_without_mac_address_ip_address,
133-
nmconn_without_mac_address_ip_address)
145+
nmconn_without_mac_address_ip_address),
146+
(nmconn_file_with_space, nmconn_without_mac_address_and_id),
147+
(nmconn_file_with_space, nmconn_with_interface_name)
134148
]
135149

136150
self.netpreserver.interface_info = {}
@@ -150,10 +164,18 @@ def test_parse_network(self, mock_get_keyfiles_by_type):
150164
"mac_address": None,
151165
"ip_addresses": ["192.168.1.30"]
152166
},
153-
"eth3": {
167+
"id_eth3": {
168+
"mac_address": None,
169+
"ip_addresses": ["192.168.1.40"]
170+
},
171+
"System_ethx": {
172+
"mac_address": None,
173+
"ip_addresses": ["192.168.1.50"]
174+
},
175+
"eth4": {
154176
"mac_address": None,
155-
"ip_addresses": []
177+
"ip_addresses": ["192.168.1.60"]
156178
}
157179
}
158180

159-
self.assertEqual(self.netpreserver.interface_info, expected_info)
181+
self.assertEqual(expected_info, self.netpreserver.interface_info)

0 commit comments

Comments
 (0)