Change in vdsm[master]: tests: Support DHCPv6 in dnsmasq and dhclient wrappers

osvoboda at redhat.com osvoboda at redhat.com
Tue Dec 23 01:21:21 UTC 2014


Ondřej Svoboda has uploaded a new change for review.

Change subject: tests: Support DHCPv6 in dnsmasq and dhclient wrappers
......................................................................

tests: Support DHCPv6 in dnsmasq and dhclient wrappers

Also account for EL6's dnsmasq not supporting DHCPv6.

Change-Id: I2ac7e88351dc7e737db6effeead5a76c0a1a61d1
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M tests/functional/dhcp.py
M tests/functional/firewall.py
M tests/functional/networkTests.py
3 files changed, 49 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/47/36347/1

diff --git a/tests/functional/dhcp.py b/tests/functional/dhcp.py
index e719ba8..404b8de 100644
--- a/tests/functional/dhcp.py
+++ b/tests/functional/dhcp.py
@@ -45,7 +45,8 @@
     def __init__(self):
         self.proc = None
 
-    def start(self, interface, dhcp_range_from, dhcp_range_to, router=None):
+    def start(self, interface, dhcp_range_from, dhcp_range_to,
+              dhcpv6_range_from=None, dhcpv6_range_to=None, router=None):
         # -p 0                      don't act as a DNS server
         # --dhcp-option=3,<router>  advertise a specific gateway (or None)
         # --dhcp-option=6           don't reply with any DNS servers
@@ -57,7 +58,10 @@
             '--dhcp-option=3' + (',{0}'.format(router) if router else ''),
             '--dhcp-option=6',
             '-i', interface, '-I', 'lo', '-d',
