bugfix for vstf running
[bottlenecks.git] / testsuites / vstf / run_vstf.py
index 20cfa21..b9c782d 100755 (executable)
@@ -11,6 +11,7 @@
 import os
 import argparse
 import time
+import subprocess
 import logging
 import urllib2
 import shutil
@@ -72,7 +73,7 @@ def _download_url(src_url, dest_dir):
 
     with open(dest, 'wb') as f:
         shutil.copyfileobj(response, f)
-    return file_name
+    return dest
 
 def vstf_stack_satisfy(name="bottlenecks_vstf_stack", status="CREATE_COMPLETE"):
     heat = _get_heat_client()
@@ -127,15 +128,14 @@ def vstf_env_cleanup():
     else:
         return True
 
-def vstf_create_images(src_url=None, image_name="bottlenecks_vstf_image"):
+def vstf_create_images(imagefile=None, image_name="bottlenecks_vstf_image"):
     print "========== Create vstf image in OS =========="
-    dest_dir = '/tmp'
-    file_name = _download_url(src_url, dest_dir)
-    if file_name == None:
+
+    if imagefile == None:
+       print "imagefile not set/found"
        return False
 
     glance = _get_glance_client()
-    imagefile = dest_dir + "/" + file_name
     image = glance.images.create(name=image_name, disk_format="qcow2", container_format="bare")
     with open(imagefile) as fimage:
         glance.images.upload(image.id, fimage)
@@ -192,15 +192,29 @@ def get_instances(nova_client):
         print "Error [get_instances(nova_client)]:", e
         return None
 
-def vstf_run():
+def vstf_run(launch_file=None, test_file=None):
     print "================run vstf==============="
 
     nova = _get_nova_client()
     print(nova.servers.list())
+    print "## neutruon net-list:"
+    subprocess.call("neutron net-list", shell=True)
+    print "## nova list:"
+    subprocess.call("nova list", shell=True)
+    time.sleep(100)
     instances = get_instances(nova)
     if instances == None:
         print "Found *None* instances, exit vstf_run()!"
         return False
+    if launch_file == None or test_file == None:
+         print "Error, vstf launch/test file not given"
+         return False
+    cmd = "bash " + launch_file
+    subprocess.call(cmd, shell=True)
+    time.sleep(50)
+    cmd = "bash " + test_file
+    subprocess.call(cmd, shell=True)
+    time.sleep(20)
 
 def main():
 
@@ -209,6 +223,19 @@ def main():
     manager_image_url = 'http://artifacts.opnfv.org/bottlenecks/vstf-manager-new.img'
     agent_image_url = 'http://artifacts.opnfv.org/bottlenecks/vstf-agent-new.img'
 
+    #vstf_env_prepare(testcase_cfg)
+    vstf_env_cleanup()
+
+    dest_dir = "/tmp"
+    manager_file = _download_url(manager_image_url, dest_dir)
+    if manager_file == None:
+       print "error with downloading image(s)"
+       exit(-1)
+    agent_file = _download_url(agent_image_url, dest_dir)
+    if agent_file == None:
+       print "error with downloading image(s)"
+       exit(-1)
+
     #TO DO:the parameters are all used defaults here, it should be changed depends on what it is really named
     parameters={'key_name': 'bottlenecks_vstf_keypair',
                 'flavor': 'bottlenecks_vstf_flavor',
@@ -228,12 +255,9 @@ def main():
     target_image_created = False
     stack_created = False
 
-    #vstf_env_prepare(testcase_cfg)
-    vstf_env_cleanup()
-
-    manager_image_created = vstf_create_images(src_url=manager_image_url, image_name="vstf-manager")
-    tester_image_created = vstf_create_images(src_url=agent_image_url, image_name="vstf-tester")
-    target_image_created = vstf_create_images(src_url=agent_image_url, image_name="vstf-target")
+    manager_image_created = vstf_create_images(imagefile=manager_file, image_name="vstf-manager")
+    tester_image_created = vstf_create_images(imagefile=agent_file, image_name="vstf-tester")
+    target_image_created = vstf_create_images(imagefile=agent_file, image_name="vstf-target")
     keyPath = Bottlenecks_repo_dir + "/utils/infra_setup/bottlenecks_key/bottlenecks_key.pub"
     vstf_create_keypairs(key_path=keyPath)
     vstf_create_flavors()
@@ -244,10 +268,12 @@ def main():
         print "Cannot create instances, as Failed to create image(s)."
         exit (-1)
 
-    print "Wait 100 seconds after stack creation..."
-    time.sleep(100)
+    print "Wait 300 seconds after stack creation..."
+    time.sleep(300)
 
-    vstf_run()
+    launchfile = Bottlenecks_repo_dir + "/utils/infra_setup/heat_template/vstf_heat_template/launch_vstf.sh"
+    testfile = Bottlenecks_repo_dir + "/utils/infra_setup/heat_template/vstf_heat_template/test_vstf.sh"
+    vstf_run(launch_file=launchfile, test_file=testfile)
 
     vstf_env_cleanup()