Skip to content

Commit 5f74208

Browse files
daniloegeaslyon
authored andcommitted
state_diff: add more information to the missing_interfaces result
For netplan interfaces add the name and type. For system interfaces add the name, type and index.
1 parent 2531d16 commit 5f74208

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

netplan_cli/cli/state_diff.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,22 @@ def _analyze_missing_interfaces(self, report: dict) -> None:
326326
if iface.netdef_id not in netplan_interfaces:
327327
system_only.append(iface.name)
328328

329-
report['missing_interfaces_system'] = sorted(netplan_only)
330-
report['missing_interfaces_netplan'] = sorted(system_only)
329+
netplan_only = sorted(netplan_only)
330+
system_only = sorted(system_only)
331+
332+
system_state = self.system_state.get_data()
333+
334+
for iface in netplan_only:
335+
iface_type = self.netplan_state.netdefs.get(iface).type
336+
report['missing_interfaces_system'][iface] = {
337+
'type': DEVICE_TYPES.get(iface_type, 'unknown')
338+
}
339+
340+
for iface in system_only:
341+
report['missing_interfaces_netplan'][iface] = {
342+
'type': system_state.get(iface).get('type', 'unknown'),
343+
'index': system_state.get(iface).get('index'),
344+
}
331345

332346
def _normalize_routes(self, routes: set) -> set:
333347
''' Apply some transformations to Netplan routes so their representation

tests/cli/test_state_diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ def test_diff_not_missing_system_interface_with_match(self):
462462

463463
diff = NetplanDiffState(system_state, netplan_state)
464464
diff_data = diff.get_diff()
465-
missing = diff_data.get('missing_interfaces_system', [])
466-
self.assertListEqual(missing, [])
465+
missing = diff_data.get('missing_interfaces_system', {})
466+
self.assertDictEqual(missing, {})
467467

468468
def test__get_comparable_interfaces_empty(self):
469469
res = self.diff_state._get_comparable_interfaces({})

0 commit comments

Comments
 (0)