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