1*** Settings ***
2
3Documentation   Test OpenBMC GUI "SNMP Alerts" sub-menu of "Settings".
4
5Resource        ../../../lib/snmp/redfish_snmp_utils.robot
6Resource        ../../../lib/snmp/resource.robot
7Resource        ../../lib/gui_resource.robot
8Resource        ../../lib/bmc_network_utils.robot
9
10Suite Setup     Suite Setup Execution
11Suite Teardown  Close Browser
12
13
14*** Variables ***
15
16${xpath_snmp_alerts_sub_menu}                     //*[@data-test-id='nav-item-snmp-alerts']
17${xpath_snmp_alerts_heading}                      //h1[text()="SNMP alerts"]
18${xpath_select_all_snmp}                          //*[@data-test-id='snmpAlerts-checkbox-selectAll']
19${xpath_add_destination}                          //button[contains(text(),'Add destination')]
20${xpath_snmp_alert_destination_heading}           //h5[contains(text(),'Add SNMP alert destination')]
21${xpath_ip_address_input_button}                  //*[@data-test-id='snmpAlerts-input-ipAddress']
22${xpath_port_optional_input_button}               //*[@data-test-id='snmpAlerts-input-port']
23${xpath_snmp_add_destination_button}              //*[@data-test-id='snmpAlerts-button-ok']
24${xpath_cancel_button}                            //button[contains(text(),'Cancel')]
25${xpath_delete_button}                            //*[@data-test-id='snmpAlerts-button-deleteRow-undefined']
26${xpath_delete_destination}                       //button[contains(text(),'Delete destination')]
27
28${snmp_page_heading}                              SNMP alerts
29${invalid_port_error}                             Value must be between 0 – 65535
30${invalid_destination_error}                      Error in adding SNMP alert destination
31${invalid_ip_error}                               Field required
32${dns_server}                                     10.10.10.10
33
34
35*** Test Cases ***
36
37Verify Navigation To SNMP Alerts Page
38    [Documentation]  Verify navigation to SNMP alerts page.
39    [Tags]  Verify_Navigation_To_SNMP_Alerts_Page
40
41    Page Should Contain Element  ${xpath_snmp_alerts_heading}
42
43
44Verify Existence Of All Input Boxes In SNMP Alerts Page
45    [Documentation]  Verify existence of all sections in SNMP alerts page.
46    [Tags]  Verify_Existence_Of_All_Input_Boxes_In_SNMP_Alerts_Page
47
48    Page Should Contain Checkbox  ${xpath_select_all_snmp}
49
50
51Verify Existence Of All Buttons In SNMP Alerts Page
52    [Documentation]  Verify existence of all buttons in SNMP alerts page.
53    [Tags]  Verify_Existence_Of_All_Buttons_In_SNMP_Alerts_Page
54
55    Page should Contain Button  ${xpath_add_destination}
56
57
58Verify Existence Of All Fields In Add Destination
59    [Documentation]  Verify existence of all buttons and fields in add destination page.
60    [Tags]  Verify_Existence_Of_All_Fields_In_Add_Destination
61    [Teardown]  Run Keywords  Click Button  ${xpath_cancel_button}  AND
62    ...  Wait Until Keyword Succeeds  10 sec  5 sec
63    ...  Refresh GUI And Verify Element Value  ${xpath_snmp_alerts_heading}  ${snmp_page_heading}
64
65    Click Element  ${xpath_add_destination}
66    Wait Until Page Contains Element  ${xpath_snmp_alert_destination_heading}
67    Page Should Contain Element  ${xpath_ip_address_input_button}
68    Page Should Contain Element  ${xpath_port_optional_input_button}
69    Page Should Contain Element  ${xpath_cancel_button}
70    Page Should Contain Element  ${xpath_snmp_add_destination_button}
71
72
73Configure SNMP Settings On BMC With Non Default Port Via GUI And Verify
74    [Documentation]  Configure SNMP settings on BMC with non default port via GUI and verify.
75    [Tags]  Configure_SNMP_Settings_On_BMC_With_Non_Default_Port_Via_GUI_And_Verify
76    [Teardown]  Delete SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
77
78    Configure SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
79
80    Wait Until Page Contains  ${SNMP_MGR1_IP}  timeout=45s
81
82    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
83
84
85Configure SNMP Settings On BMC Via GUI And Verify
86    [Documentation]  Configure SNMP settings on BMC via GUI and verify.
87    [Tags]  Configure_SNMP_Settings_On_BMC_Via_GUI_And_Verify
88    [Teardown]  Delete SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
89
90    Configure SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
91
92    Wait Until Page Contains  ${SNMP_MGR1_IP}  timeout=45s
93
94    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
95
96
97Configure SNMP Settings On BMC With Empty Port Via GUI And Verify
98    [Documentation]  Configure SNMP settings on BMC with empty port via GUI and verify.
99    [Tags]  Configure_SNMP_Settings_On_BMC_With_Empty_Port_Via_GUI_And_Verify
100    [Teardown]  Delete SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
101
102    Configure SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${empty_port}
103
104    Wait Until Page Contains  ${SNMP_MGR1_IP}  timeout=45s
105
106    # SNMP Manager IP is set with default port number when no port number is provided.
107    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
108
109
110Configure Invalid SNMP Settings On BMC Via GUI And Verify
111
112    [Documentation]  Configure invalid SNMP settings on BMC via GUI and verify.
113    [Tags]  Configure_Invalid_SNMP_Settings_On_BMC_Via_GUI_And_Verify
114    [Template]  Configure SNMP Manager On BMC With Invalid Setting Via GUI And Verify
115
116    # snmp_manager_ip   snmp_manager_port        Expected status
117    ${SNMP_MGR1_IP}     ${out_of_range_port}     ${invalid_port_error}
118    ${SNMP_MGR1_IP}     ${alpha_port}            ${invalid_port_error}
119    ${SNMP_MGR1_IP}     ${negative_port}         ${invalid_port_error}
120    ${SNMP_MGR1_IP}     ${alphanumeric_port}     ${invalid_port_error}
121    ${empty_ip}         ${NON_DEFAULT_PORT1}     ${invalid_ip_error}
122    ${out_of_range_ip}  ${NON_DEFAULT_PORT1}     ${invalid_destination_error}
123    ${alpha_ip}         ${NON_DEFAULT_PORT1}     ${invalid_destination_error}
124    ${negative_ip}      ${NON_DEFAULT_PORT1}     ${invalid_destination_error}
125    ${less_octet_ip}    ${NON_DEFAULT_PORT1}     ${invalid_destination_error}
126
127
128Configure Multiple SNMP Managers On BMC Via GUI And Verify
129    [Documentation]  Configure multiple SNMP managers on BMC via GUI and verify.
130    [Tags]  Configure_Multiple_SNMP_Managers_On_BMC_Via_GUI_And_Verify
131    [Template]  Configure Multiple SNMP Managers On BMC With Valid Port Via GUI And Verify
132
133    # snmp_manager_ip      snmp_port
134    ${SNMP_MGR1_IP}     ${SNMP_DEFAULT_PORT}
135    ${SNMP_MGR2_IP}     ${SNMP_DEFAULT_PORT}
136
137
138Configure Multiple SNMP Managers With Non Default Port Via GUI And Verify
139    [Documentation]  Configure multiple SNMP managers with non-default port via GUI and verify.
140    [Tags]  Configure_Multiple_SNMP_Managers_With_Non_Default_Port_Via_GUI_And_Verify
141    [Template]  Configure Multiple SNMP Managers On BMC With Valid Port Via GUI And Verify
142
143    # snmp_manager_ip      snmp_port
144    ${SNMP_MGR1_IP}     ${NON_DEFAULT_PORT1}
145    ${SNMP_MGR2_IP}     ${NON_DEFAULT_PORT1}
146
147
148Configure Multiple SNMP Managers With Different Ports Via GUI And Verify
149    [Documentation]  Configure multiple SNMP managers with different ports via GUI and verify.
150    [Tags]  Configure_Multiple_SNMP_Managers_With_Different_Ports_Via_GUI_And_Verify
151    [Template]  Configure Multiple SNMP Managers On BMC With Valid Port Via GUI And Verify
152
153    # snmp_manager_ip      snmp_port
154    ${SNMP_MGR1_IP}     ${NON_DEFAULT_PORT1}
155    ${SNMP_MGR2_IP}     ${SNMP_DEFAULT_PORT}
156    ${SNMP_MGR3_IP}     ${NON_DEFAULT_PORT2}
157
158
159Configure Multiple SNMP Managers On BMC Via GUI And Verify Persistency On BMC Reboot
160    [Documentation]  Login GUI SNMP alerts page and
161    ...  add multiple SNMP Managers on BMC via GUI and verify persistency on BMC reboot.
162    [Tags]  Configure_Multiple_SNMP_Managers_On_BMC_Via_GUI_And_Verify_Persistency_On_BMC_Reboot
163    [Teardown]   Run Keywords  Delete SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
164    ...  AND  Delete SNMP Manager Via GUI  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
165
166    Configure SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
167    Wait Until Page Contains  ${SNMP_MGR1_IP}  timeout=45s
168
169    Configure SNMP Manager Via GUI  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
170    Wait Until Page Contains  ${SNMP_MGR2_IP}  timeout=45s
171
172    # Reboot BMC and check persistency SNMP manager.
173    Reboot BMC via GUI
174
175    Suite Setup Execution
176    Wait Until Page Contains  ${snmp_page_heading}  timeout=1min
177
178    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
179    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
180
181
182Configure SNMP Manager Via GUI And Verify SNMP Trap
183    [Documentation]  Login GUI SNMP alerts page and add SNMP manager via GUI
184    ...  and generate error on BMC and verify trap and its fields.
185    [Tags]  Configure_SNMP_Manager_Via_GUI_And_Verify_SNMP_Trap
186    [Template]  Create Error On BMC And Verify Trap On Default Port
187    [Teardown]  Delete SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
188
189    # event_log                 expected_error
190
191    # Generate internal failure error.
192    ${CMD_INTERNAL_FAILURE}     ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
193
194    # Generate timeout error.
195    ${CMD_FRU_CALLOUT}          ${SNMP_TRAP_BMC_CALLOUT_ERROR}
196
197    # Generate informational error.
198    ${CMD_INFORMATIONAL_ERROR}  ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
199
200
201Configure SNMP Manager By Its Hostname Via GUI And Verify
202    [Documentation]  Login GUI SNMP alerts page and add SNMP manager with its hostname
203    ...  via GUI and verify.
204    [Tags]  Configure_SNMP_Manager_By_Its_Hostname_Via_GUI_And_Verify
205
206    Set DNS Server IP
207
208    # Navigate to SNMP page and configure SNMP manager.
209    Click Element  ${xpath_snmp_alerts_sub_menu}
210    Wait Until Keyword Succeeds  30 sec  10 sec  Location Should Contain  snmp-alerts
211
212    Configure SNMP Manager Via GUI  ${SNMP_HOSTNAME}  ${SNMP_DEFAULT_PORT}
213    Wait Until Page Contains  ${HOSTNAME}  timeout=15s
214
215
216*** Keywords ***
217
218Suite Setup Execution
219    [Documentation]  Do test case setup tasks.
220
221    Launch Browser And Login GUI
222
223    Click Element  ${xpath_settings_menu}
224    Click Element  ${xpath_snmp_alerts_sub_menu}
225    Wait Until Keyword Succeeds  30 sec  10 sec  Location Should Contain  snmp-alerts
226    Wait Until Element Is Not Visible   ${xpath_page_loading_progress_bar}  timeout=30
227
228Configure SNMP Manager Via GUI
229    [Documentation]  Configure SNMP manager via GUI.
230    [Arguments]  ${snmp_ip}  ${port}
231
232    # Description of argument(s):
233    # snmp_ip  SNMP manager IP address.
234    # port     SNMP manager port.
235
236    Click Element  ${xpath_add_destination}
237    Wait Until Page Contains Element  ${xpath_snmp_alert_destination_heading}
238    Input Text  ${xpath_ip_address_input_button}  ${snmp_ip}
239    Wait Until Keyword Succeeds  30 sec  5 sec  Get Value  ${xpath_ip_address_input_button}
240    Input Text  ${xpath_port_optional_input_button}  ${port}
241    Click Element  ${xpath_snmp_add_destination_button}
242
243
244Delete SNMP Manager Via GUI
245    [Documentation]  Delete SNMP manager via GUI.
246    [Arguments]  ${snmp_mgr_ip}  ${snmp_mgr_port}
247
248    # Description of argument(s):
249    # snmp_mgr_ip       SNMP manager IP address.
250    # snmp_mgr_port     SNMP manager port.
251
252    Wait Until Page Contains  ${snmp_mgr_ip}  ${snmp_mgr_port}
253    Click Element At Coordinates  ${xpath_select_all_snmp}  0  0
254    Wait Until Keyword Succeeds  30 sec  5 sec  Click Element  ${xpath_delete_button}
255    Wait Until Page Contains  Delete SNMP alert destination
256    Click Element  ${xpath_delete_destination}
257    Wait Until Page Contains  Successfully deleted SNMP alert destination  timeout=45s
258    Wait Until Keyword Succeeds  30 sec  10 sec  Refresh GUI And Verify Element Value
259    ...  ${xpath_snmp_alerts_heading}  ${snmp_page_heading}
260
261
262Configure SNMP Manager On BMC With Invalid Setting Via GUI And Verify
263
264    [Documentation]  Configure SNMP manager on BMC with invalid setting via GUI and verify.
265    [Arguments]  ${snmp_manager_ip}  ${snmp_manager_port}  ${expected_error}
266    [Teardown]  Close Add SNMP Alerts Destination Window  ${expected_error}
267
268    # Description of argument(s):
269    # snmp_manager_ip     SNMP manager IP address.
270    # snmp_manager_port   SNMP manager port.
271    # expected_error      Expected error optionally provided in testcase
272    # ....                (e.g. Invalid format / Value must be between 0 – 65535).
273
274    Configure SNMP Manager Via GUI  ${snmp_manager_ip}  ${snmp_manager_port}
275    Wait Until Page Contains   ${expected_error}
276    ${status}=  Run Keyword And Return Status
277    ...  Verify SNMP Manager Configured On BMC  ${snmp_manager_ip}  ${snmp_manager_port}
278    Should Be Equal As Strings  ${status}  False
279    ...  msg=BMC is allowing to configure with invalid SNMP settings.
280
281
282Configure Multiple SNMP Managers On BMC With Valid Port Via GUI And Verify
283    [Documentation]  Configure multiple SNMP managers on BMC with valid port value via GUI and verify.
284    [Arguments]  ${snmp_ip_value}  ${snmp_port_value}
285    [Teardown]  Delete SNMP Manager Via GUI  ${snmp_ip_value}  ${snmp_port_value}
286
287    # Description of argument(s):
288    # snmp_ip_value     SNMP manager IP address.
289    # snmp_port_value   SNMP manager port.
290
291    Configure SNMP Manager Via GUI  ${snmp_ip_value}  ${snmp_port_value}
292    Verify SNMP Manager Configured On BMC  ${snmp_ip_value}  ${snmp_port_value}
293
294
295Create Error On BMC And Verify Trap On Default Port
296    [Documentation]  Generate error on BMC and verify if trap is sent to default port.
297    [Arguments]  ${event_log}=${CMD_INTERNAL_FAILURE}  ${expected_error}=${SNMP_TRAP_BMC_INTERNAL_FAILURE}
298
299    # Description of argument(s):
300    # event_log       Event logs to be created.
301    # expected_error  Expected error on SNMP.
302
303    Configure SNMP Manager Via GUI  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
304
305    Start SNMP Manager
306
307    # Generate error log.
308    BMC Execute Command  ${event_log}
309
310    SSHLibrary.Switch Connection  snmp_server
311    ${SNMP_LISTEN_OUT}=  Read  delay=1s
312
313    # Stop SNMP manager process.
314    SSHLibrary.Execute Command  sudo killall snmptrapd
315
316    # Sample SNMP trap:
317    # 2021-06-16 07:05:29 xx.xx.xx.xx [UDP: [xx.xx.xx.xx]:58154->[xx.xx.xx.xx]:xxx]:
318    # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (2100473) 5:50:04.73
319    #   SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
320    #  SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 369    SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque:
321    # UInt64: 1397718405502468474     SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
322    #      SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING: "xxx.xx.xx Failure"
323
324    ${lines}=  Split To Lines  ${SNMP_LISTEN_OUT}
325    ${trap_info}=  Get From List  ${lines}  -1
326    ${snmp_trap}=  Split String  ${trap_info}  \t
327
328    Verify SNMP Trap  ${snmp_trap}  ${expected_error}
329
330
331Close Add SNMP Alerts Destination Window
332    [Documentation]  Close Add SNMP Alerts Destination window.
333    [Arguments]  ${expected_error}=${invalid_port_error}
334
335    # Description of argument(s):
336    # expected_error  Expected error on SNMP alerts page.
337
338    Run Keyword If  '${expected_error}' == '${invalid_port_error}'
339    ...  Click Element  ${xpath_cancel_button}
340    ...  ELSE IF  '${expected_error}' == '${invalid_ip_error}'
341    ...  Click Element  ${xpath_cancel_button}
342
343
344Set DNS Server IP
345    [Documentation]  Add static DNS IP.
346
347    Click Element  ${xpath_network_sub_menu}
348    Wait Until Keyword Succeeds  30 sec  10 sec  Location Should Contain  network
349
350    Add DNS Servers And Verify  ${dns_server}
351