Merge pull request #1789 from ogayot/netdev-deleted
network: fix crash when Wi-Fi or eth interface gets removed from the system
This commit is contained in:
commit
16688c56c4
|
@ -209,7 +209,12 @@ class NetworkDev:
|
||||||
|
|
||||||
def netdev_info(self) -> NetDevInfo:
|
def netdev_info(self) -> NetDevInfo:
|
||||||
if self.type == "eth":
|
if self.type == "eth":
|
||||||
is_connected = bool(self.info.is_connected)
|
if self.info is not None:
|
||||||
|
is_connected = bool(self.info.is_connected)
|
||||||
|
else:
|
||||||
|
# If the device has just disappeared, let's pretend it's not
|
||||||
|
# connected.
|
||||||
|
is_connected = False
|
||||||
else:
|
else:
|
||||||
is_connected = True
|
is_connected = True
|
||||||
bond_master = None
|
bond_master = None
|
||||||
|
@ -234,10 +239,17 @@ class NetworkDev:
|
||||||
wlan: Optional[WLANStatus] = None
|
wlan: Optional[WLANStatus] = None
|
||||||
if self.type == "wlan":
|
if self.type == "wlan":
|
||||||
ssid, psk = self.configured_ssid
|
ssid, psk = self.configured_ssid
|
||||||
|
# If the device has just disappeared, let's pretend it's not
|
||||||
|
# scanning and has no visible SSID.
|
||||||
|
scan_state = None
|
||||||
|
visible_ssids: List[str] = []
|
||||||
|
if self.info is not None:
|
||||||
|
scan_state = self.info.wlan["scan_state"]
|
||||||
|
visible_ssids = self.info.wlan["visible_ssids"]
|
||||||
wlan = WLANStatus(
|
wlan = WLANStatus(
|
||||||
config=WLANConfig(ssid=ssid, psk=psk),
|
config=WLANConfig(ssid=ssid, psk=psk),
|
||||||
scan_state=self.info.wlan["scan_state"],
|
scan_state=scan_state,
|
||||||
visible_ssids=self.info.wlan["visible_ssids"],
|
visible_ssids=visible_ssids,
|
||||||
)
|
)
|
||||||
|
|
||||||
dhcp_addresses = self.dhcp_addresses()
|
dhcp_addresses = self.dhcp_addresses()
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
from subiquitycore.models.network import NetworkDev
|
from subiquitycore.models.network import NetworkDev
|
||||||
from subiquitycore.tests import SubiTestCase
|
from subiquitycore.tests import SubiTestCase
|
||||||
|
|
||||||
|
@ -39,3 +41,26 @@ class TestRouteManagement(SubiTestCase):
|
||||||
self.nd.remove_routes(6)
|
self.nd.remove_routes(6)
|
||||||
expected = self.ipv4s
|
expected = self.ipv4s
|
||||||
self.assertEqual(expected, self.nd.config["routes"])
|
self.assertEqual(expected, self.nd.config["routes"])
|
||||||
|
|
||||||
|
|
||||||
|
class TestNetworkDev(SubiTestCase):
|
||||||
|
def test_netdev_info_eth_inexistent(self):
|
||||||
|
# LP: #2012659 - just after physically removing an Ethernet interface
|
||||||
|
# from the system, Subiquity tries to collect information via
|
||||||
|
# netdev_info. The code would try to dereference dev.info - but it was
|
||||||
|
# reset to None when the interface got removed.
|
||||||
|
# In other private reports, the same issue would occur with Wi-Fi
|
||||||
|
# interfaces.
|
||||||
|
model = Mock(get_all_netdevs=Mock(return_value=[]))
|
||||||
|
nd = NetworkDev(model, "testdev0", "eth")
|
||||||
|
info = nd.netdev_info()
|
||||||
|
self.assertFalse(info.is_connected)
|
||||||
|
|
||||||
|
def test_netdev_info_wlan_inexistent(self):
|
||||||
|
# Just like test_netdev_info_eth_inexistent but with Wi-Fi interfaces
|
||||||
|
# which suffer the same issue.
|
||||||
|
model = Mock(get_all_netdevs=Mock(return_value=[]))
|
||||||
|
nd = NetworkDev(model, "testdev0", "wlan")
|
||||||
|
info = nd.netdev_info()
|
||||||
|
self.assertIsNone(info.wlan.scan_state)
|
||||||
|
self.assertEqual(info.wlan.visible_ssids, [])
|
||||||
|
|
Loading…
Reference in New Issue