Prashanth Katti | 391000c | 2021-06-11 04:09:21 -0500 | [diff] [blame] | 1 | Documentation Utility for SNMP configurations via Redfish. |
| 2 | |
| 3 | *** Settings *** |
| 4 | |
| 5 | Resource ../../lib/utils.robot |
| 6 | Resource ../../lib/connection_client.robot |
| 7 | Library ../../lib/gen_misc.py |
| 8 | Library ../../lib/utils.py |
| 9 | |
| 10 | |
| 11 | *** Keywords *** |
| 12 | |
| 13 | Get SNMP Manager List |
| 14 | [Documentation] Get the list of SNMP managers and return IP addresses and ports. |
| 15 | |
| 16 | # Get the list of SNMP manager URIs. |
| 17 | @{snmp_mgr_uris}= Get SNMP Child URIs |
| 18 | |
| 19 | ${snmp_mgr_list}= Create List |
| 20 | |
| 21 | FOR ${snmp_mgr_uri} IN @{snmp_mgr_uris} |
| 22 | # Sample output: |
| 23 | # { |
| 24 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp1", |
| 25 | # "@odata.type": "#EventDestination.v1_7_0.EventDestination", |
| 26 | # "Context": "", |
| 27 | # "Destination": "snmp://xx.xx.xx.xx:162", |
| 28 | # "EventFormatType": "Event", |
| 29 | # "Id": "snmp1", |
| 30 | # "Name": "Event Destination snmp1", |
| 31 | # "Protocol": "SNMPv2c", |
| 32 | # "SubscriptionType": "SNMPTrap" |
| 33 | |
| 34 | ${resp}= Redfish.Get ${snmp_mgr_uri} |
| 35 | ${snmp_mgr}= Get From Dictionary ${resp.dict} Destination |
| 36 | Append To List ${snmp_mgr_list} ${snmp_mgr} |
| 37 | END |
| 38 | |
| 39 | [Return] ${snmp_mgr_list} |
| 40 | |
| 41 | |
| 42 | Configure SNMP Manager Via Redfish |
| 43 | [Documentation] Configure SNMP manager on BMC via Redfish. |
| 44 | [Arguments] ${snmp_mgr_ip} ${snmp_port} ${valid_status_codes}=${HTTP_CREATED} |
| 45 | |
| 46 | # Description of argument(s): |
| 47 | # snmp_mgr_ip SNMP manager IP address |
| 48 | # snmp_port SNMP manager port |
| 49 | # valid_status_code expected code |
| 50 | |
| 51 | ${snmp_mgr_data}= Create Dictionary Destination=snmp://${snmp_mgr_ip}:${snmp_port} |
| 52 | ... SubscriptionType=${snmp_function} Protocol=${snmp_version} |
| 53 | |
| 54 | Redfish.Post ${subscription_uri} body=&{snmp_mgr_data} |
| 55 | ... valid_status_codes=[${valid_status_codes}] |
| 56 | |
| 57 | |
| 58 | Verify SNMP Manager Configured On BMC |
| 59 | [Documentation] Verify SNMP manager configured on BMC. |
| 60 | [Arguments] ${snmp_mgr_ip} ${snmp_port} |
| 61 | |
| 62 | # Description of argument(s): |
| 63 | # snmp_mgr_ip SNMP manager IP address |
| 64 | # snmp_port SNMP manager port |
| 65 | |
| 66 | # Get the list of SNMP managers that are configured on BMC. |
| 67 | @{snmp_mgr_list}= Get SNMP Manager List |
| 68 | |
| 69 | ${snmp_ip_port}= Catenate ${snmp_mgr_ip}:${snmp_port} |
| 70 | |
| 71 | List Should Contain Value ${snmp_mgr_list} snmp://${snmp_ip_port} |
| 72 | ... msg=SNMP manager is not configured. |
| 73 | |
| 74 | |
| 75 | Get SNMP Child URIs |
| 76 | [Documentation] Get the list of all SNMP manager URIs. |
| 77 | |
| 78 | # Sample output of SNMP URI: |
| 79 | # { |
| 80 | # "@odata.id": "/redfish/v1/EventService/Subscriptions", |
| 81 | # "@odata.type": "#EventDestinationCollection.EventDestinationCollection", |
| 82 | # "Members": [ |
| 83 | # { |
| 84 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp6" |
| 85 | # }, |
| 86 | # { |
| 87 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp2" |
| 88 | # }, |
| 89 | # { |
| 90 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp9" |
| 91 | # }, |
| 92 | # { |
| 93 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp1" |
| 94 | # }, |
| 95 | # { |
| 96 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp8" |
| 97 | # }, |
| 98 | # { |
| 99 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp4" |
| 100 | # }, |
| 101 | # { |
| 102 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp7" |
| 103 | # }, |
| 104 | # { |
| 105 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp5" |
| 106 | # }, |
| 107 | # { |
| 108 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp3" |
| 109 | # } |
| 110 | # ], |
| 111 | # "Members@odata.count": 9, |
| 112 | # "Name": "Event Destination Collections" |
| 113 | |
| 114 | # Get the list of child URIs. |
| 115 | @{snmp_mgr_uris}= Redfish.Get Members List ${subscription_uri} filter=snmp |
| 116 | |
| 117 | [Return] ${snmp_mgr_uris} |
Prashanth Katti | dd99a91 | 2021-06-14 09:12:02 -0500 | [diff] [blame] | 118 | |
| 119 | |
| 120 | Delete SNMP Manager Via Redfish |
| 121 | [Documentation] Delete SNMP manager. |
| 122 | [Arguments] ${snmp_mgr_ip} ${snmp_port} |
| 123 | |
| 124 | # Description of argument(s): |
| 125 | # snmp_mgr_ip SNMP manager IP. |
| 126 | # snmp_port Network port where SNMP manager is listening. |
| 127 | |
| 128 | ${is_snmp_found}= Set Variable ${False} |
| 129 | ${snmp_ip_port}= Catenate ${snmp_mgr_ip}:${snmp_port} |
| 130 | |
| 131 | # Get the list of SNMP manager URIs. |
| 132 | @{snmp_mgr_uris}= Get SNMP Child URIs |
| 133 | |
| 134 | # Find the SNMP manager URI that has IP and port configured. |
| 135 | FOR ${snmp_mgr_uri} IN @{snmp_mgr_uris} |
| 136 | # Sample output: |
| 137 | # { |
| 138 | # "@odata.id": "/redfish/v1/EventService/Subscriptions/snmp1", |
| 139 | # "@odata.type": "#EventDestination.v1_7_0.EventDestination", |
| 140 | # "Context": "", |
| 141 | # "Destination": "snmp://xx.xx.xx.xx:162", |
| 142 | # "EventFormatType": "Event", |
| 143 | # "Id": "snmp1", |
| 144 | # "Name": "Event Destination snmp1", |
| 145 | # "Protocol": "SNMPv2c", |
| 146 | # "SubscriptionType": "SNMPTrap" |
| 147 | |
| 148 | # Find the SNMP manager that has matching destination details. |
| 149 | ${snmp_mgr}= Redfish.Get Attribute ${snmp_mgr_uri} Destination |
| 150 | |
| 151 | # Delete the SNMP manager if the requested IP & ports are found |
| 152 | # and mark is_snmp_found to true. |
| 153 | Run Keyword If 'snmp://${snmp_ip_port}' == '${snmp_mgr}' |
| 154 | ... Run Keywords Set Local Variable ${is_snmp_found} ${True} |
| 155 | ... AND Redfish.Delete ${snmp_mgr_uri} |
| 156 | ... AND Exit For Loop |
| 157 | END |
| 158 | |
| 159 | Pass Execution If ${is_snmp_found} == ${False} |
| 160 | ... SNMP Manager: ${snmp_mgr_ip}:${snmp_port} is not configured on BMC |
| 161 | |
| 162 | # Check if the SNMP manager is really deleted from BMC. |
| 163 | ${status}= Run Keyword And Return Status |
| 164 | ... Verify SNMP Manager Configured On BMC ${snmp_mgr_ip} ${snmp_port} |
| 165 | |
| 166 | Should Be Equal ${status} ${False} msg=SNMP manager is not deleted in the backend. |