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)
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)
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
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'''
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'''