[PATCH 27/27] Wait for all devices activated by nm-c-e (#520146).

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We used to activate just one device when enabling network,
so it was ok to use waitForConnection (wait just for any
connection). Now that more devices can be set to be activated
in nm-c-e (by checking [] Connect automatically), we should
wait for all devices activated by nm-c-e this way, otherwise
we can fail with traceback in next steps reading device
configuration.
---
 gui.py       |   40 ++++++++++++++++++++++++++++------------
 isys/isys.py |    1 +
 network.py   |   29 ++++++++++++++++++++++++++++-
 3 files changed, 57 insertions(+), 13 deletions(-)

diff --git a/gui.py b/gui.py
index f7ee82f..ccb0690 100755
--- a/gui.py
+++ b/gui.py
@@ -1006,35 +1006,51 @@ class InstallInterface(InstallInterfaceBase):
             self.anaconda.network.update()
 
             if just_setup:
-                # TODORV check which devices were actually activated by nmce
-                # and which we should wait for (the case for more than one
-                # device)
-                onboot_devs = self.anaconda.network.getOnbootIfaces()
-                if onboot_devs:
-                    install_device = onboot_devs[0]
+                waited_devs = self.anaconda.network.getOnbootIfaces()
+            else:
+                waited_devs = [install_device]
 
             self.anaconda.network.write()
 
-            if install_device:
+            if waited_devs:
                 w = WaitWindow(_("Waiting for NetworkManager"),
-                               _("Waiting for NetworkManager to get connection."))
-                networkEnabled = self.anaconda.network.waitForConnection()
-                if not networkEnabled and not just_setup:
-                    self._handleNetworkError(install_device)
+                               _("Waiting for NetworkManager to activate "
+                                 "these devices: %s" % ",".join(waited_devs)))
+                failed_devs = self.anaconda.network.waitForDevicesActivation(waited_devs)
                 w.pop()
 
+                networkEnabled = network.hasActiveNetDev()
+
+                if just_setup:
+                    if failed_devs:
+                        self._handleDeviceActivationFail(failed_devs)
+                else:
+                    if not networkEnabled:
+                        self._handleNetworkError(install_device)
+
             if just_setup:
                 break
 
         return networkEnabled
 
+    def _handleDeviceActivationFail(self, devices):
+        d = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
+                              gtk.BUTTONS_OK,
+                              _("Failed to activate these "
+                                "network interfaces: %s" %
+                                ",".join(devices)))
+        d.set_title(_("Network Configuration"))
+        d.set_position(gtk.WIN_POS_CENTER)
+        addFrame(d)
+        d.run()
+        d.destroy()
 
     def _handleNetworkError(self, field):
         d = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,
                               gtk.BUTTONS_OK,
                               _("An error occurred trying to bring up the "
                                 "%s network interface.") % (field,))
-        d.set_title(_("Error Configuring Network"))
+        d.set_title(_("Error Enabling Network"))
         d.set_position(gtk.WIN_POS_CENTER)
         addFrame(d)
         d.run()
diff --git a/isys/isys.py b/isys/isys.py
index b16c8e4..3d3e2c5 100755
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -54,6 +54,7 @@ NM_STATE_ASLEEP = 1
 NM_STATE_CONNECTING = 2
 NM_STATE_CONNECTED = 3
 NM_STATE_DISCONNECTED = 4
+NM_DEVICE_STATE_ACTIVATED = 8
 
 DBUS_PROPS_IFACE = "org.freedesktop.DBus.Properties"
 
diff --git a/network.py b/network.py
index 97eb992..cbdb5ab 100644
--- a/network.py
+++ b/network.py
@@ -47,6 +47,7 @@ sysconfigDir = "/etc/sysconfig"
 netscriptsDir = "%s/network-scripts" % (sysconfigDir)
 networkConfFile = "%s/network" % (sysconfigDir)
 ifcfgLogFile = "/tmp/ifcfg.log"
+CONNECTION_TIMEOUT = 45
 
 class IPError(Exception):
     pass
@@ -762,6 +763,32 @@ class Network:
 
         f.close()
 
+    def waitForDevicesActivation(self, devices):
+        waited_devs_props = {}
+
+        bus = dbus.SystemBus()
+        nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
+        device_paths = nm.get_dbus_method("GetDevices")()
+        for device_path in device_paths:
+            device = bus.get_object(isys.NM_SERVICE, device_path)
+            device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)
+            iface = str(device_props_iface.Get(isys.NM_MANAGER_IFACE, "Interface"))
+            if iface in devices:
+                waited_devs_props[iface] = device_props_iface
+
+        i = 0
+        while True:
+            for dev, device_props_iface in waited_devs_props.items():
+                state = device_props_iface.Get(isys.NM_MANAGER_IFACE, "State")
+                if state == isys.NM_DEVICE_STATE_ACTIVATED:
+                    waited_devs_props.pop(dev)
+            if len(waited_devs_props) == 0:
+                return []
+            if i >= CONNECTION_TIMEOUT:
+                return waited_devs_props.keys()
+            i += 1
+            time.sleep(1)
+
     # write out current configuration state and wait for NetworkManager
     # to bring the device up, watch NM state and return to the caller
     # once we have a state
@@ -771,7 +798,7 @@ class Network:
         props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)
 
         i = 0
-        while i < 45:
+        while i < CONNECTION_TIMEOUT:
             state = props.Get(isys.NM_SERVICE, "State")
             if int(state) == isys.NM_STATE_CONNECTED:
                 isys.resetResolv()
-- 
1.6.0.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux