blob: f43ae7cfa00e30cb3883a07053ed7c6dc4bdc652 [file] [log] [blame]
Michael Walsh0bbd8602016-11-22 11:31:49 -06001#!/usr/bin/env python
2
3r"""
4This module is the python counterpart to obmc_boot_test.
5"""
6
Michael Walsh0b93fbf2017-03-02 14:42:41 -06007import os
8import imp
9import time
10import glob
11import random
12import cPickle as pickle
13
14from robot.utils import DotDict
15from robot.libraries.BuiltIn import BuiltIn
16
Michael Walsh6741f742017-02-20 16:16:38 -060017from boot_data import *
Michael Walshc9116812017-03-10 14:23:06 -060018import gen_print as gp
Michael Walsh0bbd8602016-11-22 11:31:49 -060019import gen_robot_print as grp
Michael Walsh55302292017-01-10 11:43:02 -060020import gen_robot_plug_in as grpi
Michael Walsh6741f742017-02-20 16:16:38 -060021import gen_robot_valid as grv
22import gen_misc as gm
23import gen_cmd as gc
Michael Walshb5839d02017-04-12 16:11:20 -050024import gen_robot_keyword as grk
Michael Walsh55302292017-01-10 11:43:02 -060025import state as st
Michael Walsh0bbd8602016-11-22 11:31:49 -060026
Michael Walsh0b93fbf2017-03-02 14:42:41 -060027base_path = os.path.dirname(os.path.dirname(
28 imp.find_module("gen_robot_print")[1])) +\
Michael Walshc9116812017-03-10 14:23:06 -060029 os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060030sys.path.append(base_path + "extended/")
31import run_keyword as rk
Michael Walsh0bbd8602016-11-22 11:31:49 -060032
Michael Walshe1e26442017-03-06 17:50:07 -060033# Setting master_pid correctly influences the behavior of plug-ins like
34# DB_Logging
35program_pid = os.getpid()
36master_pid = os.environ.get('AUTOBOOT_MASTER_PID', program_pid)
37
Michael Walshb5839d02017-04-12 16:11:20 -050038# Set up boot data structures.
39boot_table = create_boot_table()
40valid_boot_types = create_valid_boot_list(boot_table)
Michael Walsh0b93fbf2017-03-02 14:42:41 -060041
Michael Walsh6741f742017-02-20 16:16:38 -060042boot_lists = read_boot_lists()
43last_ten = []
Michael Walsh6741f742017-02-20 16:16:38 -060044
45state = st.return_default_state()
46cp_setup_called = 0
47next_boot = ""
48base_tool_dir_path = os.path.normpath(os.environ.get(
49 'AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")) + os.sep
Michael Walshb5839d02017-04-12 16:11:20 -050050
Michael Walsh6741f742017-02-20 16:16:38 -060051ffdc_dir_path = os.path.normpath(os.environ.get('FFDC_DIR_PATH', '')) + os.sep
Michael Walsh6741f742017-02-20 16:16:38 -060052boot_success = 0
Michael Walsh6741f742017-02-20 16:16:38 -060053status_dir_path = os.environ.get('STATUS_DIR_PATH', "")
54if status_dir_path != "":
55 status_dir_path = os.path.normpath(status_dir_path) + os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060056default_power_on = "REST Power On"
57default_power_off = "REST Power Off"
Michael Walsh6741f742017-02-20 16:16:38 -060058boot_count = 0
Michael Walsh0bbd8602016-11-22 11:31:49 -060059
Michael Walsh85678942017-03-27 14:34:22 -050060LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}")
61
62
63###############################################################################
Michael Walshb5839d02017-04-12 16:11:20 -050064def process_pgm_parms():
65
66 r"""
67 Process the program parameters by assigning them all to corresponding
68 globals. Also, set some global values that depend on program parameters.
69 """
70
71 # Program parameter processing.
72 # Assign all program parms to python variables which are global to this
73 # module.
74
75 global parm_list
76 parm_list = BuiltIn().get_variable_value("${parm_list}")
77 # The following subset of parms should be processed as integers.
78 int_list = ['max_num_tests', 'boot_pass', 'boot_fail', 'ffdc_only',
79 'boot_fail_threshold', 'quiet', 'test_mode', 'debug']
80 for parm in parm_list:
81 if parm in int_list:
82 sub_cmd = "int(BuiltIn().get_variable_value(\"${" + parm +\
83 "}\", \"0\"))"
84 else:
85 sub_cmd = "BuiltIn().get_variable_value(\"${" + parm + "}\")"
86 cmd_buf = "global " + parm + " ; " + parm + " = " + sub_cmd
87 exec(cmd_buf)
88
89 global ffdc_dir_path_style
90 global boot_list
91 global boot_stack
92 global boot_results_file_path
93 global boot_results
94 global ffdc_list_file_path
95
96 if ffdc_dir_path_style == "":
97 ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0'))
98
99 # Convert these program parms to lists for easier processing..
100 boot_list = filter(None, boot_list.split(":"))
101 boot_stack = filter(None, boot_stack.split(":"))
102
103 boot_results_file_path = "/tmp/" + openbmc_nickname + ":pid_" +\
104 str(master_pid) + ":boot_results"
105
106 if os.path.isfile(boot_results_file_path):
107 # We've been called before in this run so we'll load the saved
108 # boot_results object.
109 boot_results = pickle.load(open(boot_results_file_path, 'rb'))
110 else:
111 boot_results = boot_results(boot_table, boot_pass, boot_fail)
112
113 ffdc_list_file_path = base_tool_dir_path + openbmc_nickname +\
114 "/FFDC_FILE_LIST"
115
116###############################################################################
117
118
119###############################################################################
Michael Walsh85678942017-03-27 14:34:22 -0500120def initial_plug_in_setup():
121
122 r"""
123 Initialize all plug-in environment variables which do not change for the
124 duration of the program.
125
126 """
127
128 global LOG_LEVEL
129 BuiltIn().set_log_level("NONE")
130
131 BuiltIn().set_global_variable("${master_pid}", master_pid)
132 BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path)
133 BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path)
134 BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path)
135 BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}",
136 ffdc_list_file_path)
137
138 BuiltIn().set_global_variable("${FFDC_DIR_PATH_STYLE}",
139 ffdc_dir_path_style)
140 BuiltIn().set_global_variable("${FFDC_CHECK}",
141 ffdc_check)
142
143 # For each program parameter, set the corresponding AUTOBOOT_ environment
144 # variable value. Also, set an AUTOBOOT_ environment variable for every
145 # element in additional_values.
146 additional_values = ["program_pid", "master_pid", "ffdc_dir_path",
147 "status_dir_path", "base_tool_dir_path",
148 "ffdc_list_file_path"]
149
150 plug_in_vars = parm_list + additional_values
151
152 for var_name in plug_in_vars:
153 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
154 var_name = var_name.upper()
155 if var_value is None:
156 var_value = ""
157 os.environ["AUTOBOOT_" + var_name] = str(var_value)
158
159 BuiltIn().set_log_level(LOG_LEVEL)
160
161
162###############################################################################
163
Michael Walsh0bbd8602016-11-22 11:31:49 -0600164
165###############################################################################
Michael Walsh0bbd8602016-11-22 11:31:49 -0600166def plug_in_setup():
167
168 r"""
Michael Walsh85678942017-03-27 14:34:22 -0500169 Initialize all changing plug-in environment variables for use by the
170 plug-in programs.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600171 """
172
Michael Walsh85678942017-03-27 14:34:22 -0500173 global LOG_LEVEL
174 global test_really_running
175
176 BuiltIn().set_log_level("NONE")
177
Michael Walsh6741f742017-02-20 16:16:38 -0600178 boot_pass, boot_fail = boot_results.return_total_pass_fail()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600179 if boot_pass > 1:
180 test_really_running = 1
181 else:
182 test_really_running = 0
183
Michael Walsh0bbd8602016-11-22 11:31:49 -0600184 seconds = time.time()
185 loc_time = time.localtime(seconds)
186 time_string = time.strftime("%y%m%d.%H%M%S.", loc_time)
187
Michael Walsh6741f742017-02-20 16:16:38 -0600188 ffdc_prefix = openbmc_nickname + "." + time_string
Michael Walsh0bbd8602016-11-22 11:31:49 -0600189
Michael Walsh6741f742017-02-20 16:16:38 -0600190 BuiltIn().set_global_variable("${test_really_running}",
191 test_really_running)
192 BuiltIn().set_global_variable("${boot_type_desc}", next_boot)
Michael Walsh6741f742017-02-20 16:16:38 -0600193 BuiltIn().set_global_variable("${boot_pass}", boot_pass)
194 BuiltIn().set_global_variable("${boot_fail}", boot_fail)
195 BuiltIn().set_global_variable("${boot_success}", boot_success)
196 BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix)
Michael Walsh4c9a6452016-12-13 16:03:11 -0600197
Michael Walsh0bbd8602016-11-22 11:31:49 -0600198 # For each program parameter, set the corresponding AUTOBOOT_ environment
199 # variable value. Also, set an AUTOBOOT_ environment variable for every
200 # element in additional_values.
201 additional_values = ["boot_type_desc", "boot_success", "boot_pass",
Michael Walsh85678942017-03-27 14:34:22 -0500202 "boot_fail", "test_really_running", "ffdc_prefix"]
Michael Walsh0bbd8602016-11-22 11:31:49 -0600203
Michael Walsh85678942017-03-27 14:34:22 -0500204 plug_in_vars = additional_values
Michael Walsh0bbd8602016-11-22 11:31:49 -0600205
206 for var_name in plug_in_vars:
207 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
208 var_name = var_name.upper()
209 if var_value is None:
210 var_value = ""
Michael Walsh6741f742017-02-20 16:16:38 -0600211 os.environ["AUTOBOOT_" + var_name] = str(var_value)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600212
Michael Walsh0bbd8602016-11-22 11:31:49 -0600213 if debug:
Michael Walsh6741f742017-02-20 16:16:38 -0600214 shell_rc, out_buf = \
215 gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600216
Michael Walsh85678942017-03-27 14:34:22 -0500217 BuiltIn().set_log_level(LOG_LEVEL)
218
Michael Walsh0bbd8602016-11-22 11:31:49 -0600219###############################################################################
220
221
222###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600223def setup():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600224
225 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600226 Do general program setup tasks.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600227 """
228
Michael Walsh6741f742017-02-20 16:16:38 -0600229 global cp_setup_called
Michael Walsh0bbd8602016-11-22 11:31:49 -0600230
Michael Walshb5839d02017-04-12 16:11:20 -0500231 gp.qprintn()
232
233 shell_rc, out_buf = gc.cmd_fnc_u("which ssh_pw", quiet=1, print_output=0,
234 show_err=0)
235 if shell_rc != 0:
236 robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
237 os.environ['PATH'] = robot_pgm_dir_path +\
238 "../bin:" + os.environ.get('PATH', "")
239 os.environ['PYTHONPATH'] = robot_pgm_dir_path +\
240 os.environ.get('PYTHONPATH', "")
Michael Walsh6741f742017-02-20 16:16:38 -0600241
242 validate_parms()
243
244 grp.rqprint_pgm_header()
245
Michael Walshb5839d02017-04-12 16:11:20 -0500246 grk.run_key("Set BMC Power Policy RESTORE_LAST_STATE")
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500247
Michael Walsh85678942017-03-27 14:34:22 -0500248 initial_plug_in_setup()
249
Michael Walsh6741f742017-02-20 16:16:38 -0600250 plug_in_setup()
251 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
252 call_point='setup')
253 if rc != 0:
254 error_message = "Plug-in setup failed.\n"
255 grp.rprint_error_report(error_message)
256 BuiltIn().fail(error_message)
257 # Setting cp_setup_called lets our Teardown know that it needs to call
258 # the cleanup plug-in call point.
259 cp_setup_called = 1
260
261 # Keyword "FFDC" will fail if TEST_MESSAGE is not set.
262 BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}")
Michael Walsh85678942017-03-27 14:34:22 -0500263 # FFDC_LOG_PATH is used by "FFDC" keyword.
264 BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path)
Michael Walsh6741f742017-02-20 16:16:38 -0600265
Michael Walshb5839d02017-04-12 16:11:20 -0500266 gp.dprint_var(boot_table, 1)
267 gp.dprint_var(boot_lists)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600268
269###############################################################################
270
271
272###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600273def validate_parms():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600274
275 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600276 Validate all program parameters.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600277 """
278
Michael Walshb5839d02017-04-12 16:11:20 -0500279 process_pgm_parms()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600280
Michael Walshb5839d02017-04-12 16:11:20 -0500281 gp.qprintn()
282
283 global openbmc_model
Michael Walsh6741f742017-02-20 16:16:38 -0600284 grv.rvalid_value("openbmc_host")
285 grv.rvalid_value("openbmc_username")
286 grv.rvalid_value("openbmc_password")
287 if os_host != "":
288 grv.rvalid_value("os_username")
289 grv.rvalid_value("os_password")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600290
Michael Walsh6741f742017-02-20 16:16:38 -0600291 if pdu_host != "":
292 grv.rvalid_value("pdu_username")
293 grv.rvalid_value("pdu_password")
Michael Walsh85678942017-03-27 14:34:22 -0500294 grv.rvalid_integer("pdu_slot_no")
Michael Walsh6741f742017-02-20 16:16:38 -0600295 if openbmc_serial_host != "":
296 grv.rvalid_integer("openbmc_serial_port")
Michael Walshb5839d02017-04-12 16:11:20 -0500297 if openbmc_model == "":
298 status, ret_values =\
299 grk.run_key_u("Get BMC System Model")
300 openbmc_model = ret_values
301 BuiltIn().set_global_variable("${openbmc_model}", openbmc_model)
Michael Walsh6741f742017-02-20 16:16:38 -0600302 grv.rvalid_value("openbmc_model")
Michael Walshb5839d02017-04-12 16:11:20 -0500303 grv.rvalid_integer("max_num_tests")
Michael Walsh6741f742017-02-20 16:16:38 -0600304 grv.rvalid_integer("boot_pass")
305 grv.rvalid_integer("boot_fail")
306
307 plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths)
308 BuiltIn().set_global_variable("${plug_in_packages_list}",
309 plug_in_packages_list)
310
Michael Walshb5839d02017-04-12 16:11:20 -0500311 grv.rvalid_value("stack_mode", valid_values=['normal', 'skip'])
Michael Walsha20da402017-03-31 16:27:45 -0500312 if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only:
Michael Walsh6741f742017-02-20 16:16:38 -0600313 error_message = "You must provide either a value for either the" +\
314 " boot_list or the boot_stack parm.\n"
315 BuiltIn().fail(gp.sprint_error(error_message))
316
317 valid_boot_list(boot_list, valid_boot_types)
318 valid_boot_list(boot_stack, valid_boot_types)
319
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500320 selected_PDU_boots = list(set(boot_list + boot_stack) &
321 set(boot_lists['PDU_reboot']))
322
323 if len(selected_PDU_boots) > 0 and pdu_host == "":
324 error_message = "You have selected the following boots which" +\
325 " require a PDU host but no value for pdu_host:\n"
326 error_message += gp.sprint_var(selected_PDU_boots)
327 error_message += gp.sprint_var(pdu_host, 2)
328 BuiltIn().fail(gp.sprint_error(error_message))
329
Michael Walsh6741f742017-02-20 16:16:38 -0600330 return
Michael Walsh0bbd8602016-11-22 11:31:49 -0600331
332###############################################################################
333
334
335###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600336def my_get_state():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600337
338 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600339 Get the system state plus a little bit of wrapping.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600340 """
341
Michael Walsh6741f742017-02-20 16:16:38 -0600342 global state
343
344 req_states = ['epoch_seconds'] + st.default_req_states
345
Michael Walshb5839d02017-04-12 16:11:20 -0500346 gp.qprint_timen("Getting system state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600347 if test_mode:
348 state['epoch_seconds'] = int(time.time())
349 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500350 state = st.get_state(req_states=req_states, quiet=quiet)
351 gp.qprint_var(state)
Michael Walsh341c21e2017-01-17 16:25:20 -0600352
353###############################################################################
354
355
356###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600357def select_boot():
Michael Walsh341c21e2017-01-17 16:25:20 -0600358
359 r"""
360 Select a boot test to be run based on our current state and return the
361 chosen boot type.
362
363 Description of arguments:
Michael Walsh6741f742017-02-20 16:16:38 -0600364 state The state of the machine.
Michael Walsh341c21e2017-01-17 16:25:20 -0600365 """
366
Michael Walsh30dadae2017-02-27 14:25:52 -0600367 global boot_stack
368
Michael Walshb5839d02017-04-12 16:11:20 -0500369 gp.qprint_timen("Selecting a boot test.")
Michael Walsh6741f742017-02-20 16:16:38 -0600370
371 my_get_state()
372
373 stack_popped = 0
374 if len(boot_stack) > 0:
375 stack_popped = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500376 gp.qprint_dashes()
377 gp.qprint_var(boot_stack)
378 gp.qprint_dashes()
379 skip_boot_printed = 0
380 while len(boot_stack) > 0:
381 boot_candidate = boot_stack.pop()
382 if stack_mode == 'normal':
383 break
384 else:
385 if st.compare_states(state, boot_table[boot_candidate]['end']):
386 if not skip_boot_printed:
387 gp.print_var(stack_mode)
388 gp.printn()
389 gp.print_timen("Skipping the following boot tests" +
390 " which are unnecessary since their" +
391 " required end states match the" +
392 " current machine state:")
393 skip_boot_printed = 1
394 gp.print_var(boot_candidate)
395 boot_candidate = ""
396 if boot_candidate == "":
397 gp.qprint_dashes()
398 gp.qprint_var(boot_stack)
399 gp.qprint_dashes()
400 return boot_candidate
Michael Walsh6741f742017-02-20 16:16:38 -0600401 if st.compare_states(state, boot_table[boot_candidate]['start']):
Michael Walshb5839d02017-04-12 16:11:20 -0500402 gp.qprint_timen("The machine state is valid for a '" +
403 boot_candidate + "' boot test.")
404 gp.qprint_dashes()
405 gp.qprint_var(boot_stack)
406 gp.qprint_dashes()
Michael Walsh6741f742017-02-20 16:16:38 -0600407 return boot_candidate
Michael Walsh341c21e2017-01-17 16:25:20 -0600408 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500409 gp.qprint_timen("The machine state does not match the required" +
410 " starting state for a '" + boot_candidate +
411 "' boot test:")
412 gp.print_varx("boot_table[" + boot_candidate + "][start]",
413 boot_table[boot_candidate]['start'], 1)
Michael Walsh6741f742017-02-20 16:16:38 -0600414 boot_stack.append(boot_candidate)
415 popped_boot = boot_candidate
416
417 # Loop through your list selecting a boot_candidates
418 boot_candidates = []
419 for boot_candidate in boot_list:
420 if st.compare_states(state, boot_table[boot_candidate]['start']):
421 if stack_popped:
422 if st.compare_states(boot_table[boot_candidate]['end'],
423 boot_table[popped_boot]['start']):
424 boot_candidates.append(boot_candidate)
425 else:
426 boot_candidates.append(boot_candidate)
427
428 if len(boot_candidates) == 0:
Michael Walshb5839d02017-04-12 16:11:20 -0500429 gp.qprint_timen("The user's boot list contained no boot tests" +
430 " which are valid for the current machine state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600431 boot_candidate = default_power_on
432 if not st.compare_states(state, boot_table[default_power_on]['start']):
433 boot_candidate = default_power_off
434 boot_candidates.append(boot_candidate)
Michael Walshb5839d02017-04-12 16:11:20 -0500435 gp.qprint_timen("Using default '" + boot_candidate +
436 "' boot type to transition to valid state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600437
Michael Walshb5839d02017-04-12 16:11:20 -0500438 gp.dprint_var(boot_candidates)
Michael Walsh6741f742017-02-20 16:16:38 -0600439
440 # Randomly select a boot from the candidate list.
441 boot = random.choice(boot_candidates)
Michael Walsh341c21e2017-01-17 16:25:20 -0600442
443 return boot
Michael Walsh0bbd8602016-11-22 11:31:49 -0600444
445###############################################################################
Michael Walsh55302292017-01-10 11:43:02 -0600446
447
448###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600449def print_last_boots():
450
451 r"""
452 Print the last ten boots done with their time stamps.
453 """
454
455 # indent 0, 90 chars wide, linefeed, char is "="
Michael Walshb5839d02017-04-12 16:11:20 -0500456 gp.qprint_dashes(0, 90)
457 gp.qprintn("Last 10 boots:\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600458
459 for boot_entry in last_ten:
460 grp.rqprint(boot_entry)
Michael Walshb5839d02017-04-12 16:11:20 -0500461 gp.qprint_dashes(0, 90)
Michael Walsh341c21e2017-01-17 16:25:20 -0600462
463###############################################################################
464
465
466###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600467def print_defect_report():
468
469 r"""
470 Print a defect report.
471 """
472
Michael Walshb5839d02017-04-12 16:11:20 -0500473 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600474 # indent=0, width=90, linefeed=1, char="="
Michael Walshb5839d02017-04-12 16:11:20 -0500475 gp.qprint_dashes(0, 90, 1, "=")
476 gp.qprintn("Copy this data to the defect:\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600477
Michael Walsh341c21e2017-01-17 16:25:20 -0600478 grp.rqpvars(*parm_list)
479
Michael Walshb5839d02017-04-12 16:11:20 -0500480 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600481
482 print_last_boots()
Michael Walshb5839d02017-04-12 16:11:20 -0500483 gp.qprintn()
484 gp.qprint_var(state)
Michael Walsh341c21e2017-01-17 16:25:20 -0600485
486 # At some point I'd like to have the 'Call FFDC Methods' return a list
487 # of files it has collected. In that case, the following "ls" command
488 # would no longer be needed. For now, however, glob shows the files
489 # named in FFDC_LIST_FILE_PATH so I will refrain from printing those
490 # out (so we don't see duplicates in the list).
491
492 LOG_PREFIX = BuiltIn().get_variable_value("${LOG_PREFIX}")
493
494 output = '\n'.join(glob.glob(LOG_PREFIX + '*'))
Michael Walsh341c21e2017-01-17 16:25:20 -0600495 try:
Michael Walsh6741f742017-02-20 16:16:38 -0600496 ffdc_list = open(ffdc_list_file_path, 'r')
Michael Walsh341c21e2017-01-17 16:25:20 -0600497 except IOError:
498 ffdc_list = ""
499
Michael Walshb5839d02017-04-12 16:11:20 -0500500 gp.qprintn()
501 gp.qprintn("FFDC data files:")
Michael Walsh341c21e2017-01-17 16:25:20 -0600502 if status_file_path != "":
Michael Walshb5839d02017-04-12 16:11:20 -0500503 gp.qprintn(status_file_path)
Michael Walsh341c21e2017-01-17 16:25:20 -0600504
Michael Walshb5839d02017-04-12 16:11:20 -0500505 gp.qprintn(output)
506 # gp.qprintn(ffdc_list)
507 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600508
Michael Walshb5839d02017-04-12 16:11:20 -0500509 gp.qprint_dashes(0, 90, 1, "=")
Michael Walsh341c21e2017-01-17 16:25:20 -0600510
511###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600512
513
514###############################################################################
515def my_ffdc():
516
517 r"""
518 Collect FFDC data.
519 """
520
521 global state
522
523 plug_in_setup()
524 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
525 call_point='ffdc', stop_on_plug_in_failure=1)
526
527 AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX']
528
Michael Walsh6741f742017-02-20 16:16:38 -0600529 cmd_buf = ["FFDC", "ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX]
530 grp.rpissuing_keyword(cmd_buf)
Michael Walsh3328caf2017-03-21 17:04:08 -0500531 try:
532 BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
533 except:
534 gp.print_error("Call to ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600535
536 my_get_state()
537
538 print_defect_report()
539
540###############################################################################
541
542
543###############################################################################
544def print_test_start_message(boot_keyword):
545
546 r"""
547 Print a message indicating what boot test is about to run.
548
549 Description of arguments:
550 boot_keyword The name of the boot which is to be run
551 (e.g. "BMC Power On").
552 """
553
554 global last_ten
555
556 doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".")
Michael Walshb5839d02017-04-12 16:11:20 -0500557 gp.qprint(doing_msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600558
559 last_ten.append(doing_msg)
560
561 if len(last_ten) > 10:
562 del last_ten[0]
563
564###############################################################################
565
566
567###############################################################################
568def run_boot(boot):
569
570 r"""
571 Run the specified boot.
572
573 Description of arguments:
574 boot The name of the boot test to be performed.
575 """
576
577 global state
578
579 print_test_start_message(boot)
580
581 plug_in_setup()
582 rc, shell_rc, failed_plug_in_name = \
583 grpi.rprocess_plug_in_packages(call_point="pre_boot")
584 if rc != 0:
585 error_message = "Plug-in failed with non-zero return code.\n" +\
586 gp.sprint_var(rc, 1)
587 BuiltIn().fail(gp.sprint_error(error_message))
588
589 if test_mode:
590 # In test mode, we'll pretend the boot worked by assigning its
591 # required end state to the default state value.
Michael Walsh30dadae2017-02-27 14:25:52 -0600592 state = st.strip_anchor_state(boot_table[boot]['end'])
Michael Walsh6741f742017-02-20 16:16:38 -0600593 else:
594 # Assertion: We trust that the state data was made fresh by the
595 # caller.
596
Michael Walshb5839d02017-04-12 16:11:20 -0500597 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600598
599 if boot_table[boot]['method_type'] == "keyword":
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600600 rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
Michael Walshb5839d02017-04-12 16:11:20 -0500601 boot_table[boot]['method'],
602 quiet=quiet)
Michael Walsh6741f742017-02-20 16:16:38 -0600603
604 if boot_table[boot]['bmc_reboot']:
605 st.wait_for_comm_cycle(int(state['epoch_seconds']))
Michael Walsh30dadae2017-02-27 14:25:52 -0600606 plug_in_setup()
607 rc, shell_rc, failed_plug_in_name = \
608 grpi.rprocess_plug_in_packages(call_point="post_reboot")
609 if rc != 0:
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600610 error_message = "Plug-in failed with non-zero return code.\n"
611 error_message += gp.sprint_var(rc, 1)
Michael Walsh30dadae2017-02-27 14:25:52 -0600612 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600613 else:
614 match_state = st.anchor_state(state)
615 del match_state['epoch_seconds']
616 # Wait for the state to change in any way.
617 st.wait_state(match_state, wait_time=state_change_timeout,
618 interval="3 seconds", invert=1)
619
Michael Walshb5839d02017-04-12 16:11:20 -0500620 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600621 if boot_table[boot]['end']['chassis'] == "Off":
622 boot_timeout = power_off_timeout
623 else:
624 boot_timeout = power_on_timeout
625 st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout,
626 interval="3 seconds")
627
628 plug_in_setup()
629 rc, shell_rc, failed_plug_in_name = \
630 grpi.rprocess_plug_in_packages(call_point="post_boot")
631 if rc != 0:
632 error_message = "Plug-in failed with non-zero return code.\n" +\
633 gp.sprint_var(rc, 1)
634 BuiltIn().fail(gp.sprint_error(error_message))
635
636###############################################################################
637
638
639###############################################################################
640def test_loop_body():
641
642 r"""
643 The main loop body for the loop in main_py.
644
645 Description of arguments:
646 boot_count The iteration number (starts at 1).
647 """
648
649 global boot_count
650 global state
651 global next_boot
652 global boot_success
653
Michael Walshb5839d02017-04-12 16:11:20 -0500654 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600655
656 next_boot = select_boot()
Michael Walshb5839d02017-04-12 16:11:20 -0500657 if next_boot == "":
658 return True
Michael Walsh6741f742017-02-20 16:16:38 -0600659
Michael Walshb5839d02017-04-12 16:11:20 -0500660 boot_count += 1
661 gp.qprint_timen("Starting boot " + str(boot_count) + ".")
Michael Walsh6741f742017-02-20 16:16:38 -0600662
663 # Clear the ffdc_list_file_path file. Plug-ins may now write to it.
664 try:
665 os.remove(ffdc_list_file_path)
666 except OSError:
667 pass
668
669 cmd_buf = ["run_boot", next_boot]
670 boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
671 if boot_status == "FAIL":
Michael Walshb5839d02017-04-12 16:11:20 -0500672 gp.qprint(msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600673
Michael Walshb5839d02017-04-12 16:11:20 -0500674 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600675 if boot_status == "PASS":
676 boot_success = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500677 gp.qprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.")
Michael Walsh6741f742017-02-20 16:16:38 -0600678 else:
679 boot_success = 0
Michael Walshb5839d02017-04-12 16:11:20 -0500680 gp.qprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.")
Michael Walsh6741f742017-02-20 16:16:38 -0600681
682 boot_results.update(next_boot, boot_status)
683
684 plug_in_setup()
685 # NOTE: A post_test_case call point failure is NOT counted as a boot
686 # failure.
687 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
688 call_point='post_test_case', stop_on_plug_in_failure=1)
689
690 plug_in_setup()
691 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
692 call_point='ffdc_check', shell_rc=0x00000200,
693 stop_on_plug_in_failure=1, stop_on_non_zero_rc=1)
694 if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200:
695 cmd_buf = ["my_ffdc"]
696 grp.rpissuing_keyword(cmd_buf)
Michael Walsh3328caf2017-03-21 17:04:08 -0500697 try:
698 BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
699 except:
700 gp.print_error("Call to my_ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600701
Michael Walshd139f282017-04-04 18:00:23 -0500702 # We need to purge error logs between boots or they build up.
Michael Walshb5839d02017-04-12 16:11:20 -0500703 grk.run_key("Delete Error logs", ignore=1)
Michael Walshd139f282017-04-04 18:00:23 -0500704
Michael Walsh952f9b02017-03-09 13:11:14 -0600705 boot_results.print_report()
Michael Walshb5839d02017-04-12 16:11:20 -0500706 gp.qprint_timen("Finished boot " + str(boot_count) + ".")
Michael Walsh952f9b02017-03-09 13:11:14 -0600707
Michael Walsh6741f742017-02-20 16:16:38 -0600708 plug_in_setup()
709 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
710 call_point='stop_check')
711 if rc != 0:
712 error_message = "Stopping as requested by user.\n"
713 grp.rprint_error_report(error_message)
714 BuiltIn().fail(error_message)
715
Michael Walshd139f282017-04-04 18:00:23 -0500716 # This should help prevent ConnectionErrors.
Michael Walshb5839d02017-04-12 16:11:20 -0500717 grk.run_key_u("Delete All Sessions")
Michael Walshd139f282017-04-04 18:00:23 -0500718
Michael Walsh6741f742017-02-20 16:16:38 -0600719 return True
720
721###############################################################################
722
723
724###############################################################################
Michael Walshc9116812017-03-10 14:23:06 -0600725def main_keyword_teardown():
Michael Walsh6741f742017-02-20 16:16:38 -0600726
727 r"""
Michael Walshc9116812017-03-10 14:23:06 -0600728 Clean up after the Main keyword.
Michael Walsh6741f742017-02-20 16:16:38 -0600729 """
730
731 if cp_setup_called:
732 plug_in_setup()
733 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
734 call_point='cleanup', stop_on_plug_in_failure=1)
735
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600736 # Save boot_results object to a file in case it is needed again.
Michael Walshb5839d02017-04-12 16:11:20 -0500737 gp.qprint_timen("Saving boot_results to the following path.")
738 gp.qprint_var(boot_results_file_path)
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600739 pickle.dump(boot_results, open(boot_results_file_path, 'wb'),
740 pickle.HIGHEST_PROTOCOL)
741
Michael Walsh6741f742017-02-20 16:16:38 -0600742###############################################################################
743
744
745###############################################################################
Michael Walshc9116812017-03-10 14:23:06 -0600746def test_teardown():
747
748 r"""
749 Clean up after this test case.
750 """
751
752 gp.qprintn()
753 cmd_buf = ["Print Error",
754 "A keyword timeout occurred ending this program.\n"]
755 BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf)
756
Michael Walshb5839d02017-04-12 16:11:20 -0500757 grp.rqprint_pgm_footer()
758
Michael Walshc9116812017-03-10 14:23:06 -0600759###############################################################################
760
761
762###############################################################################
Michael Walshb5839d02017-04-12 16:11:20 -0500763def obmc_boot_test(alt_boot_stack=None):
Michael Walsh6741f742017-02-20 16:16:38 -0600764
765 r"""
766 Do main program processing.
767 """
768
Michael Walshb5839d02017-04-12 16:11:20 -0500769 if alt_boot_stack is not None:
770 BuiltIn().set_global_variable("${boot_stack}", alt_boot_stack)
771
Michael Walsh6741f742017-02-20 16:16:38 -0600772 setup()
773
Michael Walsha20da402017-03-31 16:27:45 -0500774 if ffdc_only:
775 gp.qprint_timen("Caller requested ffdc_only.")
776 cmd_buf = ["my_ffdc"]
777 grp.rpissuing_keyword(cmd_buf)
778 try:
779 BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
780 except:
781 gp.print_error("Call to my_ffdc failed.\n")
782
Michael Walsh6741f742017-02-20 16:16:38 -0600783 # Process caller's boot_stack.
784 while (len(boot_stack) > 0):
785 test_loop_body()
786
Michael Walshb5839d02017-04-12 16:11:20 -0500787 gp.qprint_timen("Finished processing stack.")
Michael Walsh30dadae2017-02-27 14:25:52 -0600788
Michael Walsh6741f742017-02-20 16:16:38 -0600789 # Process caller's boot_list.
790 if len(boot_list) > 0:
791 for ix in range(1, max_num_tests + 1):
792 test_loop_body()
793
Michael Walshb5839d02017-04-12 16:11:20 -0500794 gp.qprint_timen("Completed all requested boot tests.")
795
796 boot_pass, boot_fail = boot_results.return_total_pass_fail()
797 if boot_fail > boot_fail_threshold:
798 error_message = "Boot failures exceed the boot failure" +\
799 " threshold:\n" +\
800 gp.sprint_var(boot_fail) +\
801 gp.sprint_var(boot_fail_threshold)
802 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600803
804###############################################################################