Antoni Segura Puimedon has uploaded a new change for review. Change subject: ethtool: remove some more usages ......................................................................
ethtool: remove some more usages This patch continues with the removal of the python ethtool dependency, as it is not really necessary now that the libnl bindings are mature. Change-Id: Ib97f8d536edf293af748f5c16316ee92f162fe5f Signed-off-by: Antoni S. Puimedon <[email protected]> --- M lib/vdsm/ipwrapper.py M tests/tcTests.py M vdsm/network/tc/__init__.py 3 files changed, 38 insertions(+), 43 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/81/32381/1 diff --git a/lib/vdsm/ipwrapper.py b/lib/vdsm/ipwrapper.py index 5fa874e..9e38bf6 100644 --- a/lib/vdsm/ipwrapper.py +++ b/lib/vdsm/ipwrapper.py @@ -21,6 +21,7 @@ from contextlib import closing from glob import iglob import array +import ctypes import errno import fcntl import os @@ -116,6 +117,7 @@ _hiddenNics = config.get('vars', 'hidden_nics').split(',') _hiddenVlans = config.get('vars', 'hidden_vlans').split(',') IFF_RUNNING = 1 << 6 + IFF_PROMISC = 1 << 8 def __init__(self, address, index, linkType, mtu, name, qdisc, state, vlanid=None, vlanprotocol=None, master=None, device=None, @@ -243,6 +245,35 @@ def oper_up(self): return bool(self.flags & self.IFF_RUNNING) + @property + def promisc(self): + return bool(self.flags & self.IFF_PROMISC) + + @promisc.setter + def promisc(self, value): + """Takes a boolean to enable/disable Link promiscuity""" + if value: + self.flags |= self.IFF_PROMISC + else: + self.flags &= ~self.IFF_PROMISC + self.set_flags(self.flags) + + def set_flags(self, flags): + "Set device flags. We need this local definition until ethtool has it" + + SIOCSIFFLAGS = 0x8914 + + class ifreq(ctypes.Structure): + _fields_ = [("ifr_ifrn", ctypes.c_char * 16), + ("ifr_flags", ctypes.c_short)] + + with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as s: + ifr = ifreq() + ifr.ifr_ifrn = self.name + ifr.ifr_flags = flags + + fcntl.ioctl(s.fileno(), SIOCSIFFLAGS, ifr) + def drv_name(devName): """Returns the driver used by a device. diff --git a/tests/tcTests.py b/tests/tcTests.py index 606e2d0..1e59653 100644 --- a/tests/tcTests.py +++ b/tests/tcTests.py @@ -31,12 +31,12 @@ from subprocess import Popen, check_call, PIPE import fcntl import struct -import ethtool from testlib import VdsmTestCase as TestCaseBase from testValidation import ValidateRunningAsRoot from vdsm.constants import EXT_BRCTL, EXT_TC +from vdsm import ipwrapper from nose.plugins.skip import SkipTest from network import tc @@ -191,13 +191,11 @@ def testTogglePromisc(self): tc.set_promisc(self._bridge.devName, True) - self.assertTrue(ethtool.get_flags(self._bridge.devName) & - ethtool.IFF_PROMISC, + self.assertTrue(ipwrapper.getLink(self._bridge.devName).promisc, "Could not enable promiscuous mode.") tc.set_promisc(self._bridge.devName, False) - self.assertFalse(ethtool.get_flags(self._bridge.devName) & - ethtool.IFF_PROMISC, + self.assertFalse(ipwrapper.getLink(self._bridge.devName).promisc, "Could not disable promiscuous mode.") def testException(self): diff --git a/vdsm/network/tc/__init__.py b/vdsm/network/tc/__init__.py index 61602ac..9b6c9bb 100644 --- a/vdsm/network/tc/__init__.py +++ b/vdsm/network/tc/__init__.py @@ -19,14 +19,10 @@ # from collections import namedtuple -from contextlib import closing from functools import partial -import ctypes import errno -import fcntl -import socket -import ethtool +from vdsm import ipwrapper from . import filter as tc_filter from . import _parser @@ -55,7 +51,7 @@ else: return [] - devices = set(ethtool.get_devices()) + devices = set(link.name for link in ipwrapper.getLinks()) acts = [act for act in filt.actions if act.target in devices and act.target != target] @@ -74,8 +70,7 @@ qdisc_replace_prio(network) qdisc_id = _qdiscs_of_device(network).next() _addTarget(network, qdisc_id, target) - - set_promisc(network, True) + ipwrapper.getLink(network).promisc = True def unsetPortMirroring(network, target): @@ -91,7 +86,7 @@ if not acts: qdisc_del(network, 'root') qdisc_del(network, 'ingress') - set_promisc(network, False) + ipwrapper.getLink(network).promisc = False def qdisc_replace_ingress(dev): @@ -141,35 +136,6 @@ except TrafficControlException as e: if e.errCode != errno.ENOENT: raise - - -def set_flags(dev, flags): - "Set device flags. We need this local definition until ethtool has it" - - SIOCSIFFLAGS = 0x8914 - - class ifreq(ctypes.Structure): - _fields_ = [("ifr_ifrn", ctypes.c_char * 16), - ("ifr_flags", ctypes.c_short)] - - with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as s: - ifr = ifreq() - ifr.ifr_ifrn = dev - ifr.ifr_flags = flags - - fcntl.ioctl(s.fileno(), SIOCSIFFLAGS, ifr) - - -def set_promisc(dev, on=True): - flags = ethtool.get_flags(dev) - - if bool(flags & ethtool.IFF_PROMISC) != on: - if on: - flags |= ethtool.IFF_PROMISC - else: - flags &= ~ethtool.IFF_PROMISC - - set_flags(dev, flags) Filter = namedtuple('Filter', 'prio handle actions') -- To view, visit http://gerrit.ovirt.org/32381 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib97f8d536edf293af748f5c16316ee92f162fe5f Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Antoni Segura Puimedon <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
