blob: 969e23bfa66fd4893a035f229083690706d9bd1a [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 Walsh55302292017-01-10 11:43:02 -060024import state as st
Michael Walsh0bbd8602016-11-22 11:31:49 -060025
Michael Walsh0b93fbf2017-03-02 14:42:41 -060026base_path = os.path.dirname(os.path.dirname(
27 imp.find_module("gen_robot_print")[1])) +\
Michael Walshc9116812017-03-10 14:23:06 -060028 os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060029sys.path.append(base_path + "extended/")
30import run_keyword as rk
Michael Walsh0bbd8602016-11-22 11:31:49 -060031
Michael Walsh6741f742017-02-20 16:16:38 -060032# Program parameter processing.
33# Assign all program parms to python variables which are global to this module.
34parm_list = BuiltIn().get_variable_value("${parm_list}")
35int_list = ['max_num_tests', 'boot_pass', 'boot_fail', 'quiet', 'test_mode',
36 'debug']
37for parm in parm_list:
38 if parm in int_list:
39 sub_cmd = "int(BuiltIn().get_variable_value(\"${" + parm +\
40 "}\", \"0\"))"
41 else:
42 sub_cmd = "BuiltIn().get_variable_value(\"${" + parm + "}\")"
43 cmd_buf = parm + " = " + sub_cmd
44 exec(cmd_buf)
Michael Walsh0bbd8602016-11-22 11:31:49 -060045
Michael Walsh6741f742017-02-20 16:16:38 -060046if ffdc_dir_path_style == "":
47 ffdc_dir_path_style = int(os.environ.get('FFDC_DIR_PATH_STYLE', '0'))
48
49# Set up boot data structures.
50boot_table = create_boot_table()
51valid_boot_types = create_valid_boot_list(boot_table)
Michael Walsh0b93fbf2017-03-02 14:42:41 -060052
Michael Walshe1e26442017-03-06 17:50:07 -060053# Setting master_pid correctly influences the behavior of plug-ins like
54# DB_Logging
55program_pid = os.getpid()
56master_pid = os.environ.get('AUTOBOOT_MASTER_PID', program_pid)
57
58boot_results_file_path = "/tmp/" + openbmc_nickname + ":pid_" +\
Michael Walshc9116812017-03-10 14:23:06 -060059 str(master_pid) + ":boot_results"
Michael Walshe1e26442017-03-06 17:50:07 -060060if os.path.isfile(boot_results_file_path):
Michael Walsh0b93fbf2017-03-02 14:42:41 -060061 # We've been called before in this run so we'll load the saved
62 # boot_results object.
63 boot_results = pickle.load(open(boot_results_file_path, 'rb'))
64else:
65 boot_results = boot_results(boot_table, boot_pass, boot_fail)
66
Michael Walsh6741f742017-02-20 16:16:38 -060067boot_lists = read_boot_lists()
68last_ten = []
69# Convert these program parms to more useable lists.
70boot_list = filter(None, boot_list.split(":"))
71boot_stack = filter(None, boot_stack.split(":"))
72
73state = st.return_default_state()
74cp_setup_called = 0
75next_boot = ""
76base_tool_dir_path = os.path.normpath(os.environ.get(
77 'AUTOBOOT_BASE_TOOL_DIR_PATH', "/tmp")) + os.sep
78ffdc_dir_path = os.path.normpath(os.environ.get('FFDC_DIR_PATH', '')) + os.sep
79ffdc_list_file_path = base_tool_dir_path + openbmc_nickname + "/FFDC_FILE_LIST"
80boot_success = 0
Michael Walsh6741f742017-02-20 16:16:38 -060081status_dir_path = os.environ.get('STATUS_DIR_PATH', "")
82if status_dir_path != "":
83 status_dir_path = os.path.normpath(status_dir_path) + os.sep
Michael Walsh0b93fbf2017-03-02 14:42:41 -060084default_power_on = "REST Power On"
85default_power_off = "REST Power Off"
Michael Walsh6741f742017-02-20 16:16:38 -060086boot_count = 0
Michael Walsh0bbd8602016-11-22 11:31:49 -060087
Michael Walsh85678942017-03-27 14:34:22 -050088LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}")
89
90
91###############################################################################
92def initial_plug_in_setup():
93
94 r"""
95 Initialize all plug-in environment variables which do not change for the
96 duration of the program.
97
98 """
99
100 global LOG_LEVEL
101 BuiltIn().set_log_level("NONE")
102
103 BuiltIn().set_global_variable("${master_pid}", master_pid)
104 BuiltIn().set_global_variable("${FFDC_DIR_PATH}", ffdc_dir_path)
105 BuiltIn().set_global_variable("${STATUS_DIR_PATH}", status_dir_path)
106 BuiltIn().set_global_variable("${BASE_TOOL_DIR_PATH}", base_tool_dir_path)
107 BuiltIn().set_global_variable("${FFDC_LIST_FILE_PATH}",
108 ffdc_list_file_path)
109
110 BuiltIn().set_global_variable("${FFDC_DIR_PATH_STYLE}",
111 ffdc_dir_path_style)
112 BuiltIn().set_global_variable("${FFDC_CHECK}",
113 ffdc_check)
114
115 # For each program parameter, set the corresponding AUTOBOOT_ environment
116 # variable value. Also, set an AUTOBOOT_ environment variable for every
117 # element in additional_values.
118 additional_values = ["program_pid", "master_pid", "ffdc_dir_path",
119 "status_dir_path", "base_tool_dir_path",
120 "ffdc_list_file_path"]
121
122 plug_in_vars = parm_list + additional_values
123
124 for var_name in plug_in_vars:
125 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
126 var_name = var_name.upper()
127 if var_value is None:
128 var_value = ""
129 os.environ["AUTOBOOT_" + var_name] = str(var_value)
130
131 BuiltIn().set_log_level(LOG_LEVEL)
132
133
134###############################################################################
135
Michael Walsh0bbd8602016-11-22 11:31:49 -0600136
137###############################################################################
Michael Walsh0bbd8602016-11-22 11:31:49 -0600138def plug_in_setup():
139
140 r"""
Michael Walsh85678942017-03-27 14:34:22 -0500141 Initialize all changing plug-in environment variables for use by the
142 plug-in programs.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600143 """
144
Michael Walsh85678942017-03-27 14:34:22 -0500145 global LOG_LEVEL
146 global test_really_running
147
148 BuiltIn().set_log_level("NONE")
149
Michael Walsh6741f742017-02-20 16:16:38 -0600150 boot_pass, boot_fail = boot_results.return_total_pass_fail()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600151 if boot_pass > 1:
152 test_really_running = 1
153 else:
154 test_really_running = 0
155
Michael Walsh0bbd8602016-11-22 11:31:49 -0600156 seconds = time.time()
157 loc_time = time.localtime(seconds)
158 time_string = time.strftime("%y%m%d.%H%M%S.", loc_time)
159
Michael Walsh6741f742017-02-20 16:16:38 -0600160 ffdc_prefix = openbmc_nickname + "." + time_string
Michael Walsh0bbd8602016-11-22 11:31:49 -0600161
Michael Walsh6741f742017-02-20 16:16:38 -0600162 BuiltIn().set_global_variable("${test_really_running}",
163 test_really_running)
164 BuiltIn().set_global_variable("${boot_type_desc}", next_boot)
Michael Walsh6741f742017-02-20 16:16:38 -0600165 BuiltIn().set_global_variable("${boot_pass}", boot_pass)
166 BuiltIn().set_global_variable("${boot_fail}", boot_fail)
167 BuiltIn().set_global_variable("${boot_success}", boot_success)
168 BuiltIn().set_global_variable("${ffdc_prefix}", ffdc_prefix)
Michael Walsh4c9a6452016-12-13 16:03:11 -0600169
Michael Walsh0bbd8602016-11-22 11:31:49 -0600170 # For each program parameter, set the corresponding AUTOBOOT_ environment
171 # variable value. Also, set an AUTOBOOT_ environment variable for every
172 # element in additional_values.
173 additional_values = ["boot_type_desc", "boot_success", "boot_pass",
Michael Walsh85678942017-03-27 14:34:22 -0500174 "boot_fail", "test_really_running", "ffdc_prefix"]
Michael Walsh0bbd8602016-11-22 11:31:49 -0600175
Michael Walsh85678942017-03-27 14:34:22 -0500176 plug_in_vars = additional_values
Michael Walsh0bbd8602016-11-22 11:31:49 -0600177
178 for var_name in plug_in_vars:
179 var_value = BuiltIn().get_variable_value("${" + var_name + "}")
180 var_name = var_name.upper()
181 if var_value is None:
182 var_value = ""
Michael Walsh6741f742017-02-20 16:16:38 -0600183 os.environ["AUTOBOOT_" + var_name] = str(var_value)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600184
Michael Walsh0bbd8602016-11-22 11:31:49 -0600185 if debug:
Michael Walsh6741f742017-02-20 16:16:38 -0600186 shell_rc, out_buf = \
187 gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600188
Michael Walsh85678942017-03-27 14:34:22 -0500189 BuiltIn().set_log_level(LOG_LEVEL)
190
Michael Walsh0bbd8602016-11-22 11:31:49 -0600191###############################################################################
192
193
194###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600195def setup():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600196
197 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600198 Do general program setup tasks.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600199 """
200
Michael Walsh6741f742017-02-20 16:16:38 -0600201 global cp_setup_called
Michael Walsh0bbd8602016-11-22 11:31:49 -0600202
Michael Walsh6741f742017-02-20 16:16:38 -0600203 grp.rqprintn()
204
205 validate_parms()
206
207 grp.rqprint_pgm_header()
208
Michael Walsh85678942017-03-27 14:34:22 -0500209 initial_plug_in_setup()
210
Michael Walsh6741f742017-02-20 16:16:38 -0600211 plug_in_setup()
212 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
213 call_point='setup')
214 if rc != 0:
215 error_message = "Plug-in setup failed.\n"
216 grp.rprint_error_report(error_message)
217 BuiltIn().fail(error_message)
218 # Setting cp_setup_called lets our Teardown know that it needs to call
219 # the cleanup plug-in call point.
220 cp_setup_called = 1
221
222 # Keyword "FFDC" will fail if TEST_MESSAGE is not set.
223 BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}")
Michael Walsh85678942017-03-27 14:34:22 -0500224 # FFDC_LOG_PATH is used by "FFDC" keyword.
225 BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path)
Michael Walsh6741f742017-02-20 16:16:38 -0600226
227 grp.rdprint_var(boot_table, 1)
228 grp.rdprint_var(boot_lists)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600229
230###############################################################################
231
232
233###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600234def validate_parms():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600235
236 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600237 Validate all program parameters.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600238 """
239
Michael Walsh6741f742017-02-20 16:16:38 -0600240 grp.rqprintn()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600241
Michael Walsh6741f742017-02-20 16:16:38 -0600242 grv.rvalid_value("openbmc_host")
243 grv.rvalid_value("openbmc_username")
244 grv.rvalid_value("openbmc_password")
245 if os_host != "":
246 grv.rvalid_value("os_username")
247 grv.rvalid_value("os_password")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600248
Michael Walsh6741f742017-02-20 16:16:38 -0600249 if pdu_host != "":
250 grv.rvalid_value("pdu_username")
251 grv.rvalid_value("pdu_password")
Michael Walsh85678942017-03-27 14:34:22 -0500252 grv.rvalid_integer("pdu_slot_no")
Michael Walsh6741f742017-02-20 16:16:38 -0600253 if openbmc_serial_host != "":
254 grv.rvalid_integer("openbmc_serial_port")
255 grv.rvalid_integer("max_num_tests")
256 grv.rvalid_value("openbmc_model")
257 grv.rvalid_integer("boot_pass")
258 grv.rvalid_integer("boot_fail")
259
260 plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths)
261 BuiltIn().set_global_variable("${plug_in_packages_list}",
262 plug_in_packages_list)
263
264 if len(boot_list) == 0 and len(boot_stack) == 0:
265 error_message = "You must provide either a value for either the" +\
266 " boot_list or the boot_stack parm.\n"
267 BuiltIn().fail(gp.sprint_error(error_message))
268
269 valid_boot_list(boot_list, valid_boot_types)
270 valid_boot_list(boot_stack, valid_boot_types)
271
272 return
Michael Walsh0bbd8602016-11-22 11:31:49 -0600273
274###############################################################################
275
276
277###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600278def my_get_state():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600279
280 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600281 Get the system state plus a little bit of wrapping.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600282 """
283
Michael Walsh6741f742017-02-20 16:16:38 -0600284 global state
285
286 req_states = ['epoch_seconds'] + st.default_req_states
287
288 grp.rqprint_timen("Getting system state.")
289 if test_mode:
290 state['epoch_seconds'] = int(time.time())
291 else:
292 state = st.get_state(req_states=req_states, quiet=0)
293 grp.rprint_var(state)
Michael Walsh341c21e2017-01-17 16:25:20 -0600294
295###############################################################################
296
297
298###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600299def select_boot():
Michael Walsh341c21e2017-01-17 16:25:20 -0600300
301 r"""
302 Select a boot test to be run based on our current state and return the
303 chosen boot type.
304
305 Description of arguments:
Michael Walsh6741f742017-02-20 16:16:38 -0600306 state The state of the machine.
Michael Walsh341c21e2017-01-17 16:25:20 -0600307 """
308
Michael Walsh30dadae2017-02-27 14:25:52 -0600309 global boot_stack
310
Michael Walsh6741f742017-02-20 16:16:38 -0600311 grp.rprint_timen("Selecting a boot test.")
312
313 my_get_state()
314
315 stack_popped = 0
316 if len(boot_stack) > 0:
317 stack_popped = 1
318 grp.rprint_dashes()
319 grp.rprint_var(boot_stack)
320 grp.rprint_dashes()
321 boot_candidate = boot_stack.pop()
322 if st.compare_states(state, boot_table[boot_candidate]['start']):
323 grp.rprint_timen("The machine state is valid for a '" +
324 boot_candidate + "' boot test.")
325 grp.rprint_dashes()
326 grp.rprint_var(boot_stack)
327 grp.rprint_dashes()
328 return boot_candidate
Michael Walsh341c21e2017-01-17 16:25:20 -0600329 else:
Michael Walsh6741f742017-02-20 16:16:38 -0600330 grp.rprint_timen("The machine state is not valid for a '" +
331 boot_candidate + "' boot test.")
332 boot_stack.append(boot_candidate)
333 popped_boot = boot_candidate
334
335 # Loop through your list selecting a boot_candidates
336 boot_candidates = []
337 for boot_candidate in boot_list:
338 if st.compare_states(state, boot_table[boot_candidate]['start']):
339 if stack_popped:
340 if st.compare_states(boot_table[boot_candidate]['end'],
341 boot_table[popped_boot]['start']):
342 boot_candidates.append(boot_candidate)
343 else:
344 boot_candidates.append(boot_candidate)
345
346 if len(boot_candidates) == 0:
347 grp.rprint_timen("The user's boot list contained no boot tests" +
348 " which are valid for the current machine state.")
349 boot_candidate = default_power_on
350 if not st.compare_states(state, boot_table[default_power_on]['start']):
351 boot_candidate = default_power_off
352 boot_candidates.append(boot_candidate)
353 grp.rprint_timen("Using default '" + boot_candidate +
354 "' boot type to transtion to valid state.")
355
356 grp.rdprint_var(boot_candidates)
357
358 # Randomly select a boot from the candidate list.
359 boot = random.choice(boot_candidates)
Michael Walsh341c21e2017-01-17 16:25:20 -0600360
361 return boot
Michael Walsh0bbd8602016-11-22 11:31:49 -0600362
363###############################################################################
Michael Walsh55302292017-01-10 11:43:02 -0600364
365
366###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600367def print_last_boots():
368
369 r"""
370 Print the last ten boots done with their time stamps.
371 """
372
373 # indent 0, 90 chars wide, linefeed, char is "="
374 grp.rqprint_dashes(0, 90)
375 grp.rqprintn("Last 10 boots:\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600376
377 for boot_entry in last_ten:
378 grp.rqprint(boot_entry)
379 grp.rqprint_dashes(0, 90)
380
381###############################################################################
382
383
384###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600385def print_defect_report():
386
387 r"""
388 Print a defect report.
389 """
390
391 grp.rqprintn()
392 # indent=0, width=90, linefeed=1, char="="
393 grp.rqprint_dashes(0, 90, 1, "=")
394 grp.rqprintn("Copy this data to the defect:\n")
395
Michael Walsh341c21e2017-01-17 16:25:20 -0600396 grp.rqpvars(*parm_list)
397
398 grp.rqprintn()
399
400 print_last_boots()
401 grp.rqprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600402 grp.rqpvar(state)
403
404 # At some point I'd like to have the 'Call FFDC Methods' return a list
405 # of files it has collected. In that case, the following "ls" command
406 # would no longer be needed. For now, however, glob shows the files
407 # named in FFDC_LIST_FILE_PATH so I will refrain from printing those
408 # out (so we don't see duplicates in the list).
409
410 LOG_PREFIX = BuiltIn().get_variable_value("${LOG_PREFIX}")
411
412 output = '\n'.join(glob.glob(LOG_PREFIX + '*'))
Michael Walsh341c21e2017-01-17 16:25:20 -0600413 try:
Michael Walsh6741f742017-02-20 16:16:38 -0600414 ffdc_list = open(ffdc_list_file_path, 'r')
Michael Walsh341c21e2017-01-17 16:25:20 -0600415 except IOError:
416 ffdc_list = ""
417
Michael Walsh341c21e2017-01-17 16:25:20 -0600418 grp.rqprintn()
419 grp.rqprintn("FFDC data files:")
420 if status_file_path != "":
421 grp.rqprintn(status_file_path)
422
423 grp.rqprintn(output)
424 # grp.rqprintn(ffdc_list)
425 grp.rqprintn()
426
427 grp.rqprint_dashes(0, 90, 1, "=")
428
429###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600430
431
432###############################################################################
433def my_ffdc():
434
435 r"""
436 Collect FFDC data.
437 """
438
439 global state
440
441 plug_in_setup()
442 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
443 call_point='ffdc', stop_on_plug_in_failure=1)
444
445 AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX']
446
Michael Walsh6741f742017-02-20 16:16:38 -0600447 cmd_buf = ["FFDC", "ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX]
448 grp.rpissuing_keyword(cmd_buf)
Michael Walsh3328caf2017-03-21 17:04:08 -0500449 try:
450 BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
451 except:
452 gp.print_error("Call to ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600453
454 my_get_state()
455
456 print_defect_report()
457
458###############################################################################
459
460
461###############################################################################
462def print_test_start_message(boot_keyword):
463
464 r"""
465 Print a message indicating what boot test is about to run.
466
467 Description of arguments:
468 boot_keyword The name of the boot which is to be run
469 (e.g. "BMC Power On").
470 """
471
472 global last_ten
473
474 doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".")
475 grp.rqprint(doing_msg)
476
477 last_ten.append(doing_msg)
478
479 if len(last_ten) > 10:
480 del last_ten[0]
481
482###############################################################################
483
484
485###############################################################################
486def run_boot(boot):
487
488 r"""
489 Run the specified boot.
490
491 Description of arguments:
492 boot The name of the boot test to be performed.
493 """
494
495 global state
496
497 print_test_start_message(boot)
498
499 plug_in_setup()
500 rc, shell_rc, failed_plug_in_name = \
501 grpi.rprocess_plug_in_packages(call_point="pre_boot")
502 if rc != 0:
503 error_message = "Plug-in failed with non-zero return code.\n" +\
504 gp.sprint_var(rc, 1)
505 BuiltIn().fail(gp.sprint_error(error_message))
506
507 if test_mode:
508 # In test mode, we'll pretend the boot worked by assigning its
509 # required end state to the default state value.
Michael Walsh30dadae2017-02-27 14:25:52 -0600510 state = st.strip_anchor_state(boot_table[boot]['end'])
Michael Walsh6741f742017-02-20 16:16:38 -0600511 else:
512 # Assertion: We trust that the state data was made fresh by the
513 # caller.
514
515 grp.rprintn()
516
517 if boot_table[boot]['method_type'] == "keyword":
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600518 rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
519 boot_table[boot]['method'])
Michael Walsh6741f742017-02-20 16:16:38 -0600520
521 if boot_table[boot]['bmc_reboot']:
522 st.wait_for_comm_cycle(int(state['epoch_seconds']))
Michael Walsh30dadae2017-02-27 14:25:52 -0600523 plug_in_setup()
524 rc, shell_rc, failed_plug_in_name = \
525 grpi.rprocess_plug_in_packages(call_point="post_reboot")
526 if rc != 0:
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600527 error_message = "Plug-in failed with non-zero return code.\n"
528 error_message += gp.sprint_var(rc, 1)
Michael Walsh30dadae2017-02-27 14:25:52 -0600529 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600530 else:
531 match_state = st.anchor_state(state)
532 del match_state['epoch_seconds']
533 # Wait for the state to change in any way.
534 st.wait_state(match_state, wait_time=state_change_timeout,
535 interval="3 seconds", invert=1)
536
537 grp.rprintn()
538 if boot_table[boot]['end']['chassis'] == "Off":
539 boot_timeout = power_off_timeout
540 else:
541 boot_timeout = power_on_timeout
542 st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout,
543 interval="3 seconds")
544
545 plug_in_setup()
546 rc, shell_rc, failed_plug_in_name = \
547 grpi.rprocess_plug_in_packages(call_point="post_boot")
548 if rc != 0:
549 error_message = "Plug-in failed with non-zero return code.\n" +\
550 gp.sprint_var(rc, 1)
551 BuiltIn().fail(gp.sprint_error(error_message))
552
553###############################################################################
554
555
556###############################################################################
557def test_loop_body():
558
559 r"""
560 The main loop body for the loop in main_py.
561
562 Description of arguments:
563 boot_count The iteration number (starts at 1).
564 """
565
566 global boot_count
567 global state
568 global next_boot
569 global boot_success
570
571 grp.rqprintn()
572
573 boot_count += 1
574
575 next_boot = select_boot()
576
577 grp.rqprint_timen("Starting boot " + str(boot_count) + ".")
578
579 # Clear the ffdc_list_file_path file. Plug-ins may now write to it.
580 try:
581 os.remove(ffdc_list_file_path)
582 except OSError:
583 pass
584
585 cmd_buf = ["run_boot", next_boot]
586 boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
587 if boot_status == "FAIL":
588 grp.rprint(msg)
589
590 grp.rqprintn()
591 if boot_status == "PASS":
592 boot_success = 1
593 grp.rqprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.")
594 else:
595 boot_success = 0
596 grp.rqprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.")
597
598 boot_results.update(next_boot, boot_status)
599
600 plug_in_setup()
601 # NOTE: A post_test_case call point failure is NOT counted as a boot
602 # failure.
603 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
604 call_point='post_test_case', stop_on_plug_in_failure=1)
605
606 plug_in_setup()
607 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
608 call_point='ffdc_check', shell_rc=0x00000200,
609 stop_on_plug_in_failure=1, stop_on_non_zero_rc=1)
610 if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200:
611 cmd_buf = ["my_ffdc"]
612 grp.rpissuing_keyword(cmd_buf)
Michael Walsh3328caf2017-03-21 17:04:08 -0500613 try:
614 BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
615 except:
616 gp.print_error("Call to my_ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600617
Michael Walsh952f9b02017-03-09 13:11:14 -0600618 boot_results.print_report()
619 grp.rqprint_timen("Finished boot " + str(boot_count) + ".")
620
Michael Walsh6741f742017-02-20 16:16:38 -0600621 plug_in_setup()
622 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
623 call_point='stop_check')
624 if rc != 0:
625 error_message = "Stopping as requested by user.\n"
626 grp.rprint_error_report(error_message)
627 BuiltIn().fail(error_message)
628
Michael Walsh6741f742017-02-20 16:16:38 -0600629 return True
630
631###############################################################################
632
633
634###############################################################################
Michael Walshc9116812017-03-10 14:23:06 -0600635def main_keyword_teardown():
Michael Walsh6741f742017-02-20 16:16:38 -0600636
637 r"""
Michael Walshc9116812017-03-10 14:23:06 -0600638 Clean up after the Main keyword.
Michael Walsh6741f742017-02-20 16:16:38 -0600639 """
640
641 if cp_setup_called:
642 plug_in_setup()
643 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
644 call_point='cleanup', stop_on_plug_in_failure=1)
645
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600646 # Save boot_results object to a file in case it is needed again.
647 grp.rprint_timen("Saving boot_results to the following path.")
648 grp.rprint_var(boot_results_file_path)
649 pickle.dump(boot_results, open(boot_results_file_path, 'wb'),
650 pickle.HIGHEST_PROTOCOL)
651
Michael Walsh6741f742017-02-20 16:16:38 -0600652###############################################################################
653
654
655###############################################################################
Michael Walshc9116812017-03-10 14:23:06 -0600656def test_teardown():
657
658 r"""
659 Clean up after this test case.
660 """
661
662 gp.qprintn()
663 cmd_buf = ["Print Error",
664 "A keyword timeout occurred ending this program.\n"]
665 BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf)
666
667###############################################################################
668
669
670###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600671def main_py():
672
673 r"""
674 Do main program processing.
675 """
676
677 setup()
678
679 # Process caller's boot_stack.
680 while (len(boot_stack) > 0):
681 test_loop_body()
682
Michael Walsh30dadae2017-02-27 14:25:52 -0600683 grp.rprint_timen("Finished processing stack.")
684
Michael Walsh6741f742017-02-20 16:16:38 -0600685 # Process caller's boot_list.
686 if len(boot_list) > 0:
687 for ix in range(1, max_num_tests + 1):
688 test_loop_body()
689
690 grp.rqprint_timen("Completed all requested boot tests.")
691
692###############################################################################