Fri, Jul 19, 2013 at 02:42:31PM CEST, olichtne(a)redhat.com wrote:
On Fri, Jul 19, 2013 at 02:23:50PM +0200, Jiri Pirko wrote:
> Fri, Jul 19, 2013 at 02:16:44PM CEST, olichtne(a)redhat.com wrote:
> >From: Ondrej Lichtner <olichtne(a)redhat.com>
> >
> >This method is automatically called by the controller when initializing
> >interfaces before they are configured.
> >
> >When the interface is managed by NM calling ip link set <if> down will
> >make NM see it as unavailable to repair this we had to set the if back
> >to up before using NM. Instead when NM is present we will disconnect the
> >device through the dbus interface.
> >
> >I didn't remove the code that "resets" the interface if it's
unavailable
> >before using NM, just in case there will be similar problems in the
> >future.
> >
> >Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
> >---
> > lnst/Slave/NetTestSlave.py | 22 +++++++++++++++++++++-
> > 1 file changed, 21 insertions(+), 1 deletion(-)
> >
> >diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
> >index 77ad679..4be56ce 100644
> >--- a/lnst/Slave/NetTestSlave.py
> >+++ b/lnst/Slave/NetTestSlave.py
> >@@ -17,6 +17,7 @@ import os
> > import sys, traceback
> > import datetime
> > import socket
> >+import dbus
> > from time import sleep
> > from xmlrpclib import Binary
> > from tempfile import NamedTemporaryFile
> >@@ -116,7 +117,26 @@ class SlaveMethods:
> > devs = self.get_devices_by_hwaddr(hwaddr)
> >
> > for dev in devs:
> >- exec_cmd("ip link set %s down" % dev["name"])
> >+ if check_process_running("NetworkManager") and\
> >+ self._config.get_option("environment",
"use_nm"):
> >+ bus = dbus.SystemBus()
> >+ nm_obj =
bus.get_object("org.freedesktop.NetworkManager",
> >+
"/org/freedesktop/NetworkManager")
> >+ nm_if = dbus.Interface(nm_obj,
"org.freedesktop.NetworkManager")
> >+ dev_obj_path = nm_if.GetDeviceByIpIface(dev["name"])
> >+ dev_obj =
bus.get_object("org.freedesktop.NetworkManager",
> >+ dev_obj_path)
> >+ dev_props = dbus.Interface(dev_obj,
> >+
"org.freedesktop.DBus.Properties")
> >+ if
dev_props.Get("org.freedesktop.NetworkManager.Device",
> >+ "ActiveConnection") !=
"/":
> >+ dev_if = dbus.Interface(dev_obj,
> >+
"org.freedesktop.NetworkManager.Device")
> >+ logging.debug("Disconnecting device %s: %s" %
> >+ (dev["name"],
dev_obj_path))
> >+ dev_if.Disconnect()
> >+ else:
> >+ exec_cmd("ip link set %s down" %
dev["name"])
>
>
> What if NM is running but does not handle specified device? I guess we
> need to call "ip link set x down" in that case as well.
Yes, that would probably be the case, I don't detect these cases yet and
just assume that NM either manages all of them except the controller
device, or none of them. The problem is that currently mixing NM with
normal configuration is not a very good idea anyway... I could add this
check if you want it but I already dislike that I need 20 lines of dbus
code just to disconnect a device and would prefer it shorter.
hmm, right. I think we should be able to do this mixed config scenario.
Should not be problem to just look at the beginning if devices is
handled by NM or not and act accordingly...
Another alternative is to use ifdown for this, I didn't test it but
yesterday pavlix and jklimes told me that it detects if NM is running
and either uses 'nmcli' or 'ip' to disconnect the device. But since
it's
a part of initscripts which is kinda getting replaced by systemd I don't
know if it's a good idea.
We should not depend on initscripts - they are RHEL/Fedora specific.
>
> >
> > return True
> >
> >--
> >1.8.3.1
> >
> >_______________________________________________
> >LNST-developers mailing list
> >LNST-developers(a)lists.fedorahosted.org
> >https://lists.fedorahosted.org/mailman/listinfo/lnst-developers