diff --git a/diag_cmd.py b/diag_cmd.py index 377b84cc..4aa67792 100644 --- a/diag_cmd.py +++ b/diag_cmd.py @@ -949,29 +949,29 @@ def __init__(self): super(ObdiagRCARunCommand, self).__init__('run', 'root cause analysis') self.parser.add_option('--scene', type='string', help="rca scene name. The argument is required.") self.parser.add_option('--store_dir', type='string', help='the dir to store rca result, current dir by default.', default='./rca/') - self.parser.add_option('--input_parameters', action='callback', type='string', callback=self._input_parameters_scene, help='input parameters of scene') + self.parser.add_option('--input_parameters', action='callback', type='string', callback=self._env_scene, help='input parameters of scene') + self.parser.add_option('--env', action='callback', type='string', callback=self._env_scene, help='env of scene') self.parser.add_option('-c', type='string', help='obdiag custom config', default=os.path.expanduser('~/.obdiag/config.yml')) self.parser.add_option('--config', action="append", type="string", help='config options Format: --config key=value') self.scene_input_param_map = {} - def _input_parameters_scene(self, option, opt_str, value, parser): + def _env_scene(self, option, opt_str, value, parser): """ - input parameters of scene + env of scene """ try: - # input_parameters option is json format + # env option is json format try: self.scene_input_param_map = json.loads(value) return except Exception as e: - # raise Exception("Failed to parse input_parameters. Please check the option is json:{0}".format(value)) - ROOT_IO.verbose("input_parameters option {0} is not json.".format(value)) + ROOT_IO.verbose("env option {0} is not json.".format(value)) - # input_parameters option is key=val format + # env option is key=val format key, val = value.split('=', 1) if key is None or key == "": return - m = self._input_parameters_scene_set(key, val) + m = self._env_scene_set(key, val) def _scene_input_param(param_map, scene_param_map): for scene_param_map_key, scene_param_map_value in scene_param_map.items(): @@ -988,7 +988,7 @@ def _scene_input_param(param_map, scene_param_map): except Exception as e: raise Exception("Key or val ({1}) is illegal: {0}".format(e, value)) - def _input_parameters_scene_set(self, key, val): + def _env_scene_set(self, key, val): def recursion(param_map, key, val): if key is None or key == "": raise Exception("key is None") @@ -1013,6 +1013,7 @@ def init(self, cmd, args): def _do_command(self, obdiag): Util.set_option(self.opts, 'input_parameters', self.scene_input_param_map) + Util.set_option(self.opts, 'env', self.scene_input_param_map) return obdiag.rca_run(self.opts) diff --git a/handler/rca/rca_handler.py b/handler/rca/rca_handler.py index 89fcfe44..d1391c26 100644 --- a/handler/rca/rca_handler.py +++ b/handler/rca/rca_handler.py @@ -124,6 +124,7 @@ def __init__(self, context): self.report = None self.tasks = None self.context.set_variable("input_parameters", Util.get_option(self.options, "input_parameters")) + self.context.set_variable("env", Util.get_option(self.options, "input_parameters")) self.store_dir = Util.get_option(self.options, "store_dir", "./rca/") self.context.set_variable("store_dir", self.store_dir) self.stdio.verbose(