| 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 |  | 
| Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 13 | modules = [ | 
|  | 14 | "gen_arg", | 
|  | 15 | "gen_print", | 
|  | 16 | "gen_valid", | 
|  | 17 | "gen_misc", | 
|  | 18 | "gen_cmd", | 
|  | 19 | "gen_plug_in_utils", | 
|  | 20 | "gen_call_robot", | 
|  | 21 | ] | 
| Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 22 | for module in modules: | 
|  | 23 | exec("from " + module + " import *") | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 24 |  | 
| Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 25 | sys.path.insert(0, save_dir_path) | 
|  | 26 |  | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 27 |  | 
|  | 28 | # Set exit_on_error for gen_valid functions. | 
|  | 29 | set_exit_on_error(True) | 
|  | 30 |  | 
|  | 31 | parser = argparse.ArgumentParser( | 
| Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 32 | usage="%(prog)s [OPTIONS]", | 
|  | 33 | description=( | 
|  | 34 | "%(prog)s will set the auto_boot policy according to the user's" | 
|  | 35 | " wishes." | 
|  | 36 | ), | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 37 | formatter_class=argparse.RawTextHelpFormatter, | 
| Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 38 | prefix_chars="-+", | 
|  | 39 | ) | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 40 |  | 
|  | 41 |  | 
|  | 42 | # Populate stock_list with options we want. | 
| Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 43 | stock_list = [ | 
|  | 44 | ("test_mode", get_plug_default("test_mode", 0)), | 
|  | 45 | ("quiet", get_plug_default("quiet", 0)), | 
|  | 46 | ("debug", get_plug_default("debug", 0)), | 
|  | 47 | ] | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 48 |  | 
|  | 49 | AUTO_REBOOT_DISABLE = "1" | 
|  | 50 |  | 
| Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 51 |  | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 52 | def validate_parms(): | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 53 | r""" | 
| Michael Walsh | 318a4fe | 2019-10-17 10:38:56 -0500 | [diff] [blame] | 54 | 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] | 55 | """ | 
|  | 56 |  | 
|  | 57 | get_plug_vars() | 
|  | 58 |  | 
| Michael Walsh | 2ea965c | 2019-08-01 16:14:25 -0500 | [diff] [blame] | 59 | valid_value(AUTOBOOT_OPENBMC_HOST) | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 60 | global AUTO_REBOOT_DISABLE | 
|  | 61 | if pgm_name == "cp_cleanup": | 
|  | 62 | AUTO_REBOOT_DISABLE = 0 | 
|  | 63 | else: | 
|  | 64 | valid_value(AUTO_REBOOT_DISABLE, valid_values=["0", "1"]) | 
|  | 65 | AUTO_REBOOT_DISABLE = int(AUTO_REBOOT_DISABLE) | 
|  | 66 |  | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 67 |  | 
|  | 68 | def main(): | 
| Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 69 | gen_setup() | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 70 |  | 
| Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 71 | set_term_options(term_requests="children") | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 72 |  | 
| Michael Walsh | 80caea0 | 2019-06-21 11:31:41 -0500 | [diff] [blame] | 73 | print_plug_in_header() | 
|  | 74 |  | 
|  | 75 | if pgm_name == "cp_setup" or pgm_name == "cp_cleanup": | 
|  | 76 | exit_not_master() | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 77 |  | 
|  | 78 | init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") | 
|  | 79 |  | 
|  | 80 | lib_file_path = init_robot_file_path("lib/utils.robot") | 
|  | 81 |  | 
| Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 82 | REDFISH_SUPPORT_TRANS_STATE = int( | 
|  | 83 | os.environ.get("REDFISH_SUPPORT_TRANS_STATE", 0) | 
|  | 84 | ) or int(os.environ.get("AUTOBOOT_REDFISH_SUPPORT_TRANS_STATE", 0)) | 
| Michael Shepos | 1cf49cd | 2021-10-25 11:40:47 -0500 | [diff] [blame] | 85 |  | 
| Michael Walsh | 318a4fe | 2019-10-17 10:38:56 -0500 | [diff] [blame] | 86 | enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE | 
|  | 87 | print_var(enable_auto_reboot) | 
| Michael Shepos | ea568c2 | 2021-01-08 12:38:23 -0600 | [diff] [blame] | 88 | keyword_string = "Set Auto Reboot Setting  ${%i}" % enable_auto_reboot | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 89 |  | 
| Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 90 | cmd_buf = create_robot_cmd_string( | 
|  | 91 | "extended/run_keyword.robot", | 
|  | 92 | OPENBMC_HOST, | 
|  | 93 | SSH_PORT, | 
|  | 94 | HTTPS_PORT, | 
|  | 95 | REST_USERNAME, | 
|  | 96 | REST_PASSWORD, | 
|  | 97 | OPENBMC_USERNAME, | 
|  | 98 | OPENBMC_PASSWORD, | 
|  | 99 | IPMI_USERNAME, | 
|  | 100 | IPMI_PASSWORD, | 
|  | 101 | REDFISH_SUPPORT_TRANS_STATE, | 
|  | 102 | keyword_string, | 
|  | 103 | lib_file_path, | 
|  | 104 | quiet, | 
|  | 105 | test_mode, | 
|  | 106 | debug, | 
|  | 107 | outputdir, | 
|  | 108 | output, | 
|  | 109 | log, | 
|  | 110 | report, | 
|  | 111 | ) | 
| Michael Shepos | 34c7956 | 2021-03-18 18:49:44 -0500 | [diff] [blame] | 112 |  | 
| Michael Shepos | 1cf49cd | 2021-10-25 11:40:47 -0500 | [diff] [blame] | 113 | retry_count = 3 | 
|  | 114 | while not robot_cmd_fnc(cmd_buf): | 
|  | 115 | retry_count -= 1 | 
|  | 116 | if retry_count == 0: | 
|  | 117 | print_error_report("Robot command execution failed.") | 
|  | 118 | exit(1) | 
|  | 119 | time.sleep(30) | 
|  | 120 | return | 
| Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 121 |  | 
|  | 122 |  | 
|  | 123 | main() |