]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Introduce functions using arping executable
authorJakub Libosvar <libosvar@redhat.com>
Tue, 9 Jun 2015 16:08:50 +0000 (16:08 +0000)
committerJakub Libosvar <libosvar@redhat.com>
Wed, 10 Jun 2015 08:43:33 +0000 (10:43 +0200)
The arpinger is gonna be used in the next changeset introducing
connection testers.

Change-Id: I90ae32c2f52f1debfb11ae2a08b2828ee2be04cc

neutron/tests/common/net_helpers.py

index 8884c66966cc62a140f2cff6b82b065120f832af..cce352d0cbf3ee1856d63cc8e962ced616dd782c 100644 (file)
@@ -81,6 +81,31 @@ def assert_no_ping(src_namespace, dst_ip, timeout=1, count=1):
                    {'ns': src_namespace, 'destination': dst_ip})
 
 
+def assert_arping(src_namespace, dst_ip, source=None, timeout=1, count=1):
+    """Send arp request using arping executable.
+
+    NOTE: ARP protocol is used in IPv4 only. IPv6 uses Neighbour Discovery
+    Protocol instead.
+    """
+    ns_ip_wrapper = ip_lib.IPWrapper(src_namespace)
+    arping_cmd = ['arping', '-c', count, '-w', timeout]
+    if source:
+        arping_cmd.extend(['-s', source])
+    arping_cmd.append(dst_ip)
+    ns_ip_wrapper.netns.execute(arping_cmd)
+
+
+def assert_no_arping(src_namespace, dst_ip, source=None, timeout=1, count=1):
+    try:
+        assert_arping(src_namespace, dst_ip, source, timeout, count)
+    except RuntimeError:
+        pass
+    else:
+        tools.fail("destination ip %(destination)s is replying to arp from "
+                   "namespace %(ns)s, but it shouldn't" %
+                   {'ns': src_namespace, 'destination': dst_ip})
+
+
 class NamespaceFixture(fixtures.Fixture):
     """Create a namespace.