1#!/usr/bin/env python
2
3r"""
4This module is the python counterpart to obmc_boot_test.
5"""
6
7import 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
17from boot_data import *
18import gen_print as gp
19import gen_robot_print as grp
20import gen_robot_plug_in as grpi
21import gen_robot_valid as grv
22import gen_misc as gm
23import gen_cmd as gc
24import gen_robot_keyword as grk
25import state as st
26
27base_path = os.path.dirname(os.path.dirname(
28                            imp.find_module("gen_robot_print")[1])) +\
29    os.sep
30sys.path.append(base_path + "extended/")
31import run_keyword as rk
32
33# 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
38# Set up boot data structures.
39boot_table = create_boot_table()
40valid_boot_types = create_valid_boot_list(boot_table)
41
42boot_lists = read_boot_lists()
43last_ten = []
44
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
50
51ffdc_dir_path = os.path.normpath(os.environ.get('FFDC_DIR_PATH', '')) + os.sep
52boot_success = 0
53status_dir_path = os.environ.get('STATUS_DIR_PATH', "")
54if status_dir_path != "":
55    status_dir_path = os.path.normpath(status_dir_path) + os.sep
56default_power_on = "REST Power On"
57default_power_off = "REST Power Off"
58boot_count = 0
59
60LOG_LEVEL = BuiltIn().get_variable_value("${LOG_LEVEL}")
61
62
63###############################################################################
64def 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###############################################################################
120def 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
164
165###############################################################################
166def plug_in_setup():
167
168    r"""
169    Initialize all changing plug-in environment variables for use by the
170    plug-in programs.
171    """
172
173    global LOG_LEVEL
174    global test_really_running
175
176    BuiltIn().set_log_level("NONE")
177
178    boot_pass, boot_fail = boot_results.return_total_pass_fail()
179    if boot_pass > 1:
180        test_really_running = 1
181    else:
182        test_really_running = 0
183
184    seconds = time.time()
185    loc_time = time.localtime(seconds)
186    time_string = time.strftime("%y%m%d.%H%M%S.", loc_time)
187
188    ffdc_prefix = openbmc_nickname + "." + time_string
189
190    BuiltIn().set_global_variable("${test_really_running}",
191                                  test_really_running)
192    BuiltIn().set_global_variable("${boot_type_desc}", next_boot)
193    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)
197
198    # 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",
202                         "boot_fail", "test_really_running", "ffdc_prefix"]
203
204    plug_in_vars = additional_values
205
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 = ""
211        os.environ["AUTOBOOT_" + var_name] = str(var_value)
212
213    if debug:
214        shell_rc, out_buf = \
215            gc.cmd_fnc_u("printenv | egrep AUTOBOOT_ | sort -u")
216
217    BuiltIn().set_log_level(LOG_LEVEL)
218
219###############################################################################
220
221
222###############################################################################
223def setup():
224
225    r"""
226    Do general program setup tasks.
227    """
228
229    global cp_setup_called
230
231    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', "")
241
242    validate_parms()
243
244    grp.rqprint_pgm_header()
245
246    grk.run_key("Set BMC Power Policy  RESTORE_LAST_STATE")
247
248    initial_plug_in_setup()
249
250    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}")
263    # FFDC_LOG_PATH is used by "FFDC" keyword.
264    BuiltIn().set_global_variable("${FFDC_LOG_PATH}", ffdc_dir_path)
265
266    gp.dprint_var(boot_table, 1)
267    gp.dprint_var(boot_lists)
268
269###############################################################################
270
271
272###############################################################################
273def validate_parms():
274
275    r"""
276    Validate all program parameters.
277    """
278
279    process_pgm_parms()
280
281    gp.qprintn()
282
283    global openbmc_model
284    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")
290
291    if pdu_host != "":
292        grv.rvalid_value("pdu_username")
293        grv.rvalid_value("pdu_password")
294        grv.rvalid_integer("pdu_slot_no")
295    if openbmc_serial_host != "":
296        grv.rvalid_integer("openbmc_serial_port")
297    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)
302    grv.rvalid_value("openbmc_model")
303    grv.rvalid_integer("max_num_tests")
304    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
311    grv.rvalid_value("stack_mode", valid_values=['normal', 'skip'])
312    if len(boot_list) == 0 and len(boot_stack) == 0 and not ffdc_only:
313        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
320    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
330    return
331
332###############################################################################
333
334
335###############################################################################
336def my_get_state():
337
338    r"""
339    Get the system state plus a little bit of wrapping.
340    """
341
342    global state
343
344    req_states = ['epoch_seconds'] + st.default_req_states
345
346    gp.qprint_timen("Getting system state.")
347    if test_mode:
348        state['epoch_seconds'] = int(time.time())
349    else:
350        state = st.get_state(req_states=req_states, quiet=quiet)
351    gp.qprint_var(state)
352
353###############################################################################
354
355
356###############################################################################
357def select_boot():
358
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:
364    state  The state of the machine.
365    """
366
367    global boot_stack
368
369    gp.qprint_timen("Selecting a boot test.")
370
371    my_get_state()
372
373    stack_popped = 0
374    if len(boot_stack) > 0:
375        stack_popped = 1
376        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
401        if st.compare_states(state, boot_table[boot_candidate]['start']):
402            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()
407            return boot_candidate
408        else:
409            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)
414            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:
429        gp.qprint_timen("The user's boot list contained no boot tests" +
430                        " which are valid for the current machine state.")
431        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)
435        gp.qprint_timen("Using default '" + boot_candidate +
436                        "' boot type to transition to valid state.")
437
438    gp.dprint_var(boot_candidates)
439
440    # Randomly select a boot from the candidate list.
441    boot = random.choice(boot_candidates)
442
443    return boot
444
445###############################################################################
446
447
448###############################################################################
449def 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 "="
456    gp.qprint_dashes(0, 90)
457    gp.qprintn("Last 10 boots:\n")
458
459    for boot_entry in last_ten:
460        grp.rqprint(boot_entry)
461    gp.qprint_dashes(0, 90)
462
463###############################################################################
464
465
466###############################################################################
467def print_defect_report():
468
469    r"""
470    Print a defect report.
471    """
472
473    gp.qprintn()
474    # indent=0, width=90, linefeed=1, char="="
475    gp.qprint_dashes(0, 90, 1, "=")
476    gp.qprintn("Copy this data to the defect:\n")
477
478    grp.rqpvars(*parm_list)
479
480    gp.qprintn()
481
482    print_last_boots()
483    gp.qprintn()
484    gp.qprint_var(state)
485
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 + '*'))
495    try:
496        ffdc_list = open(ffdc_list_file_path, 'r')
497    except IOError:
498        ffdc_list = ""
499
500    gp.qprintn()
501    gp.qprintn("FFDC data files:")
502    if status_file_path != "":
503        gp.qprintn(status_file_path)
504
505    gp.qprintn(output)
506    # gp.qprintn(ffdc_list)
507    gp.qprintn()
508
509    gp.qprint_dashes(0, 90, 1, "=")
510
511###############################################################################
512
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
529    cmd_buf = ["FFDC", "ffdc_prefix=" + AUTOBOOT_FFDC_PREFIX]
530    grp.rpissuing_keyword(cmd_buf)
531    try:
532        BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
533    except:
534        gp.print_error("Call to ffdc failed.\n")
535
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 + "\".")
557    gp.qprint(doing_msg)
558
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.
592        state = st.strip_anchor_state(boot_table[boot]['end'])
593    else:
594        # Assertion:  We trust that the state data was made fresh by the
595        # caller.
596
597        gp.qprintn()
598
599        if boot_table[boot]['method_type'] == "keyword":
600            rk.my_run_keywords(boot_table[boot].get('lib_file_path', ''),
601                               boot_table[boot]['method'],
602                               quiet=quiet)
603
604        if boot_table[boot]['bmc_reboot']:
605            st.wait_for_comm_cycle(int(state['epoch_seconds']))
606            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:
610                error_message = "Plug-in failed with non-zero return code.\n"
611                error_message += gp.sprint_var(rc, 1)
612                BuiltIn().fail(gp.sprint_error(error_message))
613        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
620        gp.qprintn()
621        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
654    gp.qprintn()
655
656    next_boot = select_boot()
657    if next_boot == "":
658        return True
659
660    boot_count += 1
661    gp.qprint_timen("Starting boot " + str(boot_count) + ".")
662
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":
672        gp.qprint(msg)
673
674    gp.qprintn()
675    if boot_status == "PASS":
676        boot_success = 1
677        gp.qprint_timen("BOOT_SUCCESS: \"" + next_boot + "\" succeeded.")
678    else:
679        boot_success = 0
680        gp.qprint_timen("BOOT_FAILED: \"" + next_boot + "\" failed.")
681
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)
697        try:
698            BuiltIn().run_keyword_and_continue_on_failure(*cmd_buf)
699        except:
700            gp.print_error("Call to my_ffdc failed.\n")
701
702    # We need to purge error logs between boots or they build up.
703    grk.run_key("Delete Error logs", ignore=1)
704
705    boot_results.print_report()
706    gp.qprint_timen("Finished boot " + str(boot_count) + ".")
707
708    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
716    # This should help prevent ConnectionErrors.
717    grk.run_key_u("Delete All Sessions")
718
719    return True
720
721###############################################################################
722
723
724###############################################################################
725def main_keyword_teardown():
726
727    r"""
728    Clean up after the Main keyword.
729    """
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
736    # Save boot_results object to a file in case it is needed again.
737    gp.qprint_timen("Saving boot_results to the following path.")
738    gp.qprint_var(boot_results_file_path)
739    pickle.dump(boot_results, open(boot_results_file_path, 'wb'),
740                pickle.HIGHEST_PROTOCOL)
741
742###############################################################################
743
744
745###############################################################################
746def 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
757    grp.rqprint_pgm_footer()
758
759###############################################################################
760
761
762###############################################################################
763def obmc_boot_test(alt_boot_stack=None):
764
765    r"""
766    Do main program processing.
767    """
768
769    if alt_boot_stack is not None:
770        BuiltIn().set_global_variable("${boot_stack}", alt_boot_stack)
771
772    setup()
773
774    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
783    # Process caller's boot_stack.
784    while (len(boot_stack) > 0):
785        test_loop_body()
786
787    gp.qprint_timen("Finished processing stack.")
788
789    # 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
794    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))
803
804###############################################################################
805