blob: 2f4851ef953432ecea721cb8b121234fab8507fa [file] [log] [blame]
Michael Walsh0a3bdb42019-01-31 16:21:44 +00001#!/usr/bin/env python
2
3r"""
4Set the auto_boot policy according to the caller's wishes.
5"""
6
7import os
8import sys
Michael Sheposcb6b53b2021-03-15 23:23:10 -05009from robot.libraries.BuiltIn import BuiltIn
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
Michael Walsh91ef4682019-12-13 12:19:56 -060013modules = ['gen_arg', 'gen_print', 'gen_valid', 'gen_misc', 'gen_cmd', 'gen_plug_in_utils', 'gen_call_robot']
14for module in modules:
15 exec("from " + module + " import *")
Michael Walsh0a3bdb42019-01-31 16:21:44 +000016
Michael Walsh91ef4682019-12-13 12:19:56 -060017sys.path.insert(0, save_dir_path)
18
Michael Walsh0a3bdb42019-01-31 16:21:44 +000019
20# Set exit_on_error for gen_valid functions.
21set_exit_on_error(True)
22
23parser = 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.
32stock_list = [("test_mode", get_plug_default("test_mode", 0)),
33 ("quiet", get_plug_default("quiet", 0)),
34 ("debug", get_plug_default("debug", 0))]
35
36AUTO_REBOOT_DISABLE = "1"
37
Michael Sheposcb6b53b2021-03-15 23:23:10 -050038REDFISH_SUPPORT_TRANS_STATE = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0))
39try:
40 REDFISH_SUPPORT_TRANS_STATE = REDFISH_SUPPORT_TRANS_STATE or \
41 int(BuiltIn().get_variable_value("${REDFISH_SUPPORT_TRANS_STATE}", default=0))
42except:
43 pass
Michael Walsh0a3bdb42019-01-31 16:21:44 +000044
45def validate_parms():
46
47 r"""
Michael Walsh318a4fe2019-10-17 10:38:56 -050048 Validate program parameters, etc. Return True or False (i.e. pass/fail) accordingly.
Michael Walsh0a3bdb42019-01-31 16:21:44 +000049 """
50
51 get_plug_vars()
52
Michael Walsh2ea965c2019-08-01 16:14:25 -050053 valid_value(AUTOBOOT_OPENBMC_HOST)
Michael Walsh0a3bdb42019-01-31 16:21:44 +000054 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 Walsh0a3bdb42019-01-31 16:21:44 +000061
62def main():
63
Michael Walsh91ef4682019-12-13 12:19:56 -060064 gen_setup()
Michael Walsh0a3bdb42019-01-31 16:21:44 +000065
Michael Walsh91ef4682019-12-13 12:19:56 -060066 set_term_options(term_requests='children')
Michael Walsh0a3bdb42019-01-31 16:21:44 +000067
Michael Walsh80caea02019-06-21 11:31:41 -050068 print_plug_in_header()
69
70 if pgm_name == "cp_setup" or pgm_name == "cp_cleanup":
71 exit_not_master()
Michael Walsh0a3bdb42019-01-31 16:21:44 +000072
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 Walsh318a4fe2019-10-17 10:38:56 -050077 enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE
78 print_var(enable_auto_reboot)
Michael Sheposea568c22021-01-08 12:38:23 -060079 keyword_string = "Set Auto Reboot Setting ${%i}" % enable_auto_reboot
Michael Walsh0a3bdb42019-01-31 16:21:44 +000080
Michael Walsh046fe222019-11-08 14:33:53 -060081 cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT,
Michael Sheposea568c22021-01-08 12:38:23 -060082 REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD,
Michael Sheposcb6b53b2021-03-15 23:23:10 -050083 REDFISH_SUPPORT_TRANS_STATE, keyword_string, lib_file_path, quiet,
Michael Walsh046fe222019-11-08 14:33:53 -060084 test_mode, debug, outputdir, output, log, report)
Michael Sheposcb6b53b2021-03-15 23:23:10 -050085
Michael Walsh0a3bdb42019-01-31 16:21:44 +000086 if not robot_cmd_fnc(cmd_buf):
87 print_error_report("Robot command execution failed.")
88 exit(1)
89
90
91main()