blob: 775cd582f256b6ba82d6e2413e2febf0197674c2 [file] [log] [blame]
Peter D Phan72ce6b82021-06-03 06:18:26 -05001#!/usr/bin/env python
2
3r"""
4
5CLI FFDC Collector.
6"""
7
8import os
9import sys
10import click
11
12# ---------Set sys.path for cli command execution---------------------------------------
13# Absolute path to openbmc-test-automation/ffdc
14full_path = os.path.abspath(os.path.dirname(sys.argv[0])).split('ffdc')[0]
15sys.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
24@click.command()
25@click.option('-h', '--hostname', envvar='OPENBMC_HOST',
26 help="ip or hostname of the target [default: OPENBMC_HOST]")
27@click.option('-u', '--username', envvar='OPENBMC_USERNAME',
28 help="username on targeted system [default: OPENBMC_USERNAME]")
29@click.option('-p', '--password', envvar='OPENBMC_PASSWORD',
30 help="password for username on targeted system [default: OPENBMC_PASSWORD]")
31@click.option('-f', '--ffdc_config', default="ffdc_config.yaml",
32 show_default=True, help="YAML FFDC configuration file")
33@click.option('-l', '--location', default="/tmp",
34 show_default=True, help="Location to store collected FFDC data")
35def cli_ffdc(hostname, username, password, ffdc_config, location):
36 r"""
37 Stand alone CLI to generate and collect FFDC from the selected target.
38
39 Description of argument(s):
40
George Keishing7bc01e92021-06-15 11:07:14 -050041 hostname Name/IP of the remote (targeting) host.
Peter D Phan72ce6b82021-06-03 06:18:26 -050042 username User on the remote host with access to FFDC files.
43 password Password for user on remote host.
44 ffdc_config Configuration file listing commands and files for FFDC.
45 location Where to store collected FFDC.
46
47 """
48 click.echo("\n********** FFDC Starts **********")
49
50 thisFFDC = FFDCCollector(hostname, username, password, ffdc_config, location)
51 thisFFDC.collect_ffdc()
52
53 if not thisFFDC.receive_file_list:
54 click.echo("\n\tFFDC Collection from " + hostname + " has failed\n\n.")
55 else:
56 click.echo(str("\t" + str(len(thisFFDC.receive_file_list)))
57 + " files were retrieved from " + hostname)
58 click.echo("\tFiles are stored in " + thisFFDC.ffdc_dir_path + "\n\n")
59
60 click.echo("\n********** FFDC Finishes **********\n\n")
61
62
63if __name__ == '__main__':
64 cli_ffdc()