| #!/usr/bin/env python3 |
| |
| r""" |
| Set the auto_boot policy according to the caller's wishes. |
| """ |
| |
| import os |
| import sys |
| import time |
| |
| save_dir_path = sys.path.pop(0) |
| |
| modules = ['gen_arg', 'gen_print', 'gen_valid', 'gen_misc', 'gen_cmd', 'gen_plug_in_utils', 'gen_call_robot'] |
| for module in modules: |
| exec("from " + module + " import *") |
| |
| sys.path.insert(0, save_dir_path) |
| |
| |
| # Set exit_on_error for gen_valid functions. |
| set_exit_on_error(True) |
| |
| parser = argparse.ArgumentParser( |
| usage='%(prog)s [OPTIONS]', |
| description="%(prog)s will set the auto_boot policy according to the user's wishes.", |
| formatter_class=argparse.RawTextHelpFormatter, |
| prefix_chars='-+') |
| |
| |
| # Populate stock_list with options we want. |
| stock_list = [("test_mode", get_plug_default("test_mode", 0)), |
| ("quiet", get_plug_default("quiet", 0)), |
| ("debug", get_plug_default("debug", 0))] |
| |
| AUTO_REBOOT_DISABLE = "1" |
| |
| |
| def validate_parms(): |
| |
| r""" |
| Validate program parameters, etc. Return True or False (i.e. pass/fail) accordingly. |
| """ |
| |
| get_plug_vars() |
| |
| valid_value(AUTOBOOT_OPENBMC_HOST) |
| global AUTO_REBOOT_DISABLE |
| if pgm_name == "cp_cleanup": |
| AUTO_REBOOT_DISABLE = 0 |
| else: |
| valid_value(AUTO_REBOOT_DISABLE, valid_values=["0", "1"]) |
| AUTO_REBOOT_DISABLE = int(AUTO_REBOOT_DISABLE) |
| |
| |
| def main(): |
| |
| gen_setup() |
| |
| set_term_options(term_requests='children') |
| |
| print_plug_in_header() |
| |
| if pgm_name == "cp_setup" or pgm_name == "cp_cleanup": |
| exit_not_master() |
| |
| init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") |
| |
| lib_file_path = init_robot_file_path("lib/utils.robot") |
| |
| REDFISH_SUPPORT_TRANS_STATE = int(os.environ.get('REDFISH_SUPPORT_TRANS_STATE', 0)) or \ |
| int(os.environ.get('AUTOBOOT_REDFISH_SUPPORT_TRANS_STATE', 0)) |
| |
| enable_auto_reboot = 1 - AUTO_REBOOT_DISABLE |
| print_var(enable_auto_reboot) |
| keyword_string = "Set Auto Reboot Setting ${%i}" % enable_auto_reboot |
| |
| cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", OPENBMC_HOST, SSH_PORT, HTTPS_PORT, |
| REST_USERNAME, REST_PASSWORD, OPENBMC_USERNAME, OPENBMC_PASSWORD, |
| IPMI_USERNAME, IPMI_PASSWORD, REDFISH_SUPPORT_TRANS_STATE, |
| keyword_string, lib_file_path, quiet, test_mode, debug, outputdir, |
| output, log, report) |
| |
| retry_count = 3 |
| while not robot_cmd_fnc(cmd_buf): |
| retry_count -= 1 |
| if retry_count == 0: |
| print_error_report("Robot command execution failed.") |
| exit(1) |
| time.sleep(30) |
| return |
| |
| |
| main() |