Ido Barkan has uploaded a new change for review. Change subject: Functional test for Multiple Gateways source routing ......................................................................
Functional test for Multiple Gateways source routing adding assertions on the source routing definitions taht are configured when the network is configured with DHCP. Change-Id: Ib510bb56c205dffc98aa2bae3f55c1b4c7f6f56f Signed-off-by: ibarkan <ibar...@redhat.com> --- M AUTHORS M tests/functional/dhcp.py M tests/functional/networkTests.py M tests/functional/utils.py 4 files changed, 49 insertions(+), 8 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/12/33612/1 diff --git a/AUTHORS b/AUTHORS index 25197a5..28aec45 100644 --- a/AUTHORS +++ b/AUTHORS @@ -37,6 +37,7 @@ Lee Yarwood <lyarw...@redht.com> Jarod.W <work.iec23...@gmail.com> Vitor de Lima <vitor.l...@eldorado.org.br> + Ido Barkan <ibar...@redhat.com> [....send patches to get your name here....] diff --git a/tests/functional/dhcp.py b/tests/functional/dhcp.py index abed8c8..9e1338f 100644 --- a/tests/functional/dhcp.py +++ b/tests/functional/dhcp.py @@ -42,15 +42,18 @@ def __init__(self): self.proc = None - def start(self, interface, dhcpRangeFrom, dhcpRangeTo): + def start(self, interface, dhcpRangeFrom, dhcpRangeTo, router=None): # --dhcp-option=3 don't send gateway address which would break routing + # --dhcp-option=3,<router> advertise specific router # -O 6 don't reply with any DNS servers either # -d do not daemonize and log to stderr # -p 0 disable all the dnsmasq dns functionality self.proc = execCmd([ _DNSMASQ_BINARY.cmd, '--dhcp-authoritative', '-p', '0', '--dhcp-range=' + dhcpRangeFrom + ',' + - dhcpRangeTo + ',2m', '--dhcp-option=3', '-O', '6', + dhcpRangeTo + ',2m', + '--dhcp-option=3,%s' % (router,) if router else '--dhcp-option=3', + '-O', '6', '-i', interface, '-I', 'lo', '-d', '--bind-interfaces'], sync=False) sleep(_START_CHECK_TIMEOUT) diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py index 9a49238..ca4062a 100644 --- a/tests/functional/networkTests.py +++ b/tests/functional/networkTests.py @@ -21,6 +21,7 @@ import os.path import json import signal +import netaddr from hookValidation import ValidatesHook from testlib import (VdsmTestCase as TestCaseBase, namedTemporaryDir, @@ -34,11 +35,11 @@ import veth from nose import with_setup from nose.plugins.skip import SkipTest -from utils import SUCCESS, VdsProxy, cleanupRules +from utils import SUCCESS, VdsProxy, cleanupRules, wait_for_predicate from vdsm.ipwrapper import (ruleAdd, ruleDel, routeAdd, routeDel, routeExists, ruleExists, Route, Rule, addrFlush, LinkType, - getLinks) + getLinks, routeShowTable) from vdsm.constants import EXT_BRCTL from vdsm.utils import RollbackContext, execCmd @@ -94,11 +95,12 @@ @contextmanager -def dnsmasqDhcp(interface): +def dnsmasqDhcp(interface, dhcp_router=None): """Manages the life cycle of dnsmasq as a DHCP server.""" dhcpServer = dhcp.Dnsmasq() try: - dhcpServer.start(interface, DHCP_RANGE_FROM, DHCP_RANGE_TO) + dhcpServer.start(interface, DHCP_RANGE_FROM, DHCP_RANGE_TO, + router=dhcp_router) except dhcp.DhcpError as e: raise SkipTest(e) @@ -1907,10 +1909,12 @@ @RequireVethMod @ValidateRunningAsRoot def testSetupNetworksAddDelDhcp(self, bridged): + self.assertTrue( + os.path.exists('/etc/dhcp/dhclient.d/sourceRoute.sh')) with vethIf() as (left, right): veth.setIP(left, IP_ADDRESS, IP_CIDR) veth.setLinkUp(left) - with dnsmasqDhcp(left): + with dnsmasqDhcp(left, dhcp_router=IP_GATEWAY): network = {NETWORK_NAME: {'nic': right, 'bridged': bridged, 'bootproto': 'dhcp', 'blockingdhcp': True}} @@ -1921,7 +1925,6 @@ net = self.vdsm_net.netinfo.networks[NETWORK_NAME] self.assertEqual(net['bootproto4'], 'dhcp') - if bridged: self.assertEqual(net['cfg']['BOOTPROTO'], 'dhcp') @@ -1929,11 +1932,35 @@ self.assertIn(NETWORK_NAME, devs) self.assertEqual(devs[NETWORK_NAME]['cfg']['BOOTPROTO'], 'dhcp') + route_rule_dev = NETWORK_NAME else: devs = self.vdsm_net.netinfo.nics self.assertIn(right, devs) self.assertEqual(devs[right]['cfg']['BOOTPROTO'], 'dhcp') + route_rule_dev = right + + device_ip_addr = netaddr.IPAddress(net['addr']) + routing_table = str(device_ip_addr.value) + rule1 = Rule(table=routing_table, + destination=IP_NETWORK_AND_CIDR, + srcDevice=NETWORK_NAME) + rule2 = Rule(table=routing_table, + source=IP_NETWORK_AND_CIDR) + + # DHCP source routing configuration is async hence we wait + # patiently + rules_exist = lambda: (ruleExists(rule1) and ruleExists(rule2)) + wait_for_predicate(rules_exist, 10) + routes = [Route.fromText(r) + for r in routeShowTable(routing_table)] + default_route = Route('0.0.0.0/0', via=IP_GATEWAY, + device=str(route_rule_dev)) + specific_route = Route(IP_NETWORK_AND_CIDR, + via=str(device_ip_addr), + device=str(route_rule_dev)) + self.assertIn(default_route, routes) + self.assertIn(specific_route, routes) network = {NETWORK_NAME: {'remove': True}} status, msg = self.vdsm_net.setupNetworks(network, {}, NOCHK) diff --git a/tests/functional/utils.py b/tests/functional/utils.py index 40c59ba..394b61f 100644 --- a/tests/functional/utils.py +++ b/tests/functional/utils.py @@ -227,3 +227,13 @@ def updateVmPolicy(self, vmId, vcpuLimit): result = self.vdscli.updateVmPolicy([vmId, vcpuLimit]) return result['status']['code'], result['status']['message'] + + +def wait_for_predicate(predicate, timeout, poll_period=1): + absolute_timeout = time.time() + timeout + while time.time() <= absolute_timeout: + res = predicate() + if res: + return res + time.sleep(poll_period) + return False -- To view, visit http://gerrit.ovirt.org/33612 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib510bb56c205dffc98aa2bae3f55c1b4c7f6f56f Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Ido Barkan <ibar...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches