Skip to contentSkip to conversation

virt test: Simplifying address cache messages and exceptions

PATCH New Lucas Meneghel Rodrigues 1 participant 2 messages Dec 2, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 virt test: Simplifying address cache messages and exceptions

KVM autotest relies on a system that listens network traffic and registers DHCP leases, so we know what is the IP for a given guest network card. However, the terminology used on messages is highly specific to the internal implementation.

So let's use messages with a terminology that can be more easily understood by people not too familiar with the internals of autotest.

---
 client/virt/virt_env_process.py |    2 +-
 client/virt/virt_vm.py          |    8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
client/virt/virt_env_process.py +1 -1
index ab2f77e..a4b9f71 100644
@@ -449,7 +449,7 @@ def _update_address_cache(address_cache, line):
         if matches and address_cache.get("last_seen"):
             mac_address = matches[0].lower()
             if time.time() - address_cache.get("time_%s" % mac_address, 0) > 5:
-                logging.debug("(address cache) Adding cache entry: %s ---> %s",
+                logging.debug("(address cache) DCHP lease OK: %s --> %s",
                               mac_address, address_cache.get("last_seen"))
             address_cache[mac_address] = address_cache.get("last_seen")
             address_cache["time_%s" % mac_address] = time.time()
client/virt/virt_vm.py +4 -4
index 5cb900b..e2443dd 100644
@@ -130,8 +130,8 @@ class VMAddressVerificationError(VMAddressError):
         self.ip = ip
 
     def __str__(self):
-        return ("Cannot verify MAC-IP address mapping using arping: "
-                "%s ---> %s" % (self.mac, self.ip))
+        return ("Could not verify DHCP lease: "
+                "%s --> %s" % (self.mac, self.ip))
 
 
 class VMMACAddressMissingError(VMAddressError):
@@ -140,7 +140,7 @@ class VMMACAddressMissingError(VMAddressError):
         self.nic_index = nic_index
 
     def __str__(self):
-        return "No MAC address defined for NIC #%s" % self.nic_index
+        return "No MAC defined for NIC #%s" % self.nic_index
 
 
 class VMIPAddressMissingError(VMAddressError):
@@ -149,7 +149,7 @@ class VMIPAddressMissingError(VMAddressError):
         self.mac = mac
 
     def __str__(self):
-        return "Cannot find IP address for MAC address %s" % self.mac
+        return "No DHCP lease for MAC %s" % self.mac
 
 
 class VMAddNetDevError(VMError):
Signature · 1 line
1.7.7.3
#1 lore raw

PATCH 2/2 Virt: virt_utils - Reducing verbosity of the remote login code

Make the remote login code only print messages if a debug flag is turned on. This way we can get rid of many lines that may clutter debug logs that are only really needed in special occasions.

---
 client/virt/virt_utils.py |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
client/virt/virt_utils.py +14 -8
index 9672066..2b37f76 100644
@@ -564,7 +564,7 @@ class SCPTransferFailedError(SCPError):
                 (self.status, self.output))
 
 
-def _remote_login(session, username, password, prompt, timeout=10):
+def _remote_login(session, username, password, prompt, timeout=10, debug=False):
     """
     Log into a remote host (guest) using SSH or Telnet.  Wait for questions
     and provide answers.  If timeout expires while waiting for output from the
@@ -595,12 +595,14 @@ def _remote_login(session, username, password, prompt, timeout=10):
                  r"[Pp]lease wait", r"[Ww]arning", prompt],
                 timeout=timeout, internal_timeout=0.5)
             if match == 0:  # "Are you sure you want to continue connecting"
-                logging.debug("Got 'Are you sure...', sending 'yes'")
+                if debug:
+                    logging.debug("Got 'Are you sure...', sending 'yes'")
                 session.sendline("yes")
                 continue
             elif match == 1:  # "password:"
                 if password_prompt_count == 0:
-                    logging.debug("Got password prompt, sending '%s'", password)
+                    if debug:
+                        logging.debug("Got password prompt, sending '%s'", password)
                     session.sendline(password)
                     password_prompt_count += 1
                     continue
@@ -609,7 +611,8 @@ def _remote_login(session, username, password, prompt, timeout=10):
                                                    text)
             elif match == 2:  # "login:"
                 if login_prompt_count == 0 and password_prompt_count == 0:
-                    logging.debug("Got username prompt; sending '%s'", username)
+                    if debug:
+                        logging.debug("Got username prompt; sending '%s'", username)
                     session.sendline(username)
                     login_prompt_count += 1
                     continue
@@ -624,14 +627,17 @@ def _remote_login(session, username, password, prompt, timeout=10):
             elif match == 4:  # "Connection refused"
                 raise LoginError("Client said 'connection refused'", text)
             elif match == 5:  # "Please wait"
-                logging.debug("Got 'Please wait'")
+                if debug:
+                    logging.debug("Got 'Please wait'")
                 timeout = 30
                 continue
             elif match == 6:  # "Warning added RSA"
-                logging.debug("Got 'Warning added RSA to known host list")
+                if debug:
+                    logging.debug("Got 'Warning added RSA to known host list")
                 continue
             elif match == 7:  # prompt
-                logging.debug("Got shell prompt -- logged in")
+                if debug:
+                    logging.debug("Got shell prompt -- logged in")
                 break
         except aexpect.ExpectTimeoutError, e:
             raise LoginTimeoutError(e.output)
@@ -671,7 +677,7 @@ def remote_login(client, host, port, username, password, prompt, linesep="\n",
     else:
         raise LoginBadClientError(client)
 
-    logging.debug("Trying to login with command '%s'", cmd)
+    logging.debug("Login command: '%s'", cmd)
     session = aexpect.ShellSession(cmd, linesep=linesep, prompt=prompt)
     try:
         _remote_login(session, username, password, prompt, timeout)
Signature · 1 line
1.7.7.3