Switch From Static to DHCP

Changes:
    Added test case to switch from static to DHCP

Tested: Tested bmc_network_conf.robot and multiple_interfaces_dhcp.robot
Change-Id: I0cb5629317b9bb26f01a8a6b8740500dd9a7ee47
Signed-off-by: Sweta Potthuri <spotthur@in.ibm.com>
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index 7c9ce49..334386e 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -814,3 +814,24 @@
     Verify IP On BMC  ${new_ip}
     Validate Network Config On BMC
 
+Get IPv4 DHCP Enabled Status
+    [Documentation]  Return IPv4 DHCP enabled status from redfish URI.
+
+    ${active_channel_config}=  Get Active Channel Config
+    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
+    ${resp}=  Redfish.Get Attribute  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  DHCPv4
+    Return From Keyword  ${resp['DHCPEnabled']}
+
+Get DHCP IP Info
+    [Documentation]  Return DHCP IP address, gateway and subnetmask from redfish URI.
+
+    ${active_channel_config}=  Get Active Channel Config
+    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
+    ${resp_list}=  Redfish.Get Attribute  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  IPv4Addresses
+    FOR  ${resp}  IN  @{resp_list}
+        Continue For Loop If  '${resp['AddressOrigin']}' != 'DHCP'
+        ${ip_addr}=  Set Variable  ${resp['Address']}
+        ${gateway}=  Set Variable  ${resp['Gateway']}
+        ${subnetmask}=  Set Variable  ${resp['SubnetMask']}
+        Return From Keyword  ${ip_addr}  ${gateway}  ${subnetmask}
+    END
diff --git a/redfish/managers/test_bmc_network_conf.robot b/redfish/managers/test_bmc_network_conf.robot
index c9b61c4..3acd08e 100644
--- a/redfish/managers/test_bmc_network_conf.robot
+++ b/redfish/managers/test_bmc_network_conf.robot
@@ -898,28 +898,3 @@
 
     Sleep  ${NETWORK_TIMEOUT}s
     Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
-
-
-Get IPv4 DHCP Enabled Status
-    [Documentation]  Return IPv4 DHCP enabled status from redfish URI.
-
-    ${active_channel_config}=  Get Active Channel Config
-    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
-    ${resp}=  Redfish.Get Attribute  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  DHCPv4
-    ${status}=  Set Variable  ${resp['DHCPEnabled']}
-    Return From Keyword  ${status}
-
-
-Get DHCP IP Info
-    [Documentation]  Return DHCP IP address, gateway and subnetmask from redfish URI.
-
-    ${active_channel_config}=  Get Active Channel Config
-    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
-    ${resp_list}=  Redfish.Get Attribute  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  IPv4Addresses
-    FOR  ${resp}  IN  @{resp_list}
-        Continue For Loop If  '${resp['AddressOrigin']}' != 'DHCP'
-        ${ip_addr}=  Set Variable  ${resp['Address']}
-        ${gateway}=  Set Variable  ${resp['Gateway']}
-        ${subnetmask}=  Set Variable  ${resp['SubnetMask']}
-        Return From Keyword  ${ip_addr}  ${gateway}  ${subnetmask}
-    END
diff --git a/redfish/managers/test_multiple_interfaces_dhcp.robot b/redfish/managers/test_multiple_interfaces_dhcp.robot
index 8a850ec..2ac1ca7 100644
--- a/redfish/managers/test_multiple_interfaces_dhcp.robot
+++ b/redfish/managers/test_multiple_interfaces_dhcp.robot
@@ -1,5 +1,6 @@
 *** Settings ***
 Documentation   Test BMC DHCP multiple network interface functionalities.
+                ...  Run on setup eth0 in static and eth1 in DHCP.
 
 Resource        ../../lib/resource.robot
 Resource        ../../lib/common_utils.robot
@@ -43,6 +44,8 @@
     [Teardown]  Set DHCPEnabled To Enable Or Disable  True  eth1
 
     Set DHCPEnabled To Enable Or Disable  False  eth1
+    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status
+    Should Be Equal  ${DHCPEnabled}  ${False}
     Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
 
 Enable DHCP On Eth1 And Verify System Is Accessible By Eth0
@@ -52,6 +55,8 @@
     [Setup]  Set DHCPEnabled To Enable Or Disable  False  eth1
 
     Set DHCPEnabled To Enable Or Disable  True  eth1
+    ${DHCPEnabled}=  Get IPv4 DHCP Enabled Status
+    Should Be Equal  ${DHCPEnabled}  ${True}
     Wait For Host To Ping  ${OPENBMC_HOST}  ${NETWORK_TIMEOUT}
 
 Set Network Property via Redfish And Verify
@@ -78,7 +83,7 @@
     # Getting the eth0 details before enabling DHCP.
     ${ip_data_before}=  Get BMC IP Info
 
-    # Enable DHCP.
+    # Enable DHCP on eth1.
     Set DHCPEnabled To Enable Or Disable  True  eth1
 
     # Check the value of DHCPEnabled on eth0 is not impacted.
@@ -91,16 +96,31 @@
     # Before and after IP details must match.
     Should Be Equal  ${ip_data_before}  ${ip_data_after}
 
+Switch Between DHCP And Static
+    [Documentation]  Switch between DHCP and static.
+    [Tags]  Switch_Between_DHCP_And_Static
+    [Teardown]  Set DHCPEnabled To Enable Or Disable  True  eth1
+
+    # Fetch the IP details before.
+    ${ip_addr_before}  ${gateway_before}  ${subnetmask_before}  Get DHCP IP Info
+
+    # Switch Between Static and DHCP.
+    FOR  ${i}  IN RANGE  ${10}
+      Set DHCPEnabled To Enable Or Disable  False  eth1
+      Set DHCPEnabled To Enable Or Disable  True  eth1
+    END
+    Sleep  5s
+
+    # Fetch the IP details after.
+    ${ip_addr_after}  ${gateway_after}  ${subnetmask_after}  Get DHCP IP Info
+
+    # DHCP Details must be the same before and after.
+    Should Be Equal  ${ip_addr_before}  ${ip_addr_after}
+    Should Be Equal  ${gateway_before}  ${gateway_after}
+    Should Be Equal  ${subnetmask_before}  ${subnetmask_after}
+
 *** Keywords ***
 
-Get IPv4 DHCP Enabled Status
-    [Documentation]  Return IPv4 DHCP enabled status from redfish URI.
-
-    ${active_channel_config}=  Get Active Channel Config
-    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
-    ${resp}=  Redfish.Get Attribute  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  DHCPv4
-    Return From Keyword  ${resp['DHCPEnabled']}
-
 Set DHCPEnabled To Enable Or Disable
     [Documentation]  Enable or Disable DHCP on the interface.
     [Arguments]  ${dhcp_enabled}=${False}  ${interface}=${ethernet_interface}
@@ -183,7 +203,6 @@
     [Documentation]  Do suite setup task.
 
     Ping Host  ${OPENBMC_HOST}
-    Ping Host  ${OPENBMC_HOST_1}
     Redfish.Login
 
     # Get the configuration of eth1
@@ -203,4 +222,3 @@
       ...  AND  Set Suite Variable  ${eth0_gateway}  ${network_configuration['Gateway']}
       ...  AND  Exit For Loop
     END
-