Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | Set the auto_boot policy according to the caller's wishes. |
| 5 | """ |
| 6 | |
| 7 | import os |
| 8 | import sys |
| 9 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 10 | save_dir_path = sys.path.pop(0) |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 11 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 12 | modules = ['gen_arg', 'gen_print', 'gen_valid', 'gen_misc', 'gen_cmd', 'gen_plug_in_utils', 'gen_call_robot'] |
| 13 | for module in modules: |
| 14 | exec("from " + module + " import *") |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 15 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 16 | sys.path.insert(0, save_dir_path) |
| 17 | |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 18 | |
| 19 | # Set exit_on_error for gen_valid functions. |
| 20 | set_exit_on_error(True) |
| 21 | |
| 22 | parser = 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. |
| 31 | stock_list = [("test_mode", get_plug_default("test_mode", 0)), |
| 32 | ("quiet", get_plug_default("quiet", 0)), |
| 33 | ("debug", get_plug_default("debug", 0))] |
| 34 | |
| 35 | AUTO_REBOOT_DISABLE = "1" |
| 36 | |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 37 | |
| 38 | def validate_parms(): |
| 39 | |
| 40 | r""" |
Michael Walsh | 318a4fe | 2019-10-17 10:38:56 -0500 | [diff] [blame] | 41 | Validate program parameters, etc. Return True or False (i.e. pass/fail) accordingly. |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 42 | """ |
| 43 | |
| 44 | get_plug_vars() |
| 45 | |
Michael Walsh | 2ea965c | 2019-08-01 16:14:25 -0500 | [diff] [blame] | 46 | valid_value(AUTOBOOT_OPENBMC_HOST) |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 47 | 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 Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 54 | |
| 55 | def main(): |
| 56 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 57 | gen_setup() |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 58 | |
Michael Walsh | 91ef468 | 2019-12-13 12:19:56 -0600 | [diff] [blame] | 59 | set_term_options(term_requests='children') |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 60 | |
Michael Walsh | 80caea0 | 2019-06-21 11:31:41 -0500 | [diff] [blame] | 61 | print_plug_in_header() |
| 62 | |
| 63 | if pgm_name == "cp_setup" or pgm_name == "cp_cleanup": |
| 64 | exit_not_master() |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 65 | |
| 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 Walsh | 318a4fe | 2019-10-17 10:38:56 -0500 | [diff] [blame] | 70 | enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE |
| 71 | print_var(enable_auto_reboot) |
Michael Shepos | ea568c2 | 2021-01-08 12:38:23 -0600 | [diff] [blame^] | 72 | keyword_string = "Set Auto Reboot Setting ${%i}" % enable_auto_reboot |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 73 | |
Michael Walsh | 046fe22 | 2019-11-08 14:33:53 -0600 | [diff] [blame] | 74 | cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT, |
Michael Shepos | ea568c2 | 2021-01-08 12:38:23 -0600 | [diff] [blame^] | 75 | REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD, |
| 76 | keyword_string, lib_file_path, quiet, |
Michael Walsh | 046fe22 | 2019-11-08 14:33:53 -0600 | [diff] [blame] | 77 | test_mode, debug, outputdir, output, log, report) |
Michael Walsh | 0a3bdb4 | 2019-01-31 16:21:44 +0000 | [diff] [blame] | 78 | if not robot_cmd_fnc(cmd_buf): |
| 79 | print_error_report("Robot command execution failed.") |
| 80 | exit(1) |
| 81 | |
| 82 | |
| 83 | main() |