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

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



Radek Vykydal wrote:

Improved patch:

Subject: [PATCH] Wait for specific activated network devices (#520146).

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

(1) Wait for all devices activated by nm-c-e this way, otherwise
we can fail with traceback in next steps reading device
configuration.

(2) When enabling network make sure the device selected by user
in combobox was activated, not just any device.
---
gui.py       |   39 +++++++++++++++++++++++++++------------
isys/isys.py |    1 +
network.py   |   29 ++++++++++++++++++++++++++++-
3 files changed, 56 insertions(+), 13 deletions(-)

diff --git a/gui.py b/gui.py
index d381c0b..29d8810 100755
--- a/gui.py
+++ b/gui.py
@@ -1005,35 +1005,50 @@ class InstallInterface(InstallInterfaceBase):
            self.anaconda.id.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.id.network.getOnbootIfaces()
-                if onboot_devs:
-                    install_device = onboot_devs[0]
+                waited_devs = self.anaconda.id.network.getOnbootIfaces()
+            else:
+                waited_devs = [install_device]
.
            self.anaconda.id.network.write()
.
-            if install_device:
+            if waited_devs:
                w = WaitWindow(_("Waiting for NetworkManager"),
- _("Waiting for NetworkManager to get connection.")) - networkEnabled = self.anaconda.id.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.id.network.waitForDevicesActivation(waited_devs)
                w.pop()
.
+                if just_setup:
+                    if failed_devs:
+                        self._handleDeviceActivationFail(failed_devs)
+                else:
+                    networkEnabled = install_device not in failed_devs
+                    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 8c1e2a1..9c09334 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 f1a5d5b..7b7cabc 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
@@ -751,6 +752,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
@@ -760,7 +787,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



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