blob: 8f125889564c7e1a847662bad12f9b366ff62a4a [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
Michael Walsh0a3bdb42019-01-31 16:21:44 +00002
3r"""
4Set the auto_boot policy according to the caller's wishes.
5"""
6
7import os
8import sys
Michael Shepos1cf49cd2021-10-25 11:40:47 -05009import time
Michael Walsh0a3bdb42019-01-31 16:21:44 +000010
Michael Walsh91ef4682019-12-13 12:19:56 -060011save_dir_path = sys.path.pop(0)
Michael Walsh0a3bdb42019-01-31 16:21:44 +000012
Patrick Williams20f38712022-12-08 06:18:26 -060013modules = [
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 Walsh91ef4682019-12-13 12:19:56 -060022for module in modules:
23 exec("from " + module + " import *")
Michael Walsh0a3bdb42019-01-31 16:21:44 +000024
Michael Walsh91ef4682019-12-13 12:19:56 -060025sys.path.insert(0, save_dir_path)
26
Michael Walsh0a3bdb42019-01-31 16:21:44 +000027
28# Set exit_on_error for gen_valid functions.
29set_exit_on_error(True)
30
31parser = argparse.ArgumentParser(
Patrick Williams20f38712022-12-08 06:18:26 -060032 usage="%(prog)s [OPTIONS]",
33 description=(
34 "%(prog)s will set the auto_boot policy according to the user's"
35 " wishes."
36 ),
Michael Walsh0a3bdb42019-01-31 16:21:44 +000037 formatter_class=argparse.RawTextHelpFormatter,
Patrick Williams20f38712022-12-08 06:18:26 -060038 prefix_chars="-+",
39)
Michael Walsh0a3bdb42019-01-31 16:21:44 +000040
41
42# Populate stock_list with options we want.
Patrick Williams20f38712022-12-08 06:18:26 -060043stock_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 Walsh0a3bdb42019-01-31 16:21:44 +000048
49AUTO_REBOOT_DISABLE = "1"
50
Patrick Williamsa57fef42022-12-03 07:00:14 -060051
Michael Walsh0a3bdb42019-01-31 16:21:44 +000052def validate_parms():
Michael Walsh0a3bdb42019-01-31 16:21:44 +000053 r"""
Michael Walsh318a4fe2019-10-17 10:38:56 -050054 Validate program parameters, etc. Return True or False (i.e. pass/fail) accordingly.
Michael Walsh0a3bdb42019-01-31 16:21:44 +000055 """
56
57 get_plug_vars()
58
Michael Walsh2ea965c2019-08-01 16:14:25 -050059 valid_value(AUTOBOOT_OPENBMC_HOST)
Michael Walsh0a3bdb42019-01-31 16:21:44 +000060 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 Walsh0a3bdb42019-01-31 16:21:44 +000067
68def main():
Michael Walsh91ef4682019-12-13 12:19:56 -060069 gen_setup()
Michael Walsh0a3bdb42019-01-31 16:21:44 +000070
Patrick Williams20f38712022-12-08 06:18:26 -060071 set_term_options(term_requests="children")
Michael Walsh0a3bdb42019-01-31 16:21:44 +000072
Michael Walsh80caea02019-06-21 11:31:41 -050073 print_plug_in_header()
74
75 if pgm_name == "cp_setup" or pgm_name == "cp_cleanup":
76 exit_not_master()
Michael Walsh0a3bdb42019-01-31 16:21:44 +000077
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 Williams20f38712022-12-08 06:18:26 -060082 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 Shepos1cf49cd2021-10-25 11:40:47 -050085
Michael Walsh318a4fe2019-10-17 10:38:56 -050086 enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE
87 print_var(enable_auto_reboot)
Michael Sheposea568c22021-01-08 12:38:23 -060088 keyword_string = "Set Auto Reboot Setting ${%i}" % enable_auto_reboot
Michael Walsh0a3bdb42019-01-31 16:21:44 +000089
Patrick Williams20f38712022-12-08 06:18:26 -060090 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 Shepos34c79562021-03-18 18:49:44 -0500112
Michael Shepos1cf49cd2021-10-25 11:40:47 -0500113 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 Walsh0a3bdb42019-01-31 16:21:44 +0000121
122
123main()