On Tue, Jan 14, 2014 at 09:46:02PM +0100, Jiri Pirko wrote:
Tue, Jan 14, 2014 at 03:12:56PM CET, jtluka(a)redhat.com wrote:
>NM connections might not be available immediately and in that case an
>activation of such connection will raise DBusException. This patch adds
>a check for the exception and retries to activate connection five times
>with 1 second step. After timeout the exception is passed further.
This looks like one ugly workaround. Why is this really needed? Why
there is a delay? Can't we listen to some dbus signal instead of this
polling?
DBus signals require creating a gtk main loop object and creating a
signal handler that will interrupt that loop so that the lnst-slave
process can continue. If, for whatever reason, we start that loop after
the connection was added and we won't recieve that signal we can't stop
the loop. This is also the reason why I didn't use signal handling for
activating connections or adding connections.
Even though polling is an ugly hack, it works and using signals would
require a complete rewrite of the lnst-slave process to be a gtk
application with a main loop that works for everything.
>
>Signed-off-by: Jan Tluka <jtluka(a)redhat.com>
>---
> lnst/Slave/NmConfigDevice.py | 17 ++++++++++++++---
> 1 file changed, 14 insertions(+), 3 deletions(-)
>
>diff --git a/lnst/Slave/NmConfigDevice.py b/lnst/Slave/NmConfigDevice.py
>index 396dea8..fa8fed4 100644
>--- a/lnst/Slave/NmConfigDevice.py
>+++ b/lnst/Slave/NmConfigDevice.py
>@@ -24,6 +24,7 @@ from lnst.Common.Utils import kmod_in_use, bool_it
> from lnst.Common.NetUtils import scan_netdevs
> from lnst.Common.Utils import check_process_running
> from lnst.Common.Config import lnst_config
>+from dbus.exceptions import DBusException
>
> NM_BUS = "org.freedesktop.NetworkManager"
> OBJ_PRE = "/org/freedesktop/NetworkManager"
>@@ -221,9 +222,19 @@ class NmConfigDeviceGeneric(object):
> except:
> device_obj_path = "/"
>
>- netdev["acon_obj_path"] = nm_if.ActivateConnection(
>- netdev["con_obj_path"],
>- device_obj_path, "/")
>+ timeout = 0
>+ while timeout != 5:
>+ try:
>+ netdev["acon_obj_path"] = nm_if.ActivateConnection(
>+
netdev["con_obj_path"],
>+ device_obj_path,
"/")
>+ break
>+ except DBusException as e:
>+ # connection might not be available yet, wait 1 second
>+ timeout += 1
>+ if timeout == 5:
>+ raise e
>+ time.sleep(1)
>
> logging.debug("Device object path: %s" % device_obj_path)
> logging.debug("Connection object path: %s" %
netdev["con_obj_path"])
>--
>1.8.1.4
>
>_______________________________________________
>LNST-developers mailing list
>LNST-developers(a)lists.fedorahosted.org
>https://lists.fedorahosted.org/mailman/listinfo/lnst-developers
_______________________________________________
LNST-developers mailing list
LNST-developers(a)lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/lnst-developers