Change in vdsm[master]: testSetupNetworksAddDelDhcp: Check that an DHCPv4 address is...

osvoboda at redhat.com osvoboda at redhat.com
Mon Dec 15 16:51:17 UTC 2014


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

Change subject: testSetupNetworksAddDelDhcp: Check that an DHCPv4 address is in range
......................................................................

testSetupNetworksAddDelDhcp: Check that an DHCPv4 address is in range

(At least) one address is now required to be in a range we know and control.
Also introduce range checking for IPv6.

Change-Id: Ied7e11e84b8f81c39c799fadfca06b7bde0a409c
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M tests/functional/networkTests.py
1 file changed, 26 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/86/36186/1

diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index f23f033..c09e122 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -22,6 +22,8 @@
 import json
 import signal
 import netaddr
+import socket
+import struct
 
 from hookValidation import ValidatesHook
 from network.sourceroute import StaticSourceRoute
@@ -217,6 +219,20 @@
                 del attrs['d']
 
 
+# adapted from http://stackoverflow.com/questions/10558441/
+# inet-aton-similar-function-for-ipv6
+def _ipv4_to_int(addr):
+    addr = addr.split('/')[0]  # remove the network prefix
+    return struct.unpack('>L', socket.inet_aton(addr))[0]
+
+
+def _ipv6_to_int(addr):
+    addr = addr.split('/')[0]  # remove the network prefix
+    addr = socket.inet_pton(socket.AF_INET6, addr)
+    hi, lo = struct.unpack(">QQ", addr)
+    return (hi << 64) | lo
+
+
 @expandPermutations
 class NetworkTest(TestCaseBase):
 
@@ -367,6 +383,15 @@
     def assertMtu(self, mtu, *elems):
         for elem in elems:
             self.assertEquals(int(mtu), int(self.vdsm_net.getMtu(elem)))
+
+    def assertAddrInRange(self, addrs, family=4,
+                          range_from=DHCP_RANGE_FROM, range_to=DHCP_RANGE_TO):
+        addr_to_int = _ipv4_to_int if family == 4 else _ipv6_to_int
+        range_from = addr_to_int(range_from)
+        range_to = addr_to_int(range_to)
+        passes = (range_from <= addr_to_int(a) <= range_to for a in addrs)
+        self.assertTrue(any(passes), 'no address {0} in expected range'.format(
+            addrs))
 
     def testLegacyBonds(self):
         if not (caps.getos() in (caps.OSName.RHEVH, caps.OSName.RHEL)
@@ -1773,6 +1798,7 @@
                     device_name = right
 
                 if dhcpv4:
+                    self.assertAddrInRange(test_net['ipv4addrs'])
                     # TODO: source routing not ready for IPv6
                     ip_addr = test_net['addr']
                     self.assertSourceRoutingConfiguration(device_name, ip_addr)


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ied7e11e84b8f81c39c799fadfca06b7bde0a409c
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