Lines Matching +full:self +full:- +full:working

39  - plugin:
40 - plugin_name: plugin.foo_func.foo_func_yaml
41 - plugin_args:
42 - arg1
43 - arg2
45 plugin_dir = __file__.split(__file__.split("/")[-1])[0] + "/plugins"
49 if module == "__init__.py" or module[-3:] != ".py":
51 plugin_module = "plugins." + module[:-3]
69 - plugin:
70 - plugin_name: version = plugin.ssh_execution.ssh_execute_cmd
71 - plugin_args:
72 - ${hostname}
73 - ${username}
74 - ${password}
75 - "cat /etc/os-release | grep VERSION_ID | awk -F'=' '{print $2}'"
76 - plugin:
77 - plugin_name: plugin.print_vars.print_vars
78 - plugin_args:
79 - version
118 self, argument
151 self.hostname = hostname
152 self.username = username
153 self.password = password
154 self.port_ssh = str(port_ssh)
155 self.port_https = str(port_https)
156 self.port_ipmi = str(port_ipmi)
157 self.ffdc_config = ffdc_config
158 self.location = location + "/" + remote_type.upper()
159 self.ssh_remoteclient = None
160 self.telnet_remoteclient = None
161 self.ffdc_dir_path = ""
162 self.ffdc_prefix = ""
163 self.target_type = remote_type.upper()
164 self.remote_protocol = remote_protocol.upper()
165 self.env_vars = env_vars
166 self.econfig = econfig
167 self.start_time = 0
168 self.elapsed_time = ""
169 self.logger = None
175 # self.location == local system for now
176 self.set_ffdc_default_store_path()
179 self.script_logging(getattr(logging, log_level.upper()))
182 self.validate_local_store(self.location)
184 if self.verify_script_env():
186 with open(self.ffdc_config, "r") as file:
188 self.ffdc_actions = yaml.load(file, Loader=yaml.SafeLoader)
190 self.logger.error(e)
191 sys.exit(-1)
193 if self.target_type not in self.ffdc_actions.keys():
194 self.logger.error(
196 % (self.target_type, self.ffdc_config)
198 sys.exit(-1)
200 sys.exit(-1)
203 self.logger.info("\n\tENV: User define input YAML variables")
204 self.env_dict = {}
205 self.load_env()
207 def verify_script_env(self): argument
215 self.run_tool_cmd("redfishtool -V").split(" ")[2].strip("\n")
217 ipmitool_version = self.run_tool_cmd("ipmitool -V").split(" ")[2]
219 self.logger.info("\n\t---- Script host environment ----")
220 self.logger.info(
223 self.logger.info(
226 self.logger.info(
229 self.logger.info("\t{:<10} {:>10}".format("PyYAML", yaml.__version__))
230 self.logger.info("\t{:<10} {:>10}".format("click", click.__version__))
231 self.logger.info(
234 self.logger.info(
237 self.logger.info(
242 self.logger.error(
246 self.logger.error(
251 self.logger.info("\t---- End script host environment ----")
254 def script_logging(self, log_level_attr): argument
259 self.logger = logging.getLogger()
260 self.logger.setLevel(log_level_attr)
262 self.ffdc_dir_path + "collector.log"
266 self.logger.addHandler(log_file_handler)
267 self.logger.addHandler(stdout_handler)
272 def target_is_pingable(self): argument
274 Check if target system is ping-able.
277 response = os.system("ping -c 1 %s 2>&1 >/dev/null" % self.hostname)
279 self.logger.info(
280 "\n\t[Check] %s is ping-able.\t\t [OK]" % self.hostname
284 self.logger.error(
285 "\n\tERROR: %s is not ping-able. FFDC collection aborted.\n"
286 % self.hostname
288 sys.exit(-1)
290 def collect_ffdc(self): argument
296 self.logger.info(
297 "\n\t---- Start communicating with %s ----" % self.hostname
299 self.start_time = time.time()
303 config_dict = self.ffdc_actions
306 if self.target_type != target_type:
318 self.logger.info(
320 % (self.target_type, check_protocol_list)
323 verified_working_protocol = self.verify_protocol(check_protocol_list)
326 self.logger.info(
327 "\n\t---- Completed protocol pre-requisite check ----\n"
331 self.validate_local_store(self.location)
333 if (self.remote_protocol not in verified_working_protocol) and (
334 self.remote_protocol != "ALL"
336 self.logger.info(
339 self.logger.error(
340 "\tERROR: Requested protocol %s is not in working protocol"
341 " list.\n" % self.remote_protocol
343 sys.exit(-1)
345 self.generate_ffdc(verified_working_protocol)
347 def ssh_to_target_system(self): argument
353 self.ssh_remoteclient = SSHRemoteclient(
354 self.hostname, self.username, self.password, self.port_ssh
357 if self.ssh_remoteclient.ssh_remoteclient_login():
358 self.logger.info(
360 % self.hostname
366 self.ssh_remoteclient.scp_connection()
369 self.logger.info(
371 % self.hostname
375 def telnet_to_target_system(self): argument
379 self.telnet_remoteclient = TelnetRemoteclient(
380 self.hostname, self.username, self.password
382 if self.telnet_remoteclient.tn_remoteclient_login():
383 self.logger.info(
385 % self.hostname
389 self.logger.info(
391 % self.hostname
395 def generate_ffdc(self, working_protocol_list): argument
400 working_protocol_list list of confirmed working protocols to connect to remote host.
403 self.logger.info(
404 "\n\t---- Executing commands on " + self.hostname + " ----"
406 self.logger.info(
410 config_dict = self.ffdc_actions
412 if self.target_type != target_type:
415 self.logger.info("\n\tFFDC Path: %s " % self.ffdc_dir_path)
416 global_plugin_dict["global_log_store_path"] = self.ffdc_dir_path
417 self.logger.info("\tSystem Type: %s" % target_type)
420 self.remote_protocol not in working_protocol_list
421 and self.remote_protocol != "ALL"
432 self.protocol_ssh(protocol, target_type, k)
434 self.protocol_telnet(target_type, k)
440 self.protocol_execute(protocol, target_type, k)
442 self.logger.error(
444 % (protocol, self.hostname)
448 self.elapsed_time = time.strftime(
449 "%H:%M:%S", time.gmtime(time.time() - self.start_time)
451 if self.ssh_remoteclient:
452 self.ssh_remoteclient.ssh_remoteclient_disconnect()
453 if self.telnet_remoteclient:
454 self.telnet_remoteclient.tn_remoteclient_disconnect()
456 def protocol_ssh(self, protocol, target_type, sub_type): argument
467 self.group_copy(self.ffdc_actions[target_type][sub_type])
469 self.collect_and_copy_ffdc(
470 self.ffdc_actions[target_type][sub_type]
473 def protocol_telnet(self, target_type, sub_type): argument
479 self.logger.info(
481 % (self.hostname, "TELNET")
485 list_of_commands = self.ffdc_actions[target_type][sub_type]["COMMANDS"]
487 command_txt, command_timeout = self.unpack_command(each_cmd)
488 result = self.telnet_remoteclient.execute_command(
493 targ_file = self.ffdc_actions[target_type][sub_type][
498 self.logger.warning(
502 self.logger.warning(
506 self.ffdc_dir_path + self.ffdc_prefix + targ_file
514 self.print_progress(progress_counter)
515 self.logger.info("\n\t[Run] Commands execution completed.\t\t [OK]")
517 self.logger.info("\n\t\tSuccessfully save file " + file + ".")
519 def protocol_execute(self, protocol, target_type, sub_type): argument
529 self.logger.info(
531 % (self.hostname, protocol)
535 list_of_cmd = self.get_command_list(
536 self.ffdc_actions[target_type][sub_type]
546 ] and self.plugin_error_check(each_cmd["plugin"]):
547 self.logger.info(
548 "\n\t[PLUGIN-ERROR] exit_on_error: %s"
551 self.logger.info(
552 "\t[PLUGIN-SKIP] %s" % each_cmd["plugin"][0]
557 self.logger.info("\n\t[PLUGIN-START]")
558 result = self.execute_plugin_block(each_cmd["plugin"])
559 self.logger.info("\t[PLUGIN-END]\n")
561 each_cmd = self.yaml_env_and_plugin_vars_populate(each_cmd)
564 result = self.run_tool_cmd(each_cmd)
567 file_name = self.get_file_list(
568 self.ffdc_actions[target_type][sub_type]
573 targ_file = self.yaml_env_and_plugin_vars_populate(
577 targ_file = each_cmd.split("/")[-1]
578 self.logger.warning(
582 self.logger.warning(
587 self.ffdc_dir_path + self.ffdc_prefix + targ_file
600 self.print_progress(progress_counter)
602 self.logger.info("\n\t[Run] Commands execution completed.\t\t [OK]")
605 self.logger.info("\n\t\tSuccessfully save file " + file + ".")
608 self, ffdc_actions_for_target_type, form_filename=False argument
615 form_filename if true, pre-pend self.target_type to filename
619 self.ssh_execute_ffdc_commands(
624 if self.ssh_remoteclient.scpclient:
625 self.logger.info(
627 % self.hostname
631 list_of_files = self.get_file_list(ffdc_actions_for_target_type)
632 self.scp_ffdc(
633 self.ffdc_dir_path,
634 self.ffdc_prefix,
639 self.logger.info(
641 % self.hostname
644 def get_command_list(self, ffdc_actions_for_target_type): argument
657 def get_file_list(self, ffdc_actions_for_target_type): argument
670 def unpack_command(self, command): argument
688 self, ffdc_actions_for_target_type, form_filename=False argument
695 form_filename if true, pre-pend self.target_type to filename
697 self.logger.info(
699 % (self.hostname, ffdc_actions_for_target_type["PROTOCOL"][0])
702 list_of_commands = self.get_command_list(ffdc_actions_for_target_type)
709 command_txt, command_timeout = self.unpack_command(command)
712 command_txt = str(command_txt % self.target_type)
718 ) = self.ssh_remoteclient.execute_command(
723 self.logger.warning(
727 self.logger.warning("\t\t[WARN] %s " % err)
730 self.print_progress(progress_counter)
732 self.logger.info("\n\t[Run] Commands execution completed.\t\t [OK]")
734 def group_copy(self, ffdc_actions_for_target_type): argument
742 if self.ssh_remoteclient.scpclient:
743 self.logger.info(
745 % self.hostname
748 list_of_commands = self.get_command_list(
757 command = self.yaml_env_and_plugin_vars_populate(command)
759 self.logger.error("\t\tInvalid command %s" % command)
766 ) = self.ssh_remoteclient.execute_command(command)
771 scp_result = self.ssh_remoteclient.scp_file_from_remote(
772 response.split("\n"), self.ffdc_dir_path
775 self.logger.info(
777 + self.hostname
782 self.logger.info("\t\t%s has no result" % command)
785 self.logger.info(
787 % self.hostname
791 self, argument
812 filename = str(filename % self.target_type)
815 targ_dir_path + targ_file_prefix + filename.split("/")[-1]
820 scp_result = self.ssh_remoteclient.scp_file_from_remote(
821 source_file_path, self.ffdc_dir_path
824 scp_result = self.ssh_remoteclient.scp_file_from_remote(
830 self.logger.info(
832 + self.hostname
838 self.logger.info(
840 + self.hostname
847 self.print_progress(progress_counter)
849 def set_ffdc_default_store_path(self): argument
851 Set a default value for self.ffdc_dir_path and self.ffdc_prefix.
852 Collected ffdc file will be stored in dir /self.location/hostname_timestr/.
856 self.ffdc_dir_path The dir path where collected ffdc data files should be put.
858 self.ffdc_prefix The prefix to be given to each ffdc file name.
862 timestr = time.strftime("%Y%m%d-%H%M%S")
863 self.ffdc_dir_path = (
864 self.location + "/" + self.hostname + "_" + timestr + "/"
866 self.ffdc_prefix = timestr + "_"
867 self.validate_local_store(self.ffdc_dir_path)
888 self.logger.error(
893 self.logger.error(
897 sys.exit(-1)
899 def print_progress(self, progress): argument
912 def verify_redfish(self): argument
918 "redfishtool -r "
919 + self.hostname
921 + self.port_https
922 + " -S Always raw GET /redfish/v1/"
924 return self.run_tool_cmd(redfish_parm, True)
926 def verify_ipmi(self): argument
931 if self.target_type == "OPENBMC":
933 "ipmitool -I lanplus -C 17 -U "
934 + self.username
935 + " -P "
936 + self.password
937 + " -H "
938 + self.hostname
939 + " -p "
940 + str(self.port_ipmi)
945 "ipmitool -I lanplus -P "
946 + self.password
947 + " -H "
948 + self.hostname
949 + " -p "
950 + str(self.port_ipmi)
954 return self.run_tool_cmd(ipmi_parm, True)
956 def run_tool_cmd(self, parms_string, quiet=False): argument
974 self.logger.error("\n\t\tERROR with %s " % parms_string)
975 self.logger.error("\t\t" + result.stderr)
979 def verify_protocol(self, protocol_list): argument
981 Perform protocol working check.
988 if self.target_is_pingable():
992 if self.remote_protocol != "ALL":
993 if self.remote_protocol != protocol:
1002 if self.ssh_to_target_system():
1004 if self.remote_protocol != "ALL":
1005 tmp_list.append(self.remote_protocol)
1011 if self.telnet_to_target_system():
1015 if self.verify_redfish():
1017 self.logger.info(
1019 % self.hostname
1022 self.logger.info(
1024 % self.hostname
1028 if self.verify_ipmi():
1030 self.logger.info(
1032 % self.hostname
1035 self.logger.info(
1037 % self.hostname
1042 def load_env(self): argument
1044 Perform protocol working check.
1049 # -COMMANDS:
1050 # - my_command ${hostname} ${username} ${password}
1051 os.environ["hostname"] = self.hostname
1052 os.environ["username"] = self.username
1053 os.environ["password"] = self.password
1054 os.environ["port_ssh"] = self.port_ssh
1055 os.environ["port_https"] = self.port_https
1056 os.environ["port_ipmi"] = self.port_ipmi
1059 self.env_dict["hostname"] = self.hostname
1060 self.env_dict["username"] = self.username
1061 self.env_dict["password"] = self.password
1062 self.env_dict["port_ssh"] = self.port_ssh
1063 self.env_dict["port_https"] = self.port_https
1064 self.env_dict["port_ipmi"] = self.port_ipmi
1068 if self.env_vars:
1069 tmp_env_dict = json.loads(self.env_vars)
1073 self.env_dict[key] = str(value)
1075 if self.econfig:
1076 with open(self.econfig, "r") as file:
1080 self.logger.error(e)
1081 sys.exit(-1)
1085 self.env_dict[key] = str(value)
1087 self.logger.error("\n\tERROR: %s " % e)
1088 sys.exit(-1)
1091 mask_dict = self.env_dict.copy()
1093 if k.lower().find("password") != -1:
1101 self.logger.info(json.dumps(mask_dict, indent=8, sort_keys=False))
1103 def execute_python_eval(self, eval_string): argument
1114 self.logger.info("\tExecuting plugin func()")
1115 self.logger.debug("\tCall func: %s" % eval_string)
1117 self.logger.info("\treturn: %s" % str(result))
1125 self.logger.error("\tERROR: execute_python_eval: %s" % e)
1128 self.logger.info("\treturn: PLUGIN_EVAL_ERROR")
1133 def execute_plugin_block(self, plugin_cmd_list): argument
1143 - plugin:
1144 - plugin_name: plugin.foo_func.my_func
1145 - plugin_args:
1146 - arg1
1147 - arg2
1149 - plugin:
1150 - plugin_name: result = plugin.foo_func.my_func
1151 - plugin_args:
1152 - arg1
1153 - arg2
1155 - plugin:
1156 - plugin_name: result1,result2 = plugin.foo_func.my_func
1157 - plugin_args:
1158 - arg1
1159 - arg2
1162 idx = self.key_index_list_dict("plugin_name", plugin_cmd_list)
1170 if arg == plugin_name_args[-1]:
1182 idx = self.key_index_list_dict("plugin_args", plugin_cmd_list)
1185 plugin_args = self.yaml_args_populate(plugin_args)
1189 plugin_args = self.yaml_args_populate([])
1193 parm_args_str = self.yaml_args_string(plugin_args)
1201 resp = self.execute_python_eval(plugin_func)
1204 self.response_args_data(resp)
1206 resp = self.execute_python_eval(plugin_func)
1210 self.logger.error("\tERROR: execute_plugin_block: %s" % e)
1219 idx = self.key_index_list_dict(
1226 self.plugin_expect_type(plugin_expects, resp)
1229 self.logger.error("\tWARN: Plugin error check skipped")
1230 elif not self.plugin_expect_type(plugin_expects, resp):
1231 self.logger.error(
1237 self.logger.error(
1244 def response_args_data(self, plugin_resp): argument
1261 resp_data = str(plugin_resp, "UTF-8").strip("\r\n\t")
1288 self.logger.warn("\tWARN: response_args_data: %s" % e)
1295 def yaml_args_string(self, plugin_args): argument
1311 if args != plugin_args[-1]:
1315 def yaml_args_populate(self, yaml_arg_list): argument
1323 - plugin_args:
1324 - arg1
1325 - arg2
1330 env_vars_list = list(self.env_dict)
1339 arg_str = self.yaml_env_and_plugin_vars_populate(str(arg))
1347 def yaml_env_and_plugin_vars_populate(self, yaml_arg_str): argument
1355 - cat ${MY_VAR}
1356 - ls -AX my_plugin_var
1369 self.logger.error("\tERROR:yaml_env_vars_populate: %s" % e)
1398 self.logger.error("\tERROR: yaml_plugin_vars_populate: %s" % e)
1403 def plugin_error_check(self, plugin_dict): argument
1417 def key_index_list_dict(self, key, list_dict): argument
1429 def plugin_expect_type(self, type, data): argument
1446 self.logger.info("\tInvalid data type requested: %s" % type)