1*** Settings ***
2Documentation  This testing requires special setup where SNMP trapd is
3...            configured and installed. For download, installation and
4...            configuration refer http://www.net-snmp.org/.
5
6
7Resource      ../../lib/snmp/resource.robot
8Resource      ../../lib/snmp/redfish_snmp_utils.robot
9Resource      ../../lib/bmc_redfish_resource.robot
10Resource      ../../lib/openbmc_ffdc.robot
11Resource      ../../lib/logging_utils.robot
12
13
14Test Teardown  FFDC On Test Case Fail
15Suite Setup    Suite Setup Execution
16
17
18*** Test Cases ***
19
20Configure SNMP Manager On BMC And Verify
21    [Documentation]  Configure SNMP manager on BMC via Redfish and verify.
22    [Tags]  Configure_SNMP_Manager_On_BMC_And_Verify
23    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
24
25    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  ${HTTP_CREATED}
26
27    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
28
29
30Configure SNMP Manager On BMC With Non-default Port And Verify
31    [Documentation]  Configure SNMP Manager On BMC And Verify.
32    [Tags]  Configure_SNMP_Manager_On_BMC_With_Non_Default_Port_And_Verify
33    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
34
35    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}  ${HTTP_CREATED}
36
37    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
38
39
40Configure SNMP Manager On BMC With Out Of Range Port And Verify
41    [Documentation]  Configure SNMP Manager On BMC with out-of range port and verify.
42    [Tags]  Configure_SNMP_Manager_On_BMC_With_Out_Of_Range_Port_And_Verify
43    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${out_of_range_port}
44
45    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${out_of_range_port}  ${HTTP_BAD_REQUEST}
46
47    ${status}=  Run Keyword And Return Status
48    ...  Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${out_of_range_port}
49
50    Should Be Equal As Strings  ${status}  False
51    ...  msg=BMC is allowing to configure out of range port.
52
53
54Generate Error On BMC And Verify SNMP Trap
55    [Documentation]  Generate error on BMC and verify trap and its fields.
56    [Tags]  Generate_Error_On_BMC_And_Verify_SNMP_Trap
57    [Template]  Create Error On BMC And Verify Trap
58
59    # event_log                 expected_error
60
61    # Generate internal failure error.
62    ${CMD_INTERNAL_FAILURE}     ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
63
64    # Generate timeout error.
65    ${CMD_FRU_CALLOUT}          ${SNMP_TRAP_BMC_CALLOUT_ERROR}
66
67    # Generate informational error.
68    ${CMD_INFORMATIONAL_ERROR}  ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
69
70
71Configure SNMP Manager On BMC With Alpha Port And Verify
72    [Documentation]  Configure SNMP Manager On BMC with alpha port and verify.
73    [Tags]  Configure_SNMP_Manager_On_BMC_With_Alpha_Port_And_Verify
74    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${alpha_port}
75
76    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${alpha_port}  ${HTTP_BAD_REQUEST}
77
78    ${status}=  Run Keyword And Return Status
79    ...  Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${alpha_port}
80
81    Should Be Equal As Strings  ${status}  False
82    ...  msg=BMC is allowing to configure invalid port.
83
84
85Configure SNMP Manager On BMC With Empty Port And Verify
86    [Documentation]  Configure SNMP Manager On BMC with empty port and verify
87    ...  SNMP manager gets configured with default port.
88    [Tags]  Configure_SNMP_Manager_On_BMC_With_Empty_Port_And_Verify
89    [Teardown]  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
90
91    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${empty_port}
92
93    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
94
95
96Configure Multiple SNMP Managers And Verify
97    [Documentation]  Configure multiple SNMP managers and verify.
98    [Tags]  Configure_Multiple_SNMP_Managers_And_Verify
99    [Teardown]  Run Keywords
100    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
101    ...  AND
102    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
103
104    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
105    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
106    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
107    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
108
109
110Generate Error On BMC And Verify SNMP Trap Is Sent To Non-Default Port
111    [Documentation]  Generate error on BMC and verify trap and its fields.
112    [Tags]  Generate_Error_On_BMC_And_Verify_SNMP_Trap_Is_Sent_To_Non-Default_Port
113    [Template]  Create Error On BMC And Verify Trap On Non-Default Port
114
115    # event_log                 expected_error
116
117    # Generate internal failure error.
118    ${CMD_INTERNAL_FAILURE}     ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
119
120    # Generate timeout error.
121    ${CMD_FRU_CALLOUT}          ${SNMP_TRAP_BMC_CALLOUT_ERROR}
122
123    # Generate informational error.
124    ${CMD_INFORMATIONAL_ERROR}  ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
125
126
127Verify SNMP SysUpTime
128    [Documentation]  Verify SNMP SysUpTime.
129    [Tags]  Verify_SNMP_SysUpTime
130
131    Generate Error And Verify System Up Time
132
133
134Verify SNMP SysUpTime On BMC Reboot
135    [Documentation]  Verify SNMP SysUpTime on BMC reboot.
136    [Tags]  Verify_SNMP_SysUpTime_On_BMC_Reboot
137
138    # Reboot BMC to reset system uptime.
139    OBMC Reboot (off)
140
141    ${uptime}=  Generate Error And Verify System Up Time
142
143    # Check if uptime is reset after reboot.
144    Should Be True  ${uptime} <= 1  msg=SNMP SysUpTime is not reset on reboot
145
146
147Configure Multiple SNMP Managers With Non-default Port And Verify
148    [Documentation]  Configure multiple SNMP Managers with non-default port And Verify.
149    [Tags]  Configure_Multiple_SNMP_Managers_With_Non_Default_Port_And_Verify
150    [Teardown]  Run Keywords
151    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
152    ...  AND
153    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
154
155    # Configure multiple SNMP managers with non-default port.
156    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
157    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
158
159    # Verify if SNMP managers are configured.
160    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
161    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
162
163
164Configure Multiple SNMP Managers With Different Ports And Verify
165    [Documentation]  Configure multiple SNMP Managers with different ports And Verify.
166    [Tags]  Configure_Multiple_SNMP_Managers_With_Different_Ports_And_Verify
167    [Teardown]  Run Keywords
168    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
169    ...  AND
170    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
171    ...  AND
172    ...  Delete SNMP Manager Via Redfish  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
173
174    # Configure multiple SNMP managers with different ports.
175    Configure SNMP Manager Via Redfish  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
176    Configure SNMP Manager Via Redfish  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
177    Configure SNMP Manager Via Redfish  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
178
179    # Verify if SNMP managers are configured.
180    Verify SNMP Manager Configured On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
181    Verify SNMP Manager Configured On BMC  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
182    Verify SNMP Manager Configured On BMC  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
183
184
185*** Keywords ***
186
187Suite Setup Execution
188    [Documentation]  Do suite setup execution.
189
190    Redfish.Login
191
192    # Check for SNMP configurations.
193    Valid Value  SNMP_MGR1_IP
194    Valid Value  SNMP_DEFAULT_PORT
195
196
197Generate Error And Verify System Up Time
198    [Documentation]  Generate error and verify system up time.
199
200    # Get system uptime on BMC.
201    # Example output of uptime:
202    # (8055.79 15032.86)
203
204    ${cmd_output}   ${stderr}  ${rc}=  BMC Execute Command  cat /proc/uptime
205    @{times}=  Split String  ${cmd_output}
206
207    ${bmc_uptime_in_minutes}=  Evaluate  int(${times}[0])/60
208
209    ${trap}=  Create Error On BMC And Verify Trap
210
211    # Extract System up time from SNMP trap.
212    # Example - SNMP trap:
213    # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (252367) 0:42:03.67
214    # SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
215    # SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 54
216    # SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque: UInt64: 4622921648578756984
217    # SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
218    # SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING:
219
220    @{words}=  Split String  ${trap}[0]  =
221
222    ${timeticks}=  Fetch From Right  ${words}[1]  (
223    ${snmp_sysuptime}=  Fetch From Left  ${timeticks}  )
224
225    # SNMP SysUptime will be in milli seconds.
226    # Convert into minutes.
227    ${sysuptime_in_minutes}=  Evaluate  int(${snmp_sysuptime})/6000
228
229    Should Be Equal As Integers  ${bmc_uptime_in_minutes}  ${sysuptime_in_minutes}
230
231    [Return]  ${sysuptime_in_minutes}
232