-            '--bind-interfaces'], sync=False)
+            '--bind-interfaces']
+            + (['--dhcp-range={0},{1},2m'.format(dhcpv6_range_from,
+                                                 dhcpv6_range_to)]
+               if dhcpv6_range_from and dhcpv6_range_to else []), sync=False)
         sleep(_START_CHECK_TIMEOUT)
         if self.proc.returncode:
             raise DhcpError('Failed to start dnsmasq DHCP server.' +
@@ -78,16 +82,19 @@
     In the working directory (tmp_dir), which is managed by the caller.
     dhclient accepts the following date_formats: 'default' and 'local'.
     """
-    def __init__(self, interface, tmp_dir, date_format, default_route=False):
+    def __init__(self, interface, family, tmp_dir, date_format,
+                 default_route=False):
         self._interface = interface
+        self._family = family
         self._date_format = date_format
         self._conf_file = os.path.join(tmp_dir, 'test.conf')
         self._pid_file = os.path.join(tmp_dir, 'test.pid')
         self.pid = None
         self.lease_file = os.path.join(tmp_dir, 'test.lease')
-        cmd = [_DHCLIENT_BINARY.cmd, '-v', '-lf', self.lease_file, '-pf',
-               self._pid_file, '-timeout', str(_DHCLIENT_TIMEOUT), '-1',
-               '-cf', self._conf_file]
+        cmd = [_DHCLIENT_BINARY.cmd, '-' + str(family), '-1', '-v',
+               '-timeout', str(_DHCLIENT_TIMEOUT), '-cf', self._conf_file,
+               '-pf', self._pid_file, '-lf', self.lease_file
+               ]
         if not default_route:
             # Instruct Fedora/EL's dhclient-script not to set gateway on iface
             cmd += ['-e', 'DEFROUTE=no']
diff --git a/tests/functional/firewall.py b/tests/functional/firewall.py
index dee28c2..259f296 100644
--- a/tests/functional/firewall.py
+++ b/tests/functional/firewall.py
@@ -43,7 +43,10 @@
         if _serviceRunning('iptables'):
             _execCmdChecker([_IPTABLES_BINARY.cmd, '-I', 'INPUT', '-i',
                             veth, '-p', 'udp', '--sport', '68', '--dport',
-                            '67', '-j', 'ACCEPT'])
+                            '67', '-j', 'ACCEPT'])  # DHCPv4
+            _execCmdChecker([_IPTABLES_BINARY.cmd, '-I', 'INPUT', '-i',
+                            veth, '-p', 'udp', '--sport', '546', '--dport',
+                            '547', '-j', 'ACCEPT'])  # DHCPv6
         elif _serviceRunning('firewalld'):
             _execCmdChecker([_FIREWALLD_BINARY.cmd, '--zone=trusted',
                             '--change-interface=' + veth])
@@ -67,7 +70,10 @@
     if _serviceRunning('iptables'):
         _execCmdChecker([_IPTABLES_BINARY.cmd, '-D', 'INPUT', '-i',
                         veth, '-p', 'udp', '--sport', '68', '--dport',
-                        '67', '-j', 'ACCEPT'])
+                        '67', '-j', 'ACCEPT'])  # DHCPv4
+        _execCmdChecker([_IPTABLES_BINARY.cmd, '-D', 'INPUT', '-i',
+                        veth, '-p', 'udp', '--sport', '546', '--dport',
+                        '547', '-j', 'ACCEPT'])  # DHCPv6
     elif _serviceRunning('firewalld'):
         _execCmdChecker([_FIREWALLD_BINARY.cmd, '--zone=trusted',
                         '--remove-interface=' + veth])
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 5a997cd..f0bc377 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -66,6 +66,8 @@
 IP_GATEWAY = str(_ip_network.broadcast - 1)
 DHCP_RANGE_FROM = '240.0.0.10'
 DHCP_RANGE_TO = '240.0.0.100'
+DHCPv6_RANGE_FROM = 'fdb3:84e5:4ff4:55e3::a'
+DHCPv6_RANGE_TO = 'fdb3:84e5:4ff4:55e3::64'
 CUSTOM_PROPS = {'linux': 'rules', 'vdsm': 'as well'}
 
 IPv6_ADDRESS = 'fdb3:84e5:4ff4:55e3::1'
@@ -98,12 +100,17 @@
 
 
 @contextmanager
-def dnsmasqDhcp(interface):
-    """Manages the life cycle of dnsmasq as a DHCP server."""
+def dnsmasqDhcp(interface, dhcpv6=False):
+    """Manages the life cycle of dnsmasq as a DHCP server.
+
+    'dhcpv6' parameter is solely for compatibility with EL6's dnsmasq which
+    is not able to act as a DHCPv6 server"""
     dhcpServer = dhcp.Dnsmasq()
     try:
+        dhcpv6_range_from, dhcpv6_range_to = (
+            (DHCPv6_RANGE_FROM, DHCPv6_RANGE_TO) if dhcpv6 else (None, None))
         dhcpServer.start(interface, DHCP_RANGE_FROM, DHCP_RANGE_TO,
-                         router=IP_GATEWAY)
+                         dhcpv6_range_from, dhcpv6_range_to, router=IP_GATEWAY)
     except dhcp.DhcpError as e:
         raise SkipTest(e)
 
@@ -216,6 +223,11 @@
                 del attrs['m1']
             if attrs.get('d') == 0:
                 del attrs['d']
+
+
+def _system_is_el6():
+    return (caps.getos() in (caps.OSName.RHEVH, caps.OSName.RHEL)
+            and caps.osversion()['version'].startswith('6'))
 
 
 @expandPermutations
@@ -370,8 +382,7 @@
             self.assertEquals(int(mtu), int(self.vdsm_net.getMtu(elem)))
 
     def testLegacyBonds(self):
-        if not (caps.getos() in (caps.OSName.RHEVH, caps.OSName.RHEL)
-                and caps.osversion()['version'].startswith('6')):
+        if not _system_is_el6():
             raise SkipTest('legacy bonds are expected only on el6')
 
         for b in caps._REQUIRED_BONDINGS:
@@ -1697,10 +1708,13 @@
     @cleanupNet
     @RequireVethMod
     def testSetupNetworksAddDelDhcp(self, bridged):
+        el6 = _system_is_el6()
+
         with vethIf() as (left, right):
             veth.setIP(left, IP_ADDRESS, IP_CIDR)
+            veth.setIP(left, IPv6_ADDRESS, IPv6_CIDR, 6)
             veth.setLinkUp(left)
-            with dnsmasqDhcp(left):
+            with dnsmasqDhcp(left, dhcpv6=not el6):
                 dhcpv4 = True
                 bootproto = 'dhcp'
                 network_name = NETWORK_NAME
@@ -1756,18 +1770,21 @@
     @cleanupNet
     @RequireVethMod
     def testDhclientLeases(self, dateFormat):
+        el6 = _system_is_el6()
+
         dhcpv4 = set()
         with vethIf() as (server, client):
             with avoidAnotherDhclient(client):
 
                 veth.setIP(server, IP_ADDRESS, IP_CIDR)
+                veth.setIP(server, IPv6_ADDRESS, IPv6_CIDR, 6)
                 veth.setLinkUp(server)
 
-                with dnsmasqDhcp(server):
+                with dnsmasqDhcp(server, dhcpv6=not el6):
 
                     with namedTemporaryDir(dir='/var/lib/dhclient') as dir:
-                        dhclient_runner = dhcp.DhclientRunner(client, dir,
-                                                              dateFormat)
+                        dhclient_runner = dhcp.DhclientRunner(
+                            client, 4, dir, dateFormat)
                         try:
                             with running(dhclient_runner) as dhc:
                                 dhcpv4 = _get_dhclient_ifaces([dhc.lease_file])
@@ -2040,8 +2057,8 @@
                     with namedTemporaryDir(dir='/var/lib/dhclient') as dhdir:
                         # Start a non-vdsm owned dhclient for the 'client'
                         # iface
-                        dhclient_runner = dhcp.DhclientRunner(client, dhdir,
-                                                              'default')
+                        dhclient_runner = dhcp.DhclientRunner(
+                            client, 4, dhdir, 'default')
                         with running(dhclient_runner):
                             # Set up a network over it and wait for dhcp
                             # success


-- 
To view, visit http://gerrit.ovirt.org/36347
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2ac7e88351dc7e737db6effeead5a76c0a1a61d1
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>


More information about the vdsm-patches mailing list