Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 4 | CLI FFDC Collector. |
| 5 | """ |
| 6 | |
| 7 | import os |
| 8 | import sys |
| 9 | import click |
| 10 | |
| 11 | # ---------Set sys.path for cli command execution--------------------------------------- |
| 12 | # Absolute path to openbmc-test-automation/ffdc |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 13 | abs_path = os.path.abspath(os.path.dirname(sys.argv[0])) |
| 14 | full_path = abs_path.split('ffdc')[0] |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 15 | sys.path.append(full_path) |
| 16 | # Walk path and append to sys.path |
| 17 | for 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 | |
| 21 | from ffdc_collector import FFDCCollector |
| 22 | |
| 23 | |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 24 | @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 Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 27 | @click.option('-u', '--username', envvar='OPENBMC_USERNAME', |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 28 | help="User on the remote host with access to FFDC files.[default: OPENBMC_USERNAME]") |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 29 | @click.option('-p', '--password', envvar='OPENBMC_PASSWORD', |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 30 | 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 Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 33 | @click.option('-l', '--location', default="/tmp", |
| 34 | show_default=True, help="Location to store collected FFDC data") |
Peter D Phan | 04aca3b | 2021-06-21 10:37:18 -0500 | [diff] [blame] | 35 | @click.option('-t', '--remote_type', default="OPENBMC", |
| 36 | show_default=True, help="OS type of the remote (targeting) host. OPENBMC, RHEL, UBUNTU, AIX") |
| 37 | def cli_ffdc(remote, username, password, ffdc_config, location, remote_type): |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 38 | r""" |
| 39 | Stand alone CLI to generate and collect FFDC from the selected target. |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 40 | """ |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 41 | |
George Keishing | 772c977 | 2021-06-16 23:23:42 -0500 | [diff] [blame] | 42 | click.echo("\n********** FFDC (First Failure Data Collection) Starts **********") |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 43 | |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 44 | if input_options_ok(remote, username, password, ffdc_config): |
Peter D Phan | 04aca3b | 2021-06-21 10:37:18 -0500 | [diff] [blame] | 45 | thisFFDC = FFDCCollector(remote, username, password, ffdc_config, location, remote_type) |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 46 | thisFFDC.collect_ffdc() |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 47 | |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 48 | if not thisFFDC.receive_file_list: |
Peter D Phan | 733df63 | 2021-06-17 13:13:36 -0500 | [diff] [blame] | 49 | click.echo("\n\tFFDC Collection from " + remote + " has failed.\n\n") |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 50 | else: |
| 51 | click.echo(str("\t" + str(len(thisFFDC.receive_file_list))) |
| 52 | + " files were retrieved from " + remote) |
| 53 | click.echo("\tFiles are stored in " + thisFFDC.ffdc_dir_path + "\n\n") |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 54 | |
| 55 | click.echo("\n********** FFDC Finishes **********\n\n") |
| 56 | |
| 57 | |
Peter D Phan | 8462faf | 2021-06-16 12:24:15 -0500 | [diff] [blame] | 58 | def input_options_ok(remote, username, password, ffdc_config): |
| 59 | r""" |
| 60 | Verify script options exist via CLI options or environment variables. |
| 61 | """ |
| 62 | |
| 63 | all_options_ok = True |
| 64 | |
| 65 | if not remote: |
| 66 | all_options_ok = False |
| 67 | print("\ |
| 68 | \n>>>>>\tERROR: Name/IP of the remote host is not specified in CLI options or env OPENBMC_HOST.") |
| 69 | if not username: |
| 70 | all_options_ok = False |
| 71 | print("\ |
| 72 | \n>>>>>\tERROR: User on the remote host is not specified in CLI options or env OPENBMC_USERNAME.") |
| 73 | if not password: |
| 74 | all_options_ok = False |
| 75 | print("\ |
| 76 | \n>>>>>\tERROR: Password for user on remote host is not specified in CLI options " |
| 77 | + "or env OPENBMC_PASSWORD.") |
| 78 | if not os.path.isfile(ffdc_config): |
| 79 | all_options_ok = False |
| 80 | print("\ |
| 81 | \n>>>>>\tERROR: Config file %s is not found. Please verify path and filename." % ffdc_config) |
| 82 | |
| 83 | return all_options_ok |
| 84 | |
| 85 | |
Peter D Phan | 72ce6b8 | 2021-06-03 06:18:26 -0500 | [diff] [blame] | 86 | if __name__ == '__main__': |
| 87 | cli_ffdc() |