openbmctool network testing- IP configuration

Resolve openbmc/openbmc-test-automation#1896

Change-Id: I2d9eb56dac7e16757e5cae335d7e5aa16a6a52c9
Signed-off-by: Naman Navin Hegde <nhegde89@in.ibm.com>
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index b044612..9b3605f 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -257,3 +257,61 @@
     ${data}=  Create Dictionary  HostName=${hostname}
     Redfish.patch  ${REDFISH_NW_PROTOCOL_URI}  body=&{data}
 
+
+Verify IP On BMC
+    [Documentation]  Verify IP on BMC.
+    [Arguments]  ${ip}
+
+    # Description of argument(s):
+    # ip  IP address to be verified (e.g. "10.7.7.7").
+
+    # Get IP address details on BMC using IP command.
+    @{ip_data}=  Get BMC IP Info
+    Should Contain Match  ${ip_data}  ${ip}/*
+    ...  msg=IP address does not exist.
+
+
+Verify Gateway On BMC
+    [Documentation]  Verify gateway on BMC.
+    [Arguments]  ${gateway_ip}=0.0.0.0
+
+    # Description of argument(s):
+    # gateway_ip  Gateway IP address.
+
+    ${route_info}=  Get BMC Route Info
+
+    # If gateway IP is empty or 0.0.0.0 it will not have route entry.
+
+    Run Keyword If  '${gateway_ip}' == '0.0.0.0'
+    ...      Pass Execution  Gateway IP is "0.0.0.0".
+    ...  ELSE
+    ...      Should Contain  ${route_info}  ${gateway_ip}
+    ...      msg=Gateway IP address not matching.
+
+
+Get BMC DNS Info
+    [Documentation]  Get system DNS info.
+
+
+    # Sample output of "resolv.conf":
+    # ### Generated manually via dbus settings ###
+    # nameserver 8.8.8.8
+
+    ${cmd_output}  ${stderr}  ${rc}=  BMC Execute Command
+    ...  cat /etc/resolv.conf
+
+    [Return]  ${cmd_output}
+
+
+CLI Get Nameservers
+    [Documentation]  Get the nameserver IPs from /etc/resolv.conf and return as a list.
+
+    # Example of /etc/resolv.conf data:
+    # nameserver x.x.x.x
+    # nameserver y.y.y.y
+
+    ${stdout}  ${stderr}  ${rc}=  BMC Execute Command  egrep nameserver /etc/resolv.conf | cut -f2- -d ' '
+    ${nameservers}=  Split String  ${stdout}
+
+    [Return]  ${nameservers}
+
diff --git a/openpower/tests_openbmctool/test_openbmctool_network.robot b/openpower/tests_openbmctool/test_openbmctool_network.robot
new file mode 100644
index 0000000..427f42c
--- /dev/null
+++ b/openpower/tests_openbmctool/test_openbmctool_network.robot
@@ -0,0 +1,165 @@
+*** Settings ***
+Documentation  Verify OBMC tool's network fuctionality.
+
+
+Library                 String
+Library                 OperatingSystem
+Library                 ../../lib/gen_print.py
+Library                 ../../lib/gen_robot_print.py
+Library                 ../../lib/openbmctool_utils.py
+Library                 ../../lib/gen_misc.py
+Library                 ../../lib/gen_robot_valid.py
+Resource                ../../syslib/utils_os.robot
+Resource                ../../lib/resource.robot
+Resource                ../../lib/bmc_network_utils.robot
+Resource                ../../lib/utils.robot
+Resource                ../../lib/common_utils.robot
+
+
+Suite Setup             Suite Setup Execution
+Test Setup              Printn
+
+*** Variables ***
+
+${ip}                   10.5.5.5
+${dns_ip}               10.10.10.10
+${domain_name}          randomName.com
+${parser}               |grep "ipv4"|awk -F/ 'NR==1{print$5}'
+${ignore_err}           ${0}
+
+
+*** Test Cases ***
+
+Verify GetIP
+     [Documentation]  Verify that openbmctool.py can run the getIP command.
+     [Tags]  Verify_GetIP
+
+     ${ip_records}=  Network  getIP  I=eth0
+     ${addresses}=  Nested Get  Address  ${ip_records}
+
+     Verify IP On BMC  ${addresses}[${0}]
+
+
+Verify AddIP
+    [Documentation]  Verify that openbmctool.py can run the addIP command.
+    [Tags]  Verify_AddIP
+
+    Network  addIP  I=${interface}  a=${ip}  l=24  p=ipv4
+
+    Wait And Verify IP On BMC  ${ip}
+
+
+Verify GetDefaultGW
+    [Documentation]  Verify that openbmctool.py can run the getDefaultGW command.
+    [Tags]  Verify_GetDefaultGW
+
+    ${default_gw}=  Network  getDefaultGW
+
+    Verify Gateway On BMC  ${default_gw}
+
+
+Verify RemoveIP
+    [Documentation]  Verify that openbmctool.py can run the rmIP command.
+    [Tags]  Verify_RemoveIP
+
+    Network  addIP  I=${interface}  a=${ip}  l=24  p=ipv4
+    Wait And Verify IP On BMC  ${ip}
+
+    Network  rmIP  I=${interface}  a=${ip}
+
+    ${status}=  Run Keyword And Return Status  Wait And Verify IP On BMC  ${ip}
+    Should Be Equal  ${status}  ${False}
+
+
+Verify SetDNS
+     [Documentation]  Verify that openbmctool.py can run the setDNS command.
+     [Tags]  Verify_SetDNS
+
+     Network  setDNS  I=eth0  d=${dns_ip}
+     ${dns_config}=  CLI Get Nameservers
+
+     Should Contain  ${dns_config}  ${dns_ip}
+
+
+Verify GetDNS
+     [Documentation]  Verify that openbmctool.py can run the getDNS command.
+     [Tags]  Verify_GetDNS
+
+     Network  setDNS  I=eth0  d=${dns_ip}
+     ${dns_data}=  Network  getDNS  I=eth0
+     ${dns_config}=  CLI Get Nameservers
+
+     Should Contain  ${dns_config}  ${dns_data}[${0}]
+
+
+Verify SetHostName
+     [Documentation]  Verify that openbmctool.py can run the setHostName command.
+     [Tags]  Verify_SetHostName
+
+     Network  setHostName  H=randomName
+     ${bmc_hostname}=  Get BMC Hostname
+
+     Should Be Equal As Strings  ${bmc_hostname}  randomName
+
+
+Verify GetHostName
+     [Documentation]  Verify that openbmctool.py can run the getHostName command.
+     [Tags]  Verify_GetHostName
+
+     ${tool_hostname}=  Network  getHostName
+     ${bmc_hostname}=  Get BMC Hostname
+
+     Should Be Equal As Strings  ${bmc_hostname}  ${tool_hostname}
+
+
+*** Keywords ***
+
+Suite Setup Execution
+    [Documentation]  Verify connectivity to run openbmctool commands.
+
+    Valid Value  OPENBMC_HOST
+    Valid Value  OPENBMC_USERNAME
+    Valid Value  OPENBMC_PASSWORD
+
+    # Verify connectivity to the BMC host.
+    ${bmc_version}=  Get BMC Version
+
+    # Verify can find the openbmctool.
+    ${openbmctool_file_path}=  which  openbmctool.py
+    Printn
+    Rprint Vars  openbmctool_file_path
+
+    # Get the version number from openbmctool.
+    ${openbmctool_version}=  Get Openbmctool Version
+
+    ${rc}  ${res}=  Openbmctool Execute Command  network view-config${parser}
+    Set Suite Variable  ${interface}  ${res.strip()}
+
+    Rprint Vars  openbmctool_version  OPENBMC_HOST  bmc_version[1]
+
+
+Validate Non Existence Of IP On BMC
+    [Documentation]  Verify that IP address is not present in set of IP addresses.
+    [Arguments]  ${ip_address}  ${ip_data}
+
+    # Description of argument(s):
+    # ip_address  IP address to check (e.g. xx.xx.xx.xx).
+    # ip_data     Set of the IP addresses present.
+
+    Should Not Contain Match  ${ip_data}  ${ip_address}/*
+    ...  msg=${ip_address} found in the list provided.
+
+
+Wait And Verify IP On BMC
+    [Documentation]  Wait and verify if system IP exists.
+    [Arguments]  ${ip}
+
+    # Description of argument(s):
+    # ip  IP address to verify (e.g. xx.xx.xx.xx).
+
+    # Note:Network restart takes around 15-18s after network-config with openbmctool.
+
+    Sleep  ${NETWORK_TIMEOUT}s
+    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
+
+    Verify IP On BMC  ${ip}
diff --git a/redfish/managers/test_bmc_network_conf.robot b/redfish/managers/test_bmc_network_conf.robot
index b03ae56..27d61c0 100644
--- a/redfish/managers/test_bmc_network_conf.robot
+++ b/redfish/managers/test_bmc_network_conf.robot
@@ -509,18 +509,6 @@
     [Return]  @{network_configurations}
 
 
-Verify IP On BMC
-    [Documentation]  Verify IP on BMC.
-    [Arguments]  ${ip}
-
-    # Description of argument(s):
-    # ip  IP address to be verified (e.g. "10.7.7.7").
-
-    # Get IP address details on BMC using IP command.
-    @{ip_data}=  Get BMC IP Info
-    Should Contain Match  ${ip_data}  ${ip}/*
-    ...  msg=IP address does not exist.
-
 Add IP Address
     [Documentation]  Add IP Address To BMC.
     [Arguments]  ${ip}  ${subnet_mask}  ${gateway}
@@ -627,23 +615,6 @@
     Should Contain Match  ${ip_data}  */${prefix_length}
     ...  msg=Prefix length does not exist.
 
