Assaf Muller has uploaded a new change for review.
Change subject: Functional Tests [2/3]: Added ipwrapper.ruleExists+routeExists
......................................................................
Functional Tests [2/3]: Added ipwrapper.ruleExists+routeExists
Added functional tests for both functions as well.
Change-Id: Iaf7c28e85f53f51879750308f3a9f93fc635cf33
Signed-off-by: Assaf Muller <amuller(a)redhat.com>
---
M lib/vdsm/ipwrapper.py
M tests/functional/networkTests.py
2 files changed, 80 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/40/18040/1
diff --git a/lib/vdsm/ipwrapper.py b/lib/vdsm/ipwrapper.py
index 6eade35..66458a4 100644
--- a/lib/vdsm/ipwrapper.py
+++ b/lib/vdsm/ipwrapper.py
@@ -106,6 +106,12 @@
for word in str(self).split():
yield word
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
class Rule(object):
def __init__(self, table, source=None, destination=None, srcDevice=None):
@@ -191,6 +197,12 @@
for word in str(self).split():
yield word
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
class IPRoute2Error(Exception):
pass
@@ -233,6 +245,20 @@
_execCmd(command)
+def _validate(validator, entry):
+ try:
+ validator.fromText(entry)
+ except:
+ return False
+ else:
+ return True
+
+
+def routeExists(route):
+ return route in [Route.fromText(entry) for entry in routeShowTable('all')
+ if _validate(Route, entry)]
+
+
def ruleList():
command = [_IP_BINARY.cmd, 'rule']
return _execCmd(command)
@@ -248,3 +274,8 @@
command = [_IP_BINARY.cmd, 'rule', 'del']
command += rule
_execCmd(command)
+
+
+def ruleExists(rule):
+ return rule in [Rule.fromText(entry) for entry in ruleList()
+ if _validate(Rule, entry)]
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 5fbbc73..10e42dc 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -22,13 +22,24 @@
expandPermutations, permutations)
from testValidation import RequireDummyMod, ValidateRunningAsRoot
-from utils import cleanupNet, restoreNetConfig, SUCCESS, VdsProxy
+import dummyUtils
from dummyUtils import dummyIf
+from utils import cleanupNet, restoreNetConfig, SUCCESS, VdsProxy
+
+from vdsm.ipwrapper import ruleAdd, ruleDel, routeAdd, routeDel, routeExists, \
+ ruleExists, Route, Rule
NETWORK_NAME = 'test-network'
VLAN_ID = '27'
BONDING_NAME = 'bond0'
+IP_ADDRESS = '240.0.0.1'
+IP_NETWORK = '240.0.0.0'
+IP_CIDR = '24'
+IP_NETWORK_AND_CIDR = IP_NETWORK + '/' + IP_CIDR
+IP_GATEWAY = '240.0.0.254'
+IP_TABLE = '4026531841' # Current implementation converts ip to its 32 bit int
+ # representation
def setupModule():
@@ -394,3 +405,40 @@
nics=nics,
opts={'bridged': bridged})
self.assertEqual(status, neterrors.ERR_BAD_BRIDGE, msg)
+
+ @RequireDummyMod
+ @ValidateRunningAsRoot
+ def testRuleExists(self):
+ with dummyIf(1) as nics:
+ nic = nics[0]
+ dummyUtils.setIP(nic, IP_ADDRESS + '/' + IP_CIDR)
+ dummyUtils.setLinkUp(nic)
+
+ rules = [Rule(source=IP_NETWORK_AND_CIDR, table=IP_TABLE),
+ Rule(destination=IP_NETWORK_AND_CIDR, table=IP_TABLE,
+ srcDevice=nic)]
+ for rule in rules:
+ self.assertFalse(ruleExists(rule))
+ ruleAdd(rule)
+ self.assertTrue(ruleExists(rule))
+ ruleDel(rule)
+ self.assertFalse(ruleExists(rule))
+
+ @RequireDummyMod
+ @ValidateRunningAsRoot
+ def testRouteExists(self):
+ with dummyIf(1) as nics:
+ nic = nics[0]
+ dummyUtils.setIP(nic, IP_ADDRESS + '/' + IP_CIDR)
+ dummyUtils.setLinkUp(nic)
+
+ routes = [Route(network='0.0.0.0/0', ipaddr=IP_GATEWAY,
+ device=nic, table=IP_TABLE),
+ Route(network=IP_NETWORK_AND_CIDR,
+ ipaddr=IP_ADDRESS, device=nic, table=IP_TABLE)]
+ for route in routes:
+ self.assertFalse(routeExists(route))
+ routeAdd(route)
+ self.assertTrue(routeExists(route))
+ routeDel(route)
+ self.assertFalse(routeExists(route))
--
To view, visit
http://gerrit.ovirt.org/18040
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaf7c28e85f53f51879750308f3a9f93fc635cf33
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Assaf Muller <amuller(a)redhat.com>