SNMP Automation.
This change includes:
1. Configuration of SNMP manager with default and non default ports
2. Configuration of Multiple SNMP managers with default and non default ports
3. Deconfigure SNMP manager and delete SNMP rest object
4. Deconfigure multiple SNMP manager and delete SNMP rest objects
5. Configure SNMP manager with invalid IP and invalid port.
This resolves openbmc/openbmc-test-automation#1391
Change-Id: Ic1e2e6f7488b87420b936adf23848f6259654423
Signed-off-by: Prashanth Katti <prkatti1@in.ibm.com>
diff --git a/data/variables.py b/data/variables.py
index 3abaa8b..1986a6b 100644
--- a/data/variables.py
+++ b/data/variables.py
@@ -16,7 +16,8 @@
WATCHDOG_URI = OPENBMC_BASE_URI + 'watchdog/'
TIME_MANAGER_URI = OPENBMC_BASE_URI + 'time/'
NETWORK_MANAGER = OPENBMC_BASE_URI + 'network/'
-
+# SNMP
+SNMP_MANAGER_URI = NETWORK_MANAGER + 'snmp/manager/'
# Sensors base variables.
SENSORS_URI = OPENBMC_BASE_URI + 'sensors/'
diff --git a/lib/snmp/resource.txt b/lib/snmp/resource.txt
new file mode 100644
index 0000000..9ddb262
--- /dev/null
+++ b/lib/snmp/resource.txt
@@ -0,0 +1,23 @@
+*** Variables ***
+
+# SNMP related parameters.
+
+# 10.x.x.x series is a private IP address range and does not exist in
+# our network, so this is chosen to avoid any adversary effect.
+# It can be overridden by command line arguments.
+${SNMP_MGR1_IP} 10.6.6.6
+${SNMP_MGR2_IP} 10.6.6.7
+${SNMP_MGR3_IP} 10.6.6.8
+${out_of_range_ip} 10.6.6.256
+${alpha_ip} xx.xx.xx.xx
+
+# Valid and invalid IP and ports. Valid port range is 0-65535.
+# Default port is 162.
+${SNMP_DEFAULT_PORT} ${162}
+${NON_DEFAULT_PORT1} ${186}
+${NON_DEFAULT_PORT2} ${196}
+${out_of_range_port} ${65536}
+# non numeric value
+${alpha_port} ab
+${negative_port} ${-12}
+${empty_port} ${EMPTY}
diff --git a/lib/snmp/snmp_utils.robot b/lib/snmp/snmp_utils.robot
new file mode 100644
index 0000000..792afa1
--- /dev/null
+++ b/lib/snmp/snmp_utils.robot
@@ -0,0 +1,117 @@
+*** Settings ***
+Documentation Utilities for SNMP testing.
+
+Resource ../../lib/rest_client.robot
+Resource ../../lib/utils.robot
+
+*** Keywords ***
+
+Get SNMP URI List
+ [Documentation] Get all SNMP URIs and return them as list.
+
+ # Sample output:
+ # "data": [
+ # "/xyz/openbmc_project/network/snmp/manager/e9767624",
+ # "/xyz/openbmc_project/network/snmp/manager/31f4ce8b"
+ # ],
+
+ @{snmp_uri_list}= Read Properties ${SNMP_MANAGER_URI}
+
+ [Return] @{snmp_uri_list}
+
+Configure SNMP Manager On BMC
+ [Documentation] Configure SNMP manager on BMC.
+ [Arguments] ${snmp_ip} ${port} ${expected_result}
+
+ # Description of argument(s):
+ # snmp_ip SNMP manager IP.
+ # port Network port where SNMP manager is listening.
+ # expected_result Expected status of SNMP configuration.
+
+ @{snmp_parm_list}= Create List ${snmp_ip} ${port}
+ ... xyz.openbmc_project.Network.Client.IPProtocol.IPv4
+
+ ${data}= Create Dictionary data=@{snmp_parm_list}
+
+ ${resp}= OpenBMC Post Request
+ ... ${SNMP_MANAGER_URI}/action/Client data=${data}
+
+ Run Keyword If '${expected_result}' == 'error'
+ ... Should Be Equal As Strings
+ ... ${resp.status_code} ${HTTP_BAD_REQUEST}
+ ... msg=Allowing the configuration of an invalid SNMP.
+ ... ELSE
+ ... Should Be Equal As Strings ${resp.status_code} ${HTTP_OK}
+ ... msg=Not allowing the configuration of a valid SNMP.
+
+Get List Of SNMP Manager And Port Configured On BMC
+ [Documentation] Get list of SNMP managers and return the list.
+
+ @{snmp_uri_list}= Get SNMP URI List
+ @{ip_and_port_list}= Create List
+
+ # Sample output of snmp_uri_list enumeration.
+ # {
+ # "data": {
+ # "/xyz/openbmc_project/network/snmp/manager/92ae7a66": {
+ # "Address": "10.6.6.6",
+ # "AddressFamily": "xyz.openbmc_project.Network.Client.IPProtocol.IPv4",
+ # "Port": 186
+ # },
+
+ : FOR ${snmp_uri} IN @{snmp_uri_list}
+ \ ${ip}= Read Attribute ${snmp_uri} Address
+ \ ${port}= Read Attribute ${snmp_uri} Port
+ \ Append To List ${ip_and_port_list} ${ip} ${port}
+
+ [Return] @{ip_and_port_list}
+
+Verify SNMP Manager
+ [Documentation] Verify SNMP manager configured on BMC.
+ [Arguments] ${snmp_ip} ${port}
+
+ # Description of argument(s):
+ # snmp_ip SNMP manager IP.
+ # port Network port where SNMP manager is listening.
+
+ @{ip_and_port}= Create List ${snmp_ip} ${port}
+
+ @{ip_and_port_list}= Get List Of SNMP Manager And Port Configured On BMC
+
+ List Should Contain Sub List ${ip_and_port_list} ${ip_and_port}
+ ... msg=Valid SNMP manager is not found on BMC.
+
+Delete SNMP Manager And Object
+ [Documentation] Delete SNMP manager.
+ [Arguments] ${snmp_ip} ${port}
+
+ # Description of argument(s):
+ # snmp_ip SNMP manager IP.
+ # port Network port where SNMP manager is listening.
+
+ @{snmp_uri_list}= Get SNMP URI List
+
+ # Find SNMP object having this IP and port.
+
+ : FOR ${snmp_uri} IN @{snmp_uri_list}
+ \ ${ip}= Read Attribute ${snmp_uri} Address
+ \ ${port1}= Read Attribute ${snmp_uri} Port
+ \ Run Keyword If "${snmp_ip}" == "${ip}" and "${port}" == "${port1}"
+ ... Exit For Loop
+
+ # If the given IP and port is not configured, return.
+ # Otherwise, delete the IP and object.
+
+ Run Keyword And Return If '${snmp_ip}' != '${ip}'
+ ... Pass Execution SNMP manager to be deleted is not configured.
+
+ OpenBMC Delete Request ${snmp_uri}
+
+ # Verify whether deleted SNMP is removed from BMC system.
+ @{ip_and_port}= Create List ${snmp_ip} ${port}
+ @{ip_and_port_list}= Get List Of SNMP Manager And Port Configured On BMC
+
+ ${status}= Run Keyword And Return Status List Should Contain Sub List
+ ... ${ip_and_port_list} ${ip_and_port}
+
+ Should Be Equal ${status} ${False} msg=SNMP manager is not deleted.
diff --git a/snmp/test_bmc_snmp_config.robot b/snmp/test_bmc_snmp_config.robot
new file mode 100644
index 0000000..26912c5
--- /dev/null
+++ b/snmp/test_bmc_snmp_config.robot
@@ -0,0 +1,110 @@
+*** Settings ***
+Documentation This testing require special setup where SNMP trapd is
+... configured and installed. For download, installation and
+... configuration refer http://www.net-snmp.org/.
+
+Resource ../lib/snmp/resource.txt
+Resource ../lib/snmp/snmp_utils.robot
+
+Library String
+Library SSHLibrary
+
+*** Test Cases ***
+Configure SNMP Manager On BMC And Verify
+ [Documentation] Configure SNMP Manager On BMC And Verify.
+ [Tags] Configure_SNMP_Manager_On_BMC_And_Verify
+
+ Configure SNMP Manager On BMC ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT} Valid
+ Verify SNMP Manager ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+
+ Delete SNMP Manager And Object ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+
+Configure SNMP Manager On BMC With Non-default Port And Verify
+ [Documentation] Configure SNMP Manager On BMC And Verify.
+ [Tags] Configure_SNMP_Manager_On_BMC_With_Non_Default_Port_And_Verify
+
+ Configure SNMP Manager On BMC ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1} Valid
+ Verify SNMP Manager ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1}
+
+ Delete SNMP Manager And Object ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1}
+
+Configure SNMP Manager On BMC With Out Of Range Port And Verify
+ # SNMP manager IP Port Scenario
+ ${SNMP_MGR1_IP} ${out_of_range_port} error
+ [Documentation] Configure SNMP Manager On BMC with out-of range port and verify.
+ [Tags] Configure_SNMP_Manager_On_BMC_With_Out_Of_Range_Port_And_Verify
+
+ [Template] Configure SNMP Manager On BMC
+
+Configure SNMP Manager On BMC With Alpha Port And Verify
+ # SNMP manager IP Port Scenario
+ ${SNMP_MGR1_IP} ${alpha_port} error
+ [Documentation] Configure SNMP Manager On BMC with alpha port and verify.
+ [Tags] Configure_SNMP_Manager_On_BMC_With_Alpha_Port_And_Verify
+
+ [Template] Configure SNMP Manager On BMC
+
+Configure SNMP Manager On BMC With Negative Port And Verify
+ # SNMP manager IP Port Scenario
+ ${SNMP_MGR1_IP} ${negative_port} error
+ [Documentation] Configure SNMP Manager On BMC with negative port and verify.
+ [Tags] Configure_SNMP_Manager_On_BMC_With_Negative_Port_And_Verify
+
+ [Template] Configure SNMP Manager On BMC
+
+Configure SNMP Manager On BMC With Empty Port And Verify
+ # SNMP manager IP Port Scenario
+ ${SNMP_MGR1_IP} ${empty_port} error
+ [Documentation] Configure SNMP Manager On BMC with empty port and verify.
+ [Tags] Configure_SNMP_Manager_On_BMC_With_Empty_Port_And_Verify
+
+ [Template] Configure SNMP Manager On BMC
+
+Configure SNMP Manager On BMC With Out Of Range IP And Verify
+ # SNMP manager IP Port Scenario
+ ${out_of_range_ip} ${SNMP_DEFAULT_PORT} error
+ [Documentation] Configure SNMP Manager On BMC with out-of range IP and verify.
+ [Tags] Configure_SNMP_Manager_On_BMC_With_Out_Of_Range_IP_And_Verify
+
+ [Template] Configure SNMP Manager On BMC
+
+Configure Multiple SNMP Managers And Verify
+ [Documentation] Configure multiple SNMP Managers And Verify.
+ [Tags] Configure_Multiple_SNMP_Managers_And_Verify
+
+ Configure SNMP Manager On BMC ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT} Valid
+ Configure SNMP Manager On BMC ${SNMP_MGR2_IP} ${SNMP_DEFAULT_PORT} Valid
+ Verify SNMP Manager ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+ Verify SNMP Manager ${SNMP_MGR2_IP} ${SNMP_DEFAULT_PORT}
+
+ Delete SNMP Manager And Object ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+ Delete SNMP Manager And Object ${SNMP_MGR2_IP} ${SNMP_DEFAULT_PORT}
+
+Configure Multiple SNMP Managers With Non-default Port And Verify
+ [Documentation] Configure multiple SNMP Managers with non-default port And Verify.
+ [Tags] Configure_Multiple_SNMP_Managers_With_Non_Default_Port_And_Verify
+
+ Configure SNMP Manager On BMC ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1} Valid
+ Configure SNMP Manager On BMC ${SNMP_MGR2_IP} ${NON_DEFAULT_PORT1} Valid
+ Verify SNMP Manager ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1}
+ Verify SNMP Manager ${SNMP_MGR2_IP} ${NON_DEFAULT_PORT1}
+
+ Delete SNMP Manager And Object ${SNMP_MGR1_IP} ${NON_DEFAULT_PORT1}
+ Delete SNMP Manager And Object ${SNMP_MGR2_IP} ${NON_DEFAULT_PORT1}
+
+Configure Multiple SNMP Managers With Different Ports And Verify
+ [Documentation] Configure multiple SNMP Managers with different ports And Verify.
+ [Tags] Configure_Multiple_SNMP_Managers_With_Different_Ports_And_Verify
+
+ Configure SNMP Manager On BMC ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT} Valid
+ Configure SNMP Manager On BMC ${SNMP_MGR2_IP} ${NON_DEFAULT_PORT1} Valid
+ Configure SNMP Manager On BMC ${SNMP_MGR3_IP} ${NON_DEFAULT_PORT2} Valid
+
+ Verify SNMP Manager ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+ Verify SNMP Manager ${SNMP_MGR2_IP} ${NON_DEFAULT_PORT1}
+ Verify SNMP Manager ${SNMP_MGR3_IP} ${NON_DEFAULT_PORT2}
+
+ Delete SNMP Manager And Object ${SNMP_MGR1_IP} ${SNMP_DEFAULT_PORT}
+ Delete SNMP Manager And Object ${SNMP_MGR2_IP} ${NON_DEFAULT_PORT1}
+ Delete SNMP Manager And Object ${SNMP_MGR3_IP} ${NON_DEFAULT_PORT2}
+