[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [test-API PATCH 7/7] domain/[start|destroy]: Add a optional noping flag to skip the ping test



For some tests it's not needed to ping the guest in the startup process.
This patch adds a flag to the start and destroy test to skip such
attempts (that consume a lot of time)
---
 repos/domain/destroy.py |   54 ++++++++++++++++++++++++++--------------------
 repos/domain/start.py   |   50 ++++++++++++++++++++----------------------
 2 files changed, 54 insertions(+), 50 deletions(-)

diff --git a/repos/domain/destroy.py b/repos/domain/destroy.py
index f98b602..12399d6 100644
--- a/repos/domain/destroy.py
+++ b/repos/domain/destroy.py
@@ -50,7 +50,10 @@ def destroy(params):
        {'guestname': guestname}

        logger -- an object of utils/Python/log.py
-       guestname -- same as the domain name
+       guestname -- the domain name
+       flags -- optional arguments:
+                  noping: Don't do the ping test
+

        Return 0 on SUCCESS or 1 on FAILURE
     """
@@ -62,6 +65,7 @@ def destroy(params):
     if params_check_result:
         return 1
     guestname = params['guestname']
+    flags = params['flags']

     # Connect to local hypervisor connection URI
     util = utils.Utils()
@@ -73,18 +77,19 @@ def destroy(params):
     dom_obj = domainAPI.DomainAPI(virconn)
     dom_name_list = dom_obj.get_list()
     if guestname not in dom_name_list:
-        logger.error("guest %s doesn't exist or not be running." % guestname)
+        logger.error("guest %s doesn't exist or isn't running." % guestname)
         conn.close()
         logger.info("closed hypervisor connection")
         return 1
     timeout = 60
     logger.info('destroy domain')

-    # Get domain ip
-    mac = util.get_dom_mac_addr(guestname)
-    logger.info("get ip by mac address")
-    ip = util.mac_to_ip(mac, 180)
-    logger.info("the ip address of guest is %s" % ip)
+    if not("noping" in flags):
+        # Get domain ip
+        mac = util.get_dom_mac_addr(guestname)
+        logger.info("get ip by mac address")
+        ip = util.mac_to_ip(mac, 180)
+        logger.info("the ip address of guest is %s" % ip)

     # Destroy domain
     try:
@@ -93,30 +98,31 @@ def destroy(params):
         except LibvirtAPI, e:
             logger.error("API error message: %s, error code is %s" % \
                          (e.response()['message'], e.response()['code']))
-            logger.error("fail to destroy domain")
+            logger.error("failed to destroy domain")
             return 1
     finally:
         conn.close()
         logger.info("closed hypervisor connection")

     # Check domain status by ping ip
-    while timeout:
-        time.sleep(10)
-        timeout -= 10
-        logger.info(str(timeout) + "s left")
-
-        logger.info('ping guest')
-
-        if util.do_ping(ip, 30):
-            logger.error('The guest is still active, IP: ' + str(ip))
+    if not "noping" in flags:
+        while timeout:
+            time.sleep(10)
+            timeout -= 10
+            logger.info(str(timeout) + "s left")
+
+            logger.info('ping guest')
+
+            if util.do_ping(ip, 30):
+                logger.error('The guest is still active, IP: ' + str(ip))
+                return 1
+            else:
+                logger.info("domain %s was destroyed successfully" % guestname)
+                break
+
+        if timeout <= 0:
+            logger.error("the domain couldn't be destroyed within 60 seconds.")
             return 1
-        else:
-            logger.info("domain %s is destroied successfully" % guestname)
-            break
-
-    if timeout <= 0:
-        logger.error("the domain couldn't be destroied within 60 secs.")
-        return 1

     return 0

diff --git a/repos/domain/start.py b/repos/domain/start.py
index 39ac47f..483ea7a 100644
--- a/repos/domain/start.py
+++ b/repos/domain/start.py
@@ -66,7 +66,7 @@ def start(params):

         logger -- an object of utils/Python/log.py
         mandatory arguments : guestname -- same as the domain name
-	optional arguments : flags -- domain create flags <none|start_paused>
+	optional arguments : flags -- domain create flags <none|start_paused|noping>

         Return 0 on SUCCESS or 1 on FAILURE
     """
@@ -75,13 +75,11 @@ def start(params):
     check_params(params)
     domname = params['guestname']
     logger = params['logger']
+    flags = params['flags']

-    flags = None
-    if params.has_key('flags'):
-        flags = params['flags']
-        if flags != 'none' and flags != 'start_paused':
-            logger.error("flags value either \"none\" or \"start_paused\"");
-            return 1
+    if "none" in flags and "start_paused" in flags:
+        logger.error("Flags error: Can't specify none and start_paused simultaneously")
+        return (conn, logger, 1)

     # Connect to local hypervisor connection URI
     util = utils.Utils()
@@ -95,21 +93,18 @@ def start(params):
     logger.info('start domain')

     try:
-        if flags == "none":
+        if "none" in flags:
             dom_obj.start_with_flags(domname, NONE)
-        elif flags == "start_paused":
+        elif "start_paused" in flags:
             dom_obj.start_with_flags(domname, START_PAUSED)
-        elif not flags:
-            dom_obj.start(domname)
         else:
-            logger.error("flags error")
-            return (conn, logger, 1)
+            dom_obj.start(domname)
     except LibvirtAPI, e:
         logger.error(str(e))
         logger.error("start failed")
         return return_close(conn, logger, 1)

-    if flags == "start_paused":
+    if "start_paused" in flags:
         state = dom_obj.get_state(domname)
         if state == "paused":
             logger.info("guest start with state paused successfully")
@@ -119,29 +114,32 @@ def start(params):
             return return_close(conn, logger, 1)

     while timeout:
-        time.sleep(10)
-        timeout -= 10
-        logger.info(str(timeout) + "s left")
-
         state = dom_obj.get_state(domname)
         expect_states = ['running', 'no state', 'blocked']

         if state in expect_states:
             break

+        time.sleep(10)
+        timeout -= 10
+        logger.info(str(timeout) + "s left")
+
     if timeout <= 0:
         logger.error('The domain state is not as expected, state: ' + state)
         return return_close(conn, logger, 1)

-    # Get domain ip and ping ip to check domain's status
-    mac = util.get_dom_mac_addr(domname)
-    logger.info("get ip by mac address")
-    ip = util.mac_to_ip(mac, 180)
+    logger.info("Guest started")

-    logger.info('ping guest')
-    if not util.do_ping(ip, 300):
-        logger.error('Failed on ping guest, IP: ' + str(ip))
-        return return_close(conn, logger, 1)
+    # Get domain ip and ping ip to check domain's status
+    if not "noping" in flags:
+        mac = util.get_dom_mac_addr(domname)
+        logger.info("get ip by mac address")
+        ip = util.mac_to_ip(mac, 180)
+
+        logger.info('ping guest')
+        if not util.do_ping(ip, 300):
+            logger.error('Failed on ping guest, IP: ' + str(ip))
+            return return_close(conn, logger, 1)

     logger.info("PASS")
     return return_close(conn, logger, 0)
-- 
1.7.3.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]