Skip to contentSkip to conversation

KVM Test: Add re.IGNORECASE to re.compile to verify_ip_address_ in kvm_utils.py

PATCH New Cao, Chen 1 participant 2 messages Oct 27, 2009 – Oct 28, 2009 KVM

lore
Share & tools
lore

Cao, Chen

author
#0 lore raw

PATCH 1/1 KVM Test: Add re.IGNORECASE to re.compile to verify_ip_address_ in kvm_utils.py

Since the mac address is (changed to) lowercase and the output of 'arping' is in uppercase, we need re.IGNORECASE in the re.compile.

(the re.IGNORECASE in the re.search function takes no effect on the compiled regex.)

---
 client/tests/kvm/kvm_utils.py |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
client/tests/kvm/kvm_utils.py +1 -1
index f72984a..934f223 100644
@@ -190,7 +190,7 @@ def verify_ip_address_ownership(ip, macs, timeout=10.0):
     # 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))
+    regex = re.compile(r"\b%s\b.*\b(%s)\b" % (ip, mac_regex), re.IGNORECASE)
 
     # Check the ARP cache
     o = commands.getoutput("/sbin/arp -n")
Signature · 1 line
1.6.0.6
author
#1 lore raw

PATCH 1/1 KVM Test: Add re.IGNORECASE to re.compile to verify_ip_address_ in kvm_utils.py - v2

Since the mac address is (changed to) lowercase and the output of 'arping' is in uppercase, we need re.IGNORECASE in the re.compile.

And substitute re.search(regex, 0, ...) with regex.search(o), as Michael Goldish ([email protected]) suggested.

---
 client/tests/kvm/kvm_utils.py |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
client/tests/kvm/kvm_utils.py +3 -3
index f72984a..b9219f6 100644
@@ -190,11 +190,11 @@ def verify_ip_address_ownership(ip, macs, timeout=10.0):
     # 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))
+    regex = re.compile(r"\b%s\b.*\b(%s)\b" % (ip, mac_regex), re.IGNORECASE)
 
     # Check the ARP cache
     o = commands.getoutput("/sbin/arp -n")
-    if re.search(regex, o, re.IGNORECASE):
+    if regex.search(o):
         return True
 
     # Get the name of the bridge device for arping
@@ -206,7 +206,7 @@ def verify_ip_address_ownership(ip, macs, timeout=10.0):
 
     # 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))
+    return bool(regex.search(o))
 
 
 # Functions for working with the environment (a dict-like object)
Signature · 1 line
1.6.0.6