Added Test Case "Verify Modifying IP Address Multiple Times On Interface"

Changes:

   - Added in redfish/managers/test_multiple_interfaces.robot

Tested:

    - Ran the test case on BMC environment.

Change-Id: I0df920ffd97c0b2f2089595c666fb1cbf37ddf85
Signed-off-by: Sweta Potthuri <spotthur@in.ibm.com>
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index f3632f7..2ece501 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -764,3 +764,51 @@
     ...  ${channel_number_list}  ${valid_channel_number_interface_names}
 
     [Return]  ${channel_number_list}
+
+Update IP Address
+    [Documentation]  Update and verify IP address of BMC.
+    [Arguments]  ${ip}  ${new_ip}  ${netmask}  ${gw_ip}
+    ...  ${valid_status_codes}=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
+
+    # Description of argument(s):
+    # ip                  IP address to be replaced (e.g. "10.7.7.7").
+    # new_ip              New IP address to be configured.
+    # netmask             Netmask value.
+    # gw_ip               Gateway IP address.
+    # valid_status_codes  Expected return code from patch operation
+    #                     (e.g. "200").  See prolog of rest_request
+    #                     method in redfish_plus.py for details.
+
+    ${empty_dict}=  Create Dictionary
+    ${patch_list}=  Create List
+    ${ip_data}=  Create Dictionary
+    ...  Address=${new_ip}  SubnetMask=${netmask}  Gateway=${gw_ip}
+
+    # Find the position of IP address to be modified.
+    @{network_configurations}=  Get Network Configuration
+    FOR  ${network_configuration}  IN  @{network_configurations}
+      Run Keyword If  '${network_configuration['Address']}' == '${ip}'
+      ...  Append To List  ${patch_list}  ${ip_data}
+      ...  ELSE  Append To List  ${patch_list}  ${empty_dict}
+    END
+
+    # Modify the IP address only if given IP is found
+    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
+    ...  ${patch_list}  ${ip_data}  msg=${ip} does not exist on BMC
+    Pass Execution If  ${ip_found} == ${False}  ${ip} does not exist on BMC
+
+    ${data}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
+
+    ${active_channel_config}=  Get Active Channel Config
+    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
+
+    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
+    ...  body=&{data}  valid_status_codes=${valid_status_codes}
+
+    # Note: Network restart takes around 15-18s after patch request processing.
+    Sleep  ${NETWORK_TIMEOUT}s
+    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
+
+    Verify IP On BMC  ${new_ip}
+    Validate Network Config On BMC
+
diff --git a/redfish/managers/test_bmc_network_conf.robot b/redfish/managers/test_bmc_network_conf.robot
index 78768ba..73a2891 100644
--- a/redfish/managers/test_bmc_network_conf.robot
+++ b/redfish/managers/test_bmc_network_conf.robot
@@ -501,7 +501,7 @@
 
     Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
     Update IP Address  ${test_ipv4_addr}  ${test_ipv4_addr2}  ${test_subnet_mask}  ${test_gateway}
-    Update IP Address  ${test_ipv4_addr2}  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
+    Update IP Address  ${test_ipv4_addr}  ${test_ipv4_addr2}  ${test_subnet_mask}  ${test_gateway}
 
 Configure Invalid Values For DNS Server
     [Documentation]  Configure invalid values for DNS server and expect an error.
@@ -814,52 +814,6 @@
     ...  Enable IPv4 DHCP Settings
 
 
-Update IP Address
-    [Documentation]  Update IP address of BMC.
-    [Arguments]  ${ip}  ${new_ip}  ${netmask}  ${gw_ip}
-    ...  ${valid_status_codes}=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
-
-    # Description of argument(s):
-    # ip                  IP address to be replaced (e.g. "10.7.7.7").
-    # new_ip              New IP address to be configured.
-    # netmask             Netmask value.
-    # gw_ip               Gateway IP address.
-    # valid_status_codes  Expected return code from patch operation
-    #                     (e.g. "200").  See prolog of rest_request
-    #                     method in redfish_plus.py for details.
-
-    ${empty_dict}=  Create Dictionary
-    ${patch_list}=  Create List
-    ${ip_data}=  Create Dictionary  Address=${new_ip}  SubnetMask=${netmask}  Gateway=${gw_ip}
-
-    # Find the position of IP address to be modified.
-    @{network_configurations}=  Get Network Configuration
-    FOR  ${network_configuration}  IN  @{network_configurations}
-      Run Keyword If  '${network_configuration['Address']}' == '${ip}'
-      ...  Append To List  ${patch_list}  ${ip_data}
-      ...  ELSE  Append To List  ${patch_list}  ${empty_dict}
-    END
-
-    ${ip_found}=  Run Keyword And Return Status  List Should Contain Value
-    ...  ${patch_list}  ${ip_data}  msg=${ip} does not exist on BMC
-    Pass Execution If  ${ip_found} == ${False}  ${ip} does not exist on BMC
-
-    # Run patch command only if given IP is found on BMC
-    ${data}=  Create Dictionary  IPv4StaticAddresses=${patch_list}
-
-    ${active_channel_config}=  Get Active Channel Config
-    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
-
-    Redfish.patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
-    ...  body=&{data}  valid_status_codes=${valid_status_codes}
-
-    # Note: Network restart takes around 15-18s after patch request processing.
-    Sleep  ${NETWORK_TIMEOUT}s
-    Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
-
-    Verify IP On BMC  ${new_ip}
-    Validate Network Config On BMC
-
 Configure Multiple Static IPv4 Addresses
     [Documentation]  Configure multiple static ipv4 address via Redfish and verify.
     [Arguments]  ${ip_addreses}  ${subnet_mask}  ${gateway}
diff --git a/redfish/managers/test_multiple_interfaces.robot b/redfish/managers/test_multiple_interfaces.robot
index c142d5c..b9717f4 100644
--- a/redfish/managers/test_multiple_interfaces.robot
+++ b/redfish/managers/test_multiple_interfaces.robot
@@ -25,6 +25,9 @@
 *** Variables ***
 
 ${cmd_prefix}  ipmitool -I lanplus -C 17 -p 623 -U ${OPENBMC_USERNAME} -P ${OPENBMC_PASSWORD}
+${test_ipv4_addr}     10.7.7.7
+${test_ipv4_addr2}    10.7.7.8
+${test_subnet_mask}   255.255.255.0
 
 *** Test Cases ***
 
@@ -131,6 +134,18 @@
     ${status2}=  Run IPMI  ${OPENBMC_HOST_1}  power status
     Should Be Equal  ${status1}  ${status2}
 
+Verify Modifying IP Address Multiple Times On Interface
+    [Documentation]  Verify modifying IP address multiple times on interface.
+    [Tags]  Verify_Modifying_IP_Address_Multiple_Times_On_Interface
+    [Teardown]  Run Keywords
+    ...  Delete IP Address  ${test_ipv4_addr}  AND  Test Teardown
+
+    ${test_gateway}=  Get BMC Default Gateway
+    Add IP Address  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
+    Update IP Address  ${test_ipv4_addr}  ${test_ipv4_addr2}  ${test_subnet_mask}  ${test_gateway}
+    Update IP Address  ${test_ipv4_addr2}  ${test_ipv4_addr}  ${test_subnet_mask}  ${test_gateway}
+    Run Keyword  Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
+    Run Keyword  Wait For Host To Ping  ${OPENBMC_HOST_1}  ${NETWORK_TIMEOUT}
 
 Verify Able To Load Certificates Via Eth1 IP Address
     [Documentation]  Verify able to load certificates via eth1 IP address.