xref: /openbmc/openbmc-test-automation/gui/lib/resource.robot (revision fba7a399e3d2ef1e931d9dd45200172e1371c2b8)
1*** Settings ***
2Documentation  This is a resource file of OpenBMC ASMI It contains the
3...            user-defined keywords which are available to all gui modules
4
5Library      String
6Library      Collections
7Library      DateTime
8Library      XvfbRobot
9Library      OperatingSystem
10Library      SeleniumLibrary
11Library      AngularJSLibrary
12Library      SSHLibrary  30 Seconds
13Library      Process
14Library      supporting_libs.py
15Library      ../../lib/gen_print.py
16Library      ../../lib/gen_robot_print.py
17Library      ../../lib/gen_valid.py
18Library      ../../lib/gen_robot_ssh.py
19Library      ../../lib/bmc_ssh_utils.py
20Resource     ../../lib/resource.robot
21Resource     ../../lib/rest_client.robot
22Resource     ../../lib/state_manager.robot
23Variables    ../data/resource_variables.py
24
25*** Variables ***
26${OPENBMC_GUI_URL}              https://${OPENBMC_HOST}:${HTTPS_PORT}
27
28${obmc_PowerOff_state}       Off
29${obmc_PowerRunning_state}   Running
30${obmc_PowerStandby_state}   Standby
31
32# Default GUI browser and mode is set to "Firefox" and "headless"
33# respectively here.
34${GUI_BROWSER}               ff
35${GUI_MODE}                  headless
36
37${CMD_INTERNAL_FAILURE}      busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
38...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
39...  xyz.openbmc_project.Logging.Entry.Level.Error 0
40
41*** Keywords ***
42Launch OpenBMC GUI Browser
43    [Documentation]  Launch the OpenBMC GUI URL on a browser.
44    # By default uses headless mode, otherwise, the GUI browser.
45
46    ${op_system}=  Get Operating System
47    Run Keyword If  '${op_system}' == 'windows'
48    ...     Launch Header Browser
49    ...  ELSE IF  '${op_system}' == 'Darwin'
50            # Mac OS is currently having some issues with firefox, so using
51            # chrome.
52    ...     Launch Header Browser  chrome
53    ...  ELSE
54            # Linux OS.
55    ...     Launch Headless Browser
56
57Get Operating System
58    [Documentation]  Identify platform/OS.
59
60    ${curdir_lower_case}=  Convert To Lowercase  ${CURDIR}
61    ${windows_platform}=  Run Keyword And Return Status
62    ...  Should Contain  ${curdir_lower_case}  c:\
63    ${op_system}=  Run Keyword If  '${windows_platform}' == 'True'
64    ...     Set Variable  windows
65    ...   ELSE
66    ...     Run  uname
67    RETURN  ${op_system}
68
69Launch Header Browser
70    [Documentation]  Open the browser with the URL and
71    ...              login on windows platform.
72    [Arguments]  ${browser_type}=${GUI_BROWSER}
73
74    # Description of argument(s):
75    # browser_type  Type of browser (e.g. "firefox", "chrome", etc.).
76
77    ${BROWSER_ID}=  Open Browser  ${OPENBMC_GUI_URL}  ${browser_type}
78    Maximize Browser Window
79    Set Global Variable  ${BROWSER_ID}
80
81Launch Headless Browser
82    [Documentation]  Launch headless browser.
83    [Arguments]  ${URL}=${OPENBMC_GUI_URL}  ${browser}=${GUI_BROWSER}
84
85    # Description of argument(s):
86    # URL      Openbmc GUI URL to be open
87    #          (e.g. https://openbmc-test.mybluemix.net/#/login).
88    # browser  Browser to open given URL in headless way
89    #          (e.g. gc for google chrome, ff for firefox).
90
91    Start Virtual Display
92    ${browser_ID}=  Open Browser  ${URL}
93    Set Window Size  1920  1080
94
95    RETURN  ${browser_ID}
96
97Login OpenBMC GUI
98    [Documentation]  Perform login to open BMC GUI.
99    [Arguments]  ${username}=${OPENBMC_USERNAME}
100    ...  ${password}=${OPENBMC_PASSWORD}
101
102    # Description of argument(s):
103    # username      The username.
104    # password      The password.
105
106    Go To  ${OPENBMC_GUI_URL}
107    Wait Until Element Is Enabled  ${xpath_textbox_hostname}
108    Input Text  ${xpath_textbox_hostname}  ${OPENBMC_HOST}
109    Input Text  ${xpath_textbox_username}  ${username}
110    Input Password  ${xpath_textbox_password}  ${password}
111    Click Element  login__submit
112    Wait Until Element Is Enabled  ${xpath_button_logout}
113    Page Should Contain  Server information
114
115
116Test Setup Execution
117    [Documentation]  Verify all the preconditions to be tested.
118    [Arguments]  ${obmc_test_setup_state}=${OBMC_PowerOff_state}
119
120    # Description of argument(s):
121    # obmc_test_setup      The OpenBMC required state.
122
123    Print Timen  ${TEST NAME} ==> [STARTED]
124    Launch Browser And Login OpenBMC GUI
125    Log To Console  Verifying the system state and stability.
126
127    Click Element  ${xpath_select_server_power}
128    Wait Until Page Does Not Contain  Unreachable
129    ${obmc_current_state}=  Get Text  ${xpath_power_indicator}
130    Rpvars  obmc_current_state
131
132    ${obmc_state_status}=  Run Keyword And Return Status
133    ...  Should Contain  ${obmc_current_state}  ${obmc_test_setup_state}
134    Return From Keyword If  '${obmc_state_status}' == 'True'
135
136    ${obmc_standby_state}=  Run Keyword And Return Status
137    ...  Should Contain  ${obmc_current_state}  ${obmc_standby_state}
138
139    Run Keyword If  '${obmc_standby_state}' == 'True'
140    ...  Reboot OpenBMC
141    Run Keyword If  '${obmc_test_setup_state}' == '${obmc_PowerRunning_state}'
142    ...  Run Keywords  Power On OpenBMC  AND
143    ...  Wait Until Keyword Succeeds  10 min  60 sec  Is Host Running
144    Run Keyword If  '${obmc_test_setup_state}' == '${obmc_PowerOff_state}'
145    ...  Run Keywords  Redfish.Login  AND  Redfish Power Off  AND  Redfish.Logout
146
147
148Power On OpenBMC
149    [Documentation]  Power on the OBMC system.
150
151    Log To Console  Power On OpenBMC...
152    Click Element  ${xpath_select_server_power}
153    Click Button  ${xpath_select_button_power_on }
154    Wait OpenBMC To Become Stable  ${obmc_running_state}
155
156Reboot OpenBMC
157    [Documentation]  Rebooting the OBMC system.
158
159    Log To Console  Reboting the OpenBMC...
160    Click Element  ${xpath_select_server_power}
161    Click Button  ${xpath_select_button_orderly_shutdown}
162    Click Yes Button  ${xpath_select_button_orderly_shutdown_yes}
163    Wait OpenBMC To Become Stable  ${obmc_off_state}
164
165Wait OpenBMC To Become Stable
166    [Documentation]  Power off the OBMC.
167    [Arguments]  ${obmc_expected_state}  ${retry_time}=15 min
168    ...  ${retry_interval}=45 sec
169
170    # Description of argument(s):
171    # OBMC_expected_state      The OBMC state which is required for test.
172    # retry_time               Total wait time after executing the command.
173    # retry_interval           Time interval for to keep checking with in the
174    #                          above total wait time.
175
176    Wait Until Keyword Succeeds  ${retry_time}  ${retry_interval}
177    ...  Wait Until Element Contains  ${xpath_select_server_power}
178    ...  ${obmc_expected_state}
179    Wait Until Keyword Succeeds  ${retry_time}  ${retry_interval}
180    ...  Verify OpenBMC State From REST Interface  ${obmc_expected_state}
181
182Verify OpenBMC State From REST Interface
183    [Documentation]  Verify system state from REST Interface.
184    [Arguments]  ${obmc_required_state}
185
186    # Description of argument(s):
187    # obmc_required_state      The OBMC state which is required for test.
188
189    ${obmc_current_state_REST}=  Get Host State
190    Should Be Equal  ${obmc_current_state_REST}  ${obmc_required_state}
191
192Click Yes Button
193    [Documentation]  Click the 'Yes' button.
194    [Arguments]  ${xpath_button_yes}
195
196    # Description of argument(s):
197    # xpath_button_yes      The xpath of 'Yes' button.
198
199    Click Button  ${xpath_button_yes}
200
201LogOut OpenBMC GUI
202    [Documentation]  Log out of OpenBMC GUI.
203    SSHLibrary.Close All Connections
204    Click Button  ${xpath_button_user_action}
205    Click Element  ${xpath_button_logout}
206    Wait Until Page Contains Element  ${xpath_button_login}
207
208Test Teardown Execution
209    [Documentation]  Do final closure activities of test case execution.
210    Print Pgm Footer
211    Print Dashes  0  100  1  =
212    Close Browser
213
214
215Open Browser With URL
216    [Documentation]  Open browser with specified URL and returns browser id.
217    [Arguments]  ${URL}  ${browser}=ff  ${mode}=${GUI_MODE}
218
219    # Description of argument(s):
220    # URL      Openbmc GUI URL to be open
221    #          (e.g. https://openbmc-test.mybluemix.net/#/login).
222    # browser  Browser used to open above URL
223    #          (e.g. gc for google chrome, ff for firefox).
224    # mode     Browser opening mode(e.g. headless, header).
225
226    ${browser_ID}=  Run Keyword If  '${mode}' == 'headless'
227    ...  Launch Headless Browser  ${URL}  ${browser}
228    ...  ELSE  Open Browser  ${URL}  ${browser}
229
230    RETURN  ${browser_ID}
231
232
233Controller Server Power Click Button
234    [Documentation]  Click main server power in the header section.
235    [Arguments]  ${controller_element}
236
237    # Description of argument(s):
238    # controller_element  Server power controller element
239    #                     (e.g. power__power-on.)
240
241    Click Element  ${xpath_select_server_power}
242    Wait Until Element Is Visible  ${controller_element}
243    Page Should Contain Button  ${controller_element}
244    Click Element  ${controller_element}
245
246
247GUI Power On
248    [Documentation]  Power on the host using GUI.
249
250    Controller Server Power Click Button  power__power-on
251    Wait Until Page Contains  Running   timeout=30s
252
253Verify Display Content
254    [Documentation]  Verify text content display.
255    [Arguments]  ${display_text}
256
257    # Description of argument(s):
258    # display_text   The text which is expected to be found on the web page.
259
260    Page Should Contain  ${display_text}
261
262
263Verify Warning Message Display Text
264    [Documentation]  Verify the warning message display text.
265    [Arguments]  ${xpath_text_message}  ${text_message}
266
267    # xpath_text_message  Xpath of warning message display.
268    # text_message        Content of the display message info.
269
270    Element Should Contain  ${xpath_text_message}  ${text_message}
271
272
273Expected Initial Test State
274    [Documentation]  Power on the host if "Running" expected, Power off the
275    ...  host if "Off" expected as per the requirement of initial test state.
276    [Arguments]  ${expectedState}
277    # Description of argument(s):
278    # expectedState    Test initial host state.
279
280    Run Keyword If  '${expectedState}' == 'Running'
281    ...  REST Power On  stack_mode=skip  quiet=1
282
283    Run Keyword If  '${expectedState}' == 'Off'
284    ...  REST Power Off  stack_mode=skip  quiet=1
285
286Launch Browser And Login OpenBMC GUI
287    [Documentation]  Launch browser and log into openbmc GUI.
288
289    Open Browser With URL  ${OPENBMC_GUI_URL}
290    Login OpenBMC GUI  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
291
292Logout And Close Browser
293    [Documentation]  Logout from openbmc application and close the browser.
294
295    Click Button  ${xpath_button_user_action}
296    Click Button  ${xpath_button_logout}
297    Close Browser
298
299