IPMI in-band network configuration test

Resolve openbmc/openbmc-test-automation#1260

Change-Id: Id1aaa189629d9dc06b3ad49ef02146eed6f6f2e8
Signed-off-by: Naman Navin Hegde <nhegde89@in.ibm.com>
diff --git a/ipmi/test_ipmi_network.robot b/ipmi/test_ipmi_network.robot
new file mode 100644
index 0000000..7857fc7
--- /dev/null
+++ b/ipmi/test_ipmi_network.robot
@@ -0,0 +1,68 @@
+*** Settings ***
+
+Documentation          Module to test IPMI network functionality.
+Resource               ../lib/ipmi_client.robot
+Resource               ../lib/openbmc_ffdc.robot
+Library                ../lib/ipmi_utils.py
+Library                ../lib/gen_robot_valid.py
+
+Test Teardown          FFDC On Test Case Fail
+
+Force Tags             IPMI_Network
+
+*** Variables ***
+
+${initial_lan_config}   &{EMPTY}
+
+
+*** Test Cases ***
+
+Verify IPMI Inband Network Configuration
+    [Documentation]  Verify BMC network configuration via inband IPMI.
+    [Tags]  Verify_IPMI_Inband_Network_Configuration
+    [Teardown]  Run Keywords  Restore Configuration  AND  FFDC On Test Case Fail
+
+    Redfish Power On
+    ${initial_lan_config}=  Get LAN Print Dict  inband
+    Set Suite Variable  ${initial_lan_config}
+
+    Set IPMI Inband Network Configuration  10.10.10.10  255.255.255.0  10.10.10.10
+    Sleep  10
+
+    ${lan_print_output}=  Get LAN Print Dict  inband
+    Valid Value  lan_print_output['IP Address']  ["10.10.10.10"]
+    Valid Value  lan_print_output['Subnet Mask']  ["255.255.255.0"]
+    Valid Value  lan_print_output['Default Gateway IP']  ["10.10.10.10"]
+
+
+*** Keywords ***
+
+Set IPMI Inband Network Configuration
+    [Documentation]  Run sequence of standard IPMI command in-band and set
+    ...              the IP configuration.
+    [Arguments]  ${ip}  ${netmask}  ${gateway}  ${login}=${1}
+
+    # Description of argument(s):
+    # ip       The IP address to be set using ipmitool-inband.
+    # netmask  The Netmask to be set using ipmitool-inband.
+    # gateway  The Gateway address to be set using ipmitool-inband.
+
+    Run Inband IPMI Standard Command
+    ...  lan set 1 ipsrc static  login_host=${login}
+    Run Inband IPMI Standard Command
+    ...  lan set 1 ipaddr ${ip}  login_host=${0}
+    Run Inband IPMI Standard Command
+    ...  lan set 1 netmask ${netmask}  login_host=${0}
+    Run Inband IPMI Standard Command
+    ...  lan set 1 defgw ipaddr ${gateway}  login_host=${0}
+
+
+Restore Configuration
+    [Documentation]  Restore the configuration to its pre-test state
+
+    ${length}=  Get Length  ${initial_lan_config}
+    Return From Keyword If  ${length} == ${0}
+
+    Set IPMI Inband Network Configuration  ${initial_lan_config['IP Address']}
+    ...  ${initial_lan_config['Subnet Mask']}
+    ...  ${initial_lan_config['Default Gateway IP']}  login=${0}
diff --git a/lib/ipmi_client.robot b/lib/ipmi_client.robot
index 47f0744..6e47168 100755
--- a/lib/ipmi_client.robot
+++ b/lib/ipmi_client.robot
@@ -118,6 +118,7 @@
     [Documentation]  Run the standard IPMI command in-band.
     [Arguments]  ${command}  ${fail_on_err}=${1}  ${os_host}=${OS_HOST}
     ...          ${os_username}=${OS_USERNAME}  ${os_password}=${OS_PASSWORD}
+    ...          ${login_host}=${1}
 
     # Description of argument(s):
     # command                       The IPMI command string to be executed
@@ -125,8 +126,10 @@
     # os_host                       The host name or IP address of the OS Host.
     # os_username                   The OS host user name.
     # os_password                   The OS host passwrd.
+    # login_host                    Indicates that this keyword should login to host OS.
 
-    Login To OS Host  ${os_host}  ${os_username}  ${os_password}
+    Run Keyword If  ${login_host} == ${1}
+    ...  Login To OS Host  ${os_host}  ${os_username}  ${os_password}
     Check If IPMI Tool Exist
 
     ${ipmi_cmd}=  Catenate  ${IPMI_INBAND_CMD}  ${command}