1*** Settings ***
2
3Documentation  Stress the system using HTX exerciser.
4
5# Test Parameters:
6# OPENBMC_HOST        The BMC host name or IP address.
7# OS_HOST             The OS host name or IP Address.
8# OS_USERNAME         The OS login userid (usually root).
9# OS_PASSWORD         The password for the OS login.
10# HTX_DURATION        Duration of HTX run, for example, 8 hours, or
11#                     30 minutes.
12# HTX_LOOP            The number of times to loop HTX.
13# HTX_INTERVAL        The time delay between consecutive checks of HTX
14#                     status, for example, 30s.
15#                     In summary: Run HTX for $HTX_DURATION, looping
16#                     $HTX_LOOP times checking every $HTX_INTERVAL.
17# HTX_KEEP_RUNNING    If set to 1, this indicates that the HTX is to
18#                     continue running after an error.
19# CHECK_INVENTORY     If set to 0 or False, OS inventory checking before
20#                     and after each HTX run will be disabled.  This
21#                     parameter is optional.
22# PREV_INV_FILE_PATH  The file path and name of an initial previous
23#                     inventory snapshot file in JSON format.  Inventory
24#                     snapshots taken before and after each HTX run will
25#                     be compared to this file.
26#                     This parameter is optional.  If not specified, an
27#                     initial inventory snapshot will be taken before
28#                     HTX startup.
29# INV_IGNORE_LIST     A comma-delimited list of strings that
30#                     indicate what to ignore if there are inventory
31#                     differences, (e.g., processor "size").
32#                     If differences are found during inventory checking
33#                     and those items are in this list, the
34#                     differences will be ignored.  This parameter is
35#                     optional.  If not specified the default value is
36#                     "size".
37
38Resource        ../syslib/utils_os.robot
39Library         ../syslib/utils_keywords.py
40Library         ../lib/utils_files.py
41
42Suite Setup     Run Keyword  Start SOL Console Logging
43Test Setup      Pre Test Case Execution
44Test Teardown   Post Test Case Execution
45
46
47*** Variables ****
48
49${stack_mode}                skip
50${json_initial_file_path}    ${EXECDIR}/os_inventory_initial.json
51${json_final_file_path}      ${EXECDIR}/os_inventory_final.json
52${json_diff_file_path}       ${EXECDIR}/os_inventory_diff.json
53${last_inventory_file_path}  ${EMPTY}
54${CHECK_INVENTORY}           True
55${INV_IGNORE_LIST}           size
56${PREV_INV_FILE_PATH}        ${EMPTY}
57
58
59*** Test Cases ***
60
61Hard Bootme Test
62    [Documentation]  Stress the system using HTX exerciser.
63    [Tags]  Hard_Bootme_Test
64
65    # Set last inventory file to PREV_INV_FILE_PATH otherwise set it
66    # to ${EMPTY}.
67    ${last_inventory_file_path}=  Get Variable Value  ${PREV_INV_FILE_PATH}
68    ...  ${EMPTY}
69
70    Rprintn
71    Rpvars  HTX_DURATION  HTX_INTERVAL  CHECK_INVENTORY  INV_IGNORE_LIST
72    ...  PREV_INV_FILE_PATH
73
74    Run Keyword If  '${last_inventory_file_path}' != '${EMPTY}'
75    ...  OperatingSystem.File Should Exist  ${last_inventory_file_path}
76
77    Set Suite Variable  ${last_inventory_file_path}  children=true
78    Set Suite Variable  ${INV_IGNORE_LIST}  children=true
79    Set Suite Variable  ${iteration}  ${0}  children=true
80
81    Repeat Keyword  ${HTX_LOOP} times  Run HTX Exerciser
82
83
84*** Keywords ***
85
86
87Run HTX Exerciser
88    [Documentation]  Run HTX exerciser.
89    # Test Flow:
90    # - Power on.
91    # - Establish SSH connection session.
92    # - Do inventory collection, compare with
93    #   previous inventory run if applicable.
94    # - Create HTX mdt profile.
95    # - Run HTX exerciser.
96    # - Check HTX status for errors.
97    # - Do inventory collection, compare with
98    #   previous inventory run.
99    # - Power off.
100
101    Set Suite Variable  ${iteration}  ${iteration + 1}
102    ${loop_count}=  Catenate  Starting iteration: ${iteration}
103    Rpvars  loop_count
104
105    Boot To OS
106
107    # Post Power off and on, the OS SSH session needs to be established.
108    Login To OS
109
110    Run Keyword If  '${CHECK_INVENTORY}' == 'True'
111    ...  Do Inventory And Compare  ${json_initial_file_path}
112    ...  ${last_inventory_file_path}
113
114    Run Keyword If  '${HTX_MDT_PROFILE}' == 'mdt.bu'
115    ...  Create Default MDT Profile
116
117    Run MDT Profile
118
119    Loop HTX Health Check
120
121    Shutdown HTX Exerciser
122
123    Run Keyword If  '${CHECK_INVENTORY}' == 'True'
124    ...  Do Inventory And Compare  ${json_final_file_path}
125    ...  ${last_inventory_file_path}
126
127    Power Off Host
128
129    # Close all SSH and REST active sessions.
130    Close All Connections
131    Flush REST Sessions
132
133    Rprint Timen  HTX Test ran for: ${HTX_DURATION}
134
135    ${loop_count}=  Catenate  Ending iteration: ${iteration}
136    Rpvars  loop_count
137
138
139Do Inventory And Compare
140    [Documentation]  Do inventory and compare.
141    [Arguments]  ${inventory_file_path}  ${last_inventory_file_path}
142    # Description of argument(s):
143    # inventory_file_path        The file to receive the inventory snapshot.
144    # last_inventory_file_path   The previous inventory to compare with.
145
146    Create JSON Inventory File  ${inventory_file_path}
147    Run Keyword If  '${last_inventory_file_path}' != '${EMPTY}'
148    ...  Compare Json Inventory Files  ${inventory_file_path}
149    ...  ${last_inventory_file_path}
150    ${last_inventory_file_path}=   Set Variable  ${inventory_file_path}
151    Set Suite Variable  ${last_inventory_file_path}  children=true
152
153
154Compare Json Inventory Files
155    [Documentation]  Compare JSON inventory files.
156    [Arguments]  ${file1}  ${file2}
157    # Description of argument(s):
158    # file1   A file that has an inventory snapshot in JSON format.
159    # file2   A file that has an inventory snapshot, to compare with file1.
160
161    ${diff_rc}=  File_Diff  ${file1}
162     ...  ${file2}  ${json_diff_file_path}  ${INV_IGNORE_LIST}
163    Run Keyword If  '${diff_rc}' != '${0}'
164    ...  Report Inventory Mismatch  ${diff_rc}  ${json_diff_file_path}
165
166
167Report Inventory Mismatch
168    [Documentation]  Report inventory mismatch.
169    [Arguments]  ${diff_rc}  ${json_diff_file_path}
170    # Description of argument(s):
171    # diff_rc              The failing return code from the difference check.
172    # json_diff_file_path  The file that has the latest inventory snapshot.
173
174    Log To Console  Significant difference in inventory found, rc=${diff_rc}
175    Log To Console  Differences are listed in file:  no_newline=true
176    Log To Console  ${json_diff_file_path}
177    Log To Console  File Contents:
178    Wait Until Created  ${json_diff_file_path}
179    ${file_contents}=  OperatingSystem.Get File  ${json_diff_file_path}
180    Log  ${file_contents}  level=WARN
181    Fail  Significant difference in inventory found, rc=${diff_rc}
182
183
184Loop HTX Health Check
185    [Documentation]  Run until HTX exerciser fails.
186    Repeat Keyword  ${HTX_DURATION}
187    ...  Run Keywords  Check HTX Run Status
188    ...  AND  Sleep  ${HTX_INTERVAL}
189
190
191Post Test Case Execution
192    [Documentation]  Do the post test teardown.
193    # 1. Shut down HTX exerciser if test Failed.
194    # 2. Capture FFDC on test failure.
195    # 3. Close all open SSH connections.
196
197    # Keep HTX running if user set HTX_KEEP_RUNNING to 1.
198    Run Keyword If
199    ...  '${TEST_STATUS}' == 'FAIL' and ${HTX_KEEP_RUNNING} == ${0}
200    ...  Shutdown HTX Exerciser
201
202    ${keyword_buf}=  Catenate  Stop SOL Console Logging
203    ...  \ targ_file_path=${EXECDIR}${/}logs${/}SOL.log
204    Run Key  ${keyword_buf}
205
206    FFDC On Test Case Fail
207    Close All Connections
208