[anaconda 3/6] Ignore safe_dbus errors in keyboard setup

Brian C. Lane bcl at redhat.com
Wed Aug 6 19:22:57 UTC 2014


When running inside a mock environment there is no dbus connection
available. Log the errors but return sane defaults so that the
installation doesn't crash.
---
 pyanaconda/keyboard.py | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/pyanaconda/keyboard.py b/pyanaconda/keyboard.py
index 6966ef8..f8258e1 100644
--- a/pyanaconda/keyboard.py
+++ b/pyanaconda/keyboard.py
@@ -329,7 +329,11 @@ class LocaledWrapper(object):
     """
 
     def __init__(self):
-        self._connection = safe_dbus.get_new_system_connection()
+        try:
+            self._connection = safe_dbus.get_new_system_connection()
+        except GLib.Error as e: #pylint: disable=E0712
+            self._connection = None
+            log.error("Failed to get safe_dbus connection: %s", e)
 
     @property
     def keymap(self):
@@ -339,7 +343,7 @@ class LocaledWrapper(object):
                                                  LOCALED_IFACE,
                                                  "VConsoleKeymap",
                                                  self._connection)
-        except safe_dbus.DBusPropertyError:
+        except (safe_dbus.DBusPropertyError, safe_dbus.DBusCallError):
             # no value for the property
             log.error("Failed to get the value for the systemd-localed's "
                       "VConsoleKeymap property")
@@ -356,7 +360,7 @@ class LocaledWrapper(object):
                                                   LOCALED_IFACE,
                                                   "X11Layout",
                                                   self._connection)
-        except safe_dbus.DBusPropertyError:
+        except (safe_dbus.DBusPropertyError, safe_dbus.DBusCallError):
             # no value for the property
             log.error("Failed to get the value for the systemd-localed's "
                       "X11Layout property")
@@ -368,7 +372,7 @@ class LocaledWrapper(object):
                                                    LOCALED_IFACE,
                                                    "X11Variant",
                                                    self._connection)
-        except safe_dbus.DBusPropertyError:
+        except (safe_dbus.DBusPropertyError, safe_dbus.DBusCallError):
             # no value for the property
             log.error("Failed to get the value for the systemd-localed's "
                       "X11Variant property")
@@ -399,7 +403,7 @@ class LocaledWrapper(object):
                                                   LOCALED_IFACE,
                                                   "X11Options",
                                                   self._connection)
-        except safe_dbus.DBusPropertyError:
+        except (safe_dbus.DBusPropertyError, safe_dbus.DBusCallError):
             # no value for the property
             log.error("Failed to get the value for the systemd-localed's "
                       "X11Options property")
@@ -426,8 +430,11 @@ class LocaledWrapper(object):
         # should ask for credentials or not
         args = GLib.Variant('(ssbb)', (keymap, "", convert, False))
 
-        safe_dbus.call_sync(LOCALED_SERVICE, LOCALED_OBJECT_PATH, LOCALED_IFACE,
-                            "SetVConsoleKeyboard", args, self._connection)
+        try:
+            safe_dbus.call_sync(LOCALED_SERVICE, LOCALED_OBJECT_PATH, LOCALED_IFACE,
+                                "SetVConsoleKeyboard", args, self._connection)
+        except safe_dbus.DBusCallError as e:
+            log.error("Failed to set keymap: %s", e)
 
     def convert_keymap(self, keymap):
         """
@@ -503,8 +510,11 @@ class LocaledWrapper(object):
         # should ask for credentials or not
         args = GLib.Variant("(ssssbb)", (layouts_str, "", variants_str, opts_str,
                                          convert, False))
-        safe_dbus.call_sync(LOCALED_SERVICE, LOCALED_OBJECT_PATH, LOCALED_IFACE,
-                            "SetX11Keyboard", args, self._connection)
+        try:
+            safe_dbus.call_sync(LOCALED_SERVICE, LOCALED_OBJECT_PATH, LOCALED_IFACE,
+                                "SetX11Keyboard", args, self._connection)
+        except safe_dbus.DBusCallError as e:
+            log.error("Failed to set layouts: %s", e)
 
     def set_and_convert_layout(self, layout_variant):
         """
-- 
1.9.3



More information about the anaconda-patches mailing list