Print all the Parser test output to a log file
[functest.git] / testcases / OpenStack / tempest / run_tempest.py
index 562249b..390c8a6 100755 (executable)
@@ -14,7 +14,6 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 #
 import ConfigParser
-import argparse
 import os
 import re
 import shutil
@@ -22,11 +21,12 @@ import subprocess
 import sys
 import time
 
+import argparse
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as ft_utils
 import functest.utils.openstack_utils as os_utils
 import yaml
-
+from functest.utils.functest_utils import FUNCTEST_REPO as FUNCTEST_REPO
 
 modes = ['full', 'smoke', 'baremetal', 'compute', 'data_processing',
          'identity', 'image', 'network', 'object_storage', 'orchestration',
@@ -58,11 +58,7 @@ args = parser.parse_args()
 """ logging configuration """
 logger = ft_logger.Logger("run_tempest").getLogger()
 
-REPO_PATH = os.environ['repos_dir'] + '/functest/'
-
-with open(os.environ["CONFIG_FUNCTEST_YAML"]) as f:
-    functest_yaml = yaml.safe_load(f)
-f.close()
+functest_yaml = ft_utils.get_functest_yaml()
 TEST_DB = functest_yaml.get("results").get("test_db_url")
 
 MODE = "smoke"
@@ -94,6 +90,7 @@ RESULTS_DIR = functest_yaml.get("general").get("directories").get(
 TEMPEST_RESULTS_DIR = RESULTS_DIR + '/tempest'
 TEST_LIST_DIR = functest_yaml.get("general").get("directories").get(
     "dir_tempest_cases")
+REPO_PATH = FUNCTEST_REPO + '/'
 TEMPEST_CUSTOM = REPO_PATH + TEST_LIST_DIR + 'test_list.txt'
 TEMPEST_BLACKLIST = REPO_PATH + TEST_LIST_DIR + 'blacklist.txt'
 TEMPEST_DEFCORE = REPO_PATH + TEST_LIST_DIR + 'defcore_req.txt'
@@ -125,55 +122,33 @@ def get_info(file_result):
 
 def create_tempest_resources():
     keystone_client = os_utils.get_keystone_client()
-    neutron_client = os_utils.get_neutron_client()
-    glance_client = os_utils.get_glance_client()
 
     logger.debug("Creating tenant and user for Tempest suite")
     tenant_id = os_utils.create_tenant(keystone_client,
                                        TENANT_NAME,
                                        TENANT_DESCRIPTION)
-    if tenant_id == '':
+    if not tenant_id:
         logger.error("Error : Failed to create %s tenant" % TENANT_NAME)
 
     user_id = os_utils.create_user(keystone_client, USER_NAME, USER_PASSWORD,
                                    None, tenant_id)
-    if user_id == '':
+    if not user_id:
         logger.error("Error : Failed to create %s user" % USER_NAME)
 
     logger.debug("Creating private network for Tempest suite")
-    network_dic = os_utils.create_network_full(neutron_client,
-                                               PRIVATE_NET_NAME,
-                                               PRIVATE_SUBNET_NAME,
-                                               ROUTER_NAME,
-                                               PRIVATE_SUBNET_CIDR)
-    if network_dic:
-        if not os_utils.update_neutron_net(neutron_client,
-                                           network_dic['net_id'],
-                                           shared=True):
-            logger.error("Failed to update private network...")
-            exit(-1)
-        else:
-            logger.debug("Network '%s' is available..." % PRIVATE_NET_NAME)
-    else:
-        logger.error("Private network creation failed")
-        exit(-1)
+    network_dic = os_utils.create_shared_network_full(PRIVATE_NET_NAME,
+                                                      PRIVATE_SUBNET_NAME,
+                                                      ROUTER_NAME,
+                                                      PRIVATE_SUBNET_CIDR)
+    if not network_dic:
+        exit(1)
 
     logger.debug("Creating image for Tempest suite")
-    # Check if the given image exists
-    image_id = os_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
-    if image_id != '':
-        logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME)
-    else:
-        logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME,
-                                                          GLANCE_IMAGE_PATH))
-        image_id = os_utils.create_glance_image(glance_client,
-                                                GLANCE_IMAGE_NAME,
-                                                GLANCE_IMAGE_PATH)
-        if not image_id:
-            logger.error("Failed to create a Glance image...")
-            exit(-1)
-        logger.debug("Image '%s' with ID=%s created successfully."
-                     % (GLANCE_IMAGE_NAME, image_id))
+    _, image_id = os_utils.get_or_create_image(GLANCE_IMAGE_NAME,
+                                               GLANCE_IMAGE_PATH,
+                                               GLANCE_IMAGE_FORMAT)
+    if not image_id:
+        exit(-1)
 
 
 def configure_tempest(deployment_dir):
@@ -364,6 +339,8 @@ def run_tempest(OPTION):
 
     if 'smoke' in args.mode:
         case_name = 'tempest_smoke_serial'
+    elif 'feature' in args.mode:
+        case_name = args.mode.replace("feature_", "")
     else:
         case_name = 'tempest_full_parallel'
 
@@ -420,13 +397,14 @@ def main():
         os.makedirs(TEMPEST_RESULTS_DIR)
 
     deployment_dir = ft_utils.get_deployment_dir(logger)
+    create_tempest_resources()
 
-    if "" != args.conf:
+    if "" == args.conf:
+        MODE = ""
         configure_tempest(deployment_dir)
     else:
         MODE = " --tempest-config " + args.conf
 
-    create_tempest_resources()
     generate_test_list(deployment_dir, args.mode)
     apply_tempest_blacklist()