diff options
Diffstat (limited to 'functest/opnfv_tests/openstack/rally/rally.py')
-rw-r--r-- | functest/opnfv_tests/openstack/rally/rally.py | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py index 9a04f3873..1242e7960 100644 --- a/functest/opnfv_tests/openstack/rally/rally.py +++ b/functest/opnfv_tests/openstack/rally/rally.py @@ -25,6 +25,7 @@ import time import pkg_resources import prettytable from ruamel.yaml import YAML +import six from six.moves import configparser from xtesting.core import testcase import yaml @@ -32,6 +33,7 @@ import yaml from functest.core import singlevm from functest.utils import config from functest.utils import env +from functest.utils import functest_utils LOGGER = logging.getLogger(__name__) @@ -66,7 +68,6 @@ class RallyBase(singlevm.VmReady2): visibility = 'public' shared_network = True - allow_no_fip = True task_timeout = 3600 def __init__(self, **kwargs): @@ -93,7 +94,6 @@ class RallyBase(singlevm.VmReady2): self.smoke = None self.start_time = None self.result = None - self.details = None self.compute_cnt = 0 self.flavor_alt = None self.tests = [] @@ -129,7 +129,14 @@ class RallyBase(singlevm.VmReady2): if self.network: task_args['netid'] = str(self.network.id) else: - task_args['netid'] = '' + LOGGER.warning( + 'No tenant network created. ' + 'Trying EXTERNAL_NETWORK as a fallback') + if env.get("EXTERNAL_NETWORK"): + network = self.cloud.get_network(env.get("EXTERNAL_NETWORK")) + task_args['netid'] = str(network.id) if network else '' + else: + task_args['netid'] = '' return task_args @@ -172,6 +179,7 @@ class RallyBase(singlevm.VmReady2): @staticmethod def create_rally_deployment(environ=None): + # pylint: disable=unexpected-keyword-arg """Create new rally deployment""" # set the architecture to default pod_arch = env.get("POD_ARCH") @@ -232,20 +240,17 @@ class RallyBase(singlevm.VmReady2): rconfig.write(config_file) @staticmethod - def get_task_id(cmd_raw): + def get_task_id(tag): """ Get task id from command rally result. - :param cmd_raw: + :param tag: :return: task_id as string """ - taskid_re = re.compile('^Task +(.*): started$') - for line in cmd_raw.splitlines(True): - line = line.strip() - match = taskid_re.match(line.decode("utf-8")) - if match: - return match.group(1) - return None + cmd = ["rally", "task", "list", "--tag", tag, "--uuids-only"] + output = subprocess.check_output(cmd).decode("utf-8").rstrip() + LOGGER.info("%s: %s", " ".join(cmd), output) + return output @staticmethod def task_succeed(json_raw): @@ -427,20 +432,17 @@ class RallyBase(singlevm.VmReady2): """Run a task.""" LOGGER.info('Starting test scenario "%s" ...', test_name) LOGGER.debug('running command: %s', self.run_cmd) - proc = subprocess.Popen(self.run_cmd, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) - try: - output = proc.communicate(timeout=self.task_timeout)[0] - except subprocess.TimeoutExpired: - proc.kill() - proc.communicate() - LOGGER.error("Failed to complete run task") - raise Exception("Failed to complete run task") - task_id = self.get_task_id(output) + if six.PY3: + subprocess.call( + self.run_cmd, timeout=self.task_timeout, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + else: + with open(os.devnull, 'wb') as devnull: + subprocess.call(self.run_cmd, stdout=devnull, stderr=devnull) + task_id = self.get_task_id(test_name) LOGGER.debug('task_id : %s', task_id) - if task_id is None: + if not task_id: LOGGER.error("Failed to retrieve task_id") - LOGGER.error("Result:\n%s", output.decode("utf-8")) raise Exception("Failed to retrieve task id") self._save_results(test_name, task_id) @@ -516,11 +518,11 @@ class RallyBase(singlevm.VmReady2): shutil.copytree(task_macro, macro_dir) self.update_keystone_default_role() - self.compute_cnt = len(self.cloud.list_hypervisors()) + self.compute_cnt = self.count_hypervisors() self.network_extensions = self.cloud.get_network_extensions() self.flavor_alt = self.create_flavor_alt() self.services = [service.name for service in - self.cloud.list_services()] + functest_utils.list_services(self.cloud)] LOGGER.debug("flavor: %s", self.flavor_alt) @@ -530,7 +532,8 @@ class RallyBase(singlevm.VmReady2): if self.file_is_empty(file_name): LOGGER.info('No tests for scenario "%s"', test_name) return False - self.run_cmd = (["rally", "task", "start", "--abort-on-sla-failure", + self.run_cmd = (["rally", "task", "start", "--tag", test_name, + "--abort-on-sla-failure", "--task", self.task_file, "--task-args", str(self.build_task_args(test_name))]) return True @@ -597,10 +600,10 @@ class RallyBase(singlevm.VmReady2): LOGGER.info("Rally '%s' success_rate is %s%% in %s/%s modules", self.case_name, success_rate, nb_modules, len(self.summary)) - payload.append({'summary': {'duration': total_duration, - 'nb tests': total_nb_tests, - 'nb success': success_rate}}) - self.details = payload + self.details['summary'] = {'duration': total_duration, + 'nb tests': total_nb_tests, + 'nb success': success_rate} + self.details["modules"] = payload @staticmethod def export_task(file_name, export_type="html"): @@ -843,7 +846,8 @@ class RallyJobs(RallyBase): os.makedirs(self.temp_dir) task_file_name = os.path.join(self.temp_dir, task_name) self.apply_blacklist(task, task_file_name) - self.run_cmd = (["rally", "task", "start", "--task", task_file_name, + self.run_cmd = (["rally", "task", "start", "--tag", test_name, + "--task", task_file_name, "--task-args", str(self.build_task_args(test_name))]) return True |