Modified suite setup & teardown in test_bmc_network_conf
- Updated Suite setup to check IPv4 AddressSource and set to static
if it is in DHCP.
- Added Suite teardown to restore IPv4 AddressSource to its
initial state .
Tested: Run robot redfish/managers/test_bmc_network_conf.robot
Signed-off-by: Aravinth R <aravinthr@ami.com>
Change-Id: I7694d7bbb89bf1346236d7905fc53037777b2a07
diff --git a/redfish/managers/test_bmc_network_conf.robot b/redfish/managers/test_bmc_network_conf.robot
index 2ac8903..ae59298 100644
--- a/redfish/managers/test_bmc_network_conf.robot
+++ b/redfish/managers/test_bmc_network_conf.robot
@@ -8,9 +8,10 @@
Library ../../lib/bmc_network_utils.py
Library Collections
-Test Setup Test Setup Execution
-Test Teardown Test Teardown Execution
-Suite Setup Suite Setup Execution
+Suite Setup Suite Setup Execution
+Suite Teardown Suite Teardown Execution
+Test Setup Test Setup Execution
+Test Teardown Test Teardown Execution
Force Tags Network_Conf_Test
@@ -771,12 +772,38 @@
# Set suite variables to trigger restoration during teardown.
Set Suite Variable ${original_nameservers}
+
Suite Setup Execution
[Documentation] Do suite setup execution.
+ # - Get DHCP IPv4 enabled/disabled status from redfish managers URI
+ # - If DHCP IPv4 is enabled ,
+ # - Get DHCP IPv4 settings - ip address, gateway, subnetmask
+ # - And set the same as static IP address
+
+ ${DHCPEnabled}= Get IPv4 DHCP Enabled Status
+ Set Suite Variable ${DHCPEnabled}
+
+ Run Keyword If ${DHCPEnabled}==True
+ ... Run Keywords
+ ... ${ip_addr} ${gateway} ${subnetmask}= Get DHCP IP Info AND
+ ... Add IP Address ${ip_addr} ${subnetmask} ${gateway} AND
+ ... Set Suite Variable ${ip_addr}
+
${test_gateway}= Get BMC Default Gateway
Set Suite Variable ${test_gateway}
+
+Suite Teardown Execution
+ [Documentation] Do suite teardown execution.
+
+ # - If the DHCP IPv4 is enabled before suite setup execution
+ # - Restore the DHCP IPv4 to enabled state
+
+ Run Keyword If ${DHCPEnabled}==True
+ ... Enable IPv4 DHCP Settings
+
+
Update IP Address
[Documentation] Update IP address of BMC.
[Arguments] ${ip} ${new_ip} ${netmask} ${gw_ip}
@@ -887,3 +914,48 @@
END
Run Keyword If '${ip_found}' == '${False}'
... Fail msg=Configured IP address not found on EthernetInterface URI.
+
+
+Enable IPv4 DHCP Settings
+ [Documentation] Set IPv4 DHCP enabled status true/false in redfish URI.
+ [Arguments] ${status}=${True}
+
+ # Description of argument(s):
+ # status IPv4 DHCPEnabled status which needs to be set.
+ # (e.g. True or False)
+
+ ${active_channel_config}= Get Active Channel Config
+ ${ethernet_interface}= Set Variable ${active_channel_config['${CHANNEL_NUMBER}']['name']}
+ ${DHCPv4}= Create Dictionary DHCPEnabled=${status}
+
+ ${payload}= Create Dictionary DHCPv4=${DHCPv4}
+ Redfish.patch ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
+ ... body=&{payload} valid_status_codes=[${HTTP_NO_CONTENT}, ${HTTP_OK}]
+
+ 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
\ No newline at end of file