Prashanth Katti | 081b3d9 | 2018-06-15 05:13:11 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Documentation Utilities for SNMP testing. |
| 3 | |
| 4 | Resource ../../lib/rest_client.robot |
| 5 | Resource ../../lib/utils.robot |
| 6 | |
| 7 | *** Keywords *** |
| 8 | |
| 9 | Get 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 | |
| 20 | [Return] @{snmp_uri_list} |
| 21 | |
| 22 | Configure 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 Katti | 081b3d9 | 2018-06-15 05:13:11 -0500 | [diff] [blame] | 32 | |
| 33 | ${data}= Create Dictionary data=@{snmp_parm_list} |
| 34 | |
| 35 | ${resp}= OpenBMC Post Request |
Steven Sombar | a8800da | 2018-12-18 16:19:05 -0600 | [diff] [blame] | 36 | ... ${SNMP_MANAGER_URI}action/Client data=${data} |
Prashanth Katti | 081b3d9 | 2018-06-15 05:13:11 -0500 | [diff] [blame] | 37 | |
| 38 | Run Keyword If '${expected_result}' == 'error' |
| 39 | ... Should Be Equal As Strings |
| 40 | ... ${resp.status_code} ${HTTP_BAD_REQUEST} |
| 41 | ... msg=Allowing the configuration of an invalid SNMP. |
| 42 | ... ELSE |
| 43 | ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK} |
| 44 | ... msg=Not allowing the configuration of a valid SNMP. |
| 45 | |
| 46 | Get 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 | |
| 61 | : 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 | |
| 66 | [Return] @{ip_and_port_list} |
| 67 | |
| 68 | Verify SNMP Manager |
| 69 | [Documentation] Verify SNMP manager configured on BMC. |
| 70 | [Arguments] ${snmp_ip} ${port} |
| 71 | |
| 72 | # Description of argument(s): |
| 73 | # snmp_ip SNMP manager IP. |
| 74 | # port Network port where SNMP manager is listening. |
| 75 | |
| 76 | @{ip_and_port}= Create List ${snmp_ip} ${port} |
| 77 | |
| 78 | @{ip_and_port_list}= Get List Of SNMP Manager And Port Configured On BMC |
| 79 | |
| 80 | List Should Contain Sub List ${ip_and_port_list} ${ip_and_port} |
| 81 | ... msg=Valid SNMP manager is not found on BMC. |
| 82 | |
| 83 | Delete SNMP Manager And Object |
| 84 | [Documentation] Delete SNMP manager. |
| 85 | [Arguments] ${snmp_ip} ${port} |
| 86 | |
| 87 | # Description of argument(s): |
| 88 | # snmp_ip SNMP manager IP. |
| 89 | # port Network port where SNMP manager is listening. |
| 90 | |
| 91 | @{snmp_uri_list}= Get SNMP URI List |
| 92 | |
| 93 | # Find SNMP object having this IP and port. |
| 94 | |
| 95 | : FOR ${snmp_uri} IN @{snmp_uri_list} |
| 96 | \ ${ip}= Read Attribute ${snmp_uri} Address |
| 97 | \ ${port1}= Read Attribute ${snmp_uri} Port |
| 98 | \ Run Keyword If "${snmp_ip}" == "${ip}" and "${port}" == "${port1}" |
| 99 | ... Exit For Loop |
| 100 | |
| 101 | # If the given IP and port is not configured, return. |
| 102 | # Otherwise, delete the IP and object. |
| 103 | |
| 104 | Run Keyword And Return If '${snmp_ip}' != '${ip}' |
| 105 | ... Pass Execution SNMP manager to be deleted is not configured. |
| 106 | |
| 107 | OpenBMC Delete Request ${snmp_uri} |
| 108 | |
| 109 | # Verify whether deleted SNMP is removed from BMC system. |
| 110 | @{ip_and_port}= Create List ${snmp_ip} ${port} |
| 111 | @{ip_and_port_list}= Get List Of SNMP Manager And Port Configured On BMC |
| 112 | |
| 113 | ${status}= Run Keyword And Return Status List Should Contain Sub List |
| 114 | ... ${ip_and_port_list} ${ip_and_port} |
| 115 | |
| 116 | Should Be Equal ${status} ${False} msg=SNMP manager is not deleted. |