Skip to content

Commit ff65879

Browse files
committed
state: get the SSID from NM if it's the backend
networkctl might return "(null)" as the SSID value. Use Network Manager to get the SSID when it's the backend.
1 parent 54d59d1 commit ff65879

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

netplan_cli/cli/state.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ def vendor(self) -> str:
349349
@property
350350
def ssid(self) -> str:
351351
if self.type == 'wifi':
352+
if self.backend == "NetworkManager":
353+
return self.query_nm_ssid(self.nm.get('name', ''))
352354
# XXX: available from networkctl's JSON output as of v250:
353355
# https://github.com/systemd/systemd/commit/da7c995
354356
# TODO: Retrieving the SSID from systemd seems to not be reliable.

tests/cli/test_state.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def test_json_nm_wlan0_2(self, networkctl_mock, nm_ssid_mock):
440440

441441
@patch('netplan_cli.cli.state.Interface.query_nm_ssid')
442442
@patch('netplan_cli.cli.state.Interface.query_networkctl')
443-
def test_json_nm_wlan1_non_ascii(self, networkctl_mock, nm_ssid_mock):
443+
def test_json_nd_wlan1_non_ascii(self, networkctl_mock, nm_ssid_mock):
444444
ND_SSID = '\\303\\241\\303\\251\\303\\255\\303\\263\\303\\272\\302\\242\\302\\242\\302\\242\\302\\243\\302\\243\\302\\243'
445445
NM_SSID = 'áéíóú¢¢¢£££'
446446
nm_ssid_mock.return_value = NM_SSID
@@ -451,7 +451,21 @@ def test_json_nm_wlan1_non_ascii(self, networkctl_mock, nm_ssid_mock):
451451
'Wi-Fi access point: {} (b4:fb:e4:75:c6:21)'.format(ND_SSID)
452452

453453
data = {'ifname': 'wlan1', 'ifindex': 123}
454-
nd = [{'Index': 123, 'Type': 'wlan', 'Name': 'wlan1'}]
454+
nd = [{'Index': 123, 'Type': 'wlan', 'Name': 'wlan1', 'SetupState': 'managed',
455+
'NetworkFile': '/run/systemd/network/10-netplan-wlan1.network'}]
456+
nm = SystemConfigState.process_nm(NMCLI)
457+
458+
itf = Interface(data, nd, nm, (None, None), (None, None))
459+
_, json = itf.json()
460+
self.assertEqual(json.get('ssid'), NM_SSID)
461+
462+
@patch('netplan_cli.cli.state.Interface.query_nm_ssid')
463+
def test_json_nm_wlan1_non_ascii(self, nm_ssid_mock):
464+
NM_SSID = 'áéíóú¢¢¢£££'
465+
nm_ssid_mock.return_value = NM_SSID
466+
467+
data = {'ifname': 'wlan1', 'ifindex': 123}
468+
nd = [{'Index': 123, 'Type': 'wlan', 'Name': 'wlan1', 'SetupState': 'unmanaged'}]
455469
nm = SystemConfigState.process_nm(NMCLI)
456470

457471
itf = Interface(data, nd, nm, (None, None), (None, None))

0 commit comments

Comments
 (0)