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
6Resource        ../../lib/snmp/resource.robot
7Resource        ../../lib/snmp/snmp_utils.robot
8Resource        ../../lib/openbmc_ffdc.robot
9Resource        ../../lib/logging_utils.robot
10
11Library         String
12Library         SSHLibrary
13
14Test Teardown   FFDC On Test Case Fail
15
16Force Tags      BMC_SNMP_Config
17
18*** Variables ***
19
20${CMD_INTERNAL_FAILURE}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
21...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.InternalFailure
22...  xyz.openbmc_project.Logging.Entry.Level.Error 0
23
24${CMD_FRU_CALLOUT}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
25...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.Timeout
26...  xyz.openbmc_project.Logging.Entry.Level.Error 2 "TIMEOUT_IN_MSEC" "5"
27...  "CALLOUT_INVENTORY_PATH" "/xyz/openbmc_project/inventory/system/chassis/motherboard"
28
29${CMD_INFORMATIONAL_ERROR}  busctl call xyz.openbmc_project.Logging /xyz/openbmc_project/logging
30...  xyz.openbmc_project.Logging.Create Create ssa{ss} xyz.openbmc_project.Common.Error.TestError2
31...  xyz.openbmc_project.Logging.Entry.Level.Informational 0
32
33${CMD_DEBUG_TRABALL_ERROR}=  /tmp/tarball/bin/logging-test -c AutoTestSimple
34${SNMP_TRAP_BMC_INTERNAL_FAILURE}  xyz.openbmc_project.Common.Error.InternalFailure
35${SNMP_TRAP_BMC_CALLOUT_ERROR}  xyz.openbmc_project.Common.Error.Timeout
36${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}  xyz.openbmc_project.Common.Error.TestError2
37
38*** Test Cases ***
39Configure SNMP Manager On BMC And Verify
40    [Documentation]  Configure SNMP Manager On BMC And Verify.
41    [Tags]  Configure_SNMP_Manager_On_BMC_And_Verify
42
43    Configure SNMP Manager On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  Valid
44    Verify SNMP Manager  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
45
46    Delete SNMP Manager And Object  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
47
48Configure SNMP Manager On BMC With Non Default Port And Verify
49    [Documentation]  Configure SNMP Manager On BMC And Verify.
50    [Tags]  Configure_SNMP_Manager_On_BMC_With_Non_Default_Port_And_Verify
51
52    Configure SNMP Manager On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}  Valid
53    Verify SNMP Manager  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
54
55    Delete SNMP Manager And Object  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
56
57Configure SNMP Manager On BMC With Out Of Range Port And Verify
58    [Documentation]  Configure SNMP Manager On BMC with out-of range port and verify.
59    [Tags]  Configure_SNMP_Manager_On_BMC_With_Out_Of_Range_Port_And_Verify
60    [Template]  Configure SNMP Manager On BMC
61
62    # SNMP manager IP  Port                  Scenario
63    ${SNMP_MGR1_IP}    ${out_of_range_port}  error
64
65Configure SNMP Manager On BMC With Alpha Port And Verify
66    [Documentation]  Configure SNMP Manager On BMC with alpha port and verify.
67    [Tags]  Configure_SNMP_Manager_On_BMC_With_Alpha_Port_And_Verify
68    [Template]  Configure SNMP Manager On BMC
69
70    # SNMP manager IP  Port           Scenario
71    ${SNMP_MGR1_IP}    ${alpha_port}  error
72
73Configure SNMP Manager On BMC With Negative Port And Verify
74    [Documentation]  Configure SNMP Manager On BMC with negative port and verify.
75    [Tags]  Configure_SNMP_Manager_On_BMC_With_Negative_Port_And_Verify
76    [Template]  Configure SNMP Manager On BMC
77
78    # SNMP manager IP  Port              Scenario
79    ${SNMP_MGR1_IP}    ${negative_port}  error
80
81Configure SNMP Manager On BMC With Empty Port And Verify
82    [Documentation]  Configure SNMP Manager On BMC with empty port and verify.
83    [Tags]  Configure_SNMP_Manager_On_BMC_With_Empty_Port_And_Verify
84    [Template]  Configure SNMP Manager On BMC
85
86    # SNMP manager IP  Port           Scenario
87    ${SNMP_MGR1_IP}    ${empty_port}  error
88
89Configure SNMP Manager On BMC With Out Of Range IP And Verify
90    [Documentation]  Configure SNMP Manager On BMC with out-of range IP and verify.
91    [Tags]  Configure_SNMP_Manager_On_BMC_With_Out_Of_Range_IP_And_Verify
92    [Template]  Configure SNMP Manager On BMC
93
94    # SNMP manager IP   Port                  Scenario
95    ${out_of_range_ip}  ${SNMP_DEFAULT_PORT}  error
96
97Configure Multiple SNMP Managers And Verify
98    [Documentation]  Configure multiple SNMP Managers And Verify.
99    [Tags]  Configure_Multiple_SNMP_Managers_And_Verify
100
101    Configure SNMP Manager On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  Valid
102    Configure SNMP Manager On BMC  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}  Valid
103    Verify SNMP Manager  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
104    Verify SNMP Manager  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
105
106    Delete SNMP Manager And Object  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
107    Delete SNMP Manager And Object  ${SNMP_MGR2_IP}  ${SNMP_DEFAULT_PORT}
108
109Configure Multiple SNMP Managers With Non Default Port And Verify
110    [Documentation]  Configure multiple SNMP Managers with non-default port And Verify.
111    [Tags]  Configure_Multiple_SNMP_Managers_With_Non_Default_Port_And_Verify
112
113    Configure SNMP Manager On BMC  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}  Valid
114    Configure SNMP Manager On BMC  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}  Valid
115    Verify SNMP Manager  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
116    Verify SNMP Manager  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
117
118    Delete SNMP Manager And Object  ${SNMP_MGR1_IP}  ${NON_DEFAULT_PORT1}
119    Delete SNMP Manager And Object  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
120
121Configure Multiple SNMP Managers With Different Ports And Verify
122    [Documentation]  Configure multiple SNMP Managers with different ports And Verify.
123    [Tags]  Configure_Multiple_SNMP_Managers_With_Different_Ports_And_Verify
124
125    Configure SNMP Manager On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  Valid
126    Configure SNMP Manager On BMC  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}  Valid
127    Configure SNMP Manager On BMC  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}  Valid
128
129    Verify SNMP Manager  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
130    Verify SNMP Manager  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
131    Verify SNMP Manager  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
132
133    Delete SNMP Manager And Object  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
134    Delete SNMP Manager And Object  ${SNMP_MGR2_IP}  ${NON_DEFAULT_PORT1}
135    Delete SNMP Manager And Object  ${SNMP_MGR3_IP}  ${NON_DEFAULT_PORT2}
136
137Generate Error On BMC And Verify If Trap Is Sent
138    [Documentation]  Generate Error On BMC And Verify If Trap Is Sent.
139    [Tags]  Generate_Error_On_BMC_And_Verify_If_Trap_Is_Sent
140    [Setup]  Install Tarball
141    [Template]  Create Error On BMC And Verify If Trap Is Sent
142
143    # event_log                   expected_error
144    ${CMD_DEBUG_TRABALL_ERROR}    ${SNMP_TRAP_BMC_ERROR}
145
146Generate Error On BMC And Verify Trap On SNMP
147    [Documentation]  Generate error on bmc and verify trap on SNMP.
148    [Tags]  Generate_Error_On_BMC_And_Verify_Trap_On_SNMP
149    [Template]  Create Error On BMC And Verify If Trap Is Sent
150
151     # event_log                  expected_error
152     ${CMD_INTERNAL_FAILURE}      ${SNMP_TRAP_BMC_INTERNAL_FAILURE}
153     ${CMD_FRU_CALLOUT}           ${SNMP_TRAP_BMC_CALLOUT_ERROR}
154     ${CMD_INFORMATIONAL_ERROR}   ${SNMP_TRAP_BMC_INFORMATIONAL_ERROR}
155
156Configure SNMP Manager With Less Octet IP And Verify
157     [Documentation]  Configure SNMP manager on BMC with less octet IP and verify.
158     [Tags]  Configure_SNMP_Manager_With_Less_Octet_IP_And_Verify
159     [Template]  Configure SNMP Manager On BMC
160
161     # SNMP manager IP   Port                  Scenario
162     10.10.10            ${SNMP_DEFAULT_PORT}  error
163
164Verify SNMP SysUpTime
165    [Documentation]  Verify SNMP SysUpTime.
166    [Tags]  Verify_SNMP_SysUpTime
167
168    Generate Error And Verify System Up Time
169
170
171Verify SNMP SysUpTime On BMC Reboot
172    [Documentation]  Verify SNMP SysUpTime on BMC reboot.
173    [Tags]  Verify_SNMP_SysUpTime_On_BMC_Reboot
174
175    # Reboot BMC to reset system uptime.
176    OBMC Reboot (off)
177
178    ${uptime}=  Generate Error And Verify System Up Time
179
180    # Check if uptime is reset after reboot.
181    Should Be True  ${uptime} <= 1  msg=SNMP SysUpTime is not reset on reboot
182
183
184*** Keywords ***
185
186Create Error On BMC And Verify If Trap Is Sent
187    [Documentation]  Generate error on BMC and verify if trap is sent.
188    [Arguments]  ${event_log}=${CMD_INTERNAL_FAILURE}  ${expected_error}=${SNMP_TRAP_BMC_INTERNAL_FAILURE}
189
190    # Description of argument(s):
191    # event_log                           Event logs to be created.
192    # expected_error                      Expected error on SNMP.
193
194    Configure SNMP Manager On BMC  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}  Valid
195
196    Start SNMP Manager
197    BMC Execute Command  ${event_log}
198    SSHLibrary.Switch Connection  snmp_server
199    ${SNMP_LISTEN_OUT}=  Read  delay=1s
200    Delete SNMP Manager And Object  ${SNMP_MGR1_IP}  ${SNMP_DEFAULT_PORT}
201    SSHLibrary.Execute Command  sudo killall snmptrapd
202    ${lines} =  Split To Lines 	 ${SNMP_LISTEN_OUT}
203    ${trap_info}=  Get From List  ${lines}  -1
204    ${SNMP_TRAP} =  Split String  ${trap_info}  \t
205
206    Should Contain  ${SNMP_TRAP}[0]  DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks:
207    Should Be Equal  ${SNMP_TRAP}[1]  SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
208    Should Match Regexp  ${SNMP_TRAP}[2]  SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: \[0-9]*
209    Should Match Regexp  ${SNMP_TRAP}[3]  SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque: UInt64: \[0-9]*
210    Should Match Regexp  ${SNMP_TRAP}[4]  SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: \[0-9]
211    Should Be Equal  ${SNMP_TRAP}[5]  SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING: "${expected_error}"
212
213    [Return]  ${SNMP_TRAP}
214
215
216Generate Error And Verify System Up Time
217    [Documentation]  Generate error and verify system up time.
218
219    # Get system uptime on BMC.
220    # Example output of uptime:
221    # (8055.79 15032.86)
222
223    ${cmd_output}   ${stderr}  ${rc}=  BMC Execute Command  cat /proc/uptime
224    @{times}=  Split String  ${cmd_output}
225
226    ${bmc_uptime_in_minutes}=  Evaluate  int(${times}[0])/60
227
228    ${trap}=  Create Error On BMC And Verify If Trap Is Sent
229
230    # Extract System up time from SNMP trap.
231    # Example - SNMP trap:
232    # DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (252367) 0:42:03.67
233    # SNMPv2-MIB::snmpTrapOID.0 = OID: SNMPv2-SMI::enterprises.49871.1.0.0.1
234    # SNMPv2-SMI::enterprises.49871.1.0.1.1 = Gauge32: 54
235    # SNMPv2-SMI::enterprises.49871.1.0.1.2 = Opaque: UInt64: 4622921648578756984
236    # SNMPv2-SMI::enterprises.49871.1.0.1.3 = INTEGER: 3
237    # SNMPv2-SMI::enterprises.49871.1.0.1.4 = STRING:
238
239    @{words}=  Split String  ${trap}[0]  =
240
241    ${timeticks}=  Fetch From Right  ${words}[1]  (
242    ${snmp_sysuptime}=  Fetch From Left  ${timeticks}  )
243
244    # SNMP SysUptime will be in milli seconds.
245    # Convert into minutes.
246    ${sysuptime_in_minutes}=  Evaluate  int(${snmp_sysuptime})/6000
247
248    Should Be Equal As Integers  ${bmc_uptime_in_minutes}  ${sysuptime_in_minutes}
249
250    [Return]  ${sysuptime_in_minutes}
251