1*** Settings ***
2
3Documentation    Test OpenBMC GUI "Policies" sub-menu of "Security and Access" menu.
4
5Resource         ../../lib/gui_resource.robot
6Resource         ../lib/ipmi_client.robot
7Resource         ../lib/protocol_setting_utils.robot
8Resource         ../lib/common_utils.robot
9Suite Setup      Run Keywords  Launch Browser And Login GUI  AND  Redfish.Login
10Suite Teardown   Close Browser
11Test Setup       Test Setup Execution
12
13
14*** Variables ***
15
16
17${xpath_policies_heading}                     //h1[text()="Policies"]
18${xpath_bmc_ssh_toggle}                       //*[@data-test-id='policies-toggle-bmcShell']
19...  /following-sibling::label
20${xpath_network_ipmi_toggle}                  //*[@data-test-id='polices-toggle-networkIpmi']
21...  /following-sibling::label
22${xpath_host_tpm_toggle}                      //input[@id='host-tpm-policy']
23${xpath_virtual_tpm_toggle}                   //*[@data-test-id='policies-toggle-vtpm']
24${xpath_rtad_toggle}                          //*[@data-test-id='policies-toggle-rtad']
25${xpath_usb_firmware_update_policy_toggle}    //*[@data-test-id='policies-toggle-usbFirmwareUpdatePolicy']
26${xpath_secure_version_lockin_toggle}         //*[@data-test-id='policies-toggle-svle']
27${xpath_host_usb_enablement_toggle}           //*[@data-test-id='policies-toggle-hostUsb']
28
29
30*** Test Cases ***
31
32Verify Navigation To Policies Page
33    [Documentation]  Verify navigation to policies page.
34    [Tags]  Verify_Navigation_To_Policies_Page
35
36    Page Should Contain Element  ${xpath_policies_heading}
37
38
39Verify Existence Of All Sections In Policies Page
40    [Documentation]  Verify existence of all sections in policies page.
41    [Tags]  Verify_Existence_Of_All_Sections_In_Policies_Page
42
43    Page Should Contain  BMC shell (via SSH)
44    Page Should Contain  Network IPMI (out-of-band IPMI)
45    Page Should Contain  Host TPM
46    Page Should Contain  VirtualTPM
47    Page Should Contain  RTAD
48    Page Should Contain  USB firmware update policy
49    Page Should Contain  Secure version lock-in
50    Page Should Contain  Host USB enablement
51
52
53Verify Existence Of All Buttons In Policies Page
54    [Documentation]  Verify existence of All Buttons in policies page.
55    [Tags]  Verify_Existence_Of_All_Buttons_In_Policies_Page
56
57    Page Should Contain Element  ${xpath_bmc_ssh_toggle}
58    Page Should Contain Element  ${xpath_network_ipmi_toggle}
59    Page Should Contain Element  ${xpath_host_tpm_toggle}
60    Page Should Contain Element  ${xpath_virtual_tpm_toggle}
61    Page Should Contain Element  ${xpath_rtad_toggle}
62    Page Should Contain Element  ${xpath_usb_firmware_update_policy_toggle}
63    Page Should Contain Element  ${xpath_secure_version_lockin_toggle}
64    Page Should Contain Element  ${xpath_host_usb_enablement_toggle}
65
66
67Enable SSH Via GUI And Verify
68    [Documentation]  Login to GUI Policies page,enable SSH toggle and
69    ...  verify that SSH to BMC starts working after enabling SSH.
70    [Tags]  Enable_SSH_Via_GUI_And_Verify
71
72    Set Policy Via GUI  SSH  Enabled
73    Wait Until Keyword Succeeds  ${NETWORK_TIMEOUT}  ${NETWORK_RETRY_TIME}  Open Connection And Login
74
75
76Disable SSH Via GUI And Verify
77    [Documentation]  Login to GUI Policies page,disable SSH and
78    ...  verify that SSH to BMC stops working after disabling SSH.
79    [Tags]  Disable_SSH_Via_GUI_And_Verify
80    [Teardown]  Run Keywords  Enable SSH Protocol  ${True}  AND
81    ...  Wait Until Keyword Succeeds  30 sec  15 sec  Open Connection And Login
82
83    Set Policy Via GUI  SSH  Disabled
84
85    ${status}=  Run Keyword And Return Status
86    ...  Open Connection And Login
87
88    Should Be Equal As Strings  ${status}  False
89    ...  msg=SSH login still working after disabling SSH.
90
91
92Disable IPMI Via GUI And Verify
93    [Documentation]  Login to GUI Policies page,disable IPMI and
94    ...  verify that IPMI command does not work after disabling IPMI.
95    [Tags]  Disable_IPMI_Via_GUI_And_Verify
96
97    Set Policy Via GUI  IPMI  Disabled
98
99    ${status}=  Run Keyword And Return Status
100    ...  Wait Until Keyword Succeeds  ${NETWORK_TIMEOUT}  ${NETWORK_RETRY_TIME}
101    ...  Run IPMI Standard Command  sel info
102
103    Should Be Equal As Strings  ${status}  False
104    ...  msg=IPMI command is working after disabling IPMI.
105
106
107Enable IPMI Via GUI And Verify
108    [Documentation]  Login to GUI Policies page,enable IPMI and
109    ...  verify that IPMI command works after enabling IPMI.
110    [Tags]  Enable_IPMI_Via_GUI_And_Verify
111
112    Set Policy Via GUI  IPMI  Enabled
113    Wait Until Keyword Succeeds  ${NETWORK_TIMEOUT}  ${NETWORK_RETRY_TIME}
114    ...  Run IPMI Standard Command  sel info
115
116
117Enable SSH Via GUI And Verify Persistency On BMC Reboot
118    [Documentation]  Login to GUI Policies page,enable SSH and
119    ...  verify persistency of SSH connection on BMC reboot.
120    [Tags]  Enable_SSH_Via_GUI_And_Verify_Persistency_On_BMC_Reboot
121
122    Set Policy Via GUI  SSH  Enabled
123
124    Reboot BMC via GUI
125
126    Wait Until Keyword Succeeds  5 min  30 sec  Open Connection And Login
127
128
129Enable IPMI Via GUI And Verify Persistency On BMC Reboot
130    [Documentation]  Login to GUI Policies page,enable IPMI and
131    ...  verify persistency of IPMI command work on BMC reboot.
132    [Tags]  Enable_IPMI_Via_GUI_And_Verify_Persistency_On_BMC_Reboot
133
134    Set Policy Via GUI  IPMI  Enabled
135
136    Reboot BMC via GUI
137
138    Wait Until Keyword Succeeds  2 min  30 sec  Run IPMI Standard Command  sel info
139
140
141Disable SSH Via GUI And Verify Persistency On BMC Reboot
142    [Documentation]  Login to GUI Policies page,disable SSH and
143    ...  verify that SSH to BMC stops working after disabling SSH on BMC reboot.
144    [Tags]  Disable_SSH_Via_GUI_And_Verify_Persistency_On_BMC_Reboot
145    [Teardown]  Run Keywords  Wait Until Keyword Succeeds  2 min  15 sec  Enable SSH Protocol  ${True}
146    ...  AND  Wait Until Keyword Succeeds  2 min  15 sec  Open Connection And Login
147
148    Set Policy Via GUI  SSH  Disabled
149
150    Reboot BMC via GUI
151
152    ${status}=  Run Keyword And Return Status
153    ...  Wait Until Keyword Succeeds  ${NETWORK_TIMEOUT}  ${NETWORK_RETRY_TIME}  Open Connection And Login
154
155    Should Be Equal As Strings  ${status}  False
156    ...  msg=SSH login still working after disabling SSH.
157
158
159Disable IPMI Via GUI And Verify Persistency On BMC Reboot
160    [Documentation]  Login to GUI Policies page,disable IPMI and
161    ...  verify persistency of IPMI command does not work on BMC reboot.
162    [Tags]  Disable_IPMI_Via_GUI_And_Verify_Persistency_On_BMC_Reboot
163    [Teardown]  Run Keywords  Wait Until Keyword Succeeds  2 min  15 sec  Enable IPMI Protocol  ${True}
164    ...  AND  Wait Until Keyword Succeeds  2 min  15 sec  Run IPMI Standard Command  sel info
165
166    Set Policy Via GUI  IPMI  Disabled
167
168    Reboot BMC via GUI
169
170    ${status}=  Run Keyword And Return Status
171    ...  Wait Until Keyword Succeeds  ${NETWORK_TIMEOUT}  ${NETWORK_RETRY_TIME}
172    ...  Run IPMI Standard Command  sel info
173
174    Should Be Equal As Strings  ${status}  False
175    ...  msg=IPMI command is working after disabling IPMI.
176
177
178Configure SSH And IPMI Settings Via GUI And Verify
179    [Documentation]  Login to GUI Policies page,set SSH and IPMI toggle and
180    ...  verify SSH & IPMI after the settings.
181    [Tags]  Configure_SSH_And_IPMI_Settings_Via_GUI_And_Verify
182    [Setup]  Fetch IPMI And SSH Settings
183    [Template]  Set SSH And IPMI State Via GUI
184    [Teardown]  Set SSH And IPMI State Via GUI  ${initial_ssh_setting}  ${initial_ipmi_setting}
185
186    # ssh_state     ipmi_state
187    Enabled         Enabled
188    Disabled        Disabled
189    Enabled         Disabled
190    Disabled        Enabled
191
192
193Configure SSH And IPMI Settings Via GUI And Verify Its Persistency
194    [Documentation]  Login to GUI Policies page,set SSH and IPMI toggle and
195    ...  verify SSH & IPMI settings after BMC reboot.
196    [Tags]  Configure_SSH_And_IPMI_Settings_Via_GUI_And_Verify_Its_Persistency
197    [Setup]  Fetch IPMI And SSH Settings
198    [Template]  Set SSH And IPMI State Via GUI
199    [Teardown]  Set SSH And IPMI State Via GUI  ${initial_ssh_setting}  ${initial_ipmi_setting}
200
201    # ssh_state     ipmi_state   persistency_check
202    Enabled         Enabled      True
203    Disabled        Disabled     True
204    Enabled         Disabled     True
205    Disabled        Enabled      True
206
207
208*** Keywords ***
209
210Test Setup Execution
211    [Documentation]  Do test case setup tasks.
212
213    Wait Until Keyword Succeeds  30 sec  15 sec  Click Element  ${xpath_secuity_and_accesss_menu}
214    Click Element  ${xpath_policies_sub_menu}
215    Wait Until Keyword Succeeds  30 sec  15 sec  Location Should Contain  policies
216    Wait Until Element Is Not Visible   ${xpath_page_loading_progress_bar}  timeout=1min
217
218Set Policy Via GUI
219
220    [Documentation]  Login to GUI Policies page and set policy.
221    [Arguments]  ${policy}  ${state}
222
223    # Description of argument(s):
224    # policy   policy to be set(e.g. SSH, IPMI).
225    # state    state to be set(e.g. Enable, Disable).
226
227    ${opposite_state_gui}  ${opposite_state_redfish}=  Run Keyword If
228    ...  '${state}' == 'Enabled'  Set Variable  Disabled  ${False}
229    ...  ELSE IF  '${state}' == 'Disabled'  Set Variable  Enabled  ${True}
230
231    # Setting policy to an opposite value via Redfish.
232    Run Keyword If  '${policy}' == 'SSH'
233    ...  Enable SSH Protocol  ${opposite_state_redfish}
234    ...  ELSE IF  '${policy}' == 'IPMI'
235    ...  Enable IPMI Protocol  ${opposite_state_redfish}
236
237    ${policy_toggle_button}=  Run Keyword If  '${policy}' == 'SSH'
238    ...  Set variable  ${xpath_bmc_ssh_toggle}
239    ...  ELSE IF  '${policy}' == 'IPMI'
240    ...  Set variable  ${xpath_network_ipmi_toggle}
241
242    Wait Until Keyword Succeeds  1 min  30 sec
243    ...  Refresh GUI And Verify Element Value  ${policy_toggle_button}  ${opposite_state_gui}
244    Click Element  ${policy_toggle_button}
245
246    # Wait for GUI to reflect policy status.
247    Wait Until Keyword Succeeds  1 min  30 sec
248    ...  Refresh GUI And Verify Element Value  ${policy_toggle_button}  ${state}
249
250
251Verify Policy State
252    [Documentation]  Verify if the current SSH and IPMI setting matches with
253    ...  given values.
254
255    # Verify SSH state value.
256    ${status}=  Run Keyword And Return Status
257    ...  Open Connection And Login
258
259    Run Keyword If  '${status}' == 'True'
260    ...  Element Text Should Be  ${xpath_bmc_ssh_toggle}  Enabled
261    ...  ELSE IF  '${status}' == 'False'
262    ...  Element Text Should Be  ${xpath_bmc_ssh_toggle}  Disabled
263
264    # Verify IPMI state value.
265    ${status}=  Run Keyword And Return Status
266    ...  Wait Until Keyword Succeeds  ${NETWORK_TIMEOUT}  ${NETWORK_RETRY_TIME}
267    ...  Run IPMI Standard Command  sel info
268
269    Run Keyword If  '${status}' == 'True'
270    ...  Element Text Should Be  ${xpath_network_ipmi_toggle}  Enabled
271    ...  ELSE IF  '${status}' == 'False'
272    ...  Element Text Should Be  ${xpath_network_ipmi_toggle}  Disabled
273
274
275Set SSH And IPMI State Via GUI
276    [Documentation]  Set SSH and IPMI states via GUI.
277    [Arguments]  ${ssh_state}  ${ipmi_state}  ${persistency_check}=${False}
278
279    # Description of argument(s):
280    # ssh_state     State of SSH to be set (e.g. Enabled, Disabled).
281    # ipmi_state    State of IPMI to be set (e.g. Enabled, Disabled).
282
283    ${current_ssh_state}=  Get Text  ${xpath_bmc_ssh_toggle}
284
285    Run Keyword If  '${ssh_state}' == '${current_ssh_state}'
286    # When SSH state is already set to given value, click SSH toggle
287    # button twice to reset SSH value back to its original value.
288    ...  Run Keywords  Click Element  ${xpath_bmc_ssh_toggle}
289    ...  AND  Click Element  ${xpath_bmc_ssh_toggle}
290    ...  ELSE IF  '${ssh_state}' != '${current_ssh_state}'
291    ...  Click Element  ${xpath_bmc_ssh_toggle}
292
293    ${current_ipmi_state}=  Get Text  ${xpath_network_ipmi_toggle}
294
295    Run Keyword If  '${ipmi_state}' == '${current_ipmi_state}'
296    # When IPMI state is already set to given value, click IPMI toggle
297    # button twice to reset IPMI value back to its original value.
298    ...  Run Keywords  Click Element  ${xpath_network_ipmi_toggle}
299    ...  AND  Click Element  ${xpath_network_ipmi_toggle}
300    ...  ELSE IF  '${ipmi_state}' != '${current_ipmi_state}'
301    ...  Click Element  ${xpath_network_ipmi_toggle}
302
303    Run Keyword If  ${persistency_check} == ${True}
304    ...  Run Keywords  Reboot BMC via GUI  AND  Test Setup Execution
305
306    Wait Until Keyword Succeeds  30 sec  15 sec  Verify Policy State
307
308
309Fetch IPMI And SSH Settings
310    [Documentation]  Note down the initial states of SSH and IPMI.
311
312    Test Setup Execution
313    ${initial_ssh_setting}=  Get Text  ${xpath_bmc_ssh_toggle}
314    Set Suite Variable  ${initial_ssh_setting}
315    ${initial_ipmi_setting}=  Get Text  ${xpath_network_ipmi_toggle}
316    Set Suite Variable  ${initial_ipmi_setting}
317