Change in vdsm[master]: change the device state monitor to use iproute2 monitor
asegurap at redhat.com
asegurap at redhat.com
Thu Oct 17 08:32:18 UTC 2013
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: change the device state monitor to use iproute2 monitor
......................................................................
change the device state monitor to use iproute2 monitor
Change-Id: I26f70adb9f2ccb1bd4b8653ed5ad20297785284d
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M tests/functional/networkTests.py
1 file changed, 42 insertions(+), 27 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/55/20255/1
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 7cb87ad..09a9b7c 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -17,8 +17,9 @@
# Refer to the README and COPYING files for full details of the license
#
from contextlib import contextmanager
-from threading import Thread
+from threading import Event, Thread
import os.path
+import subprocess
import time
import neterrors
@@ -34,7 +35,7 @@
from vdsm.ipwrapper import (ruleAdd, ruleDel, routeAdd, routeDel, routeExists,
ruleExists, Route, Rule, addrFlush)
-from vdsm.netinfo import operstate, prefix2netmask
+from vdsm.netinfo import prefix2netmask
NETWORK_NAME = 'test-network'
@@ -83,39 +84,53 @@
pass
+class MonitoringThread(Thread):
+ def __init__(self, dev):
+ Thread.__init__(self)
+ self.dev = dev
+ self.changes = []
+ self.monitoring = Event()
+ self.done = False
+ self.process = None
+
+ def _procLines(self):
+ while not self.done:
+ line = self.process.stdout.readline()
+ if not line:
+ time.sleep(0.1)
+ continue
+ yield line
+
+ def run(self):
+ self.process = subprocess.Popen(['ip', 'monitor', 'link'],
+ stdout=subprocess.PIPE, close_fds=True)
+ self.monitoring.set()
+ try:
+ for line in self._procLines():
+ if '%s:' % self.dev in line:
+ self.changes.append(line.split()[-1])
+ finally:
+ self.process.kill()
+
+ def finish(self):
+ self.process.kill()
+ self.done = True
+
+
@contextmanager
def nonChangingOperstate(device):
"""Raises an exception if it detects that the device operstate changes."""
- # The current implementation is raceful (but empirically tested to work)
- # due to the fact that two changes could happen between iterations and no
- # exception would be raised.
- def changed(dev, changes):
- status = operstate(dev)
- while not done:
- try:
- newState = operstate(dev)
- time.sleep(0.1)
- except IOError as ioe:
- _, message = ioe.args
- changes.append(message)
- break
- if status != newState:
- changes.append(newState)
- status = newState
-
try:
- done = False
- changes = []
- monitoring_t = Thread(target=changed, name='operstate_mon',
- args=(device, changes))
+ monitoring_t = MonitoringThread(device)
monitoring_t.start()
+ monitoring_t.monitoring.wait()
yield
finally:
- time.sleep(3) # So that the last action in yield gets to kernel
- done = True
- if changes:
+ monitoring_t.finish()
+ monitoring_t.join()
+ if monitoring_t.changes:
raise OperStateChangedError('%s operstate changed: %r' %
- (device, changes))
+ (device, monitoring_t.changes))
@expandPermutations
--
To view, visit http://gerrit.ovirt.org/20255
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I26f70adb9f2ccb1bd4b8653ed5ad20297785284d
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
More information about the vdsm-patches
mailing list