From: kubi Date: Fri, 5 Feb 2016 08:48:00 +0000 (+0000) Subject: add precondition check X-Git-Tag: colorado.1.0~236 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=ff5cb9501b155e07fe75f03062217270b9745131;p=yardstick.git add precondition check as we discussed yersterday, for daily jenkins task, i have a new idea, i add a precondition check and a key parameter in test case, if environment info(eg. "DEPLOY_SCENARIO") meet the preconditon which was defined in test case , this test case will run, if not meet, this test case will skip. and default is allow all test case to run, so this patch will not influence existing test case. any comments are welcomed Change-Id: I4300ac58994d51c0ddb4dd6d58b7191f796ddcee Signed-off-by: kubi --- diff --git a/tests/opnfv/test_cases/opnfv_yardstick_tc027.yaml b/tests/opnfv/test_cases/opnfv_yardstick_tc027.yaml index e360b4bd0..cf3afc866 100644 --- a/tests/opnfv/test_cases/opnfv_yardstick_tc027.yaml +++ b/tests/opnfv/test_cases/opnfv_yardstick_tc027.yaml @@ -24,6 +24,9 @@ scenarios: max_rtt: 30 action: monitor +precondition: + installer_type: compass + deploy_scenarios: os-nosdn context: type: Node diff --git a/tests/unit/cmd/commands/test_task.py b/tests/unit/cmd/commands/test_task.py index e785e99a9..5b404c48d 100644 --- a/tests/unit/cmd/commands/test_task.py +++ b/tests/unit/cmd/commands/test_task.py @@ -56,3 +56,17 @@ class TaskCommandsTestCase(unittest.TestCase): mock_base_runner.Runner.get.return_value = runner t._run([scenario], False, "yardstick.out") self.assertTrue(runner.run.called) + + @mock.patch('yardstick.cmd.commands.task.os') + def test_check_precondition(self, mock_os): + cfg = \ + {'precondition': + {'installer_type': 'compass', + 'deploy_scenarios': 'os-nosdn' + } + } + + t = task.TaskParser('/opt') + mock_os.environ.get.side_effect = ['compass', 'os-nosdn'] + result = t._check_precondition(cfg) + self.assertTrue(result) diff --git a/yardstick/cmd/commands/task.py b/yardstick/cmd/commands/task.py index 17e8f4c42..55898e1cb 100644 --- a/yardstick/cmd/commands/task.py +++ b/yardstick/cmd/commands/task.py @@ -84,9 +84,13 @@ class TaskCommands(object): one_task_start_time = time.time() parser.path = task_files[i] task_name = os.path.splitext(os.path.basename(task_files[i]))[0] - scenarios, run_in_parallel = parser.parse_task(task_name, - task_args[i], - task_args_fnames[i]) + scenarios, run_in_parallel, meet_precondition = parser.parse_task( + task_name, task_args[i], task_args_fnames[i]) + + if not meet_precondition: + LOG.info("meet_precondition is %s, please check envrionment", + meet_precondition) + continue self._run(scenarios, run_in_parallel, args.output_file) @@ -232,6 +236,7 @@ class TaskParser(object): sys.exit(ioerror) self._check_schema(cfg["schema"], "task") + meet_precondition = self._check_precondition(cfg) # TODO: support one or many contexts? Many would simpler and precise # TODO: support hybrid context type @@ -261,7 +266,7 @@ class TaskParser(object): scenario["task_id"] = task_id # TODO we need something better here, a class that represent the file - return cfg["scenarios"], run_in_parallel + return cfg["scenarios"], run_in_parallel, meet_precondition def _check_schema(self, cfg_schema, schema_type): '''Check if config file is using the correct schema type''' @@ -270,6 +275,26 @@ class TaskParser(object): sys.exit("error: file %s has unknown schema %s" % (self.path, cfg_schema)) + def _check_precondition(self, cfg): + '''Check if the envrionment meet the preconditon''' + + if "precondition" in cfg: + precondition = cfg["precondition"] + installer_type = precondition.get("installer_type", None) + deploy_scenarios = precondition.get("deploy_scenarios", None) + installer_type_env = os.environ.get('INSTALL_TYPE', None) + deploy_scenario_env = os.environ.get('DEPLOY_SCENARIO', None) + if installer_type and installer_type_env: + if installer_type_env not in installer_type: + return False + if deploy_scenarios and deploy_scenario_env: + deploy_scenarios_list = deploy_scenarios.split(',') + for deploy_scenario in deploy_scenarios_list: + if deploy_scenario_env.startswith(deploy_scenario): + return True + return False + return True + def atexit_handler(): '''handler for process termination'''