Added new testcases to policies sub-menu

  - Modified previous testcase by replacing with existing keyword to reduce lines of code
  - Enable SSH Via GUI And Verify Persistency On BMC Reboot
  - Enable IPMI Via GUI And Verify Persistency On BMC Reboot
  - Added xpath of reboot operation to gui/data/gui_variables.py
  - Added Reboot Via GUI keyword to gui/lib/gui_resource.robot

Change-Id: I1f4925bb69a4cae916524a890d2060d58f514b39
Signed-off-by: meghagn <Megha.GN@ibm.com>
diff --git a/gui/data/gui_variables.py b/gui/data/gui_variables.py
index c531253..2a93d41 100644
--- a/gui/data/gui_variables.py
+++ b/gui/data/gui_variables.py
@@ -74,3 +74,9 @@
     # Common variables
     xpath_save_settings_button = "//button[contains(text(),'Save settings')]"
     xpath_confirm_button = "//button[contains(text(),'Confirm')]"
+    xpath_cancel_button = "//button[contains(text(),'Cancel')]"
+
+    # Reboot sub meanu
+    xpath_reboot_bmc_heading = "//h1[text()='Reboot BMC']"
+    xpath_reboot_bmc_button = "//button[contains(text(),'Reboot BMC')]"
+    xpath_confirm_bmc_reboot = "//*[@class='btn btn-primary']"
diff --git a/gui/gui_test/security_and_access_menu/test_policies_sub_menu.robot b/gui/gui_test/security_and_access_menu/test_policies_sub_menu.robot
index df63d11..078c7a0 100644
--- a/gui/gui_test/security_and_access_menu/test_policies_sub_menu.robot
+++ b/gui/gui_test/security_and_access_menu/test_policies_sub_menu.robot
@@ -4,6 +4,8 @@
 
 Resource         ../../lib/gui_resource.robot
 Resource         ../lib/ipmi_client.robot
+Resource         ../lib/protocol_setting_utils.robot
+Resource         ../lib/common_utils.robot
 Suite Setup      Launch Browser And Login GUI
 Suite Teardown   Close Browser
 Test Setup       Test Setup Execution
@@ -32,7 +34,7 @@
     Page Should Contain  Network services
     Page Should Contain  BMC shell (via SSH)
     Page Should Contain  Network IPMI (out-of-band IPMI)
-    Page Should Contain  Host TPM
+
 
 Verify Existence Of All Buttons In Policies Page
     [Documentation]  Verify existence of All Buttons in policies page.
@@ -43,51 +45,22 @@
 
 
 Enable SSH Via GUI And Verify
-    [Documentation]  Verify that SSH to BMC starts working after enabling SSH.
+    [Documentation]  Login to GUI Policies page,enable SSH toggle and
+    ...  verify that SSH to BMC starts working after enabling SSH.
     [Tags]  Enable_SSH_Via_GUI_And_Verify
-    [Teardown]  Run Keywords  Redfish.Patch  /redfish/v1/Managers/bmc/NetworkProtocol
-    ...  body={"SSH":{"ProtocolEnabled":True}}  valid_status_codes=[200, 204]  AND
-    ...  Wait Until Keyword Succeeds  30 sec  5 sec  Open Connection And Login
 
-    # Disable ssh via Redfish.
-    Redfish.Patch  /redfish/v1/Managers/bmc/NetworkProtocol  body={"SSH":{"ProtocolEnabled":False}}
-    ...   valid_status_codes=[200, 204]
-
-    # Wait for GUI to reflect disable SSH status.
-    Wait Until Keyword Succeeds  30 sec  10 sec
-    ...  Refresh GUI And Verify Element Value  ${xpath_bmc_ssh_toggle}  Disabled
-
-    # Enable ssh via GUI.
-    Click Element  ${xpath_bmc_ssh_toggle}
-
-    # Wait for GUI to reflect enable SSH status.
-    Wait Until Keyword Succeeds  30 sec  10 sec
-    ...  Refresh GUI And Verify Element Value  ${xpath_bmc_ssh_toggle}  Enabled
-
+    Set Policy Via GUI  SSH  Enabled
     Wait Until Keyword Succeeds  10 sec  5 sec  Open Connection And Login
 
 
 Disable SSH Via GUI And Verify
-    [Documentation]  Verify that SSH to BMC stops working after disabling SSH.
+    [Documentation]  Login to GUI Policies page,disable SSH and
+    ...  verify that SSH to BMC stops working after disabling SSH.
     [Tags]  Disable_SSH_Via_GUI_And_Verify
