Change in vdsm[master]: net: synchronous ifup

phoracek at redhat.com phoracek at redhat.com
Mon Aug 31 11:57:19 UTC 2015


Petr Horáček has uploaded a new change for review.

Change subject: net: synchronous ifup
......................................................................

net: synchronous ifup

Return device only after it's properly created and up.

Change-Id: Id739556e9ebcdd2882d2b055762007204c61cef3
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
M vdsm/network/configurators/ifcfg.py
1 file changed, 48 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/33/45533/1

diff --git a/vdsm/network/configurators/ifcfg.py b/vdsm/network/configurators/ifcfg.py
index e1d3e94..cf1ef74 100644
--- a/vdsm/network/configurators/ifcfg.py
+++ b/vdsm/network/configurators/ifcfg.py
@@ -18,6 +18,7 @@
 #
 from __future__ import absolute_import
 
+from contextlib import contextmanager
 import copy
 import errno
 import glob
@@ -40,6 +41,7 @@
 from vdsm import sysctl
 from vdsm import utils
 from vdsm.netconfpersistence import RunningConfig, PersistentConfig
+from vdsm.netlink import monitor
 
 if utils.isOvirtNode():
     from ovirt.node.utils import fs as node_fs
@@ -787,7 +789,20 @@
         t.daemon = True
         t.start()
     else:
-        _exec_ifup(iface.name, cgroup)
+        if not iface.master:
+            if iface.ipv4:
+                expected_event = {'label': iface.name, 'family': 'inet',
+                                  'scope': 'global'}
+            elif iface.ipv6:
+                expected_event = {'label': iface.name, 'family': 'inet6',
+                                  'scope': 'global'}
+            else:
+                expected_event = {'label': iface.name, 'family': 'inet6',
+                                  'scope': 'link'}
+            with _wait_for_event(iface, expected_event):
+                _exec_ifup(iface.name, cgroup)
+        else:
+            _exec_ifup(iface.name, cgroup)
 
 
 def _restore_default_bond_options(bond_name, desired_options):
@@ -916,3 +931,35 @@
         ifcfgs.add(ROUTE_PATH % top_level_device)
 
     return ifcfgs
+
+
+def _netmask2prefix(netmask):
+    return sum([bin(int(x)).count('1') for x in netmask.split('.')])
+
+
+def _is_subdict(subdict, superdict):
+    return all(item in frozenset(superdict.items())
+               for item in frozenset(subdict.items()))
+
+
+ at contextmanager
+def _wait_for_event(iface, expected_event, timeout=10):
+    with monitor.Monitor(groups=('ipv4-ifaddr', 'ipv6-ifaddr'),
+                         timeout=timeout) as mon:
+        try:
+            yield
+        finally:
+            caught_events = []
+            try:
+                for event in mon:
+                    caught_events.append(event)
+                    if _is_subdict(expected_event, event):
+                        mon.stop()
+            except monitor.MonitorError as e:
+                if e[0] == monitor.E_TIMEOUT:
+                    logging.warning('Expected event "%s" of interface "%s" '
+                                    'was not caught within the given timeout. '
+                                    'Caught events: %s', expected_event, iface,
+                                    caught_events)
+                else:
+                    raise


-- 
To view, visit https://gerrit.ovirt.org/45533
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id739556e9ebcdd2882d2b055762007204c61cef3
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>


More information about the vdsm-patches mailing list