Antoni Segura Puimedon has uploaded a new change for review. Change subject: ipwrapper Monitor: fix for deleted links ......................................................................
ipwrapper Monitor: fix for deleted links The previous parsing would not work when a link was deleted. This patch fixes it and sets the state as DELETED on those cases. Change-Id: I2220d5b196efe1cc34821ff8145fbddcc431d7b9 Signed-off-by: Antoni S. Puimedon <asegu...@redhat.com> --- M lib/vdsm/ipwrapper.py M tests/ipwrapperTests.py 2 files changed, 21 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/34/21534/1 diff --git a/lib/vdsm/ipwrapper.py b/lib/vdsm/ipwrapper.py index cb029a6..bc7ee85 100644 --- a/lib/vdsm/ipwrapper.py +++ b/lib/vdsm/ipwrapper.py @@ -532,6 +532,8 @@ class Monitor(object): """Minimal wrapper over `ip monitor link`""" + _DELETED_TEXT = 'Deleted' + LINK_STATE_DELETED = 'DELETED' def __init__(self): self.proc = None @@ -548,17 +550,22 @@ changes = [] for line in text.splitlines(): state = None + if line.startswith(cls._DELETED_TEXT): + state = cls.LINK_STATE_DELETED + line = line[len(cls._DELETED_TEXT):] + _, device, data = [el.strip() for el in line.split(':', 2)] flagVal, _ = data.split('\\', 1) # We don't parse link/ether flags, values = data.split('>') flags = frozenset(flags[1:].split(',')) - values = (el for el in values.strip().split(' ') if el) - for key, value in pairwise(values): - if key == 'state': - state = value - break + if state is None: + values = (el for el in values.strip().split(' ') if el) + for key, value in pairwise(values): + if key == 'state': + state = value + break changes.append(MonitorEvent(device, flags, state)) diff --git a/tests/ipwrapperTests.py b/tests/ipwrapperTests.py index 7e0be2a..d85deb3 100644 --- a/tests/ipwrapperTests.py +++ b/tests/ipwrapperTests.py @@ -194,7 +194,10 @@ 'noqueue state DOWN \\ link/ether 33:44:55:66:77:88 brd ' 'ff:ff:ff:ff:ff:ff \n' '4: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> \\ ' - 'link/ether \n') + 'link/ether \n' + 'Deleted 418: foo: <BROADCAST,MULTICAST> mtu 1500 qdisc noop ' + 'state DOWN group default \\ link/ether ba:2c:7b:68:b8:77 ' + 'brd ff:ff:ff:ff:ff:ff\n') expected = [ MonitorEvent( 'bond0', @@ -203,6 +206,10 @@ MonitorEvent( 'wlp3s0', frozenset(['BROADCAST', 'MULTICAST', 'UP', 'LOWER_UP']), - None)] + None), + MonitorEvent( + 'foo', + frozenset(['BROADCAST', 'MULTICAST']), + 'DELETED')] self.assertEqual(Monitor._parse(out), expected) -- To view, visit http://gerrit.ovirt.org/21534 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2220d5b196efe1cc34821ff8145fbddcc431d7b9 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Antoni Segura Puimedon <asegu...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches