Merge "Re-Enable Promise testcases"
[functest.git] / functest / opnfv_tests / openstack / rally / rally.py
index f984c36..86ec355 100644 (file)
@@ -8,7 +8,10 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 #
 
+from __future__ import division
+
 import json
+import logging
 import os
 import re
 import subprocess
@@ -17,26 +20,27 @@ import time
 import iniparse
 import yaml
 
-from functest.core import testcase_base
+from functest.core import testcase
 from functest.utils.constants import CONST
-import functest.utils.functest_logger as ft_logger
-import functest.utils.functest_utils as ft_utils
 import functest.utils.openstack_utils as os_utils
 
-logger = ft_logger.Logger('Rally').getLogger()
+logger = logging.getLogger(__name__)
 
 
-class RallyBase(testcase_base.TestcaseBase):
+class RallyBase(testcase.TestCase):
     TESTS = ['authenticate', 'glance', 'cinder', 'heat', 'keystone',
              'neutron', 'nova', 'quotas', 'requests', 'vm', 'all']
-    GLANCE_IMAGE_NAME = CONST.openstack_image_name
-    GLANCE_IMAGE_FILENAME = CONST.openstack_image_file_name
-    GLANCE_IMAGE_PATH = os.path.join(CONST.dir_functest_data,
-                                     GLANCE_IMAGE_FILENAME)
-    GLANCE_IMAGE_FORMAT = CONST.openstack_image_disk_format
+    GLANCE_IMAGE_NAME = CONST.__getattribute__('openstack_image_name')
+    GLANCE_IMAGE_FILENAME = CONST.__getattribute__('openstack_image_file_name')
+    GLANCE_IMAGE_PATH = os.path.join(
+        CONST.__getattribute__('dir_functest_images'),
+        GLANCE_IMAGE_FILENAME)
+    GLANCE_IMAGE_FORMAT = CONST.__getattribute__('openstack_image_disk_format')
     FLAVOR_NAME = "m1.tiny"
 
-    RALLY_DIR = os.path.join(CONST.dir_repo_functest, CONST.dir_rally)
+    RALLY_DIR = os.path.join(
+        CONST.__getattribute__('dir_repo_functest'),
+        CONST.__getattribute__('dir_rally'))
     RALLY_SCENARIO_DIR = os.path.join(RALLY_DIR, "scenario")
     TEMPLATE_DIR = os.path.join(RALLY_SCENARIO_DIR, "templates")
     SUPPORT_DIR = os.path.join(RALLY_SCENARIO_DIR, "support")
@@ -44,20 +48,20 @@ class RallyBase(testcase_base.TestcaseBase):
     TENANTS_AMOUNT = 3
     ITERATIONS_AMOUNT = 10
     CONCURRENCY = 4
-    RESULTS_DIR = os.path.join(CONST.dir_results, 'rally')
-    TEMPEST_CONF_FILE = os.path.join(CONST.dir_results,
+    RESULTS_DIR = os.path.join(CONST.__getattribute__('dir_results'), 'rally')
+    TEMPEST_CONF_FILE = os.path.join(CONST.__getattribute__('dir_results'),
                                      'tempest/tempest.conf')
     BLACKLIST_FILE = os.path.join(RALLY_DIR, "blacklist.txt")
     TEMP_DIR = os.path.join(RALLY_DIR, "var")
 
     CINDER_VOLUME_TYPE_NAME = "volume_test"
-    RALLY_PRIVATE_NET_NAME = CONST.rally_network_name
-    RALLY_PRIVATE_SUBNET_NAME = CONST.rally_subnet_name
-    RALLY_PRIVATE_SUBNET_CIDR = CONST.rally_subnet_cidr
-    RALLY_ROUTER_NAME = CONST.rally_router_name
+    RALLY_PRIVATE_NET_NAME = CONST.__getattribute__('rally_network_name')
+    RALLY_PRIVATE_SUBNET_NAME = CONST.__getattribute__('rally_subnet_name')
+    RALLY_PRIVATE_SUBNET_CIDR = CONST.__getattribute__('rally_subnet_cidr')
+    RALLY_ROUTER_NAME = CONST.__getattribute__('rally_router_name')
 
-    def __init__(self):
-        super(RallyBase, self).__init__()
+    def __init__(self, **kwargs):
+        super(RallyBase, self).__init__(**kwargs)
         self.mode = ''
         self.summary = []
         self.scenario_dir = ''
@@ -66,6 +70,7 @@ class RallyBase(testcase_base.TestcaseBase):
         self.cinder_client = os_utils.get_cinder_client()
         self.network_dict = {}
         self.volume_type = None
+        self.smoke = None
 
     def _build_task_args(self, test_file_name):
         task_args = {'service_list': [test_file_name]}
@@ -95,7 +100,7 @@ class RallyBase(testcase_base.TestcaseBase):
             task_args['netid'] = ''
 
         # get keystone auth endpoint
-        task_args['request_url'] = CONST.OS_AUTH_URL or ''
+        task_args['request_url'] = CONST.__getattribute__('OS_AUTH_URL') or ''
 
         return task_args
 
@@ -181,8 +186,8 @@ class RallyBase(testcase_base.TestcaseBase):
             with open(RallyBase.BLACKLIST_FILE, 'r') as black_list_file:
                 black_list_yaml = yaml.safe_load(black_list_file)
 
-            installer_type = CONST.INSTALLER_TYPE
-            deploy_scenario = CONST.DEPLOY_SCENARIO
+            installer_type = CONST.__getattribute__('INSTALLER_TYPE')
+            deploy_scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
             if (bool(installer_type) * bool(deploy_scenario)):
                 if 'scenario' in black_list_yaml.keys():
                     for item in black_list_yaml['scenario']:
@@ -287,7 +292,7 @@ class RallyBase(testcase_base.TestcaseBase):
             cmd_line = ("rally task validate "
                         "--task {0} "
                         "--task-args \"{1}\""
-                        .format(task_file, self.__build_task_args(test_name)))
+                        .format(task_file, self._build_task_args(test_name)))
             logger.debug('running command line: {}'.format(cmd_line))
             p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE,
                                  stderr=subprocess.STDOUT, shell=True)