-Verify Gateway On BMC
-    [Documentation]  Verify gateway on BMC.
-    [Arguments]  ${gateway_ip}=0.0.0.0
-
-    # Description of argument(s):
-    # gateway_ip  Gateway IP address.
-
-    ${route_info}=  Get BMC Route Info
-
-    # If gateway IP is empty or 0.0.0.0 it will not have route entry.
-
-    Run Keyword If  '${gateway_ip}' == '0.0.0.0'
-    ...      Pass Execution  Gateway IP is "0.0.0.0".
-    ...  ELSE
-    ...      Should Contain  ${route_info}  ${gateway_ip}
-    ...      msg=Gateway IP address not matching.
-
 Verify IP And Netmask On BMC
     [Documentation]  Verify IP and netmask on BMC.
     [Arguments]  ${ip}  ${netmask}
@@ -703,18 +674,6 @@
     Should Be True  ${match}
     ...  The nameservers obtained via Redfish do not match those found in /etc/resolv.conf.
 
-CLI Get Nameservers
-    [Documentation]  Get the nameserver IPs from /etc/resolv.conf and return as a list.
-
-    # Example of /etc/resolv.conf data:
-    # nameserver x.x.x.x
-    # nameserver y.y.y.y
-
-    ${stdout}  ${stderr}  ${rc}=  BMC Execute Command  egrep nameserver /etc/resolv.conf | cut -f2- -d ' '
-    ${nameservers}=  Split String  ${stdout}
-
-    [Return]  ${nameservers}
-
 
 Configure Static Name Servers
     [Documentation]  Configure DNS server on BMC.