Automation fix for Network sub menu

Changes:
    - Modified "Delete DNS Servers And Verify" keyword
    - Modified "Add DNS Servers And Verify"
    - Removed "DNS Test Setup Execution" keyword from
      redfish/managers/test_bmc_network_conf.robot
      and added in lib/bmc_network_utils.robot

Tested:
    - Ran successfully
      gui/gui_test/settings_menu
      /test_network_sub_menu.robot
      gui/lib/gui_resource.robot
      lib/bmc_network_utils.robot
      redfish/managers/test_bmc_network_conf.robot

Change-Id: I6ffcb7aba29312fa1e4cc843453bca49cd44d0f1
Signed-off-by: Megha G N <Megha.G.N@ibm.com>
diff --git a/gui/gui_test/settings_menu/test_network_sub_menu.robot b/gui/gui_test/settings_menu/test_network_sub_menu.robot
index a7e800b..8a83246 100644
--- a/gui/gui_test/settings_menu/test_network_sub_menu.robot
+++ b/gui/gui_test/settings_menu/test_network_sub_menu.robot
@@ -129,7 +129,9 @@
     [Documentation]  Login to GUI Network page, add DNS server IP
     ...  and verify that the page reflects server IP.
     [Tags]  Configure_And_Verify_DNS_Server_Via_GUI
-    [Teardown]  Delete DNS Servers And Verify
+    [Setup]  DNS Test Setup Execution
+    [Teardown]  Run Keywords  Delete Static Name Servers  AND
+    ...  Configure Static Name Servers
 
     Add DNS Servers And Verify  ${dns_server}
 
@@ -240,7 +242,11 @@
     Wait Until Page Contains Element  ${xpath_add_dns_ip_address_button}  timeout=15
     # Check if all name servers deleted on BMC.
     ${nameservers}=  CLI Get Nameservers
-    Should Be Empty  ${nameservers}
+    Should Not Contain  ${nameservers}  ${original_nameservers}
+
+    DNS Test Setup Execution
+
+    Should Be Empty  ${original_nameservers}
 
 
 Add Static IP Address And Verify
diff --git a/gui/lib/gui_resource.robot b/gui/lib/gui_resource.robot
index 4a22f34..d53091d 100644
--- a/gui/lib/gui_resource.robot
+++ b/gui/lib/gui_resource.robot
@@ -194,6 +194,9 @@
     ${cli_name_servers}=  CLI Get Nameservers
     ${cmd_status}=  Run Keyword And Return Status
     ...  List Should Contain Sub List  ${cli_name_servers}  ${dns_server}
+    Run Keyword If  '${expected_status}' == '${HTTP_OK}'
+    ...  Should Be True  ${cmd_status} == ${True}
+    ...  ELSE  Should Not Be True  ${cmd_status}
 
 
 Navigate To Server Power Page
diff --git a/lib/bmc_network_utils.robot b/lib/bmc_network_utils.robot
index d321543..f43aece 100644
--- a/lib/bmc_network_utils.robot
+++ b/lib/bmc_network_utils.robot
@@ -854,3 +854,62 @@
         ${subnetmask}=  Set Variable  ${resp['SubnetMask']}
         Return From Keyword  ${ip_addr}  ${gateway}  ${subnetmask}
     END