-    [Teardown]  Run Keywords  Redfish.Patch  /redfish/v1/Managers/bmc/NetworkProtocol
-    ...  body={"SSH":{"ProtocolEnabled":True}}  valid_status_codes=[200, 204]  AND
-    ...  Wait Until Keyword Succeeds  30 sec  5 sec  Open Connection And Login
+    [Teardown]  Run Keywords  Enable SSH Protocol  ${True}  AND
+    ...  Wait Until Keyword Succeeds  30 sec  10 sec  Open Connection And Login
 
-    # Enable ssh via Redfish.
-    Redfish.Patch  /redfish/v1/Managers/bmc/NetworkProtocol  body={"SSH":{"ProtocolEnabled":True}}
-    ...   valid_status_codes=[200, 204]
-
-    # Wait for GUI to reflect enable SSH status.
-    Wait Until Keyword Succeeds  30 sec  10 sec
-    ...  Refresh GUI And Verify Element Value  ${xpath_bmc_ssh_toggle}  Enabled
-
-    # Disable ssh via GUI.
-    Click Element  ${xpath_bmc_ssh_toggle}
-
-    # Wait for GUI to reflect disable SSH status.
-    Wait Until Keyword Succeeds  30 sec  10 sec
-    ...  Refresh GUI And Verify Element Value  ${xpath_bmc_ssh_toggle}  Disabled
+    Set Policy Via GUI  SSH  Disabled
 
     ${status}=  Run Keyword And Return Status
     ...  Open Connection And Login
@@ -97,27 +70,11 @@
 
 
 Disable IPMI Via GUI And Verify
-    [Documentation]  Verify that IPMI command does not work after disabling IPMI.
+    [Documentation]  Login to GUI Policies page,disable IPMI and
+    ...  verify that IPMI command doesnot work after disabling IPMI.
     [Tags]  Disable_IPMI_Via_GUI_And_Verify
-    [Teardown]  Redfish.Patch  /redfish/v1/Managers/bmc/NetworkProtocol
-    ...  body={"IPMI":{"ProtocolEnabled":True}}  valid_status_codes=[200, 204]
 
-    # Due to github issue 2125 we are using click element instead of select checkbox.
-    # https://github.com/openbmc/openbmc-test-automation/issues/2125.
-    # Enable IPMI via Redfish.
-    Redfish.Patch  /redfish/v1/Managers/bmc/NetworkProtocol  body={"IPMI":{"ProtocolEnabled":True}}
-    ...   valid_status_codes=[200, 204]
-
-    # Wait for GUI to reflect enable IPMI status.
-    Wait Until Keyword Succeeds  30 sec  10 sec
-    ...  Refresh GUI And Verify Element Value  ${xpath_network_ipmi_toggle}  Enabled
-
-    # Disable IPMI via GUI.
-    Click Element  ${xpath_network_ipmi_toggle}
-
-    # Wait for GUI to reflect disable IPMI status.
-    Wait Until Keyword Succeeds  30 sec  10 sec
-    ...  Refresh GUI And Verify Element Value  ${xpath_network_ipmi_toggle}  Disabled
+    Set Policy Via GUI  IPMI  Disabled
 
     ${status}=  Run Keyword And Return Status
     ...  Wait Until Keyword Succeeds  10 sec  5 sec  Run IPMI Standard Command  sel info
@@ -127,37 +84,76 @@
 
 
 Enable IPMI Via GUI And Verify
-    [Documentation]  Verify that IPMI command works after enabling IPMI.
+    [Documentation]  Login to GUI Policies page,enable IPMI and
+    ...  verify that IPMI command works after enabling IPMI.
     [Tags]  Enable_IPMI_Via_GUI_And_Verify
-    [Teardown]  Redfish.Patch  /redfish/v1/Managers/bmc/NetworkProtocol
-    ...  body={"IPMI":{"ProtocolEnabled":True}}  valid_status_codes=[200, 204]
 
-    # Due to github issue 2125 we are using click element instead of select checkbox.
-    # https://github.com/openbmc/openbmc-test-automation/issues/2125.
-    # Disable ipmi via Redfish.
-    Redfish.Patch  /redfish/v1/Managers/bmc/NetworkProtocol  body={"IPMI":{"ProtocolEnabled":False}}
-    ...   valid_status_codes=[200, 204]
-
-    # Wait for GUI to reflect disable IPMI status.
-    Wait Until Keyword Succeeds  30 sec  10 sec
-    ...  Refresh GUI And Verify Element Value  ${xpath_network_ipmi_toggle}  Disabled
-
-    # Enable ipmi via GUI.
-    Click Element  ${xpath_network_ipmi_toggle}
-
-    # Wait for GUI to reflect enable IPMI status.
-    Wait Until Keyword Succeeds  30 sec  10 sec
-    ...  Refresh GUI And Verify Element Value  ${xpath_network_ipmi_toggle}  Enabled
-
+    Set Policy Via GUI  IPMI  Enabled
     Wait Until Keyword Succeeds  10 sec  5 sec  Run IPMI Standard Command  sel info
 
 
