blob: 50b3f42a3c6735cc5f8fb6d070181c7047665302 [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
9
10save_path_0 = sys.path[0]
11del sys.path[0]
12
13from gen_print import *
14from gen_valid import *
15from gen_arg import *
16from gen_misc import *
17from gen_cmd import *
18from gen_plug_in_utils import *
19from gen_call_robot import *
20
21# Restore sys.path[0].
22sys.path.insert(0, save_path_0)
23
24# Set exit_on_error for gen_valid functions.
25set_exit_on_error(True)
26
27parser = argparse.ArgumentParser(
28 usage='%(prog)s [OPTIONS]',
29 description="%(prog)s will set the auto_boot policy according to the"
30 + " user's wishes.",
31 formatter_class=argparse.RawTextHelpFormatter,
32 prefix_chars='-+')
33
34
35# Populate stock_list with options we want.
36stock_list = [("test_mode", get_plug_default("test_mode", 0)),
37 ("quiet", get_plug_default("quiet", 0)),
38 ("debug", get_plug_default("debug", 0))]
39
40AUTO_REBOOT_DISABLE = "1"
41
42def exit_function(signal_number=0,
43 frame=None):
44 r"""
Michael Walsh318a4fe2019-10-17 10:38:56 -050045 Execute whenever the program ends normally or with the signals that we catch (i.e. TERM, INT).
Michael Walsh0a3bdb42019-01-31 16:21:44 +000046 """
47
48 dprint_executing()
49 dprint_var(signal_number)
50
51 # Your cleanup code here.
52
53 qprint_pgm_footer()
54
55
56def signal_handler(signal_number,
57 frame):
58 r"""
Michael Walsh318a4fe2019-10-17 10:38:56 -050059 Handle signals. Without a function to catch a SIGTERM or SIGINT, our program would terminate immediately
60 with return code 143 and without calling our exit_function.
Michael Walsh0a3bdb42019-01-31 16:21:44 +000061 """
62
Michael Walsh318a4fe2019-10-17 10:38:56 -050063 # Our convention is to set up exit_function with atexit.register() so there is no need to explicitly
64 # call exit_function from here.
Michael Walsh0a3bdb42019-01-31 16:21:44 +000065
66 dprint_executing()
67
Michael Walsh318a4fe2019-10-17 10:38:56 -050068 # Calling exit prevents us from returning to the code that was running when we received the signal.
Michael Walsh0a3bdb42019-01-31 16:21:44 +000069 exit(0)
70
71
72def validate_parms():
73
74 r"""
Michael Walsh318a4fe2019-10-17 10:38:56 -050075 Validate program parameters, etc. Return True or False (i.e. pass/fail) accordingly.
Michael Walsh0a3bdb42019-01-31 16:21:44 +000076 """
77
78 get_plug_vars()
79
Michael Walsh2ea965c2019-08-01 16:14:25 -050080 valid_value(AUTOBOOT_OPENBMC_HOST)
Michael Walsh0a3bdb42019-01-31 16:21:44 +000081 global AUTO_REBOOT_DISABLE
82 if pgm_name == "cp_cleanup":
83 AUTO_REBOOT_DISABLE = 0
84 else:
85 valid_value(AUTO_REBOOT_DISABLE, valid_values=["0", "1"])
86 AUTO_REBOOT_DISABLE = int(AUTO_REBOOT_DISABLE)
87
88 gen_post_validation(exit_function, signal_handler)
89
90
91def main():
92
93 gen_get_options(parser, stock_list)
94
95 validate_parms()
96
97 qprint_pgm_header()
98
Michael Walsh80caea02019-06-21 11:31:41 -050099 print_plug_in_header()
100
101 if pgm_name == "cp_setup" or pgm_name == "cp_cleanup":
102 exit_not_master()
Michael Walsh0a3bdb42019-01-31 16:21:44 +0000103
104 init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".")
105
106 lib_file_path = init_robot_file_path("lib/utils.robot")
107
Michael Walsh318a4fe2019-10-17 10:38:56 -0500108 enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE
109 print_var(enable_auto_reboot)
110 keyword_string = "Set Auto Reboot ${%i}" % enable_auto_reboot
Michael Walsh0a3bdb42019-01-31 16:21:44 +0000111
112 cmd_buf = create_robot_cmd_string("extended/run_keyword.robot",
113 OPENBMC_HOST, REST_USERNAME,
114 REST_PASSWORD, keyword_string,
115 lib_file_path, quiet, test_mode, debug,
116 outputdir, output, log, report)
117 if not robot_cmd_fnc(cmd_buf):
118 print_error_report("Robot command execution failed.")
119 exit(1)
120
121
122main()