Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | Set the auto_boot policy according to the caller's wishes. |
| 5 | """ |
| 6 | |
| 7 | import os |
| 8 | import sys |
Michael Shepos | cb6b53b | 2021-03-15 23:23:10 -0500 | [diff] [blame^] | 9 | from robot.libraries.BuiltIn import BuiltIn |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 10 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 11 | save_dir_path = sys.path.pop(0) |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 12 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 13 | modules = ['gen_arg', 'gen_print', 'gen_valid', 'gen_misc', 'gen_cmd', 'gen_plug_in_utils', 'gen_call_robot'] |
| 14 | for module in modules: |
| 15 | exec("from " + module + " import *") |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 16 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 17 | sys.path.insert(0, save_dir_path) |
| 18 | |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 19 | |
| 20 | # Set exit_on_error for gen_valid functions. |
| 21 | set_exit_on_error(True) |
| 22 | |
| 23 | parser = argparse.ArgumentParser( |
| 24 | usage='%(prog)s [OPTIONS]', |
| 25 | description="%(prog)s will set the auto_boot policy according to the" |
| 26 | + " user's wishes.", |
| 27 | formatter_class=argparse.RawTextHelpFormatter, |
| 28 | prefix_chars='-+') |
| 29 | |
| 30 | |
| 31 | # Populate stock_list with options we want. |
| 32 | stock_list = [("test_mode", get_plug_default("test_mode", 0)), |
| 33 | ("quiet", get_plug_default("quiet", 0)), |
| 34 | ("debug", get_plug_default("debug", 0))] |
| 35 | |
| 36 | AUTO_REBOOT_DISABLE = "1" |
| 37 | |
Michael Shepos | cb6b53b | 2021-03-15 23:23:10 -0500 | [diff] [blame^] | 38 | REDFISH_SUPPORT_TRANS_STATE = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) |
| 39 | try: |
| 40 | REDFISH_SUPPORT_TRANS_STATE = REDFISH_SUPPORT_TRANS_STATE or \ |
| 41 | int(BuiltIn().get_variable_value("${REDFISH_SUPPORT_TRANS_STATE}", default=0)) |
| 42 | except: |
| 43 | pass |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 44 | |
| 45 | def validate_parms(): |
| 46 | |
| 47 | r""" |
Michael Walsh | 318a4fe | 2019-10-17 10:38:56 -0500 | [diff] [blame] | 48 | Validate program parameters, etc. Return True or False (i.e. pass/fail) accordingly. |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 49 | """ |
| 50 | |
| 51 | get_plug_vars() |
| 52 | |
Michael Walsh | 2ea965c | 2019-08-01 16:14:25 -0500 | [diff] [blame] | 53 | valid_value(AUTOBOOT_OPENBMC_HOST) |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 54 | global AUTO_REBOOT_DISABLE |
| 55 | if pgm_name == "cp_cleanup": |
| 56 | AUTO_REBOOT_DISABLE = 0 |
| 57 | else: |
| 58 | valid_value(AUTO_REBOOT_DISABLE, valid_values=["0", "1"]) |
| 59 | AUTO_REBOOT_DISABLE = int(AUTO_REBOOT_DISABLE) |
| 60 | |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 61 | |
| 62 | def main(): |
| 63 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 64 | gen_setup() |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 65 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 66 | set_term_options(term_requests='children') |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 67 | |
Michael Walsh | 80caea0 | 2019-06-21 11:31:41 -0500 | [diff] [blame] | 68 | print_plug_in_header() |
| 69 | |
| 70 | if pgm_name == "cp_setup" or pgm_name == "cp_cleanup": |
| 71 | exit_not_master() |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 72 | |
| 73 | init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") |
| 74 | |
| 75 | lib_file_path = init_robot_file_path("lib/utils.robot") |
| 76 | |
Michael Walsh | 318a4fe | 2019-10-17 10:38:56 -0500 | [diff] [blame] | 77 | enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE |
| 78 | print_var(enable_auto_reboot) |
Michael Shepos | ea568c2 | 2021-01-08 12:38:23 -0600 | [diff] [blame] | 79 | keyword_string = "Set Auto Reboot Setting ${%i}" % enable_auto_reboot |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 80 | |
Michael Walsh | 046fe22 | 2019-11-08 14:33:53 -0600 | [diff] [blame] | 81 | cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT, |
Michael Shepos | ea568c2 | 2021-01-08 12:38:23 -0600 | [diff] [blame] | 82 | REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD, |
Michael Shepos | cb6b53b | 2021-03-15 23:23:10 -0500 | [diff] [blame^] | 83 | REDFISH_SUPPORT_TRANS_STATE, keyword_string, lib_file_path, quiet, |
Michael Walsh | 046fe22 | 2019-11-08 14:33:53 -0600 | [diff] [blame] | 84 | test_mode, debug, outputdir, output, log, report) |
Michael Shepos | cb6b53b | 2021-03-15 23:23:10 -0500 | [diff] [blame^] | 85 | |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 86 | if not robot_cmd_fnc(cmd_buf): |
| 87 | print_error_report("Robot command execution failed.") |
| 88 | exit(1) |
| 89 | |
| 90 | |
| 91 | main() |