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