[anaconda 5/6] Modify nm to return defaults when no dbus is available
Brian C. Lane
bcl at redhat.com
Wed Aug 6 19:22:59 UTC 2014
When running inside a mock there is no dbus connection. Log the error
and return sane defaults so that the installation doesn't crash. The
exception is not more specific because I could not narrow it down -- the
traceback I received said it was 'Error:'
---
pyanaconda/nm.py | 41 ++++++++++++++++++++++++++++++++---------
1 file changed, 32 insertions(+), 9 deletions(-)
diff --git a/pyanaconda/nm.py b/pyanaconda/nm.py
index 8114a4d..73d4915 100644
--- a/pyanaconda/nm.py
+++ b/pyanaconda/nm.py
@@ -25,8 +25,11 @@ import IPy
import struct
import socket
import re
+import logging
+log = logging.getLogger("anaconda")
from pyanaconda.constants import DEFAULT_DBUS_TIMEOUT
+from pyanaconda.flags import flags
supported_device_types = [
NetworkManager.DeviceType.ETHERNET,
@@ -75,24 +78,32 @@ class UnknownConnectionError(Exception):
return self.__repr__()
def _get_proxy(bus_type=Gio.BusType.SYSTEM,
- flags=Gio.DBusProxyFlags.NONE,
+ proxy_flags=Gio.DBusProxyFlags.NONE,
info=None,
name="org.freedesktop.NetworkManager",
object_path="/org/freedesktop/NetworkManager",
interface_name="org.freedesktop.NetworkManager",
cancellable=None):
- proxy = Gio.DBusProxy.new_for_bus_sync(bus_type,
- flags,
- info,
- name,
- object_path,
- interface_name,
- cancellable)
+ try:
+ proxy = Gio.DBusProxy.new_for_bus_sync(bus_type,
+ proxy_flags,
+ info,
+ name,
+ object_path,
+ interface_name,
+ cancellable)
+ except Exception as e: # pylint: disable=W0703
+ log.error("_get_proxy failed: %s", e)
+ proxy = None
+
return proxy
def _get_property(object_path, prop, interface_name_suffix=""):
interface_name = "org.freedesktop.NetworkManager" + interface_name_suffix
proxy = _get_proxy(object_path=object_path, interface_name="org.freedesktop.DBus.Properties")
+ if not proxy:
+ return None
+
try:
prop = proxy.Get('(ss)', interface_name, prop)
except GLib.GError as e:
@@ -111,7 +122,13 @@ def nm_state():
:return: state of NetworkManager
:rtype: integer
"""
- return _get_property("/org/freedesktop/NetworkManager", "State")
+ prop = _get_property("/org/freedesktop/NetworkManager", "State")
+
+ # If this is an image/dir install assume the network is up
+ if not prop and (flags.imageInstall or flags.dirInstall):
+ return NetworkManager.State.CONNECTED_GLOBAL
+ else:
+ return prop
# FIXME - use just GLOBAL? There is some connectivity checking
# for GLOBAL in NM (nm_connectivity_get_connected), not sure if
@@ -145,6 +162,9 @@ def nm_devices():
interfaces = []
proxy = _get_proxy()
+ if not proxy:
+ return []
+
devices = proxy.GetDevices()
for device in devices:
device_type = _get_property(device, "DeviceType", ".Device")
@@ -165,6 +185,9 @@ def nm_activated_devices():
interfaces = []
active_connections = _get_property("/org/freedesktop/NetworkManager", "ActiveConnections")
+ if not active_connections:
+ return []
+
for ac in active_connections:
try:
state = _get_property(ac, "State", ".Connection.Active")
--
1.9.3
More information about the anaconda-patches
mailing list