| George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 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 | 1cf49cd | 2021-10-25 11:40:47 -0500 | [diff] [blame] | 9 | import time | 
| 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 Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 38 | def validate_parms(): | 
|  | 39 |  | 
|  | 40 | r""" | 
| Michael Walsh | 318a4fe | 2019-10-17 10:38:56 -0500 | [diff] [blame] | 41 | 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] | 42 | """ | 
|  | 43 |  | 
|  | 44 | get_plug_vars() | 
|  | 45 |  | 
| Michael Walsh | 2ea965c | 2019-08-01 16:14:25 -0500 | [diff] [blame] | 46 | valid_value(AUTOBOOT_OPENBMC_HOST) | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 47 | global AUTO_REBOOT_DISABLE | 
|  | 48 | if pgm_name == "cp_cleanup": | 
|  | 49 | AUTO_REBOOT_DISABLE = 0 | 
|  | 50 | else: | 
|  | 51 | valid_value(AUTO_REBOOT_DISABLE, valid_values=["0", "1"]) | 
|  | 52 | AUTO_REBOOT_DISABLE = int(AUTO_REBOOT_DISABLE) | 
|  | 53 |  | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 54 |  | 
|  | 55 | def main(): | 
|  | 56 |  | 
| Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 57 | gen_setup() | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 58 |  | 
| Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 59 | set_term_options(term_requests='children') | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 60 |  | 
| Michael Walsh | 80caea0 | 2019-06-21 11:31:41 -0500 | [diff] [blame] | 61 | print_plug_in_header() | 
|  | 62 |  | 
|  | 63 | if pgm_name == "cp_setup" or pgm_name == "cp_cleanup": | 
|  | 64 | exit_not_master() | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 65 |  | 
|  | 66 | init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") | 
|  | 67 |  | 
|  | 68 | lib_file_path = init_robot_file_path("lib/utils.robot") | 
|  | 69 |  | 
| Michael Shepos | 1cf49cd | 2021-10-25 11:40:47 -0500 | [diff] [blame] | 70 | REDFISH_SUPPORT_TRANS_STATE = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) or \ | 
|  | 71 | int(os.environ.get('AUTOBOOT_REDFISH_SUPPORT_TRANS_STATE', 0)) | 
|  | 72 |  | 
| Michael Walsh | 318a4fe | 2019-10-17 10:38:56 -0500 | [diff] [blame] | 73 | enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE | 
|  | 74 | print_var(enable_auto_reboot) | 
| Michael Shepos | ea568c2 | 2021-01-08 12:38:23 -0600 | [diff] [blame] | 75 | keyword_string = "Set Auto Reboot Setting  ${%i}" % enable_auto_reboot | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 76 |  | 
| Michael Walsh | 046fe22 | 2019-11-08 14:33:53 -0600 | [diff] [blame] | 77 | 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] | 78 | REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD, | 
| David Shaw | b86e538 | 2022-01-31 16:14:11 -0600 | [diff] [blame] | 79 | IPMI_USERNAME, IPMI_PASSWORD, REDFISH_SUPPORT_TRANS_STATE, | 
|  | 80 | keyword_string, lib_file_path, quiet, test_mode, debug, outputdir, | 
|  | 81 | output, log, report) | 
| Michael Shepos | 34c7956 | 2021-03-18 18:49:44 -0500 | [diff] [blame] | 82 |  | 
| Michael Shepos | 1cf49cd | 2021-10-25 11:40:47 -0500 | [diff] [blame] | 83 | retry_count = 3 | 
|  | 84 | while not robot_cmd_fnc(cmd_buf): | 
|  | 85 | retry_count -= 1 | 
|  | 86 | if retry_count == 0: | 
|  | 87 | print_error_report("Robot command execution failed.") | 
|  | 88 | exit(1) | 
|  | 89 | time.sleep(30) | 
|  | 90 | return | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 91 |  | 
|  | 92 |  | 
|  | 93 | main() |