blob: 7d967e25a1908881ce4367e4916f8452b085b6d3 [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
Michael Walsh91ef4682019-12-13 12:19:56 -060010save_dir_path = sys.path.pop(0)
Michael Walsh0a3bdb42019-01-31 16:21:44 +000011
Michael Walsh91ef4682019-12-13 12:19:56 -060012modules = ['gen_arg', 'gen_print', 'gen_valid', 'gen_misc', 'gen_cmd', 'gen_plug_in_utils', 'gen_call_robot']
13for module in modules:
14 exec("from " + module + " import *")
Michael Walsh0a3bdb42019-01-31 16:21:44 +000015
Michael Walsh91ef4682019-12-13 12:19:56 -060016sys.path.insert(0, save_dir_path)
17
Michael Walsh0a3bdb42019-01-31 16:21:44 +000018
19# Set exit_on_error for gen_valid functions.
20set_exit_on_error(True)
21
22parser = argparse.ArgumentParser(
23 usage='%(prog)s [OPTIONS]',
24 description="%(prog)s will set the auto_boot policy according to the"
25 + " user's wishes.",
26 formatter_class=argparse.RawTextHelpFormatter,
27 prefix_chars='-+')
28
29
30# Populate stock_list with options we want.
31stock_list = [("test_mode", get_plug_default("test_mode", 0)),
32 ("quiet", get_plug_default("quiet", 0)),
33 ("debug", get_plug_default("debug", 0))]
34
35AUTO_REBOOT_DISABLE = "1"
36
Michael Walsh0a3bdb42019-01-31 16:21:44 +000037
38def validate_parms():
39
40 r"""
Michael Walsh318a4fe2019-10-17 10:38:56 -050041 Validate program parameters, etc. Return True or False (i.e. pass/fail) accordingly.
Michael Walsh0a3bdb42019-01-31 16:21:44 +000042 """
43
44 get_plug_vars()
45
Michael Walsh2ea965c2019-08-01 16:14:25 -050046 valid_value(AUTOBOOT_OPENBMC_HOST)
Michael Walsh0a3bdb42019-01-31 16:21:44 +000047 global AUTO_REBOOT_DISABLE
48 if pgm_name == "cp_cleanup":
49 AUTO_REBOOT_DISABLE = 0
50 else:
51 valid_value(AUTO_REBOOT_DISABLE, valid_values=["0", "1"])
52 AUTO_REBOOT_DISABLE = int(AUTO_REBOOT_DISABLE)
53
Michael Walsh0a3bdb42019-01-31 16:21:44 +000054
55def main():
56
Michael Walsh91ef4682019-12-13 12:19:56 -060057 gen_setup()
Michael Walsh0a3bdb42019-01-31 16:21:44 +000058
Michael Walsh91ef4682019-12-13 12:19:56 -060059 set_term_options(term_requests='children')
Michael Walsh0a3bdb42019-01-31 16:21:44 +000060
Michael Walsh80caea02019-06-21 11:31:41 -050061 print_plug_in_header()
62
63 if pgm_name == "cp_setup" or pgm_name == "cp_cleanup":
64 exit_not_master()
Michael Walsh0a3bdb42019-01-31 16:21:44 +000065
66 init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".")
67
68 lib_file_path = init_robot_file_path("lib/utils.robot")
69
Michael Walsh318a4fe2019-10-17 10:38:56 -050070 enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE
71 print_var(enable_auto_reboot)
72 keyword_string = "Set Auto Reboot ${%i}" % enable_auto_reboot
Michael Walsh0a3bdb42019-01-31 16:21:44 +000073
Michael Walsh046fe222019-11-08 14:33:53 -060074 cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT,
75 REST_USERNAME, REST_PASSWORD, keyword_string, lib_file_path, quiet,
76 test_mode, debug, outputdir, output, log, report)
Michael Walsh0a3bdb42019-01-31 16:21:44 +000077 if not robot_cmd_fnc(cmd_buf):
78 print_error_report("Robot command execution failed.")
79 exit(1)
80
81
82main()