vPing.py: added timeout when building the VMs
authorjose.lausuch <jose.lausuch@ericsson.com>
Wed, 20 May 2015 20:27:12 +0000 (22:27 +0200)
committerjose.lausuch <jose.lausuch@ericsson.com>
Wed, 20 May 2015 20:30:35 +0000 (22:30 +0200)
JIRA: FUNCTEST-3

Change-Id: I5dfc80bb7a42d92a684d57f30abbe837518422df
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
testcases/vPing/CI/libraries/vPing.py

index 3836a1a..1eb219d 100644 (file)
@@ -24,6 +24,7 @@ with open(HOME+'.functest/functest.yaml') as f:
     functest_yaml = yaml.safe_load(f)
 f.close()
 
+VM_BOOT_TIMEOUT = 180
 PING_TIMEOUT = functest_yaml.get("vping").get("ping_timeout")
 NAME_VM_1 = functest_yaml.get("vping").get("vm_name_1")
 NAME_VM_2 = functest_yaml.get("vping").get("vm_name_2")
@@ -98,10 +99,18 @@ def get_server(creds, servername):
 
 def waitVmActive(nova,vm):
     # sleep and wait for VM status change
-    while get_status(nova,vm) != "ACTIVE":
-        time.sleep(3)
-        logger.debug("Status: %s" % vm.status)
-    logger.debug("Status: %s" % vm.status)
+    sleep_time = 3
+    count = VM_BOOT_TIMEOUT / sleep_time
+    while True:
+        status = get_status(nova,vm)
+        logger.debug("Status: %s" % status)
+        if status == "ACTIVE":
+            return True
+        if status == "ERROR" or count == 0:
+            return False
+            count-=1
+        time.sleep(sleep_time)
+    return False
 
 def get_status(nova,vm):
     vm = nova.servers.get(vm.id)
@@ -172,7 +181,11 @@ def main():
 
 
     #wait until VM status is active
-    waitVmActive(nova,vm1)
+    if not waitVmActive(nova,vm1):
+        logger.error("Instance '%s' cannot be booted. Status is '%s'" % (NAME_VM_1,get_status(nova,vm1)))
+        return (EXIT_CODE)
+    else:
+        logger.info("Instance '%s' is ACTIVE." % NAME_VM_1)
 
     #retrieve IP of first VM
     logger.debug("Fetching IP...")
@@ -199,7 +212,11 @@ def main():
         userdata           = u,
     )
 
-    waitVmActive(nova,vm2)
+    if not waitVmActive(nova,vm2):
+        logger.error("Instance '%s' cannot be booted. Status is '%s'" % (NAME_VM_2,get_status(nova,vm2)))
+        return (EXIT_CODE)
+    else:
+        logger.info("Instance '%s' is ACTIVE." % NAME_VM_2)
 
     sec = 0
     console_log = vm2.get_console_output()