network: fix crash upon accessing Help after creating a bond

When accessing the Help menu, Subiquity looks up the IP addresses
currently configured - so it knows whether to show the "Help on SSH
access" option.

Unfortunately, it also looks for IP addresses on devices that were
"configured" through the network screen but that still do not exist in
the system. When such a device exist (e.g., a bond), the Subiquity
client crashes with the following exception:

 Traceback (most recent call last):
   File "subiquity/common/api/server.py", line 164, in handler
     result = await implementation(**args)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "subiquity/server/server.py", line 117, in ssh_info_GET
     ips.extend(map(str, dev.actual_global_ip_addresses))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File "subiquitycore/models/network.py", line 394, in actual_global_ip_addresses
     for _, addr in sorted(self.info.addresses.items())
                           ^^^^^^^^^^^^^^^^^^^
 AttributeError: 'NoneType' object has no attribute 'addresses'

A similar crash is observed when calling /network/global_addresses after
creating the bond.

Fixed by only checking the IP addresses of devices that have a
probert.network.Link instance (i.e., they exist in the system).

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2023-09-04 17:50:31 +02:00
parent 8e03050dbb
commit dc26a1d252
2 changed files with 4 additions and 0 deletions

View File

@ -255,6 +255,8 @@ class NetworkController(BaseNetworkController, SubiquityController):
async def global_addresses_GET(self) -> List[str]:
ips: List[str] = []
for dev in self.model.get_all_netdevs():
if dev.info is None:
continue
ips.extend(map(str, dev.actual_global_ip_addresses))
return ips

View File

@ -114,6 +114,8 @@ class MetaController:
ips: List[str] = []
if self.app.base_model.network:
for dev in self.app.base_model.network.get_all_netdevs():
if dev.info is None:
continue
ips.extend(map(str, dev.actual_global_ip_addresses))
if not ips:
return None