@@ -479,11 +484,12 @@ class RallyBase(testcase_base.TestcaseBase):
         total_duration_str2 = "{0:<10}".format(total_duration_str)
         total_nb_tests_str = "{0:<13}".format(total_nb_tests)
 
-        if len(self.summary):
-            success_rate = total_success / len(self.summary)
-        else:
-            success_rate = 100
-        success_rate = "{:0.2f}".format(success_rate)
+        try:
+            self.result = total_success / len(self.summary)
+        except ZeroDivisionError:
+            self.result = 100
+
+        success_rate = "{:0.2f}".format(self.result)
         success_rate_str = "{0:<10}".format(str(success_rate) + '%')
         report += ("+===================+============"
                    "+===============+===========+")
@@ -499,12 +505,10 @@ class RallyBase(testcase_base.TestcaseBase):
                                     'nb tests': total_nb_tests,
                                     'nb success': success_rate}})
 
-        self.criteria = ft_utils.check_success_rate(
-            self.case_name, success_rate)
         self.details = payload
 
-        logger.info("Rally '%s' success_rate is %s%%, is marked as %s"
-                    % (self.case_name, success_rate, self.criteria))
+        logger.info("Rally '%s' success_rate is %s%%"
+                    % (self.case_name, success_rate))
 
     def _clean_up(self):
         if self.volume_type:
@@ -525,20 +529,20 @@ class RallyBase(testcase_base.TestcaseBase):
             self._run_tests()
             self._generate_report()
             self._clean_up()
+            res = testcase.TestCase.EX_OK
         except Exception as e:
             logger.error('Error with run: %s' % e)
-            return testcase_base.TestcaseBase.EX_RUN_ERROR
-        self.stop_time = time.time()
+            res = testcase.TestCase.EX_RUN_ERROR
 
-        # If we are here, it means that the test case was successfully executed
-        # criteria is managed by the criteria Field
-        return testcase_base.TestcaseBase.EX_OK
+        self.stop_time = time.time()
+        return res
 
 
 class RallySanity(RallyBase):
-    def __init__(self):
-        super(RallySanity, self).__init__()
-        self.case_name = 'rally_sanity'
+    def __init__(self, **kwargs):
+        if "case_name" not in kwargs:
+            kwargs["case_name"] = "rally_sanity"
+        super(RallySanity, self).__init__(**kwargs)
         self.mode = 'sanity'
         self.test_name = 'all'
         self.smoke = True
@@ -546,9 +550,10 @@ class RallySanity(RallyBase):
 
 
 class RallyFull(RallyBase):
-    def __init__(self):
-        super(RallyFull, self).__init__()
-        self.case_name = 'rally_full'
+    def __init__(self, **kwargs):
+        if "case_name" not in kwargs:
+            kwargs["case_name"] = "rally_full"
+        super(RallyFull, self).__init__(**kwargs)
         self.mode = 'full'
         self.test_name = 'all'
         self.smoke = False