diff --git a/netplan_cli/cli/state.py b/netplan_cli/cli/state.py index b1370bbe3..e3ebfc35f 100644 --- a/netplan_cli/cli/state.py +++ b/netplan_cli/cli/state.py @@ -348,6 +348,8 @@ def vendor(self) -> str: @property def ssid(self) -> str: if self.type == 'wifi': + if self.backend == "NetworkManager": + return self.query_nm_ssid(self.nm.get('name', '')) # XXX: available from networkctl's JSON output as of v250: # https://github.com/systemd/systemd/commit/da7c995 # TODO: Retrieving the SSID from systemd seems to not be reliable. diff --git a/tests/cli/test_state.py b/tests/cli/test_state.py index 7d0e6172e..699227f7b 100644 --- a/tests/cli/test_state.py +++ b/tests/cli/test_state.py @@ -440,7 +440,7 @@ def test_json_nm_wlan0_2(self, networkctl_mock, nm_ssid_mock): @patch('netplan_cli.cli.state.Interface.query_nm_ssid') @patch('netplan_cli.cli.state.Interface.query_networkctl') - def test_json_nm_wlan1_non_ascii(self, networkctl_mock, nm_ssid_mock): + def test_json_nd_wlan1_non_ascii(self, networkctl_mock, nm_ssid_mock): ND_SSID = '\\303\\241\\303\\251\\303\\255\\303\\263\\303\\272\\302\\242\\302\\242\\302\\242\\302\\243\\302\\243\\302\\243' NM_SSID = 'áéíóú¢¢¢£££' nm_ssid_mock.return_value = NM_SSID @@ -451,7 +451,21 @@ def test_json_nm_wlan1_non_ascii(self, networkctl_mock, nm_ssid_mock): 'Wi-Fi access point: {} (b4:fb:e4:75:c6:21)'.format(ND_SSID) data = {'ifname': 'wlan1', 'ifindex': 123} - nd = [{'Index': 123, 'Type': 'wlan', 'Name': 'wlan1'}] + nd = [{'Index': 123, 'Type': 'wlan', 'Name': 'wlan1', 'SetupState': 'managed', + 'NetworkFile': '/run/systemd/network/10-netplan-wlan1.network'}] + nm = SystemConfigState.process_nm(NMCLI) + + itf = Interface(data, nd, nm, (None, None), (None, None)) + _, json = itf.json() + self.assertEqual(json.get('ssid'), NM_SSID) + + @patch('netplan_cli.cli.state.Interface.query_nm_ssid') + def test_json_nm_wlan1_non_ascii(self, nm_ssid_mock): + NM_SSID = 'áéíóú¢¢¢£££' + nm_ssid_mock.return_value = NM_SSID + + data = {'ifname': 'wlan1', 'ifindex': 123} + nd = [{'Index': 123, 'Type': 'wlan', 'Name': 'wlan1', 'SetupState': 'unmanaged'}] nm = SystemConfigState.process_nm(NMCLI) itf = Interface(data, nd, nm, (None, None), (None, None))