All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/19] KVM test: kvm_utils.py: make verify_ip_address_ownership() more robust
@ 2009-09-09 18:11 Michael Goldish
  2009-09-09 18:11 ` [PATCH 02/19] KVM test: Migration test cleanup Michael Goldish
  2009-09-10  3:25 ` [Autotest] [PATCH 01/19] KVM test: kvm_utils.py: make verify_ip_address_ownership() more robust Lucas Meneghel Rodrigues
  0 siblings, 2 replies; 27+ messages in thread
From: Michael Goldish @ 2009-09-09 18:11 UTC (permalink / raw)
  To: autotest, kvm; +Cc: Michael Goldish

Use arping in addition to querying the arp cache.
Under certain circumstances a TCP connection may not trigger an ARP request so
it must be triggered explicitly using arping.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 client/tests/kvm/kvm_utils.py |   40 ++++++++++++++++++----------------------
 1 files changed, 18 insertions(+), 22 deletions(-)

diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py
index dfca938..f046810 100644
--- a/client/tests/kvm/kvm_utils.py
+++ b/client/tests/kvm/kvm_utils.py
@@ -152,39 +152,35 @@ def get_mac_ip_pair_from_dict(dict):
     return (None, None)
 
 
-def verify_ip_address_ownership(ip, macs, timeout=3.0):
+def verify_ip_address_ownership(ip, macs, timeout=10.0):
     """
-    Connect to a given IP address and make sure its MAC address equals one of
-    the given MAC address.
+    Use arping and the ARP cache to make sure a given IP address belongs to one
+    of the given MAC addresses.
 
     @param ip: An IP address.
     @param macs: A list or tuple of MAC addresses.
     @return: True iff ip is assigned to a MAC address in macs.
     """
-    def check_arp_cache(regex):
-        o = commands.getoutput("/sbin/arp -n")
-        return bool(re.search(regex, o, re.IGNORECASE))
-
+    # Compile a regex that matches the given IP address and any of the given
+    # MAC addresses
     mac_regex = "|".join("(%s)" % mac for mac in macs)
     regex = re.compile(r"\b%s\b.*\b(%s)\b" % (ip, mac_regex))
 
-    if check_arp_cache(regex):
+    # Check the ARP cache
+    o = commands.getoutput("/sbin/arp -n")
+    if re.search(regex, o, re.IGNORECASE):
         return True
 
-    s = socket.socket()
-    s.setblocking(False)
-    try:
-        s.connect((ip, 55555))
-    except socket.error:
-        pass
-    end_time = time.time() + timeout
-    while time.time() < end_time:
-        time.sleep(0.2)
-        if check_arp_cache(regex):
-            s.close()
-            return True
-    s.close()
-    return False
+    # Get the name of the bridge device for arping
+    o = commands.getoutput("/sbin/ip route get %s" % ip)
+    dev = re.findall("dev\s+\S+", o, re.IGNORECASE)
+    if not dev:
+        return False
+    dev = dev[0].split()[-1]
+
+    # Send an ARP request
+    o = commands.getoutput("/sbin/arping -f -c 3 -I %s %s" % (dev, ip))
+    return bool(re.search(regex, o, re.IGNORECASE))
 
 
 # Functions for working with the environment (a dict-like object)
-- 
1.5.4.1


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2009-11-24  4:12 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-09 18:11 [PATCH 01/19] KVM test: kvm_utils.py: make verify_ip_address_ownership() more robust Michael Goldish
2009-09-09 18:11 ` [PATCH 02/19] KVM test: Migration test cleanup Michael Goldish
2009-09-09 18:11   ` [PATCH 03/19] KVM test: scan_results.py: allow parsing and printing of multiple result files Michael Goldish
2009-09-09 18:11     ` [PATCH 04/19] KVM test: kvm_utils.py: add kill_process_tree() Michael Goldish
2009-09-09 18:11       ` [PATCH 05/19] KVM test: kvm_subprocess: use kill_process_tree() to close child processes Michael Goldish
2009-09-09 18:11         ` [PATCH 06/19] KVM test: timedrift test: set CPU affinity recursively for all children Michael Goldish
2009-09-09 18:12           ` [PATCH 07/19] KVM test: kvm_subprocess: get rid of get_pid() (replace it with get_shell_pid()) Michael Goldish
2009-09-09 18:12             ` [PATCH 08/19] KVM test: remove unused function is_sshd_running() Michael Goldish
2009-09-09 18:12               ` [PATCH 09/19] KVM test: kvm_config.py: remove unused function get_match_block_indices() Michael Goldish
2009-09-09 18:12                 ` [PATCH 10/19] KVM test: boot test: add option to reboot using system_reset Michael Goldish
2009-09-09 18:12                   ` [PATCH 11/19] KVM test: shutdown test: allow shutting down using system_powerdown Michael Goldish
2009-09-09 18:12                     ` [PATCH 12/19] KVM test: Add new module kvm_test_utils.py Michael Goldish
2009-09-09 18:12                       ` [PATCH 13/19] KVM test: kvm_tests.py: save test code by using utilities in kvm_test_utils.py Michael Goldish
2009-09-09 18:12                         ` [PATCH 14/19] KVM test: kvm_preprocessing.py: don't explicitly print failure messages Michael Goldish
2009-09-09 18:12                           ` [PATCH 15/19] KVM test: Autotest test wrapper cleanup Michael Goldish
2009-09-09 18:12                             ` [PATCH 16/19] KVM test: kvm_subprocess: robustify the test for child process termination Michael Goldish
2009-09-09 18:12                               ` [PATCH 17/19] KVM test: kvm_vm.py: add macaddr= to command line only if a MAC address is given Michael Goldish
2009-09-09 18:12                                 ` [PATCH 18/19] KVM test: kvm_tests.cfg.sample: get all Windows test utilities from a single ISO Michael Goldish
2009-09-09 18:12                                   ` [PATCH 19/19] KVM test: kvm_preprocessing.py: verify PPM file validity before passing to PIL Michael Goldish
2009-09-10  3:24                                     ` [Autotest] " Lucas Meneghel Rodrigues
2009-09-10  3:19                                   ` [Autotest] [PATCH 18/19] KVM test: kvm_tests.cfg.sample: get all Windows test utilities from a single ISO Lucas Meneghel Rodrigues
2009-11-24  4:12                                     ` sudhir kumar
2009-09-10  3:16                             ` [Autotest] [PATCH 15/19] KVM test: Autotest test wrapper cleanup Lucas Meneghel Rodrigues
2009-09-14  5:26                       ` [Autotest] [PATCH 12/19] KVM test: Add new module kvm_test_utils.py Yolkfull Chow
2009-09-14  7:58                         ` Uri Lublin
2009-09-14  8:40                           ` Yolkfull Chow
2009-09-10  3:25 ` [Autotest] [PATCH 01/19] KVM test: kvm_utils.py: make verify_ip_address_ownership() more robust Lucas Meneghel Rodrigues

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.