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