blob: 36d40f213a14f10336e95190f0fffff3e0436ff3 [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"""
45 Execute whenever the program ends normally or with the signals that we
46 catch (i.e. TERM, INT).
47 """
48
49 dprint_executing()
50 dprint_var(signal_number)
51
52 # Your cleanup code here.
53
54 qprint_pgm_footer()
55
56
57def signal_handler(signal_number,
58 frame):
59 r"""
60 Handle signals. Without a function to catch a SIGTERM or SIGINT, our
61 program would terminate immediately with return code 143 and without
62 calling our exit_function.
63 """
64
65 # Our convention is to set up exit_function with atexit.register() so
66 # there is no need to explicitly call exit_function from here.
67
68 dprint_executing()
69
70 # Calling exit prevents us from returning to the code that was running
71 # when we received the signal.
72 exit(0)
73
74
75def validate_parms():
76
77 r"""
78 Validate program parameters, etc. Return True or False (i.e. pass/fail)
79 accordingly.
80 """
81
82 get_plug_vars()
83
84 valid_value(AUTOBOOT_OPENBMC_HOST, ["", None])
85 global AUTO_REBOOT_DISABLE
86 if pgm_name == "cp_cleanup":
87 AUTO_REBOOT_DISABLE = 0
88 else:
89 valid_value(AUTO_REBOOT_DISABLE, valid_values=["0", "1"])
90 AUTO_REBOOT_DISABLE = int(AUTO_REBOOT_DISABLE)
91
92 gen_post_validation(exit_function, signal_handler)
93
94
95def main():
96
97 gen_get_options(parser, stock_list)
98
99 validate_parms()
100
101 qprint_pgm_header()
102
103 dprint_plug_vars()
104
105 init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".")
106
107 lib_file_path = init_robot_file_path("lib/utils.robot")
108
109 keyword_string = "Set Auto Reboot ${%i}" % AUTO_REBOOT_DISABLE
110
111 cmd_buf = create_robot_cmd_string("extended/run_keyword.robot",
112 OPENBMC_HOST, REST_USERNAME,
113 REST_PASSWORD, keyword_string,
114 lib_file_path, quiet, test_mode, debug,
115 outputdir, output, log, report)
116 if not robot_cmd_fnc(cmd_buf):
117 print_error_report("Robot command execution failed.")
118 exit(1)
119
120
121main()