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, 2h, or 30m.
11# HTX_LOOP            The number of times to loop HTX.
12# HTX_INTERVAL        The time delay between consecutive checks of HTX
13#                     status, for example, 15m.
14#                     In summary: Run HTX for $HTX_DURATION, looping
15#                     $HTX_LOOP times checking for errors every
16#                     $HTX_INTERVAL.  Then allow extra time for OS
17#                     Boot, HTX startup, shutdown.
18# HTX_KEEP_RUNNING    If set to 1, this indicates that the HTX is to
19#                     continue running after an error was found.
20# CHECK_INVENTORY     If set to 0 or False, OS inventory checking before
21#                     and after each HTX run will be disabled.  This
22#                     parameter is optional.  The default value is True.
23# PREV_INV_FILE_PATH  The file path and name of an initial previous
24#                     inventory snapshot file in JSON format.  Inventory
25#                     snapshots taken before and after each HTX run will
26#                     be compared to this file.
27#                     This parameter is optional.  If not specified an
28#                     initial inventory snapshot will be taken before
29#                     HTX startup.
30# INV_IGNORE_LIST     A comma-delimited list of strings that
31#                     indicate what to ignore if there are inventory
32#                     differences, (e.g., processor "size").
33#                     If differences are found during inventory checking
34#                     and those items are in this list, the
35#                     differences will be ignored.  This parameter is
36#                     optional.  If not specified the default value is
37#                     "size".
38
39Resource        ../syslib/utils_os.robot
40Resource        ../lib/openbmc_ffdc_utils.robot
41Resource        ../lib/logging_utils.robot
42Resource        ../lib/code_update_utils.robot
43Resource        ../lib/esel_utils.robot
44Resource        ../syslib/resource.robot
45Library         ../syslib/utils_keywords.py
46Library         ../lib/utils_files.py
47Library         ../lib/logging_utils.py
48Library         ../syslib/utils_os.py
49
50Suite Setup     Run Keyword  Start SOL Console Logging
51Test Setup      Test Setup Execution
52Test Teardown   Test Teardown Execution
53
54
55*** Variables ****
56
57${stack_mode}                skip
58${json_initial_file_path}    ${EXECDIR}/os_inventory_initial.json
59${json_final_file_path}      ${EXECDIR}/os_inventory_final.json
60${json_diff_file_path}       ${EXECDIR}/os_inventory_diff.json
61${CHECK_INVENTORY}           True
62${INV_IGNORE_LIST}           size
63${PREV_INV_FILE_PATH}        NONE
64
65${rest_keyword}              REST
66
67# Error log Severities to ignore when checking Error Logs.
68@{ESEL_IGNORE_LIST}
69...  xyz.openbmc_project.Logging.Entry.Level.Informational
70
71
72
73*** Test Cases ***
74
75Hard Bootme Test
76    [Documentation]  Stress the system using HTX exerciser.
77    [Tags]  Hard_Bootme_Test
78
79    Printn
80    Rprint Vars  HTX_DURATION  HTX_LOOP  HTX_INTERVAL  CHECK_INVENTORY
81    ...  INV_IGNORE_LIST  PREV_INV_FILE_PATH
82
83    Run Keyword If  '${PREV_INV_FILE_PATH}' != 'NONE'
84    ...  OperatingSystem.File Should Exist  ${PREV_INV_FILE_PATH}
85
86    Set Suite Variable  ${PREV_INV_FILE_PATH}  children=true
87    Set Suite Variable  ${INV_IGNORE_LIST}  children=true
88
89    # Set up the iteration (loop) counter.
90    Set Suite Variable  ${iteration}  ${0}  children=true
91
92    # Estimate the time required for a single iteration loop.
93    # HTX_DURATION + 10 minutes for OS boot, HTX startup, shutdown.
94    ${loop_body_seconds}=  Add Time To Time  ${HTX_DURATION}  10m
95    Set Suite Variable  ${loop_body_seconds}  children=true
96    # And save it in printable (compact) format.
97    ${estimated_loop_time}=  Convert Time
98    ...  ${loop_body_seconds}  result_format=compact
99    Set Suite Variable  ${estimated_loop_time}  children=true
100
101    # Estimated time remaining =  loop_body_seconds * HTX_LOOP + 5m
102    ${est_seconds_left}=  Evaluate  ${loop_body_seconds}*${HTX_LOOP}+(5*60)
103    Set Suite Variable  ${est_seconds_left}  children=true
104
105    Repeat Keyword  ${HTX_LOOP} times  Run HTX Exerciser
106
107
108*** Keywords ***
109
110
111Run HTX Exerciser
112    [Documentation]  Run HTX exerciser.
113    # Test Flow:
114    # - Power on.
115    # - Establish SSH connection session.
116    # - Do inventory collection, compare with
117    #   previous inventory run if applicable.
118    # - Create HTX mdt profile.
119    # - Run HTX exerciser.
120    # - Check HTX status for errors.
121    # - Do inventory collection, compare with
122    #   previous inventory run.
123    # - Power off.
124
125    Set Suite Variable  ${iteration}  ${iteration + 1}
126    ${loop_count}=  Catenate  Starting iteration: ${iteration}
127    ${estimated_time_remaining}=  Convert Time
128    ...  ${est_seconds_left}  result_format=compact
129    Printn
130    Rprint Vars  loop_count  estimated_loop_time   estimated_time_remaining
131
132    Run Keyword  ${rest_keyword} Power On  stack_mode=skip
133    Run Key U  Sleep \ 15s
134
135    # Post Power off and on, the OS SSH session needs to be established.
136    Login To OS
137
138    Run Keyword If  '${CHECK_INVENTORY}' == 'True'
139    ...  Do Inventory And Compare  ${json_initial_file_path}
140    ...  ${PREV_INV_FILE_PATH}
141
142    Run Keyword If  '${HTX_MDT_PROFILE}' == 'mdt.bu'
143    ...  Create Default MDT Profile
144
145    Run MDT Profile
146
147    Loop HTX Health Check
148
149    Shutdown HTX Exerciser
150
151    Run Keyword If  '${CHECK_INVENTORY}' == 'True'
152    ...  Do Inventory And Compare  ${json_final_file_path}
153    ...  ${PREV_INV_FILE_PATH}
154
155    Run Keyword  ${rest_keyword} Power Off
156
157    # Close all SSH and REST active sessions.
158    Close All Connections
159    Flush REST Sessions
160
161    Print Timen  HTX Test ran for: ${HTX_DURATION}
162
163    ${loop_count}=  Catenate  Ending iteration: ${iteration}
164
165    ${est_seconds_left}=  Evaluate  ${est_seconds_left}-${loop_body_seconds}
166    Set Suite Variable  ${est_seconds_left}  children=true
167    ${estimated_time_remaining}=  Convert Time
168    ...  ${est_seconds_left}  result_format=compact
169
170    Rprint Vars  loop_count  estimated_time_remaining
171
172
173Do Inventory And Compare
174    [Documentation]  Do inventory and compare.
175    [Arguments]  ${inventory_file_path}  ${PREV_INV_FILE_PATH}
176    # Description of argument(s):
177    # inventory_file_path  The file to receive the inventory snapshot.
178    # PREV_INV_FILE_PATH   The previous inventory to compare with.
179
180    Create JSON Inventory File  ${inventory_file_path}
181    Run Keyword If  '${PREV_INV_FILE_PATH}' != 'NONE'
182    ...  Compare Json Inventory Files  ${inventory_file_path}
183    ...  ${PREV_INV_FILE_PATH}
184    ${PREV_INV_FILE_PATH}=   Set Variable  ${inventory_file_path}
185    Set Suite Variable  ${PREV_INV_FILE_PATH}  children=true
186
187
188Compare Json Inventory Files
189    [Documentation]  Compare JSON inventory files.
190    [Arguments]  ${file1}  ${file2}
191    # Description of argument(s):
192    # file1   A file that has an inventory snapshot in JSON format.
193    # file2   A file that has an inventory snapshot, to compare with file1.
194
195    ${diff_rc}=  File_Diff  ${file1}
196     ...  ${file2}  ${json_diff_file_path}  ${INV_IGNORE_LIST}
197    Run Keyword If  '${diff_rc}' != '${0}'
198    ...  Report Inventory Mismatch  ${diff_rc}  ${json_diff_file_path}
199    ...  ELSE  Print Timen  Inventoy check: No differences found.
200
201
202Report Inventory Mismatch
203    [Documentation]  Report inventory mismatch.
204    [Arguments]  ${diff_rc}  ${json_diff_file_path}
205    # Description of argument(s):
206    # diff_rc              The failing return code from the difference check.
207    # json_diff_file_path  The file that has the latest inventory snapshot.
208
209    Log To Console  Significant difference in inventory found, rc=${diff_rc}
210    Log To Console  Differences are listed in file:  no_newline=true
211    Log To Console  ${json_diff_file_path}
212    Log To Console  File Contents:
213    Wait Until Created  ${json_diff_file_path}
214    ${file_contents}=  OperatingSystem.Get File  ${json_diff_file_path}
215    Log  ${file_contents}  level=WARN
216    Fail  Significant difference in inventory found, rc=${diff_rc}
217
218
219Loop HTX Health Check
220    [Documentation]  Run until HTX exerciser fails.
221    Repeat Keyword  ${HTX_DURATION}
222    ...  Run Keywords  Check HTX Run Status
223    ...  AND  Check For Error Logs  ${ESEL_IGNORE_LIST}
224    ...  AND  Sleep  ${HTX_INTERVAL}
225
226
227Test Setup Execution
228    [Documentation]  Do the initial test setup.
229
230    ${bmc_version}  ${stderr}  ${rc}=  BMC Execute Command
231    ...  cat /etc/os-release
232    Printn
233    Rprint Vars  bmc_version
234
235    ${fw_version}=  Get BMC Version
236    Rprint Vars  fw_version
237
238    ${is_redfish}=  Run Keyword And Return Status  Redfish.Login
239    ${rest_keyword}=  Set Variable If  ${is_redfish}  Redfish  REST
240    Rprint Vars  rest_keyword
241    Set Suite Variable  ${rest_keyword}  children=true
242
243    Run Keyword  ${rest_keyword} Power On  stack_mode=skip
244
245    Run Key U  Sleep \ 15s
246    Run Keyword And Ignore Error  Delete All Error Logs
247    Run Keyword And Ignore Error  Redfish Purge Event Log
248    Tool Exist  htxcmdline
249
250    ${os_release_info}=  utils_os.Get OS Release Info  uname
251    Rprint Vars  os_release_info  fmt=1
252
253    # Shutdown if HTX is running.
254    ${status}=  Is HTX Running
255    Run Keyword If  '${status}' == 'True'
256    ...  Shutdown HTX Exerciser
257
258
259Test Teardown Execution
260    [Documentation]  Do the post-test teardown.
261
262    # Keep HTX running if user set HTX_KEEP_RUNNING to 1.
263    Run Keyword If
264    ...  '${TEST_STATUS}' == 'FAIL' and ${HTX_KEEP_RUNNING} == ${0}
265    ...  Shutdown HTX Exerciser
266
267    ${keyword_buf}=  Catenate  Stop SOL Console Logging
268    ...  \ targ_file_path=${EXECDIR}${/}logs${/}SOL.log
269    Run Key  ${keyword_buf}
270
271    FFDC On Test Case Fail
272    Close All Connections
273