1#!/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) 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 print_plug_in_header() 104 105 if pgm_name == "cp_setup" or pgm_name == "cp_cleanup": 106 exit_not_master() 107 108 init_robot_out_parms(get_plug_in_package_name() + "." + pgm_name + ".") 109 110 lib_file_path = init_robot_file_path("lib/utils.robot") 111 112 keyword_string = "Set Auto Reboot ${%i}" % AUTO_REBOOT_DISABLE 113 114 cmd_buf = create_robot_cmd_string("extended/run_keyword.robot", 115 OPENBMC_HOST, REST_USERNAME, 116 REST_PASSWORD, keyword_string, 117 lib_file_path, quiet, test_mode, debug, 118 outputdir, output, log, report) 119 if not robot_cmd_fnc(cmd_buf): 120 print_error_report("Robot command execution failed.") 121 exit(1) 122 123 124main() 125