+Enable SSH Via GUI And Verify Persistency On BMC Reboot
+    [Documentation]  Login to GUI Policies page,enable SSH and
+    ...  verify persistency of SSH connection on BMC reboot.
+    [Tags]  Enable_SSH_Via_GUI_And_Verify_Persistency_On_BMC_Reboot
+
+    Set Policy Via GUI  SSH  Enabled
+
+    Reboot BMC via GUI
+
+    Wait Until Keyword Succeeds  5 min  30 sec  Open Connection And Login
+
+
+Enable IPMI Via GUI And Verify Persistency On BMC Reboot
+    [Documentation]  Login to GUI Policies page,enable IPMI and
+    ...  verify persistency of IPMI command work on BMC reboot.
+    [Tags]  Enable_IPMI_Via_GUI_And_Verify_Persistency_On_BMC_Reboot
+
+    Set Policy Via GUI  IPMI  Enabled
+
+    Reboot BMC via GUI
+
+    Wait Until Keyword Succeeds  2 min  30 sec  Run IPMI Standard Command  sel info
+
+
 *** Keywords ***
 
 Test Setup Execution
     [Documentation]  Do test case setup tasks.
+
     Click Element  ${xpath_secuity_and_accesss_menu}
     Click Element  ${xpath_policies_sub_menu}
     Wait Until Keyword Succeeds  30 sec  10 sec  Location Should Contain  policies
 
 
+Set Policy Via GUI
+
+    [Documentation]  Login to GUI Policies page and set policy.
+    [Arguments]  ${policy}  ${state}
+
+    # Description of argument(s):
+    # policy   policy to be set(e.g. SSH, IPMI).
+    # state    state to be set(e.g. Enable, Disable).
+
+    ${opposite_state_gui}  ${opposite_state_redfish}=  Run Keyword If
+    ...  '${state}' == 'Enabled'  Set Variable  Disabled  ${False}
+    ...  ELSE IF  '${state}' == 'Disabled'  Set Variable  Enabled  ${True}
+
+    # Setting policy to an opposite value via Redfish.
+    Run Keyword If  '${policy}' == 'SSH'
+    ...  Enable SSH Protocol  ${opposite_state_redfish}
+    ...  ELSE IF  '${policy}' == 'IPMI'
+    ...  Enable IPMI Protocol  ${opposite_state_redfish}
+
+    ${policy_toggle_button}=  Run Keyword If  '${policy}' == 'SSH'
+    ...  Set variable  ${xpath_bmc_ssh_toggle}
+    ...  ELSE IF  '${policy}' == 'IPMI'
+    ...  Set variable  ${xpath_network_ipmi_toggle}
+
+    Wait Until Keyword Succeeds  1 min  30 sec
+    ...  Refresh GUI And Verify Element Value  ${policy_toggle_button}  ${opposite_state_gui}
+    Click Element  ${policy_toggle_button}
+
+    # Wait for GUI to reflect policy status.
+    Wait Until Keyword Succeeds  1 min  30 sec
+    ...  Refresh GUI And Verify Element Value  ${policy_toggle_button}  ${state}
diff --git a/gui/lib/gui_resource.robot b/gui/lib/gui_resource.robot
index 794adf7..0296468 100644
--- a/gui/lib/gui_resource.robot
+++ b/gui/lib/gui_resource.robot
@@ -147,3 +147,13 @@
     Log  ${element_value}
     Should Contain  ${element_value}  ${expected_value}
 
+
+Reboot BMC via GUI
+    [Documentation]  Reboot BMC via GUI.
+
+    Click Element  ${xpath_operations_menu}
+    Click Element  ${xpath_reboot_bmc_sub_menu}
+    Click Button  ${xpath_reboot_bmc_button}
+    Click Button  ${xpath_confirm_bmc_reboot}
+    Wait Until Keyword Succeeds  2 min  10 sec  Is BMC Unpingable
+    Wait For Host To Ping  ${OPENBMC_HOST}  1 min