blob: bf10ec90fdec840d24a14c223083ad808d115794 [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
Michael Walsh83f4bc72017-04-20 16:49:43 -0500233 robot_pgm_dir_path = os.path.dirname(__file__) + os.sep
234 repo_bin_path = robot_pgm_dir_path.replace("/lib/", "/bin/")
235 # If we can't find ssh_pw, then we don't have our repo bin in PATH.
Michael Walshb5839d02017-04-12 16:11:20 -0500236 shell_rc, out_buf = gc.cmd_fnc_u("which ssh_pw", quiet=1, print_output=0,
237 show_err=0)
238 if shell_rc != 0:
Michael Walsh83f4bc72017-04-20 16:49:43 -0500239 os.environ['PATH'] = repo_bin_path + ":" + os.environ.get('PATH', "")
240 # Likewise, our repo lib subdir needs to be in sys.path and PYTHONPATH.
241 if robot_pgm_dir_path not in sys.path:
242 sys.path.append(robot_pgm_dir_path)
243 PYTHONPATH = os.environ.get("PYTHONPATH", "")
244 if PYTHONPATH == "":
245 os.environ['PYTHONPATH'] = robot_pgm_dir_path
246 else:
247 os.environ['PYTHONPATH'] = robot_pgm_dir_path + ":" + PYTHONPATH
Michael Walsh6741f742017-02-20 16:16:38 -0600248
249 validate_parms()
250
251 grp.rqprint_pgm_header()
252
Michael Walshb5839d02017-04-12 16:11:20 -0500253 grk.run_key("Set BMC Power Policy RESTORE_LAST_STATE")
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500254
Michael Walsh85678942017-03-27 14:34:22 -0500255 initial_plug_in_setup()
256
Michael Walsh6741f742017-02-20 16:16:38 -0600257 plug_in_setup()
258 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
259 call_point='setup')
260 if rc != 0:
261 error_message = "Plug-in setup failed.\n"
262 grp.rprint_error_report(error_message)
263 BuiltIn().fail(error_message)
264 # Setting cp_setup_called lets our Teardown know that it needs to call
265 # the cleanup plug-in call point.
266 cp_setup_called = 1
267
268 # Keyword "FFDC" will fail if TEST_MESSAGE is not set.
269 BuiltIn().set_global_variable("${TEST_MESSAGE}", "${EMPTY}")
Michael Walsh85678942017-03-27 14:34:22 -0500270 # FFDC_LOG_PATH is used by "FFDC" keyword.
271 BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path)
Michael Walsh6741f742017-02-20 16:16:38 -0600272
Michael Walshb5839d02017-04-12 16:11:20 -0500273 gp.dprint_var(boot_table, 1)
274 gp.dprint_var(boot_lists)
Michael Walsh0bbd8602016-11-22 11:31:49 -0600275
276###############################################################################
277
278
279###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600280def validate_parms():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600281
282 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600283 Validate all program parameters.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600284 """
285
Michael Walshb5839d02017-04-12 16:11:20 -0500286 process_pgm_parms()
Michael Walsh0bbd8602016-11-22 11:31:49 -0600287
Michael Walshb5839d02017-04-12 16:11:20 -0500288 gp.qprintn()
289
290 global openbmc_model
Michael Walsh6741f742017-02-20 16:16:38 -0600291 grv.rvalid_value("openbmc_host")
292 grv.rvalid_value("openbmc_username")
293 grv.rvalid_value("openbmc_password")
294 if os_host != "":
295 grv.rvalid_value("os_username")
296 grv.rvalid_value("os_password")
Michael Walsh0bbd8602016-11-22 11:31:49 -0600297
Michael Walsh6741f742017-02-20 16:16:38 -0600298 if pdu_host != "":
299 grv.rvalid_value("pdu_username")
300 grv.rvalid_value("pdu_password")
Michael Walsh85678942017-03-27 14:34:22 -0500301 grv.rvalid_integer("pdu_slot_no")
Michael Walsh6741f742017-02-20 16:16:38 -0600302 if openbmc_serial_host != "":
303 grv.rvalid_integer("openbmc_serial_port")
Michael Walshb5839d02017-04-12 16:11:20 -0500304 if openbmc_model == "":
305 status, ret_values =\
306 grk.run_key_u("Get BMC System Model")
307 openbmc_model = ret_values
308 BuiltIn().set_global_variable("${openbmc_model}", openbmc_model)
Michael Walsh6741f742017-02-20 16:16:38 -0600309 grv.rvalid_value("openbmc_model")
Michael Walshb5839d02017-04-12 16:11:20 -0500310 grv.rvalid_integer("max_num_tests")
Michael Walsh6741f742017-02-20 16:16:38 -0600311 grv.rvalid_integer("boot_pass")
312 grv.rvalid_integer("boot_fail")
313
314 plug_in_packages_list = grpi.rvalidate_plug_ins(plug_in_dir_paths)
315 BuiltIn().set_global_variable("${plug_in_packages_list}",
316 plug_in_packages_list)
317
Michael Walshb5839d02017-04-12 16:11:20 -0500318 grv.rvalid_value("stack_mode", valid_values=['normal', 'skip'])
Michael Walsha20da402017-03-31 16:27:45 -0500319 if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only:
Michael Walsh6741f742017-02-20 16:16:38 -0600320 error_message = "You must provide either a value for either the" +\
321 " boot_list or the boot_stack parm.\n"
322 BuiltIn().fail(gp.sprint_error(error_message))
323
324 valid_boot_list(boot_list, valid_boot_types)
325 valid_boot_list(boot_stack, valid_boot_types)
326
Michael Walsh11cfc8c2017-03-31 09:40:55 -0500327 selected_PDU_boots = list(set(boot_list + boot_stack) &
328 set(boot_lists['PDU_reboot']))
329
330 if len(selected_PDU_boots) > 0 and pdu_host == "":
331 error_message = "You have selected the following boots which" +\
332 " require a PDU host but no value for pdu_host:\n"
333 error_message += gp.sprint_var(selected_PDU_boots)
334 error_message += gp.sprint_var(pdu_host, 2)
335 BuiltIn().fail(gp.sprint_error(error_message))
336
Michael Walsh6741f742017-02-20 16:16:38 -0600337 return
Michael Walsh0bbd8602016-11-22 11:31:49 -0600338
339###############################################################################
340
341
342###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600343def my_get_state():
Michael Walsh0bbd8602016-11-22 11:31:49 -0600344
345 r"""
Michael Walsh6741f742017-02-20 16:16:38 -0600346 Get the system state plus a little bit of wrapping.
Michael Walsh0bbd8602016-11-22 11:31:49 -0600347 """
348
Michael Walsh6741f742017-02-20 16:16:38 -0600349 global state
350
351 req_states = ['epoch_seconds'] + st.default_req_states
352
Michael Walshb5839d02017-04-12 16:11:20 -0500353 gp.qprint_timen("Getting system state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600354 if test_mode:
355 state['epoch_seconds'] = int(time.time())
356 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500357 state = st.get_state(req_states=req_states, quiet=quiet)
358 gp.qprint_var(state)
Michael Walsh341c21e2017-01-17 16:25:20 -0600359
360###############################################################################
361
362
363###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600364def select_boot():
Michael Walsh341c21e2017-01-17 16:25:20 -0600365
366 r"""
367 Select a boot test to be run based on our current state and return the
368 chosen boot type.
369
370 Description of arguments:
Michael Walsh6741f742017-02-20 16:16:38 -0600371 state The state of the machine.
Michael Walsh341c21e2017-01-17 16:25:20 -0600372 """
373
Michael Walsh30dadae2017-02-27 14:25:52 -0600374 global boot_stack
375
Michael Walshb5839d02017-04-12 16:11:20 -0500376 gp.qprint_timen("Selecting a boot test.")
Michael Walsh6741f742017-02-20 16:16:38 -0600377
378 my_get_state()
379
380 stack_popped = 0
381 if len(boot_stack) > 0:
382 stack_popped = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500383 gp.qprint_dashes()
384 gp.qprint_var(boot_stack)
385 gp.qprint_dashes()
386 skip_boot_printed = 0
387 while len(boot_stack) > 0:
388 boot_candidate = boot_stack.pop()
389 if stack_mode == 'normal':
390 break
391 else:
392 if st.compare_states(state, boot_table[boot_candidate]['end']):
393 if not skip_boot_printed:
394 gp.print_var(stack_mode)
395 gp.printn()
396 gp.print_timen("Skipping the following boot tests" +
397 " which are unnecessary since their" +
398 " required end states match the" +
399 " current machine state:")
400 skip_boot_printed = 1
401 gp.print_var(boot_candidate)
402 boot_candidate = ""
403 if boot_candidate == "":
404 gp.qprint_dashes()
405 gp.qprint_var(boot_stack)
406 gp.qprint_dashes()
407 return boot_candidate
Michael Walsh6741f742017-02-20 16:16:38 -0600408 if st.compare_states(state, boot_table[boot_candidate]['start']):
Michael Walshb5839d02017-04-12 16:11:20 -0500409 gp.qprint_timen("The machine state is valid for a '" +
410 boot_candidate + "' boot test.")
411 gp.qprint_dashes()
412 gp.qprint_var(boot_stack)
413 gp.qprint_dashes()
Michael Walsh6741f742017-02-20 16:16:38 -0600414 return boot_candidate
Michael Walsh341c21e2017-01-17 16:25:20 -0600415 else:
Michael Walshb5839d02017-04-12 16:11:20 -0500416 gp.qprint_timen("The machine state does not match the required" +
417 " starting state for a '" + boot_candidate +
418 "' boot test:")
419 gp.print_varx("boot_table[" + boot_candidate + "][start]",
420 boot_table[boot_candidate]['start'], 1)
Michael Walsh6741f742017-02-20 16:16:38 -0600421 boot_stack.append(boot_candidate)
422 popped_boot = boot_candidate
423
424 # Loop through your list selecting a boot_candidates
425 boot_candidates = []
426 for boot_candidate in boot_list:
427 if st.compare_states(state, boot_table[boot_candidate]['start']):
428 if stack_popped:
429 if st.compare_states(boot_table[boot_candidate]['end'],
430 boot_table[popped_boot]['start']):
431 boot_candidates.append(boot_candidate)
432 else:
433 boot_candidates.append(boot_candidate)
434
435 if len(boot_candidates) == 0:
Michael Walshb5839d02017-04-12 16:11:20 -0500436 gp.qprint_timen("The user's boot list contained no boot tests" +
437 " which are valid for the current machine state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600438 boot_candidate = default_power_on
439 if not st.compare_states(state, boot_table[default_power_on]['start']):
440 boot_candidate = default_power_off
441 boot_candidates.append(boot_candidate)
Michael Walshb5839d02017-04-12 16:11:20 -0500442 gp.qprint_timen("Using default '" + boot_candidate +
443 "' boot type to transition to valid state.")
Michael Walsh6741f742017-02-20 16:16:38 -0600444
Michael Walshb5839d02017-04-12 16:11:20 -0500445 gp.dprint_var(boot_candidates)
Michael Walsh6741f742017-02-20 16:16:38 -0600446
447 # Randomly select a boot from the candidate list.
448 boot = random.choice(boot_candidates)
Michael Walsh341c21e2017-01-17 16:25:20 -0600449
450 return boot
Michael Walsh0bbd8602016-11-22 11:31:49 -0600451
452###############################################################################
Michael Walsh55302292017-01-10 11:43:02 -0600453
454
455###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600456def print_last_boots():
457
458 r"""
459 Print the last ten boots done with their time stamps.
460 """
461
462 # indent 0, 90 chars wide, linefeed, char is "="
Michael Walshb5839d02017-04-12 16:11:20 -0500463 gp.qprint_dashes(0, 90)
464 gp.qprintn("Last 10 boots:\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600465
466 for boot_entry in last_ten:
467 grp.rqprint(boot_entry)
Michael Walshb5839d02017-04-12 16:11:20 -0500468 gp.qprint_dashes(0, 90)
Michael Walsh341c21e2017-01-17 16:25:20 -0600469
470###############################################################################
471
472
473###############################################################################
Michael Walsh341c21e2017-01-17 16:25:20 -0600474def print_defect_report():
475
476 r"""
477 Print a defect report.
478 """
479
Michael Walshb5839d02017-04-12 16:11:20 -0500480 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600481 # indent=0, width=90, linefeed=1, char="="
Michael Walshb5839d02017-04-12 16:11:20 -0500482 gp.qprint_dashes(0, 90, 1, "=")
483 gp.qprintn("Copy this data to the defect:\n")
Michael Walsh341c21e2017-01-17 16:25:20 -0600484
Michael Walsh341c21e2017-01-17 16:25:20 -0600485 grp.rqpvars(*parm_list)
486
Michael Walshb5839d02017-04-12 16:11:20 -0500487 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600488
489 print_last_boots()
Michael Walshb5839d02017-04-12 16:11:20 -0500490 gp.qprintn()
491 gp.qprint_var(state)
Michael Walsh341c21e2017-01-17 16:25:20 -0600492
493 # At some point I'd like to have the 'Call FFDC Methods' return a list
494 # of files it has collected. In that case, the following "ls" command
495 # would no longer be needed. For now, however, glob shows the files
496 # named in FFDC_LIST_FILE_PATH so I will refrain from printing those
497 # out (so we don't see duplicates in the list).
498
499 LOG_PREFIX = BuiltIn().get_variable_value("${LOG_PREFIX}")
500
501 output = '\n'.join(glob.glob(LOG_PREFIX + '*'))
Michael Walsh341c21e2017-01-17 16:25:20 -0600502 try:
Michael Walsh6741f742017-02-20 16:16:38 -0600503 ffdc_list = open(ffdc_list_file_path, 'r')
Michael Walsh341c21e2017-01-17 16:25:20 -0600504 except IOError:
505 ffdc_list = ""
506
Michael Walshb5839d02017-04-12 16:11:20 -0500507 gp.qprintn()
508 gp.qprintn("FFDC data files:")
Michael Walsh341c21e2017-01-17 16:25:20 -0600509 if status_file_path != "":
Michael Walshb5839d02017-04-12 16:11:20 -0500510 gp.qprintn(status_file_path)
Michael Walsh341c21e2017-01-17 16:25:20 -0600511
Michael Walshb5839d02017-04-12 16:11:20 -0500512 gp.qprintn(output)
513 # gp.qprintn(ffdc_list)
514 gp.qprintn()
Michael Walsh341c21e2017-01-17 16:25:20 -0600515
Michael Walshb5839d02017-04-12 16:11:20 -0500516 gp.qprint_dashes(0, 90, 1, "=")
Michael Walsh341c21e2017-01-17 16:25:20 -0600517
518###############################################################################
Michael Walsh6741f742017-02-20 16:16:38 -0600519
520
521###############################################################################
522def my_ffdc():
523
524 r"""
525 Collect FFDC data.
526 """
527
528 global state
529
530 plug_in_setup()
531 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
532 call_point='ffdc', stop_on_plug_in_failure=1)
533
534 AUTOBOOT_FFDC_PREFIX = os.environ['AUTOBOOT_FFDC_PREFIX']
Michael Walsh83f4bc72017-04-20 16:49:43 -0500535 status, ret_values = grk.run_key_u("FFDC ffdc_prefix=" +
536 AUTOBOOT_FFDC_PREFIX +
537 " ffdc_function_list=" +
538 ffdc_function_list, ignore=1)
539 if status != 'PASS':
Michael Walsh3328caf2017-03-21 17:04:08 -0500540 gp.print_error("Call to ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600541
542 my_get_state()
543
544 print_defect_report()
545
546###############################################################################
547
548
549###############################################################################
550def print_test_start_message(boot_keyword):
551
552 r"""
553 Print a message indicating what boot test is about to run.
554
555 Description of arguments:
556 boot_keyword The name of the boot which is to be run
557 (e.g. "BMC Power On").
558 """
559
560 global last_ten
561
562 doing_msg = gp.sprint_timen("Doing \"" + boot_keyword + "\".")
Michael Walshb5839d02017-04-12 16:11:20 -0500563 gp.qprint(doing_msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600564
565 last_ten.append(doing_msg)
566
567 if len(last_ten) > 10:
568 del last_ten[0]
569
570###############################################################################
571
572
573###############################################################################
574def run_boot(boot):
575
576 r"""
577 Run the specified boot.
578
579 Description of arguments:
580 boot The name of the boot test to be performed.
581 """
582
583 global state
584
585 print_test_start_message(boot)
586
587 plug_in_setup()
588 rc, shell_rc, failed_plug_in_name = \
589 grpi.rprocess_plug_in_packages(call_point="pre_boot")
590 if rc != 0:
591 error_message = "Plug-in failed with non-zero return code.\n" +\
592 gp.sprint_var(rc, 1)
593 BuiltIn().fail(gp.sprint_error(error_message))
594
595 if test_mode:
596 # In test mode, we'll pretend the boot worked by assigning its
597 # required end state to the default state value.
Michael Walsh30dadae2017-02-27 14:25:52 -0600598 state = st.strip_anchor_state(boot_table[boot]['end'])
Michael Walsh6741f742017-02-20 16:16:38 -0600599 else:
600 # Assertion: We trust that the state data was made fresh by the
601 # caller.
602
Michael Walshb5839d02017-04-12 16:11:20 -0500603 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600604
605 if boot_table[boot]['method_type'] == "keyword":
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600606 rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
Michael Walshb5839d02017-04-12 16:11:20 -0500607 boot_table[boot]['method'],
608 quiet=quiet)
Michael Walsh6741f742017-02-20 16:16:38 -0600609
610 if boot_table[boot]['bmc_reboot']:
611 st.wait_for_comm_cycle(int(state['epoch_seconds']))
Michael Walsh30dadae2017-02-27 14:25:52 -0600612 plug_in_setup()
613 rc, shell_rc, failed_plug_in_name = \
614 grpi.rprocess_plug_in_packages(call_point="post_reboot")
615 if rc != 0:
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600616 error_message = "Plug-in failed with non-zero return code.\n"
617 error_message += gp.sprint_var(rc, 1)
Michael Walsh30dadae2017-02-27 14:25:52 -0600618 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600619 else:
620 match_state = st.anchor_state(state)
621 del match_state['epoch_seconds']
622 # Wait for the state to change in any way.
623 st.wait_state(match_state, wait_time=state_change_timeout,
624 interval="3 seconds", invert=1)
625
Michael Walshb5839d02017-04-12 16:11:20 -0500626 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600627 if boot_table[boot]['end']['chassis'] == "Off":
628 boot_timeout = power_off_timeout
629 else:
630 boot_timeout = power_on_timeout
631 st.wait_state(boot_table[boot]['end'], wait_time=boot_timeout,
632 interval="3 seconds")
633
634 plug_in_setup()
635 rc, shell_rc, failed_plug_in_name = \
636 grpi.rprocess_plug_in_packages(call_point="post_boot")
637 if rc != 0:
638 error_message = "Plug-in failed with non-zero return code.\n" +\
639 gp.sprint_var(rc, 1)
640 BuiltIn().fail(gp.sprint_error(error_message))
641
642###############################################################################
643
644
645###############################################################################
646def test_loop_body():
647
648 r"""
649 The main loop body for the loop in main_py.
650
651 Description of arguments:
652 boot_count The iteration number (starts at 1).
653 """
654
655 global boot_count
656 global state
657 global next_boot
658 global boot_success
659
Michael Walshb5839d02017-04-12 16:11:20 -0500660 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600661
662 next_boot = select_boot()
Michael Walshb5839d02017-04-12 16:11:20 -0500663 if next_boot == "":
664 return True
Michael Walsh6741f742017-02-20 16:16:38 -0600665
Michael Walshb5839d02017-04-12 16:11:20 -0500666 boot_count += 1
667 gp.qprint_timen("Starting boot " + str(boot_count) + ".")
Michael Walsh6741f742017-02-20 16:16:38 -0600668
669 # Clear the ffdc_list_file_path file. Plug-ins may now write to it.
670 try:
671 os.remove(ffdc_list_file_path)
672 except OSError:
673 pass
674
675 cmd_buf = ["run_boot", next_boot]
676 boot_status, msg = BuiltIn().run_keyword_and_ignore_error(*cmd_buf)
677 if boot_status == "FAIL":
Michael Walshb5839d02017-04-12 16:11:20 -0500678 gp.qprint(msg)
Michael Walsh6741f742017-02-20 16:16:38 -0600679
Michael Walshb5839d02017-04-12 16:11:20 -0500680 gp.qprintn()
Michael Walsh6741f742017-02-20 16:16:38 -0600681 if boot_status == "PASS":
682 boot_success = 1
Michael Walshb5839d02017-04-12 16:11:20 -0500683 gp.qprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.")
Michael Walsh6741f742017-02-20 16:16:38 -0600684 else:
685 boot_success = 0
Michael Walshb5839d02017-04-12 16:11:20 -0500686 gp.qprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.")
Michael Walsh6741f742017-02-20 16:16:38 -0600687
688 boot_results.update(next_boot, boot_status)
689
690 plug_in_setup()
691 # NOTE: A post_test_case call point failure is NOT counted as a boot
692 # failure.
693 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
694 call_point='post_test_case', stop_on_plug_in_failure=1)
695
696 plug_in_setup()
697 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
698 call_point='ffdc_check', shell_rc=0x00000200,
699 stop_on_plug_in_failure=1, stop_on_non_zero_rc=1)
700 if boot_status != "PASS" or ffdc_check == "All" or shell_rc == 0x00000200:
Michael Walsh83f4bc72017-04-20 16:49:43 -0500701 status, ret_values = grk.run_key_u("my_ffdc", ignore=1)
702 if status != 'PASS':
Michael Walsh3328caf2017-03-21 17:04:08 -0500703 gp.print_error("Call to my_ffdc failed.\n")
Michael Walsh6741f742017-02-20 16:16:38 -0600704
Michael Walshd139f282017-04-04 18:00:23 -0500705 # We need to purge error logs between boots or they build up.
Michael Walshb5839d02017-04-12 16:11:20 -0500706 grk.run_key("Delete Error logs", ignore=1)
Michael Walshd139f282017-04-04 18:00:23 -0500707
Michael Walsh952f9b02017-03-09 13:11:14 -0600708 boot_results.print_report()
Michael Walshb5839d02017-04-12 16:11:20 -0500709 gp.qprint_timen("Finished boot " + str(boot_count) + ".")
Michael Walsh952f9b02017-03-09 13:11:14 -0600710
Michael Walsh6741f742017-02-20 16:16:38 -0600711 plug_in_setup()
712 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
713 call_point='stop_check')
714 if rc != 0:
715 error_message = "Stopping as requested by user.\n"
716 grp.rprint_error_report(error_message)
717 BuiltIn().fail(error_message)
718
Michael Walshd139f282017-04-04 18:00:23 -0500719 # This should help prevent ConnectionErrors.
Michael Walshb5839d02017-04-12 16:11:20 -0500720 grk.run_key_u("Delete All Sessions")
Michael Walshd139f282017-04-04 18:00:23 -0500721
Michael Walsh6741f742017-02-20 16:16:38 -0600722 return True
723
724###############################################################################
725
726
727###############################################################################
Michael Walsh83f4bc72017-04-20 16:49:43 -0500728def obmc_boot_test_teardown():
Michael Walsh6741f742017-02-20 16:16:38 -0600729
730 r"""
Michael Walshc9116812017-03-10 14:23:06 -0600731 Clean up after the Main keyword.
Michael Walsh6741f742017-02-20 16:16:38 -0600732 """
733
734 if cp_setup_called:
735 plug_in_setup()
736 rc, shell_rc, failed_plug_in_name = grpi.rprocess_plug_in_packages(
737 call_point='cleanup', stop_on_plug_in_failure=1)
738
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600739 # Save boot_results object to a file in case it is needed again.
Michael Walshb5839d02017-04-12 16:11:20 -0500740 gp.qprint_timen("Saving boot_results to the following path.")
741 gp.qprint_var(boot_results_file_path)
Michael Walsh0b93fbf2017-03-02 14:42:41 -0600742 pickle.dump(boot_results, open(boot_results_file_path, 'wb'),
743 pickle.HIGHEST_PROTOCOL)
744
Michael Walsh6741f742017-02-20 16:16:38 -0600745###############################################################################
746
747
748###############################################################################
Michael Walshc9116812017-03-10 14:23:06 -0600749def test_teardown():
750
751 r"""
752 Clean up after this test case.
753 """
754
755 gp.qprintn()
756 cmd_buf = ["Print Error",
757 "A keyword timeout occurred ending this program.\n"]
758 BuiltIn().run_keyword_if_timeout_occurred(*cmd_buf)
759
Michael Walshb5839d02017-04-12 16:11:20 -0500760 grp.rqprint_pgm_footer()
761
Michael Walshc9116812017-03-10 14:23:06 -0600762###############################################################################
763
764
765###############################################################################
Michael Walsh83f4bc72017-04-20 16:49:43 -0500766def obmc_boot_test_py(alt_boot_stack=None):
Michael Walsh6741f742017-02-20 16:16:38 -0600767
768 r"""
769 Do main program processing.
770 """
771
Michael Walshb5839d02017-04-12 16:11:20 -0500772 if alt_boot_stack is not None:
773 BuiltIn().set_global_variable("${boot_stack}", alt_boot_stack)
774
Michael Walsh6741f742017-02-20 16:16:38 -0600775 setup()
776
Michael Walsha20da402017-03-31 16:27:45 -0500777 if ffdc_only:
778 gp.qprint_timen("Caller requested ffdc_only.")
Michael Walsh83f4bc72017-04-20 16:49:43 -0500779 grk.run_key_u("my_ffdc")
Michael Walsha20da402017-03-31 16:27:45 -0500780
Michael Walsh6741f742017-02-20 16:16:38 -0600781 # Process caller's boot_stack.
782 while (len(boot_stack) > 0):
783 test_loop_body()
784
Michael Walshb5839d02017-04-12 16:11:20 -0500785 gp.qprint_timen("Finished processing stack.")
Michael Walsh30dadae2017-02-27 14:25:52 -0600786
Michael Walsh6741f742017-02-20 16:16:38 -0600787 # Process caller's boot_list.
788 if len(boot_list) > 0:
789 for ix in range(1, max_num_tests + 1):
790 test_loop_body()
791
Michael Walshb5839d02017-04-12 16:11:20 -0500792 gp.qprint_timen("Completed all requested boot tests.")
793
794 boot_pass, boot_fail = boot_results.return_total_pass_fail()
795 if boot_fail > boot_fail_threshold:
796 error_message = "Boot failures exceed the boot failure" +\
797 " threshold:\n" +\
798 gp.sprint_var(boot_fail) +\
799 gp.sprint_var(boot_fail_threshold)
800 BuiltIn().fail(gp.sprint_error(error_message))
Michael Walsh6741f742017-02-20 16:16:38 -0600801
802###############################################################################