blob: 98ae49b45580a5e91a23a3d8406eb9de4a9f5175 [file] [log] [blame]
Peter D Phan72ce6b82021-06-03 06:18:26 -05001#!/usr/bin/env python
2
3r"""
4See class prolog below for details.
5"""
6
7import os
8import sys
9import yaml
George Keishing4885b2f2021-07-21 15:22:45 -050010import json
Peter D Phan72ce6b82021-06-03 06:18:26 -050011import time
Peter D Phane86d9a52021-07-15 10:42:25 -050012import logging
Peter D Phan72ce6b82021-06-03 06:18:26 -050013import platform
14from errno import EACCES, EPERM
Peter D Phan0c669772021-06-24 13:52:42 -050015import subprocess
Peter D Phan72ce6b82021-06-03 06:18:26 -050016from ssh_utility import SSHRemoteclient
Peter D Phan5963d632021-07-12 09:58:55 -050017from telnet_utility import TelnetRemoteclient
Peter D Phan72ce6b82021-06-03 06:18:26 -050018
19
20class FFDCCollector:
21
22 r"""
23 Sends commands from configuration file to the targeted system to collect log files.
24 Fetch and store generated files at the specified location.
25
26 """
27
Peter D Phan0c669772021-06-24 13:52:42 -050028 def __init__(self,
29 hostname,
30 username,
31 password,
32 ffdc_config,
33 location,
34 remote_type,
Peter D Phane86d9a52021-07-15 10:42:25 -050035 remote_protocol,
George Keishing4885b2f2021-07-21 15:22:45 -050036 env_vars,
George Keishing8e94f8c2021-07-23 15:06:32 -050037 econfig,
Peter D Phane86d9a52021-07-15 10:42:25 -050038 log_level):
Peter D Phan72ce6b82021-06-03 06:18:26 -050039 r"""
40 Description of argument(s):
41
George Keishing8e94f8c2021-07-23 15:06:32 -050042 hostname name/ip of the targeted (remote) system
43 username user on the targeted system with access to FFDC files
44 password password for user on targeted system
45 ffdc_config configuration file listing commands and files for FFDC
46 location where to store collected FFDC
47 remote_type os type of the remote host
48 remote_protocol Protocol to use to collect data
49 env_vars User define CLI env vars '{"key : "value"}'
50 econfig User define env vars YAML file
Peter D Phan72ce6b82021-06-03 06:18:26 -050051
52 """
Peter D Phane86d9a52021-07-15 10:42:25 -050053
54 self.hostname = hostname
55 self.username = username
56 self.password = password
George Keishing04d29102021-07-16 02:05:57 -050057 # This is for the env vars a user can use in YAML to load it at runtime.
58 # Example YAML:
59 # -COMMANDS:
60 # - my_command ${hostname} ${username} ${password}
61 os.environ['hostname'] = hostname
62 os.environ['username'] = username
63 os.environ['password'] = password
64
Peter D Phane86d9a52021-07-15 10:42:25 -050065 self.ffdc_config = ffdc_config
66 self.location = location + "/" + remote_type.upper()
67 self.ssh_remoteclient = None
68 self.telnet_remoteclient = None
69 self.ffdc_dir_path = ""
70 self.ffdc_prefix = ""
71 self.target_type = remote_type.upper()
72 self.remote_protocol = remote_protocol.upper()
73 self.start_time = 0
74 self.elapsed_time = ''
75 self.logger = None
76
77 # Set prefix values for scp files and directory.
78 # Since the time stamp is at second granularity, these values are set here
79 # to be sure that all files for this run will have same timestamps
80 # and they will be saved in the same directory.
81 # self.location == local system for now
82 self.set_ffdc_defaults()
83
84 # Logger for this run. Need to be after set_ffdc_defaults()
85 self.script_logging(getattr(logging, log_level.upper()))
86
87 # Verify top level directory exists for storage
88 self.validate_local_store(self.location)
89
Peter D Phan72ce6b82021-06-03 06:18:26 -050090 if self.verify_script_env():
Peter D Phane86d9a52021-07-15 10:42:25 -050091 # Load default or user define YAML configuration file.
92 with open(self.ffdc_config, 'r') as file:
93 self.ffdc_actions = yaml.load(file, Loader=yaml.FullLoader)
94
95 if self.target_type not in self.ffdc_actions.keys():
96 self.logger.error(
97 "\n\tERROR: %s is not listed in %s.\n\n" % (self.target_type, self.ffdc_config))
98 sys.exit(-1)
Peter D Phan72ce6b82021-06-03 06:18:26 -050099 else:
Peter D Phan8462faf2021-06-16 12:24:15 -0500100 sys.exit(-1)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500101
George Keishing4885b2f2021-07-21 15:22:45 -0500102 # Load ENV vars from user.
George Keishingaa1f8482021-07-22 00:54:55 -0500103 self.logger.info("\n\tENV: User define input YAML variables")
104 self.env_dict = {}
105
George Keishing4885b2f2021-07-21 15:22:45 -0500106 try:
107 if env_vars:
George Keishingaa1f8482021-07-22 00:54:55 -0500108 self.env_dict = json.loads(env_vars)
George Keishing4885b2f2021-07-21 15:22:45 -0500109
110 # Export ENV vars default.
George Keishingaa1f8482021-07-22 00:54:55 -0500111 for key, value in self.env_dict.items():
George Keishing4885b2f2021-07-21 15:22:45 -0500112 os.environ[key] = value
George Keishingaa1f8482021-07-22 00:54:55 -0500113
George Keishing8e94f8c2021-07-23 15:06:32 -0500114 if econfig:
115 with open(econfig, 'r') as file:
116 env_config_dict = yaml.load(file, Loader=yaml.FullLoader)
117 # Export ENV vars.
118 for key, value in env_config_dict['env_params'].items():
119 os.environ[key] = str(value)
120 self.env_dict[key] = str(value)
121
George Keishing4885b2f2021-07-21 15:22:45 -0500122 except json.decoder.JSONDecodeError as e:
123 self.logger.error("\n\tERROR: %s " % e)
124 sys.exit(-1)
125
George Keishingaa1f8482021-07-22 00:54:55 -0500126 # Append default Env.
127 self.env_dict['hostname'] = self.hostname
128 self.env_dict['username'] = self.username
129 self.env_dict['password'] = self.password
130 self.logger.info(json.dumps(self.env_dict, indent=8, sort_keys=True))
131
Peter D Phan72ce6b82021-06-03 06:18:26 -0500132 def verify_script_env(self):
133
134 # Import to log version
135 import click
136 import paramiko
137
138 run_env_ok = True
Peter D Phan0c669772021-06-24 13:52:42 -0500139
George Keishingeafba182021-06-29 13:44:58 -0500140 redfishtool_version = self.run_redfishtool('-V').split(' ')[2].strip('\n')
141 ipmitool_version = self.run_ipmitool('-V').split(' ')[2]
Peter D Phan0c669772021-06-24 13:52:42 -0500142
Peter D Phane86d9a52021-07-15 10:42:25 -0500143 self.logger.info("\n\t---- Script host environment ----")
144 self.logger.info("\t{:<10} {:<10}".format('Script hostname', os.uname()[1]))
145 self.logger.info("\t{:<10} {:<10}".format('Script host os', platform.platform()))
146 self.logger.info("\t{:<10} {:>10}".format('Python', platform.python_version()))
147 self.logger.info("\t{:<10} {:>10}".format('PyYAML', yaml.__version__))
148 self.logger.info("\t{:<10} {:>10}".format('click', click.__version__))
149 self.logger.info("\t{:<10} {:>10}".format('paramiko', paramiko.__version__))
150 self.logger.info("\t{:<10} {:>9}".format('redfishtool', redfishtool_version))
151 self.logger.info("\t{:<10} {:>12}".format('ipmitool', ipmitool_version))
Peter D Phan72ce6b82021-06-03 06:18:26 -0500152
Peter D Phan8462faf2021-06-16 12:24:15 -0500153 if eval(yaml.__version__.replace('.', ',')) < (5, 4, 1):
Peter D Phane86d9a52021-07-15 10:42:25 -0500154 self.logger.error("\n\tERROR: Python or python packages do not meet minimum version requirement.")
155 self.logger.error("\tERROR: PyYAML version 5.4.1 or higher is needed.\n")
Peter D Phan72ce6b82021-06-03 06:18:26 -0500156 run_env_ok = False
157
Peter D Phane86d9a52021-07-15 10:42:25 -0500158 self.logger.info("\t---- End script host environment ----")
Peter D Phan72ce6b82021-06-03 06:18:26 -0500159 return run_env_ok
160
Peter D Phane86d9a52021-07-15 10:42:25 -0500161 def script_logging(self,
162 log_level_attr):
163 r"""
164 Create logger
165
166 """
167 self.logger = logging.getLogger()
168 self.logger.setLevel(log_level_attr)
169 log_file_handler = logging.FileHandler(self.ffdc_dir_path + "collector.log")
170
171 stdout_handler = logging.StreamHandler(sys.stdout)
172 self.logger.addHandler(log_file_handler)
173 self.logger.addHandler(stdout_handler)
174
175 # Turn off paramiko INFO logging
176 logging.getLogger("paramiko").setLevel(logging.WARNING)
177
Peter D Phan72ce6b82021-06-03 06:18:26 -0500178 def target_is_pingable(self):
Peter D Phan72ce6b82021-06-03 06:18:26 -0500179 r"""
180 Check if target system is ping-able.
181
182 """
George Keishing0662e942021-07-13 05:12:20 -0500183 response = os.system("ping -c 1 %s 2>&1 >/dev/null" % self.hostname)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500184 if response == 0:
Peter D Phane86d9a52021-07-15 10:42:25 -0500185 self.logger.info("\n\t[Check] %s is ping-able.\t\t [OK]" % self.hostname)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500186 return True
187 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500188 self.logger.error(
George Keishing7bf55092021-07-22 12:33:34 -0500189 "\n\tERROR: %s is not ping-able. FFDC collection aborted.\n" % self.hostname)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500190 sys.exit(-1)
191
Peter D Phan72ce6b82021-06-03 06:18:26 -0500192 def collect_ffdc(self):
Peter D Phan72ce6b82021-06-03 06:18:26 -0500193 r"""
194 Initiate FFDC Collection depending on requested protocol.
195
196 """
197
Peter D Phane86d9a52021-07-15 10:42:25 -0500198 self.logger.info("\n\t---- Start communicating with %s ----" % self.hostname)
Peter D Phan7610bc42021-07-06 06:31:05 -0500199 self.start_time = time.time()
Peter D Phan0c669772021-06-24 13:52:42 -0500200
George Keishingf5a57502021-07-22 16:43:47 -0500201 # Find the list of target and protocol supported.
202 check_protocol_list = []
203 config_dict = self.ffdc_actions
Peter D Phan0c669772021-06-24 13:52:42 -0500204
George Keishingf5a57502021-07-22 16:43:47 -0500205 for target_type in config_dict.keys():
206 if self.target_type != target_type:
207 continue
George Keishingeafba182021-06-29 13:44:58 -0500208
George Keishingf5a57502021-07-22 16:43:47 -0500209 for k, v in config_dict[target_type].items():
210 if config_dict[target_type][k]['PROTOCOL'][0] not in check_protocol_list:
211 check_protocol_list.append(config_dict[target_type][k]['PROTOCOL'][0])
Peter D Phanbff617a2021-07-22 08:41:35 -0500212
George Keishingf5a57502021-07-22 16:43:47 -0500213 self.logger.info("\n\t %s protocol type: %s" % (self.target_type, check_protocol_list))
Peter D Phanbff617a2021-07-22 08:41:35 -0500214
George Keishingf5a57502021-07-22 16:43:47 -0500215 verified_working_protocol = self.verify_protocol(check_protocol_list)
Peter D Phanbff617a2021-07-22 08:41:35 -0500216
George Keishingf5a57502021-07-22 16:43:47 -0500217 if verified_working_protocol:
Peter D Phane86d9a52021-07-15 10:42:25 -0500218 self.logger.info("\n\t---- Completed protocol pre-requisite check ----\n")
Peter D Phan0c669772021-06-24 13:52:42 -0500219
George Keishingf5a57502021-07-22 16:43:47 -0500220 # Verify top level directory exists for storage
221 self.validate_local_store(self.location)
222
223 if ((self.remote_protocol not in verified_working_protocol) and (self.remote_protocol != 'ALL')):
224 self.logger.info("\n\tWorking protocol list: %s" % verified_working_protocol)
225 self.logger.error(
226 '\tERROR: Requested protocol %s is not in working protocol list.\n'
227 % self.remote_protocol)
228 sys.exit(-1)
229 else:
230 self.generate_ffdc(verified_working_protocol)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500231
232 def ssh_to_target_system(self):
233 r"""
234 Open a ssh connection to targeted system.
235
236 """
237
Peter D Phan5963d632021-07-12 09:58:55 -0500238 self.ssh_remoteclient = SSHRemoteclient(self.hostname,
239 self.username,
240 self.password)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500241
Peter D Phan5963d632021-07-12 09:58:55 -0500242 if self.ssh_remoteclient.ssh_remoteclient_login():
Peter D Phane86d9a52021-07-15 10:42:25 -0500243 self.logger.info("\n\t[Check] %s SSH connection established.\t [OK]" % self.hostname)
Peter D Phan733df632021-06-17 13:13:36 -0500244
Peter D Phan5963d632021-07-12 09:58:55 -0500245 # Check scp connection.
246 # If scp connection fails,
247 # continue with FFDC generation but skip scp files to local host.
248 self.ssh_remoteclient.scp_connection()
249 return True
250 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500251 self.logger.info("\n\t[Check] %s SSH connection.\t [NOT AVAILABLE]" % self.hostname)
Peter D Phan5963d632021-07-12 09:58:55 -0500252 return False
253
254 def telnet_to_target_system(self):
255 r"""
256 Open a telnet connection to targeted system.
257 """
258 self.telnet_remoteclient = TelnetRemoteclient(self.hostname,
259 self.username,
260 self.password)
261 if self.telnet_remoteclient.tn_remoteclient_login():
Peter D Phane86d9a52021-07-15 10:42:25 -0500262 self.logger.info("\n\t[Check] %s Telnet connection established.\t [OK]" % self.hostname)
Peter D Phan5963d632021-07-12 09:58:55 -0500263 return True
264 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500265 self.logger.info("\n\t[Check] %s Telnet connection.\t [NOT AVAILABLE]" % self.hostname)
Peter D Phan5963d632021-07-12 09:58:55 -0500266 return False
Peter D Phan72ce6b82021-06-03 06:18:26 -0500267
George Keishing772c9772021-06-16 23:23:42 -0500268 def generate_ffdc(self, working_protocol_list):
Peter D Phan72ce6b82021-06-03 06:18:26 -0500269 r"""
Peter D Phan04aca3b2021-06-21 10:37:18 -0500270 Determine actions based on remote host type
Peter D Phan72ce6b82021-06-03 06:18:26 -0500271
Peter D Phan04aca3b2021-06-21 10:37:18 -0500272 Description of argument(s):
273 working_protocol_list list of confirmed working protocols to connect to remote host.
Peter D Phan72ce6b82021-06-03 06:18:26 -0500274 """
275
Peter D Phane86d9a52021-07-15 10:42:25 -0500276 self.logger.info("\n\t---- Executing commands on " + self.hostname + " ----")
277 self.logger.info("\n\tWorking protocol list: %s" % working_protocol_list)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500278
George Keishingf5a57502021-07-22 16:43:47 -0500279 config_dict = self.ffdc_actions
280 for target_type in config_dict.keys():
281 if self.target_type != target_type:
George Keishing6ea92b02021-07-01 11:20:50 -0500282 continue
Peter D Phan72ce6b82021-06-03 06:18:26 -0500283
Peter D Phane86d9a52021-07-15 10:42:25 -0500284 self.logger.info("\n\tFFDC Path: %s " % self.ffdc_dir_path)
George Keishingf5a57502021-07-22 16:43:47 -0500285 self.logger.info("\tSystem Type: %s" % target_type)
286 for k, v in config_dict[target_type].items():
Peter D Phan72ce6b82021-06-03 06:18:26 -0500287
George Keishingf5a57502021-07-22 16:43:47 -0500288 if self.remote_protocol not in working_protocol_list \
George Keishing6ea92b02021-07-01 11:20:50 -0500289 and self.remote_protocol != 'ALL':
290 continue
Peter D Phan72ce6b82021-06-03 06:18:26 -0500291
George Keishingf5a57502021-07-22 16:43:47 -0500292 protocol = config_dict[target_type][k]['PROTOCOL'][0]
293
294 if protocol not in working_protocol_list:
295 continue
296
297 if protocol == 'SSH' or protocol == 'SCP':
298 if 'SSH' in working_protocol_list or 'SCP' in working_protocol_list:
299 self.protocol_ssh(target_type, k)
Peter D Phan3beb02e2021-07-06 13:25:17 -0500300 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500301 self.logger.error("\n\tERROR: SSH or SCP is not available for %s." % self.hostname)
George Keishing6ea92b02021-07-01 11:20:50 -0500302
George Keishingf5a57502021-07-22 16:43:47 -0500303 if protocol == 'TELNET':
304 if protocol in working_protocol_list:
305 self.protocol_telnet(target_type, k)
Peter D Phan5963d632021-07-12 09:58:55 -0500306 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500307 self.logger.error("\n\tERROR: TELNET is not available for %s." % self.hostname)
Peter D Phan5963d632021-07-12 09:58:55 -0500308
George Keishingf5a57502021-07-22 16:43:47 -0500309 if protocol == 'REDFISH':
310 if protocol in working_protocol_list:
311 self.protocol_redfish(target_type, k)
Peter D Phan3beb02e2021-07-06 13:25:17 -0500312 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500313 self.logger.error("\n\tERROR: REDFISH is not available for %s." % self.hostname)
George Keishing6ea92b02021-07-01 11:20:50 -0500314
George Keishingf5a57502021-07-22 16:43:47 -0500315 if protocol == 'IPMI':
316 if protocol in working_protocol_list:
317 self.protocol_ipmi(target_type, k)
Peter D Phan3beb02e2021-07-06 13:25:17 -0500318 else:
Peter D Phand1fccd32021-07-21 06:45:54 -0500319 self.logger.error("\n\tERROR: IPMI is not available for %s." % self.hostname)
George Keishing04d29102021-07-16 02:05:57 -0500320
George Keishingf5a57502021-07-22 16:43:47 -0500321 if protocol == 'SHELL':
322 if protocol in working_protocol_list:
323 self.protocol_shell_script(target_type, k)
George Keishing04d29102021-07-16 02:05:57 -0500324 else:
325 self.logger.error("\n\tERROR: can't execute SHELL script")
George Keishingeafba182021-06-29 13:44:58 -0500326
Peter D Phan04aca3b2021-06-21 10:37:18 -0500327 # Close network connection after collecting all files
Peter D Phan7610bc42021-07-06 06:31:05 -0500328 self.elapsed_time = time.strftime("%H:%M:%S", time.gmtime(time.time() - self.start_time))
Peter D Phanbff617a2021-07-22 08:41:35 -0500329 if self.ssh_remoteclient:
330 self.ssh_remoteclient.ssh_remoteclient_disconnect()
331 if self.telnet_remoteclient:
332 self.telnet_remoteclient.tn_remoteclient_disconnect()
Peter D Phan04aca3b2021-06-21 10:37:18 -0500333
Peter D Phan0c669772021-06-24 13:52:42 -0500334 def protocol_ssh(self,
George Keishingf5a57502021-07-22 16:43:47 -0500335 target_type,
George Keishing6ea92b02021-07-01 11:20:50 -0500336 sub_type):
Peter D Phan0c669772021-06-24 13:52:42 -0500337 r"""
338 Perform actions using SSH and SCP protocols.
339
340 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500341 target_type OS Type of remote host.
George Keishing6ea92b02021-07-01 11:20:50 -0500342 sub_type Group type of commands.
Peter D Phan0c669772021-06-24 13:52:42 -0500343 """
344
George Keishing6ea92b02021-07-01 11:20:50 -0500345 if sub_type == 'DUMP_LOGS':
George Keishingf5a57502021-07-22 16:43:47 -0500346 self.group_copy(self.ffdc_actions[target_type][sub_type])
George Keishing6ea92b02021-07-01 11:20:50 -0500347 else:
George Keishingf5a57502021-07-22 16:43:47 -0500348 self.collect_and_copy_ffdc(self.ffdc_actions[target_type][sub_type])
Peter D Phan0c669772021-06-24 13:52:42 -0500349
Peter D Phan5963d632021-07-12 09:58:55 -0500350 def protocol_telnet(self,
George Keishingf5a57502021-07-22 16:43:47 -0500351 target_type,
Peter D Phan5963d632021-07-12 09:58:55 -0500352 sub_type):
353 r"""
354 Perform actions using telnet protocol.
355 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500356 target_type OS Type of remote host.
Peter D Phan5963d632021-07-12 09:58:55 -0500357 """
Peter D Phane86d9a52021-07-15 10:42:25 -0500358 self.logger.info("\n\t[Run] Executing commands on %s using %s" % (self.hostname, 'TELNET'))
Peter D Phan5963d632021-07-12 09:58:55 -0500359 telnet_files_saved = []
360 progress_counter = 0
George Keishingf5a57502021-07-22 16:43:47 -0500361 list_of_commands = self.ffdc_actions[target_type][sub_type]['COMMANDS']
Peter D Phan5963d632021-07-12 09:58:55 -0500362 for index, each_cmd in enumerate(list_of_commands, start=0):
363 command_txt, command_timeout = self.unpack_command(each_cmd)
364 result = self.telnet_remoteclient.execute_command(command_txt, command_timeout)
365 if result:
366 try:
George Keishingf5a57502021-07-22 16:43:47 -0500367 targ_file = self.ffdc_actions[target_type][sub_type]['FILES'][index]
Peter D Phan5963d632021-07-12 09:58:55 -0500368 except IndexError:
Peter D Phane86d9a52021-07-15 10:42:25 -0500369 targ_file = command_txt
370 self.logger.warning(
371 "\n\t[WARN] Missing filename to store data from telnet %s." % each_cmd)
372 self.logger.warning("\t[WARN] Data will be stored in %s." % targ_file)
Peter D Phan5963d632021-07-12 09:58:55 -0500373 targ_file_with_path = (self.ffdc_dir_path
374 + self.ffdc_prefix
375 + targ_file)
376 # Creates a new file
377 with open(targ_file_with_path, 'wb') as fp:
378 fp.write(result)
379 fp.close
380 telnet_files_saved.append(targ_file)
381 progress_counter += 1
382 self.print_progress(progress_counter)
Peter D Phane86d9a52021-07-15 10:42:25 -0500383 self.logger.info("\n\t[Run] Commands execution completed.\t\t [OK]")
Peter D Phan5963d632021-07-12 09:58:55 -0500384 for file in telnet_files_saved:
Peter D Phane86d9a52021-07-15 10:42:25 -0500385 self.logger.info("\n\t\tSuccessfully save file " + file + ".")
Peter D Phan5963d632021-07-12 09:58:55 -0500386
Peter D Phan0c669772021-06-24 13:52:42 -0500387 def protocol_redfish(self,
George Keishingf5a57502021-07-22 16:43:47 -0500388 target_type,
George Keishing6ea92b02021-07-01 11:20:50 -0500389 sub_type):
Peter D Phan0c669772021-06-24 13:52:42 -0500390 r"""
391 Perform actions using Redfish protocol.
392
393 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500394 target_type OS Type of remote host.
George Keishing6ea92b02021-07-01 11:20:50 -0500395 sub_type Group type of commands.
Peter D Phan0c669772021-06-24 13:52:42 -0500396 """
397
Peter D Phane86d9a52021-07-15 10:42:25 -0500398 self.logger.info("\n\t[Run] Executing commands to %s using %s" % (self.hostname, 'REDFISH'))
Peter D Phan0c669772021-06-24 13:52:42 -0500399 redfish_files_saved = []
400 progress_counter = 0
George Keishingf5a57502021-07-22 16:43:47 -0500401 list_of_URL = self.ffdc_actions[target_type][sub_type]['URL']
Peter D Phan0c669772021-06-24 13:52:42 -0500402 for index, each_url in enumerate(list_of_URL, start=0):
403 redfish_parm = '-u ' + self.username + ' -p ' + self.password + ' -r ' \
404 + self.hostname + ' -S Always raw GET ' + each_url
405
406 result = self.run_redfishtool(redfish_parm)
407 if result:
408 try:
George Keishingf5a57502021-07-22 16:43:47 -0500409 targ_file = self.get_file_list(self.ffdc_actions[target_type][sub_type])[index]
Peter D Phan0c669772021-06-24 13:52:42 -0500410 except IndexError:
411 targ_file = each_url.split('/')[-1]
Peter D Phane86d9a52021-07-15 10:42:25 -0500412 self.logger.warning(
413 "\n\t[WARN] Missing filename to store data from redfish URL %s." % each_url)
414 self.logger.warning("\t[WARN] Data will be stored in %s." % targ_file)
Peter D Phan0c669772021-06-24 13:52:42 -0500415
416 targ_file_with_path = (self.ffdc_dir_path
417 + self.ffdc_prefix
418 + targ_file)
419
420 # Creates a new file
421 with open(targ_file_with_path, 'w') as fp:
422 fp.write(result)
423 fp.close
424 redfish_files_saved.append(targ_file)
425
426 progress_counter += 1
427 self.print_progress(progress_counter)
428
Peter D Phane86d9a52021-07-15 10:42:25 -0500429 self.logger.info("\n\t[Run] Commands execution completed.\t\t [OK]")
Peter D Phan0c669772021-06-24 13:52:42 -0500430
431 for file in redfish_files_saved:
Peter D Phane86d9a52021-07-15 10:42:25 -0500432 self.logger.info("\n\t\tSuccessfully save file " + file + ".")
Peter D Phan0c669772021-06-24 13:52:42 -0500433
George Keishingeafba182021-06-29 13:44:58 -0500434 def protocol_ipmi(self,
George Keishingf5a57502021-07-22 16:43:47 -0500435 target_type,
George Keishing6ea92b02021-07-01 11:20:50 -0500436 sub_type):
George Keishingeafba182021-06-29 13:44:58 -0500437 r"""
438 Perform actions using ipmitool over LAN protocol.
439
440 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500441 target_type OS Type of remote host.
George Keishing6ea92b02021-07-01 11:20:50 -0500442 sub_type Group type of commands.
George Keishingeafba182021-06-29 13:44:58 -0500443 """
444
Peter D Phane86d9a52021-07-15 10:42:25 -0500445 self.logger.info("\n\t[Run] Executing commands to %s using %s" % (self.hostname, 'IPMI'))
George Keishingeafba182021-06-29 13:44:58 -0500446 ipmi_files_saved = []
447 progress_counter = 0
George Keishingf5a57502021-07-22 16:43:47 -0500448 list_of_cmd = self.get_command_list(self.ffdc_actions[target_type][sub_type])
George Keishingeafba182021-06-29 13:44:58 -0500449 for index, each_cmd in enumerate(list_of_cmd, start=0):
450 ipmi_parm = '-U ' + self.username + ' -P ' + self.password + ' -H ' \
Peter D Phand1fccd32021-07-21 06:45:54 -0500451 + self.hostname + ' -I lanplus ' + each_cmd
George Keishingeafba182021-06-29 13:44:58 -0500452
453 result = self.run_ipmitool(ipmi_parm)
454 if result:
455 try:
George Keishingf5a57502021-07-22 16:43:47 -0500456 targ_file = self.get_file_list(self.ffdc_actions[target_type][sub_type])[index]
George Keishingeafba182021-06-29 13:44:58 -0500457 except IndexError:
George Keishing6ea92b02021-07-01 11:20:50 -0500458 targ_file = each_cmd.split('/')[-1]
Peter D Phane86d9a52021-07-15 10:42:25 -0500459 self.logger.warning("\n\t[WARN] Missing filename to store data from IPMI %s." % each_cmd)
460 self.logger.warning("\t[WARN] Data will be stored in %s." % targ_file)
George Keishingeafba182021-06-29 13:44:58 -0500461
462 targ_file_with_path = (self.ffdc_dir_path
463 + self.ffdc_prefix
464 + targ_file)
465
466 # Creates a new file
467 with open(targ_file_with_path, 'w') as fp:
468 fp.write(result)
469 fp.close
470 ipmi_files_saved.append(targ_file)
471
472 progress_counter += 1
473 self.print_progress(progress_counter)
474
Peter D Phane86d9a52021-07-15 10:42:25 -0500475 self.logger.info("\n\t[Run] Commands execution completed.\t\t [OK]")
George Keishingeafba182021-06-29 13:44:58 -0500476
477 for file in ipmi_files_saved:
Peter D Phane86d9a52021-07-15 10:42:25 -0500478 self.logger.info("\n\t\tSuccessfully save file " + file + ".")
George Keishingeafba182021-06-29 13:44:58 -0500479
Peter D Phan04aca3b2021-06-21 10:37:18 -0500480 def collect_and_copy_ffdc(self,
George Keishingf5a57502021-07-22 16:43:47 -0500481 ffdc_actions_for_target_type,
Peter D Phan2b8052d2021-06-22 10:55:41 -0500482 form_filename=False):
Peter D Phan04aca3b2021-06-21 10:37:18 -0500483 r"""
484 Send commands in ffdc_config file to targeted system.
485
486 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500487 ffdc_actions_for_target_type commands and files for the selected remote host type.
Peter D Phan2b8052d2021-06-22 10:55:41 -0500488 form_filename if true, pre-pend self.target_type to filename
Peter D Phan04aca3b2021-06-21 10:37:18 -0500489 """
490
Peter D Phan2b6cb3a2021-07-19 06:55:42 -0500491 # Executing commands, if any
George Keishingf5a57502021-07-22 16:43:47 -0500492 self.ssh_execute_ffdc_commands(ffdc_actions_for_target_type,
Peter D Phan3beb02e2021-07-06 13:25:17 -0500493 form_filename)
Peter D Phan04aca3b2021-06-21 10:37:18 -0500494
Peter D Phan3beb02e2021-07-06 13:25:17 -0500495 # Copying files
Peter D Phan5963d632021-07-12 09:58:55 -0500496 if self.ssh_remoteclient.scpclient:
Peter D Phane86d9a52021-07-15 10:42:25 -0500497 self.logger.info("\n\n\tCopying FFDC files from remote system %s.\n" % self.hostname)
Peter D Phan2b8052d2021-06-22 10:55:41 -0500498
Peter D Phan04aca3b2021-06-21 10:37:18 -0500499 # Retrieving files from target system
George Keishingf5a57502021-07-22 16:43:47 -0500500 list_of_files = self.get_file_list(ffdc_actions_for_target_type)
Peter D Phan2b8052d2021-06-22 10:55:41 -0500501 self.scp_ffdc(self.ffdc_dir_path, self.ffdc_prefix, form_filename, list_of_files)
Peter D Phan04aca3b2021-06-21 10:37:18 -0500502 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500503 self.logger.info("\n\n\tSkip copying FFDC files from remote system %s.\n" % self.hostname)
Peter D Phan04aca3b2021-06-21 10:37:18 -0500504
Peter D Phanbabf2962021-07-07 11:24:40 -0500505 def get_command_list(self,
George Keishingf5a57502021-07-22 16:43:47 -0500506 ffdc_actions_for_target_type):
Peter D Phanbabf2962021-07-07 11:24:40 -0500507 r"""
508 Fetch list of commands from configuration file
509
510 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500511 ffdc_actions_for_target_type commands and files for the selected remote host type.
Peter D Phanbabf2962021-07-07 11:24:40 -0500512 """
513 try:
George Keishingf5a57502021-07-22 16:43:47 -0500514 list_of_commands = ffdc_actions_for_target_type['COMMANDS']
Peter D Phanbabf2962021-07-07 11:24:40 -0500515 except KeyError:
516 list_of_commands = []
517 return list_of_commands
518
519 def get_file_list(self,
George Keishingf5a57502021-07-22 16:43:47 -0500520 ffdc_actions_for_target_type):
Peter D Phanbabf2962021-07-07 11:24:40 -0500521 r"""
522 Fetch list of commands from configuration file
523
524 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500525 ffdc_actions_for_target_type commands and files for the selected remote host type.
Peter D Phanbabf2962021-07-07 11:24:40 -0500526 """
527 try:
George Keishingf5a57502021-07-22 16:43:47 -0500528 list_of_files = ffdc_actions_for_target_type['FILES']
Peter D Phanbabf2962021-07-07 11:24:40 -0500529 except KeyError:
530 list_of_files = []
531 return list_of_files
532
Peter D Phan5963d632021-07-12 09:58:55 -0500533 def unpack_command(self,
534 command):
535 r"""
536 Unpack command from config file
537
538 Description of argument(s):
539 command Command from config file.
540 """
541 if isinstance(command, dict):
542 command_txt = next(iter(command))
543 command_timeout = next(iter(command.values()))
544 elif isinstance(command, str):
545 command_txt = command
546 # Default command timeout 60 seconds
547 command_timeout = 60
548
549 return command_txt, command_timeout
550
Peter D Phan3beb02e2021-07-06 13:25:17 -0500551 def ssh_execute_ffdc_commands(self,
George Keishingf5a57502021-07-22 16:43:47 -0500552 ffdc_actions_for_target_type,
Peter D Phan3beb02e2021-07-06 13:25:17 -0500553 form_filename=False):
554 r"""
555 Send commands in ffdc_config file to targeted system.
556
557 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500558 ffdc_actions_for_target_type commands and files for the selected remote host type.
Peter D Phan3beb02e2021-07-06 13:25:17 -0500559 form_filename if true, pre-pend self.target_type to filename
560 """
Peter D Phane86d9a52021-07-15 10:42:25 -0500561 self.logger.info("\n\t[Run] Executing commands on %s using %s"
George Keishingf5a57502021-07-22 16:43:47 -0500562 % (self.hostname, ffdc_actions_for_target_type['PROTOCOL'][0]))
Peter D Phan3beb02e2021-07-06 13:25:17 -0500563
George Keishingf5a57502021-07-22 16:43:47 -0500564 list_of_commands = self.get_command_list(ffdc_actions_for_target_type)
Peter D Phan3beb02e2021-07-06 13:25:17 -0500565 # If command list is empty, returns
566 if not list_of_commands:
567 return
568
569 progress_counter = 0
570 for command in list_of_commands:
Peter D Phan5963d632021-07-12 09:58:55 -0500571 command_txt, command_timeout = self.unpack_command(command)
Peter D Phan3beb02e2021-07-06 13:25:17 -0500572
573 if form_filename:
574 command_txt = str(command_txt % self.target_type)
575
Peter D Phan2b6cb3a2021-07-19 06:55:42 -0500576 cmd_exit_code, err, response = \
577 self.ssh_remoteclient.execute_command(command_txt, command_timeout)
578
579 if cmd_exit_code:
580 self.logger.warning(
581 "\n\t\t[WARN] %s exits with code %s." % (command_txt, str(cmd_exit_code)))
582 self.logger.warning("\t\t[WARN] %s " % err)
Peter D Phanbabf2962021-07-07 11:24:40 -0500583
Peter D Phan3beb02e2021-07-06 13:25:17 -0500584 progress_counter += 1
585 self.print_progress(progress_counter)
586
Peter D Phane86d9a52021-07-15 10:42:25 -0500587 self.logger.info("\n\t[Run] Commands execution completed.\t\t [OK]")
Peter D Phan3beb02e2021-07-06 13:25:17 -0500588
Peter D Phan56429a62021-06-23 08:38:29 -0500589 def group_copy(self,
George Keishingf5a57502021-07-22 16:43:47 -0500590 ffdc_actions_for_target_type):
Peter D Phan56429a62021-06-23 08:38:29 -0500591 r"""
592 scp group of files (wild card) from remote host.
593
594 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500595 fdc_actions_for_target_type commands and files for the selected remote host type.
Peter D Phan56429a62021-06-23 08:38:29 -0500596 """
Peter D Phan3beb02e2021-07-06 13:25:17 -0500597
Peter D Phan5963d632021-07-12 09:58:55 -0500598 if self.ssh_remoteclient.scpclient:
Peter D Phane86d9a52021-07-15 10:42:25 -0500599 self.logger.info("\n\tCopying DUMP files from remote system %s.\n" % self.hostname)
Peter D Phan56429a62021-06-23 08:38:29 -0500600
George Keishingf5a57502021-07-22 16:43:47 -0500601 list_of_commands = self.get_command_list(ffdc_actions_for_target_type)
Peter D Phanbabf2962021-07-07 11:24:40 -0500602 # If command list is empty, returns
603 if not list_of_commands:
604 return
Peter D Phan56429a62021-06-23 08:38:29 -0500605
Peter D Phanbabf2962021-07-07 11:24:40 -0500606 for command in list_of_commands:
607 try:
608 filename = command.split(' ')[2]
609 except IndexError:
Peter D Phane86d9a52021-07-15 10:42:25 -0500610 self.logger.info("\t\tInvalid command %s for DUMP_LOGS block." % command)
Peter D Phanbabf2962021-07-07 11:24:40 -0500611 continue
612
Peter D Phan2b6cb3a2021-07-19 06:55:42 -0500613 cmd_exit_code, err, response = \
614 self.ssh_remoteclient.execute_command(command)
Peter D Phanbabf2962021-07-07 11:24:40 -0500615
Peter D Phan2b6cb3a2021-07-19 06:55:42 -0500616 # If file does not exist, code take no action.
617 # cmd_exit_code is ignored for this scenario.
Peter D Phan56429a62021-06-23 08:38:29 -0500618 if response:
Peter D Phan5963d632021-07-12 09:58:55 -0500619 scp_result = self.ssh_remoteclient.scp_file_from_remote(filename, self.ffdc_dir_path)
Peter D Phan56429a62021-06-23 08:38:29 -0500620 if scp_result:
Peter D Phane86d9a52021-07-15 10:42:25 -0500621 self.logger.info("\t\tSuccessfully copied from " + self.hostname + ':' + filename)
Peter D Phan56429a62021-06-23 08:38:29 -0500622 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500623 self.logger.info("\t\tThere is no " + filename)
Peter D Phan56429a62021-06-23 08:38:29 -0500624
625 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500626 self.logger.info("\n\n\tSkip copying files from remote system %s.\n" % self.hostname)
Peter D Phan56429a62021-06-23 08:38:29 -0500627
Peter D Phan72ce6b82021-06-03 06:18:26 -0500628 def scp_ffdc(self,
629 targ_dir_path,
Peter D Phan2b8052d2021-06-22 10:55:41 -0500630 targ_file_prefix,
631 form_filename,
Peter D Phan72ce6b82021-06-03 06:18:26 -0500632 file_list=None,
633 quiet=None):
Peter D Phan72ce6b82021-06-03 06:18:26 -0500634 r"""
635 SCP all files in file_dict to the indicated directory on the local system.
636
637 Description of argument(s):
638 targ_dir_path The path of the directory to receive the files.
639 targ_file_prefix Prefix which will be pre-pended to each
640 target file's name.
641 file_dict A dictionary of files to scp from targeted system to this system
642
643 """
644
Peter D Phan72ce6b82021-06-03 06:18:26 -0500645 progress_counter = 0
646 for filename in file_list:
Peter D Phan2b8052d2021-06-22 10:55:41 -0500647 if form_filename:
648 filename = str(filename % self.target_type)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500649 source_file_path = filename
650 targ_file_path = targ_dir_path + targ_file_prefix + filename.split('/')[-1]
651
Peter D Phanbabf2962021-07-07 11:24:40 -0500652 # If source file name contains wild card, copy filename as is.
653 if '*' in source_file_path:
Peter D Phan5963d632021-07-12 09:58:55 -0500654 scp_result = self.ssh_remoteclient.scp_file_from_remote(source_file_path, self.ffdc_dir_path)
Peter D Phanbabf2962021-07-07 11:24:40 -0500655 else:
Peter D Phan5963d632021-07-12 09:58:55 -0500656 scp_result = self.ssh_remoteclient.scp_file_from_remote(source_file_path, targ_file_path)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500657
658 if not quiet:
659 if scp_result:
Peter D Phane86d9a52021-07-15 10:42:25 -0500660 self.logger.info(
661 "\t\tSuccessfully copied from " + self.hostname + ':' + source_file_path + ".\n")
Peter D Phan72ce6b82021-06-03 06:18:26 -0500662 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500663 self.logger.info(
664 "\t\tFail to copy from " + self.hostname + ':' + source_file_path + ".\n")
Peter D Phan72ce6b82021-06-03 06:18:26 -0500665 else:
666 progress_counter += 1
667 self.print_progress(progress_counter)
668
Peter D Phan72ce6b82021-06-03 06:18:26 -0500669 def set_ffdc_defaults(self):
Peter D Phan72ce6b82021-06-03 06:18:26 -0500670 r"""
671 Set a default value for self.ffdc_dir_path and self.ffdc_prefix.
672 Collected ffdc file will be stored in dir /self.location/hostname_timestr/.
673 Individual ffdc file will have timestr_filename.
674
675 Description of class variables:
676 self.ffdc_dir_path The dir path where collected ffdc data files should be put.
677
678 self.ffdc_prefix The prefix to be given to each ffdc file name.
679
680 """
681
682 timestr = time.strftime("%Y%m%d-%H%M%S")
683 self.ffdc_dir_path = self.location + "/" + self.hostname + "_" + timestr + "/"
684 self.ffdc_prefix = timestr + "_"
685 self.validate_local_store(self.ffdc_dir_path)
686
687 def validate_local_store(self, dir_path):
688 r"""
689 Ensure path exists to store FFDC files locally.
690
691 Description of variable:
692 dir_path The dir path where collected ffdc data files will be stored.
693
694 """
695
696 if not os.path.exists(dir_path):
697 try:
George Keishing7b3a5132021-07-13 09:24:02 -0500698 os.makedirs(dir_path, 0o755)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500699 except (IOError, OSError) as e:
700 # PermissionError
701 if e.errno == EPERM or e.errno == EACCES:
Peter D Phane86d9a52021-07-15 10:42:25 -0500702 self.logger.error(
George Keishing7bf55092021-07-22 12:33:34 -0500703 '\tERROR: os.makedirs %s failed with PermissionError.\n' % dir_path)
Peter D Phan72ce6b82021-06-03 06:18:26 -0500704 else:
Peter D Phane86d9a52021-07-15 10:42:25 -0500705 self.logger.error(
George Keishing7bf55092021-07-22 12:33:34 -0500706 '\tERROR: os.makedirs %s failed with %s.\n' % (dir_path, e.strerror))
Peter D Phan72ce6b82021-06-03 06:18:26 -0500707 sys.exit(-1)
708
709 def print_progress(self, progress):
710 r"""
711 Print activity progress +
712
713 Description of variable:
714 progress Progress counter.
715
716 """
717
718 sys.stdout.write("\r\t" + "+" * progress)
719 sys.stdout.flush()
720 time.sleep(.1)
Peter D Phan0c669772021-06-24 13:52:42 -0500721
722 def verify_redfish(self):
723 r"""
724 Verify remote host has redfish service active
725
726 """
727 redfish_parm = '-u ' + self.username + ' -p ' + self.password + ' -r ' \
728 + self.hostname + ' -S Always raw GET /redfish/v1/'
729 return(self.run_redfishtool(redfish_parm, True))
730
George Keishingeafba182021-06-29 13:44:58 -0500731 def verify_ipmi(self):
732 r"""
733 Verify remote host has IPMI LAN service active
734
735 """
736 ipmi_parm = '-U ' + self.username + ' -P ' + self.password + ' -H ' \
Peter D Phand1fccd32021-07-21 06:45:54 -0500737 + self.hostname + ' power status -I lanplus'
George Keishingeafba182021-06-29 13:44:58 -0500738 return(self.run_ipmitool(ipmi_parm, True))
739
Peter D Phan0c669772021-06-24 13:52:42 -0500740 def run_redfishtool(self,
741 parms_string,
742 quiet=False):
743 r"""
744 Run CLI redfishtool
745
746 Description of variable:
747 parms_string redfishtool subcommand and options.
748 quiet do not print redfishtool error message if True
749 """
750
751 result = subprocess.run(['redfishtool ' + parms_string],
752 stdout=subprocess.PIPE,
753 stderr=subprocess.PIPE,
754 shell=True,
755 universal_newlines=True)
756
757 if result.stderr and not quiet:
George Keishing7bf55092021-07-22 12:33:34 -0500758 self.logger.error('\n\tERROR with redfishtool ' + parms_string)
759 self.logger.error('\n\t%s' % result.stderr.split('\n'))
Peter D Phan0c669772021-06-24 13:52:42 -0500760
761 return result.stdout
George Keishingeafba182021-06-29 13:44:58 -0500762
763 def run_ipmitool(self,
764 parms_string,
765 quiet=False):
766 r"""
767 Run CLI IPMI tool.
768
769 Description of variable:
770 parms_string ipmitool subcommand and options.
771 quiet do not print redfishtool error message if True
772 """
773
774 result = subprocess.run(['ipmitool -I lanplus -C 17 ' + parms_string],
775 stdout=subprocess.PIPE,
776 stderr=subprocess.PIPE,
777 shell=True,
778 universal_newlines=True)
779
780 if result.stderr and not quiet:
Peter D Phane86d9a52021-07-15 10:42:25 -0500781 self.logger.error('\n\t\tERROR with ipmitool -I lanplus -C 17 ' + parms_string)
782 self.logger.error('\t\t' + result.stderr)
George Keishingeafba182021-06-29 13:44:58 -0500783
784 return result.stdout
George Keishing04d29102021-07-16 02:05:57 -0500785
786 def run_shell_script(self,
787 parms_string,
788 quiet=False):
789 r"""
790 Run CLI shell script tool.
791
792 Description of variable:
793 parms_string script command options.
794 quiet do not print redfishtool error message if True
795 """
796
797 result = subprocess.run([parms_string],
798 stdout=subprocess.PIPE,
799 stderr=subprocess.PIPE,
800 shell=True,
801 universal_newlines=True)
802
803 if result.stderr and not quiet:
804 self.logger.error('\n\t\tERROR executing %s' % parms_string)
805 self.logger.error('\t\t' + result.stderr)
806
807 return result.stdout
808
809 def protocol_shell_script(self,
George Keishingf5a57502021-07-22 16:43:47 -0500810 target_type,
George Keishing04d29102021-07-16 02:05:57 -0500811 sub_type):
812 r"""
813 Perform SHELL script execution locally.
814
815 Description of argument(s):
George Keishingf5a57502021-07-22 16:43:47 -0500816 target_type OS Type of remote host.
George Keishing04d29102021-07-16 02:05:57 -0500817 sub_type Group type of commands.
818 """
819
820 self.logger.info("\n\t[Run] Executing commands to %s using %s" % (self.hostname, 'SHELL'))
821 shell_files_saved = []
822 progress_counter = 0
George Keishingf5a57502021-07-22 16:43:47 -0500823 list_of_cmd = self.get_command_list(self.ffdc_actions[target_type][sub_type])
George Keishing04d29102021-07-16 02:05:57 -0500824 for index, each_cmd in enumerate(list_of_cmd, start=0):
825
826 result = self.run_shell_script(each_cmd)
827 if result:
828 try:
George Keishingf5a57502021-07-22 16:43:47 -0500829 targ_file = self.get_file_list(self.ffdc_actions[target_type][sub_type])[index]
George Keishing04d29102021-07-16 02:05:57 -0500830 except IndexError:
831 targ_file = each_cmd.split('/')[-1]
832 self.logger.warning("\n\t[WARN] Missing filename to store data %s." % each_cmd)
833 self.logger.warning("\t[WARN] Data will be stored in %s." % targ_file)
834
835 targ_file_with_path = (self.ffdc_dir_path
836 + self.ffdc_prefix
837 + targ_file)
838
839 # Creates a new file
840 with open(targ_file_with_path, 'w') as fp:
841 fp.write(result)
842 fp.close
843 shell_files_saved.append(targ_file)
844
845 progress_counter += 1
846 self.print_progress(progress_counter)
847
848 self.logger.info("\n\t[Run] Commands execution completed.\t\t [OK]")
849
850 for file in shell_files_saved:
851 self.logger.info("\n\t\tSuccessfully save file " + file + ".")
George Keishingf5a57502021-07-22 16:43:47 -0500852
853 def verify_protocol(self, protocol_list):
854 r"""
855 Perform protocol working check.
856
857 Description of argument(s):
858 protocol_list List of protocol.
859 """
860
861 tmp_list = []
862 if self.target_is_pingable():
863 tmp_list.append("SHELL")
864
865 for protocol in protocol_list:
866 if self.remote_protocol != 'ALL':
867 if self.remote_protocol != protocol:
868 continue
869
870 # Only check SSH/SCP once for both protocols
871 if protocol == 'SSH' or protocol == 'SCP' and protocol not in tmp_list:
872 if self.ssh_to_target_system():
873 tmp_list.append('SSH')
874 tmp_list.append('SCP')
875
876 if protocol == 'TELNET':
877 if self.telnet_to_target_system():
878 tmp_list.append(protocol)
879
880 if protocol == 'REDFISH':
881 if self.verify_redfish():
882 tmp_list.append(protocol)
883 self.logger.info("\n\t[Check] %s Redfish Service.\t\t [OK]" % self.hostname)
884 else:
885 self.logger.info("\n\t[Check] %s Redfish Service.\t\t [NOT AVAILABLE]" % self.hostname)
886
887 if protocol == 'IPMI':
888 if self.verify_ipmi():
889 tmp_list.append(protocol)
890 self.logger.info("\n\t[Check] %s IPMI LAN Service.\t\t [OK]" % self.hostname)
891 else:
892 self.logger.info("\n\t[Check] %s IPMI LAN Service.\t\t [NOT AVAILABLE]" % self.hostname)
893
894 return tmp_list