[PATCH] network gui: do not crash on devices without settings (eg wireless) (#1010519)

Radek Vykydal rvykydal at redhat.com
Mon Sep 23 15:17:27 UTC 2013


Please ignore, I need to address here what Brian remarked
in one recent review, v2 coming soon.

On 09/23/2013 05:02 PM, Radek Vykydal wrote:
> Also do not read slaves from settings but use new 'Slaves' property to read
> current slaves instead.
> ---
>   pyanaconda/network.py | 21 +++++++++------------
>   pyanaconda/nm.py      | 23 +++++++++++++++++++++++
>   2 files changed, 32 insertions(+), 12 deletions(-)
>
> diff --git a/pyanaconda/network.py b/pyanaconda/network.py
> index dcb6ee0..18ea892 100644
> --- a/pyanaconda/network.py
> +++ b/pyanaconda/network.py
> @@ -34,6 +34,7 @@ import threading
>   import re
>   import dbus
>   import IPy
> +import itertools
>   
>   from simpleconfig import SimpleConfigFile
>   from blivet.devices import FcoeDiskDevice, iScsiDiskDevice
> @@ -1046,22 +1047,16 @@ def status_message():
>   
>               slaves = {}
>               ssids = {}
> -            nonslaves = []
>   
>               # first find slaves and wireless aps
>               for devname in active_devs:
> -                master = nm.nm_device_setting_value(devname, "connection", "master")
> -                if master:
> -                    if master in slaves:
> -                        slaves[master].append(devname)
> -                    else:
> -                        slaves[master] = [devname]
> -                else:
> -                    nonslaves.append(devname)
> +                slaves[devname] = nm.nm_device_slaves(devname) or []
>                   if nm.nm_device_type_is_wifi(devname):
>                       ssids[devname] = nm.nm_device_active_ssid(devname) or ""
>   
> -            if len(nonslaves) == 1:
> +            all_slaves = set(itertools.chain.from_iterable(slaves.values()))
> +
> +            if len(active_devs) - len(all_slaves) == 1:
>                   if nm.nm_device_type_is_ethernet(devname):
>                       msg = _("Wired (%(interface_name)s) connected") \
>                             % {"interface_name": devname}
> @@ -1077,9 +1072,11 @@ def status_message():
>                       vlanid = nm.nm_device_setting_value(devname, "vlan", "id")
>                       msg = _("Vlan %(interface_name)s (%(parent_device)s, ID %(vlanid)s) connected") \
>                             % {"interface_name": devname, "parent_device": parent, "vlanid": vlanid}
> -            elif len(nonslaves) > 1:
> +            elif len(active_devs) - len(all_slaves) > 1:
>                   devlist = []
> -                for devname in nonslaves:
> +                for devname in active_devs:
> +                    if devname in all_slaves:
> +                        continue
>                       if nm.nm_device_type_is_ethernet(devname):
>                           devlist.append("%s" % devname)
>                       elif nm.nm_device_type_is_wifi(devname):
> diff --git a/pyanaconda/nm.py b/pyanaconda/nm.py
> index 3c587dc..17b765d 100644
> --- a/pyanaconda/nm.py
> +++ b/pyanaconda/nm.py
> @@ -440,6 +440,29 @@ def nm_device_ip_config(name, version=4):
>   
>       return [addr_list, ns_list]
>   
> +def nm_device_slaves(name):
> +    """Return slaves of device.
> +
> +       :param name: name of device
> +       :type name: str
> +       :return: names of slaves of device or None if device has no 'Slaves' property
> +       :rtype: list of strings or None
> +       :raise UnknownDeviceError if device is not found
> +    """
> +
> +    try:
> +        slaves = nm_device_property(name, "Slaves")
> +    except PropertyNotFoundError:
> +        return None
> +
> +    slave_ifaces = []
> +    for slave in slaves:
> +        iface = _get_property(slave, "Interface", ".Device")
> +        slave_ifaces.append(iface)
> +
> +    return slave_ifaces
> +
> +
>   def nm_ntp_servers_from_dhcp():
>       """Return NTP servers obtained by DHCP.
>   



More information about the anaconda-patches mailing list