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      Selenium2Library  120  120
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.txt
21Resource     ../../lib/rest_client.robot
22Resource     ../../lib/state_manager.robot
23Variables    ../data/resource_variables.py
24
25*** Variables ***
26${obmc_gui_url}              https://${OPENBMC_HOST}
27
28${obmc_PowerOff_state}       Off
29${obmc_PowerRunning_state}   Running
30${obmc_PowerStandby_state}   Standby
31
32# Default GUI broswer and mode is set to "Firefox" and "headless"
33# respectively here.
34${GUI_BROWSER}               ff
35${GUI_MODE}                  headless
36
37*** Keywords ***
38Launch OpenBMC GUI Browser
39    [Documentation]  Launch the OpenBMC GUI URL on a browser.
40    # By default uses headless mode, otherwise, the GUI browser.
41
42    ${op_system}=  Get Operating System
43    Run Keyword If  '${op_system}' == 'windows'
44    ...     Launch Header Browser
45    ...  ELSE IF  '${op_system}' == 'Darwin'
46            # Mac OS is currently having some issues with firefox, so using
47            # chrome.
48            # TODO: Need to add support for other browsers. Issue #1280.
49    ...     Launch Header Browser  chrome
50    ...  ELSE
51            # Linux OS.
52    ...     Launch Headless Browser
53
54Get Operating System
55    [Documentation]  Identify platform/OS.
56
57    ${curdir_lower_case}=  Convert To Lowercase  ${CURDIR}
58    ${windows_platform}=  Run Keyword And Return Status
59    ...  Should Contain  ${curdir_lower_case}  c:\
60    ${op_system}=  Run Keyword If  '${windows_platform}' == 'True'
61    ...     Set Variable  windows
62    ...   ELSE
63    ...     Run  uname
64    [Return]  ${op_system}
65
66Launch Header Browser
67    [Documentation]  Open the browser with the URL and
68    ...              login on windows platform.
69    [Arguments]  ${browser_type}=${GUI_BROWSER}
70
71    # Description of argument(s):
72    # browser_type  Type of browser (e.g. "firefox", "chrome", etc.).
73
74    ${BROWSER_ID}=  Open Browser  ${obmc_gui_url}  ${browser_type}
75    Maximize Browser Window
76    Set Global Variable  ${BROWSER_ID}
77
78Launch Headless Browser
79    [Documentation]  Launch headless browser.
80    [Arguments]  ${URL}=${obmc_gui_url}  ${browser}=${GUI_BROWSER}
81
82    # Description of argument(s):
83    # URL      Openbmc GUI URL to be open
84    #          (e.g. https://openbmc-test.mybluemix.net/#/login).
85    # browser  Browser to open given URL in headless way
86    #          (e.g. gc for google chrome, ff for firefox).
87
88    Start Virtual Display
89    ${browser_ID}=  Open Browser  ${URL}
90    Set Window Size  1920  1080
91
92    [Return]  ${browser_ID}
93
94Login OpenBMC GUI
95    [Documentation]  Perform login to open BMC GUI.
96    [Arguments]  ${username}=${OPENBMC_USERNAME}
97    ...  ${password}=${OPENBMC_PASSWORD}
98
99    # Description of argument(s):
100    # username      The username.
101    # password      The password.
102
103    Go To  ${obmc_gui_url}
104    Wait Until Element Is Enabled  ${xpath_textbox_hostname}
105    Input Text  ${xpath_textbox_hostname}  ${OPENBMC_HOST}
106    Input Text  ${xpath_textbox_username}  ${username}
107    Input Password  ${xpath_textbox_password}  ${password}
108    Click Element  login__submit
109    Wait Until Element Is Enabled  ${xpath_button_logout}
110    Page Should Contain  Server information
111
112
113Test Setup Execution
114    [Documentation]  Verify all the preconditions to be tested.
115    [Arguments]  ${obmc_test_setup_state}=${OBMC_PowerOff_state}
116
117    # Description of argument(s):
118    # obmc_test_setup      The OpenBMC required state.
119
120    Rprint Timen  ${TEST NAME} ==> [STARTED]
121    Launch Browser And Login OpenBMC GUI
122    Log To Console  Verifying the system state and stablity...
123
124    Click Button  ${xpath_select_server_power}
125    ${obmc_current_state}=  Get Text  ${xpath_power_indicator}
126    Rpvars  obmc_current_state
127
128    ${obmc_state_status}=  Run Keyword And Return Status
129    ...  Should Contain  ${obmc_current_state}  ${obmc_test_setup_state}
130    Return From Keyword If  '${obmc_state_status}' == 'True'
131
132    ${obmc_standby_state}=  Run Keyword And Return Status
133    ...  Should Contain  ${obmc_current_state}  ${obmc_standby_state}
134
135    Run Keyword If  '${obmc_standby_state}' == 'True'
136    ...  Reboot OpenBMC
137    Run Keyword If  '${obmc_test_setup_state}' == '${obmc_PowerRunning_state}'
138    ...  Run Keywords  Power On OpenBMC  AND
139    ...  Wait Until Keyword Succeeds  10 min  60 sec  Is Host Running
140    Run Keyword If  '${obmc_test_setup_state}' == '${obmc_PowerOff_state}'
141    ...  Power Off OpenBMC
142
143Power Off OpenBMC
144    [Documentation]  Power off the OBMC system.
145
146    Log To Console  Power Off OpenBMC...
147    Click Element  ${xpath_display_server_power_status}
148    Execute JavaScript  window.scrollTo(0, document.body.scrollHeight)
149    Click Button  ${xpath_select_button_orderly_shutdown}
150    Click Yes Button  ${xpath_select_button_orderly_shutdown_yes}
151    Wait OpenBMC To Become Stable  ${obmc_off_state}
152
153Power On OpenBMC
154    [Documentation]  Power on the OBMC system.
155
156    Log To Console  Power On OpenBMC...
157    Click Element  ${xpath_display_server_power_status}
158    Click Button  ${xpath_select_button_power_on }
159    Wait OpenBMC To Become Stable  ${obmc_running_state}
160
161Reboot OpenBMC
162    [Documentation]  Rebooting the OBMC system.
163
164    Log To Console  Reboting the OpenBMC...
165    Click Element  ${xpath_display_server_power_status}
166    Click Button  ${xpath_select_button_orderly_shutdown}
167    Click Yes Button  ${xpath_select_button_orderly_shutdown_yes}
168    Wait OpenBMC To Become Stable  ${obmc_off_state}
169
170Wait OpenBMC To Become Stable
171    [Documentation]  Power off the OBMC.
172    [Arguments]  ${obmc_expected_state}  ${retry_time}=15 min
173    ...  ${retry_interval}=45 sec
174
175    # Description of argument(s):
176    # OBMC_expected_state      The OBMC state which is required for test.
177    # retry_time               Total wait time after executing the command.
178    # retry_interval           Time interval for to keep checking with in the
179    #                          above total wait time.
180
181    Wait Until Keyword Succeeds  ${retry_time}  ${retry_interval}
182    ...  Wait Until Element Contains  ${xpath_display_server_power_status}
183    ...  ${obmc_expected_state}
184    Wait Until Keyword Succeeds  ${retry_time}  ${retry_interval}
185    ...  Verify OpenBMC State From REST Interface  ${obmc_expected_state}
186
187Verify OpenBMC State From REST Interface
188    [Documentation]  Verify system state from REST Interface.
189    [Arguments]  ${obmc_required_state}
190
191    # Description of argument(s):
192    # obmc_required_state      The OBMC state which is required for test.
193
194    ${obmc_current_state_REST}=  Get Host State
195    Should Be Equal  ${obmc_current_state_REST}  ${obmc_required_state}
196
197Click Yes Button
198    [Documentation]  Click the 'Yes' button.
199    [Arguments]  ${xpath_button_yes}
200
201    # Description of argument(s):
202    # xpath_button_yes      The xpath of 'Yes' button.
203
204    Click Button  ${xpath_button_yes}
205
206LogOut OpenBMC GUI
207    [Documentation]  Log out of OpenBMC GUI.
208    SSHLibrary.Close All Connections
209    # Passing direct id element "header" as an argument to Click Element.
210    Click Element  ${xpath_button_logout}
211    Wait Until Page Contains Element  ${xpath_button_login}
212
213Test Teardown Execution
214    [Documentation]  Do final closure activities of test case execution.
215    Rprint Pgm Footer
216    Print Dashes  0  100  1  =
217    Close Browser
218
219
220Open Browser With URL
221    [Documentation]  Open browser with specified URL and returns browser id.
222    [Arguments]  ${URL}  ${browser}=ff  ${mode}=${GUI_MODE}
223
224    # Description of argument(s):
225    # URL      Openbmc GUI URL to be open
226    #          (e.g. https://openbmc-test.mybluemix.net/#/login).
227    # browser  Browser used to open above URL
228    #          (e.g. gc for google chrome, ff for firefox).
229    # mode     Browser opening mode(e.g. headless, header).
230
231    ${browser_ID}=  Run Keyword If  '${mode}' == 'headless'
232    ...  Launch Headless Browser  ${URL}  ${browser}
233    ...  ELSE  Open Browser  ${URL}  ${browser}
234
235    [Return]  ${browser_ID}
236
237
238Model Server Power Click Button
239    [Documentation]  Click main server power in the header section.
240    [Arguments]  ${div_element}  ${anchor_element}
241
242    # Description of argument(s):
243    # div_element     Server power header divisional element
244    #                 (e.g. header_wrapper.)
245    # anchor_element  Server power header anchor element
246    #                 (e.g. header_wrapper_elt.)
247
248    Wait Until Element Is Visible
249    ...  //*[@id='header__wrapper']/div/div[${div_element}]/a[${anchor_element}]/span
250    Click Element
251    ...  //*[@id='header__wrapper']/div/div[${div_element}]/a[${anchor_element}]/span
252
253Controller Server Power Click Button
254    [Documentation]  Click main server power in the header section.
255    [Arguments]  ${controller_element}
256
257    # Description of argument(s):
258    # controller_element  Server power controller element
259    #                     (e.g. power__power-on.)
260
261    Click Element  ${xpath_select_server_power}
262    Wait Until Element Is Visible  ${controller_element}
263    Page Should Contain Button  ${controller_element}
264    Click Element  ${controller_element}
265
266Controller Power Operations Confirmation Click Button
267    [Documentation]  Click Common Power Operations Confirmation.
268    [Arguments]  ${main_element}  ${sub_element}  ${confirm_msg_elt}  ${confirmation}
269
270    # Description of argument(s):
271    # main_element     Server power operations element
272    #                  (e.g. power_operations.)
273    # sub_element      Server power operations sub element
274    #                  (e.g. warm_boot, shut_down.)
275    # confirm_msg_elt  Server power operations confirm message element
276    #                  (e.g. confirm_msg.)
277    # confirmation     Server power operations confirmation
278    #                  (e.g. yes.)
279
280    ${element_path}=  Catenate  //*[@id='power-operations']/div[${main_element}]/div[${sub_element}]
281    ...  /confirm/div/div[${confirm_msg_elt}]/button[${confirmation}]
282    Click Element  ${element_path.replace(" ","")}
283
284
285GUI Power On
286    [Documentation]  Power on the host using GUI.
287
288    Model Server Power Click Button  ${header_wrapper}  ${header_wrapper_elt}
289    Page Should Contain  Attempts to power on the server
290    Controller Server Power Click Button  power__power-on
291    Page Should Contain  Running
292
293Verify Display Content
294    [Documentation]  Verify text content display.
295    [Arguments]  ${display_text}
296
297    # Description of argument(s):
298    # display_text   The text which is expected to be found on the web page.
299
300    Page Should Contain  ${display_text}
301
302Warm Reboot openBMC
303    [Documentation]  Warm reboot the OBMC system.
304
305    Log To Console  Warm Reboting the OpenBMC...
306    Click Element  ${xpath_select_button_warm_reboot}
307    Verify Warning Message Display Text  ${xpath_warm_reboot_warning_message}
308    ...  ${text_warm_reboot_warning_message}
309    Click Yes Button  ${xpath_select_button_warm_reboot_yes}
310    Wait OpenBMC To Become Stable  ${obmc_running_state}
311
312Click No Button
313    [Documentation]  Click the 'No' button.
314    [Arguments]  ${xpath_button_no}
315
316    # Description of argument(s):
317    # xpath_button_no      The xpath of 'No' button.
318
319    Click Button  ${xpath_button_no}
320
321Cold Reboot openBMC
322    [Documentation]  Cold reboot the OBMC system.
323
324    Log To Console  Cold Reboting the OpenBMC...
325    Click Element  ${xpath_select_button_cold_reboot}
326    Verify Warning Message Display Text  ${xpath_cold_reboot_warning_message}
327    ...  ${text_cold_reboot_warning_message}
328    Click Yes Button  ${xpath_select_button_cold_reboot_yes}
329    Wait OpenBMC To Become Stable  ${obmc_running_state}
330
331Orderly Shutdown OpenBMC
332    [Documentation]  Do orderly shutdown the OBMC system.
333
334    Log To Console  Orderly Shutdown the OpenBMC...
335    Click Element  ${xpath_select_button_orderly_shutdown}
336    Verify Warning Message Display Text  ${xpath_orderly_shutdown_warning_message}
337    ...  ${text_orderly_shutdown_warning_message}
338    Click Yes Button  ${xpath_select_button_orderly_shutdown_yes}
339    Wait OpenBMC To Become Stable  ${obmc_off_state}
340
341Immediate Shutdown openBMC
342    [Documentation]  Do immediate shutdown the OBMC system.
343
344    Log To Console  Immediate Shutdown the OpenBMC...
345    Click Element  ${xpath_select_button_immediate_shutdown}
346    Verify Warning Message Display Text
347    ...  ${xpath_immediate_shutdown_warning_message}
348    ...  ${text_immediate_shutdown_warning_message}
349    Click Yes Button  ${xpath_select_button_immediate_shutdown_yes}
350    Wait OpenBMC To Become Stable  ${obmc_off_state}
351
352Verify Warning Message Display Text
353    [Documentation]  Verify the warning message display text.
354    [Arguments]  ${xpath_text_message}  ${text_message}
355
356    # xpath_text_message  Xpath of warning message display.
357    # text_message        Content of the display message info.
358
359    Element Text Should Be  ${xpath_text_message}  ${text_message}
360
361
362Expected Initial Test State
363    [Documentation]  Power on the host if "Running" expected, Power off the
364    ...  host if "Off" expected as per the requirement of initial test state.
365    [Arguments]  ${expectedState}
366    # Description of argument(s):
367    # expectedState    Test initial host state.
368
369    Run Keyword If  '${expectedState}' == 'Running'
370    ...  REST Power On  stack_mode=skip  quiet=1
371
372    Run Keyword If  '${expectedState}' == 'Off'
373    ...  REST Power Off  stack_mode=skip  quiet=1
374
375Launch Browser And Login OpenBMC GUI
376    [Documentation]  Launch browser and log into openbmc GUI.
377
378    Open Browser With URL  ${obmc_gui_url}
379    Login OpenBMC GUI  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}
380
381Logout And Close Browser
382    [Documentation]  Logout from openbmc application and close the browser.
383
384    Click Element  //*[text()='Log out']
385    Close Browser
386