blob: d94cb8ff3e31c8eb88b164b5257f6f50c8398f08 [file] [log] [blame]
Prashanth Katti081b3d92018-06-15 05:13:11 -05001*** Settings ***
2Documentation Utilities for SNMP testing.
3
4Resource ../../lib/rest_client.robot
5Resource ../../lib/utils.robot
6
7*** Keywords ***
8
9Get SNMP URI List
10 [Documentation] Get all SNMP URIs and return them as list.
11
12 # Sample output:
13 # "data": [
14 # "/xyz/openbmc_project/network/snmp/manager/e9767624",
15 # "/xyz/openbmc_project/network/snmp/manager/31f4ce8b"
16 # ],
17
18 @{snmp_uri_list}= Read Properties ${SNMP_MANAGER_URI}
19
George Keishing409df052024-01-17 22:36:14 +053020 RETURN @{snmp_uri_list}
Prashanth Katti081b3d92018-06-15 05:13:11 -050021
22Configure SNMP Manager On BMC
23 [Documentation] Configure SNMP manager on BMC.
24 [Arguments] ${snmp_ip} ${port} ${expected_result}
25
26 # Description of argument(s):
27 # snmp_ip SNMP manager IP.
28 # port Network port where SNMP manager is listening.
29 # expected_result Expected status of SNMP configuration.
30
31 @{snmp_parm_list}= Create List ${snmp_ip} ${port}
Prashanth Katti081b3d92018-06-15 05:13:11 -050032 ${data}= Create Dictionary data=@{snmp_parm_list}
33
34 ${resp}= OpenBMC Post Request
Steven Sombara8800da2018-12-18 16:19:05 -060035 ... ${SNMP_MANAGER_URI}action/Client data=${data}
Prashanth Katti081b3d92018-06-15 05:13:11 -050036
37 Run Keyword If '${expected_result}' == 'error'
38 ... Should Be Equal As Strings
39 ... ${resp.status_code} ${HTTP_BAD_REQUEST}
40 ... msg=Allowing the configuration of an invalid SNMP.
41 ... ELSE
42 ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
43 ... msg=Not allowing the configuration of a valid SNMP.
44
Vijay64a48e22019-05-02 00:21:17 -050045
Prashanth Katti081b3d92018-06-15 05:13:11 -050046Get List Of SNMP Manager And Port Configured On BMC
47 [Documentation] Get list of SNMP managers and return the list.
48
49 @{snmp_uri_list}= Get SNMP URI List
50 @{ip_and_port_list}= Create List
51
52 # Sample output of snmp_uri_list enumeration.
53 # {
54 # "data": {
55 # "/xyz/openbmc_project/network/snmp/manager/92ae7a66": {
56 # "Address": "10.6.6.6",
57 # "AddressFamily": "xyz.openbmc_project.Network.Client.IPProtocol.IPv4",
58 # "Port": 186
59 # },
60
Anves Kumar rayankula322d0fe2020-06-30 07:55:05 -050061 FOR ${snmp_uri} IN @{snmp_uri_list}
62 ${ip}= Read Attribute ${snmp_uri} Address
63 ${port}= Read Attribute ${snmp_uri} Port
64 Append To List ${ip_and_port_list} ${ip} ${port}
65 END
Prashanth Katti081b3d92018-06-15 05:13:11 -050066
George Keishing409df052024-01-17 22:36:14 +053067 RETURN @{ip_and_port_list}
Prashanth Katti081b3d92018-06-15 05:13:11 -050068
Vijay64a48e22019-05-02 00:21:17 -050069
Prashanth Katti081b3d92018-06-15 05:13:11 -050070Verify SNMP Manager
71 [Documentation] Verify SNMP manager configured on BMC.
72 [Arguments] ${snmp_ip} ${port}
73
74 # Description of argument(s):
75 # snmp_ip SNMP manager IP.
76 # port Network port where SNMP manager is listening.
77
78 @{ip_and_port}= Create List ${snmp_ip} ${port}
79
80 @{ip_and_port_list}= Get List Of SNMP Manager And Port Configured On BMC
81
82 List Should Contain Sub List ${ip_and_port_list} ${ip_and_port}
83 ... msg=Valid SNMP manager is not found on BMC.
84
Vijay64a48e22019-05-02 00:21:17 -050085
86Get SNMP Manager Object
87 [Documentation] Find the SNMP object for the given ip and port and return it.
88 # If no object can be located, return ${EMPTY}.
89 [Arguments] ${ip} ${port}
90
91 # Description of argument(s):
92 # ip SNMP manager IP.
93 # port Network port where SNMP manager is listening.
94
95 ${snmp_objs}= Read Properties ${SNMP_MANAGER_URI}enumerate
Marissa Garza9778eb22020-06-30 13:21:07 -050096 FOR ${snmp_obj} IN @{snmp_objs}
97 ${obj}= Set Variable ${snmp_objs['${snmp_obj}']}
98 Run Keyword If
99 ... '${obj['Address']}' == '${ip}' and '${obj['Port']}' == '${port}'
100 ... Return From Keyword ${snmp_obj}
101 END
Vijay64a48e22019-05-02 00:21:17 -0500102
103 Return From Keyword ${EMPTY}
104
105
Prashanth Katti081b3d92018-06-15 05:13:11 -0500106Delete SNMP Manager And Object
107 [Documentation] Delete SNMP manager.
108 [Arguments] ${snmp_ip} ${port}
109
110 # Description of argument(s):
111 # snmp_ip SNMP manager IP.
112 # port Network port where SNMP manager is listening.
113
Vijay64a48e22019-05-02 00:21:17 -0500114 ${snmp_obj}= Get SNMP Manager Object ${snmp_ip} ${port}
Prashanth Katti081b3d92018-06-15 05:13:11 -0500115
116 # If the given IP and port is not configured, return.
117 # Otherwise, delete the IP and object.
118
Vijay64a48e22019-05-02 00:21:17 -0500119 Run Keyword And Return If '${snmp_obj}' == '${EMPTY}'
Prashanth Katti081b3d92018-06-15 05:13:11 -0500120 ... Pass Execution SNMP manager to be deleted is not configured.
121
Vijay64a48e22019-05-02 00:21:17 -0500122 OpenBMC Delete Request ${snmp_obj}
Prashanth Katti081b3d92018-06-15 05:13:11 -0500123
124 # Verify whether deleted SNMP is removed from BMC system.
Vijay64a48e22019-05-02 00:21:17 -0500125 ${status}= Run Keyword And Return Status Verify SNMP Manager
126 ... ${snmp_ip} ${port}
Prashanth Katti081b3d92018-06-15 05:13:11 -0500127 Should Be Equal ${status} ${False} msg=SNMP manager is not deleted.
Naman Navin Hegdebf181332019-06-26 02:08:18 -0500128
129
130Start SNMP Manager
131 [Documentation] Start SNMP listener on the remote SNMP manager.
132
133 Open Connection And Log In ${SNMP_MGR1_USERNAME} ${SNMP_MGR1_PASSWORD}
134 ... alias=snmp_server host=${SNMP_MGR1_IP}
135
136 # The execution of the SNMP_TRAPD_CMD is necessary to cause SNMP to begin
137 # listening to SNMP messages.
138 SSHLibrary.write ${SNMP_TRAPD_CMD} &