blob: 21c67ef71bdf86c625d4afb6bd5dd1ac0907c528 [file] [log] [blame]
Peter D Phan72ce6b82021-06-03 06:18:26 -05001#!/usr/bin/env python
2
3r"""
Peter D Phan72ce6b82021-06-03 06:18:26 -05004CLI FFDC Collector.
5"""
6
7import os
8import sys
9import click
10
11# ---------Set sys.path for cli command execution---------------------------------------
12# Absolute path to openbmc-test-automation/ffdc
Peter D Phan8462faf2021-06-16 12:24:15 -050013abs_path = os.path.abspath(os.path.dirname(sys.argv[0]))
14full_path = abs_path.split('ffdc')[0]
Peter D Phan72ce6b82021-06-03 06:18:26 -050015sys.path.append(full_path)
16# Walk path and append to sys.path
17for root, dirs, files in os.walk(full_path):
18 for found_dir in dirs:
19 sys.path.append(os.path.join(root, found_dir))
20
21from ffdc_collector import FFDCCollector
22
23
Peter D Phan8462faf2021-06-16 12:24:15 -050024@click.command(context_settings=dict(help_option_names=['-h', '--help']))
25@click.option('-r', '--remote', envvar='OPENBMC_HOST',
26 help="Name/IP of the remote (targeting) host. [default: OPENBMC_HOST]")
Peter D Phan72ce6b82021-06-03 06:18:26 -050027@click.option('-u', '--username', envvar='OPENBMC_USERNAME',
Peter D Phan8462faf2021-06-16 12:24:15 -050028 help="User on the remote host with access to FFDC files.[default: OPENBMC_USERNAME]")
Peter D Phan72ce6b82021-06-03 06:18:26 -050029@click.option('-p', '--password', envvar='OPENBMC_PASSWORD',
Peter D Phan8462faf2021-06-16 12:24:15 -050030 help="Password for user on remote host. [default: OPENBMC_PASSWORD]")
31@click.option('-f', '--ffdc_config', default=abs_path + "/ffdc_config.yaml",
32 show_default=True, help="YAML Configuration file listing commands and files for FFDC.")
Peter D Phan72ce6b82021-06-03 06:18:26 -050033@click.option('-l', '--location', default="/tmp",
34 show_default=True, help="Location to store collected FFDC data")
Peter D Phan8462faf2021-06-16 12:24:15 -050035def cli_ffdc(remote, username, password, ffdc_config, location):
Peter D Phan72ce6b82021-06-03 06:18:26 -050036 r"""
37 Stand alone CLI to generate and collect FFDC from the selected target.
Peter D Phan72ce6b82021-06-03 06:18:26 -050038 """
Peter D Phan8462faf2021-06-16 12:24:15 -050039
George Keishing772c9772021-06-16 23:23:42 -050040 click.echo("\n********** FFDC (First Failure Data Collection) Starts **********")
Peter D Phan72ce6b82021-06-03 06:18:26 -050041
Peter D Phan8462faf2021-06-16 12:24:15 -050042 if input_options_ok(remote, username, password, ffdc_config):
43 thisFFDC = FFDCCollector(remote, username, password, ffdc_config, location)
44 thisFFDC.collect_ffdc()
Peter D Phan72ce6b82021-06-03 06:18:26 -050045
Peter D Phan8462faf2021-06-16 12:24:15 -050046 if not thisFFDC.receive_file_list:
47 click.echo("\n\tFFDC Collection from " + remote + " has failed\n\n.")
48 else:
49 click.echo(str("\t" + str(len(thisFFDC.receive_file_list)))
50 + " files were retrieved from " + remote)
51 click.echo("\tFiles are stored in " + thisFFDC.ffdc_dir_path + "\n\n")
Peter D Phan72ce6b82021-06-03 06:18:26 -050052
53 click.echo("\n********** FFDC Finishes **********\n\n")
54
55
Peter D Phan8462faf2021-06-16 12:24:15 -050056def input_options_ok(remote, username, password, ffdc_config):
57 r"""
58 Verify script options exist via CLI options or environment variables.
59 """
60
61 all_options_ok = True
62
63 if not remote:
64 all_options_ok = False
65 print("\
66 \n>>>>>\tERROR: Name/IP of the remote host is not specified in CLI options or env OPENBMC_HOST.")
67 if not username:
68 all_options_ok = False
69 print("\
70 \n>>>>>\tERROR: User on the remote host is not specified in CLI options or env OPENBMC_USERNAME.")
71 if not password:
72 all_options_ok = False
73 print("\
74 \n>>>>>\tERROR: Password for user on remote host is not specified in CLI options "
75 + "or env OPENBMC_PASSWORD.")
76 if not os.path.isfile(ffdc_config):
77 all_options_ok = False
78 print("\
79 \n>>>>>\tERROR: Config file %s is not found. Please verify path and filename." % ffdc_config)
80
81 return all_options_ok
82
83
Peter D Phan72ce6b82021-06-03 06:18:26 -050084if __name__ == '__main__':
85 cli_ffdc()