Skip to content

Commit

Permalink
Feature add env parameter (#392)
Browse files Browse the repository at this point in the history
* add unittest for ssh_client

* unittest for local_client

* add unittest for remote_client

* add unittest for docker_client and kubernetes_cilent

* update unittest for remote_client

* add unittest workflow

* update unittest for test_remote_client

* update unittest for workflow

* input_marameters supports input in kv format

* Delete temporary files

* Using opts to pass input_parameters options

* fix multiple = in options

* delete print()

* Change the warn prompt information to verbose

* replace input_parameters with env

* fix env parameters

* remove rca tmp files
  • Loading branch information
xiaodong-ji authored Sep 24, 2024
1 parent 6601cb0 commit 384d6c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions diag_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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")
Expand All @@ -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)


Expand Down
1 change: 1 addition & 0 deletions handler/rca/rca_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 384d6c3

Please sign in to comment.