+
+
+DNS Test Setup Execution
+    [Documentation]  Do DNS test setup execution.
+
+    Redfish.Login
+
+    ${active_channel_config}=  Get Active Channel Config
+    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
+
+    ${original_nameservers}=  Redfish.Get Attribute
+    ...  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  StaticNameServers
+
+    Rprint Vars  original_nameservers
+    # Set suite variables to trigger restoration during teardown.
+    Set Suite Variable  ${original_nameservers}
+
+
+Delete Static Name Servers
+    [Documentation]  Delete static name servers.
+
+    DNS Test Setup Execution
+    Configure Static Name Servers  static_name_servers=@{EMPTY}
+
+    # Check if all name servers deleted on BMC.
+    ${nameservers}=  CLI Get Nameservers
+    Should Not Contain  ${nameservers}  ${original_nameservers}
+
+    DNS Test Setup Execution
+
+    Should Be Empty  ${original_nameservers}
+
+
+Configure Static Name Servers
+    [Documentation]  Configure DNS server on BMC.
+    [Arguments]  ${static_name_servers}=${original_nameservers}
+     ...  ${valid_status_codes}=${HTTP_OK}
+
+    # Description of the argument(s):
+    # static_name_servers  A list of static name server IPs to be
+    #                      configured on the BMC.
+
+    ${active_channel_config}=  Get Active Channel Config
+    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
+
+    ${type} =  Evaluate  type($static_name_servers).__name__
+    ${static_name_servers}=  Set Variable If  '${type}'=='str'
+    ...  '${static_name_servers}'  ${static_name_servers}
+
+    # Currently BMC is sending 500 response code instead of 400 for invalid scenarios.
+    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
+    ...  body={'StaticNameServers': ${static_name_servers}}
+    ...  valid_status_codes=[${valid_status_codes}, ${HTTP_INTERNAL_SERVER_ERROR}]
+
+    # Patch operation takes 1 to 3 seconds to set new value.
+    Sleep  3s
+
+    # Check if newly added DNS server is configured on BMC.
+    CLI Get and Verify Name Servers  ${static_name_servers}  ${HTTP_OK}
diff --git a/redfish/managers/test_bmc_network_conf.robot b/redfish/managers/test_bmc_network_conf.robot
index 6df4f5e..a851d33 100644
--- a/redfish/managers/test_bmc_network_conf.robot
+++ b/redfish/managers/test_bmc_network_conf.robot
@@ -727,60 +727,6 @@
     List Should Contain Sub List  ${resolve_conf_nameservers}  ${redfish_nameservers}
     ...  msg=The nameservers obtained via Redfish do not match those found in /etc/resolv.conf.
 
-Configure Static Name Servers
-    [Documentation]  Configure DNS server on BMC.
-    [Arguments]  ${static_name_servers}=${original_nameservers}
-     ...  ${valid_status_codes}=${HTTP_OK}
-
-    # Description of the argument(s):
-    # static_name_servers  A list of static name server IPs to be
-    #                      configured on the BMC.
-
-    ${active_channel_config}=  Get Active Channel Config
-    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
-
-    ${type} =  Evaluate  type($static_name_servers).__name__
-    ${static_name_servers}=  Set Variable If  '${type}'=='str'
-    ...  '${static_name_servers}'  ${static_name_servers}
-
-    # Currently BMC is sending 500 response code instead of 400 for invalid scenarios.
-    Redfish.Patch  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
-    ...  body={'StaticNameServers': ${static_name_servers}}
-    ...  valid_status_codes=[${valid_status_codes}, ${HTTP_INTERNAL_SERVER_ERROR}]
-
-    # Patch operation takes 1 to 3 seconds to set new value.
-    Wait Until Keyword Succeeds  1 min  3 sec    CLI Get and Verify Name Servers    ${static_name_servers}  ${valid_status_codes}
-
-Delete Static Name Servers
-    [Documentation]  Delete static name servers.
-
-    DNS Test Setup Execution
-    Configure Static Name Servers  static_name_servers=@{EMPTY}
-
-    # Check if all name servers deleted on BMC.
-    ${nameservers}=  CLI Get Nameservers
-    Should Not Contain  ${nameservers}  ${original_nameservers}
-
-    DNS Test Setup Execution
-
-    Should Be Empty  ${original_nameservers}
-
-DNS Test Setup Execution
-    [Documentation]  Do DNS test setup execution.
-
-    Redfish.Login
-
-    ${active_channel_config}=  Get Active Channel Config
-    ${ethernet_interface}=  Set Variable  ${active_channel_config['${CHANNEL_NUMBER}']['name']}
-
-    ${original_nameservers}=  Redfish.Get Attribute
-    ...  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}  StaticNameServers
-
-    Rprint Vars  original_nameservers
-    # Set suite variables to trigger restoration during teardown.
-    Set Suite Variable  ${original_nameservers}
-
-
 Suite Setup Execution
     [Documentation]  Do suite setup execution.