Update Redfish PowerRestore policy test suites

Changes:
    - Update to Redfish variables and kewyords needed.
    - Add Redfish state in state mapping.
    - Add new keyword to do ping , SSH and Redfish auth.

Change-Id: Ia143125f01a2fb1e5ea77c4080b52ec92576ef87
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/state_map.py b/lib/state_map.py
index 7e7b504..908b159 100644
--- a/lib/state_map.py
+++ b/lib/state_map.py
@@ -97,6 +97,58 @@
         ),
     },
 }
+REDFISH_VALID_BOOT_STATES = {
+    'Off':  # Valid states when Host is Off.
+    {
+        # (BMC , Chassis , Host , BootProgress)
+        (
+            "Enabled",
+            "Off",
+            "Disabled",
+            "None",
+        ),
+    },
+    'Reboot':  # Valid states when BMC reset to standby.
+    {
+        # (BMC , Chassis , Host , BootProgress)
+        (
+            "Enabled",
+            "Off",
+            "Disabled",
+            "None",
+        ),
+    },
+    'Running':  # Valid states when Host is powering on.
+    {
+        # (BMC , Chassis , Host , BootProgress)
+        (
+            "Enabled",
+            "On",
+            "Enabled",
+            "OSRunning",
+        ),
+    },
+    'Booted':  # Valid state when Host is booted.
+    {
+        # (BMC , Chassis , Host , BootProgress)
+        (
+            "Enabled",
+            "On",
+            "Enabled",
+            "OSRunning",
+        ),
+    },
+    'ResetReload':  # Valid state BMC reset reload when host is booted.
+    {
+        # (BMC , Chassis , Host , BootProgress)
+        (
+            "Enabled",
+            "On",
+            "Enabled",
+            "OSRunning",
+        ),
+    },
+}
 
 if platform_arch_type == "x86":
     VALID_BOOT_STATES_X86 = {}
@@ -159,3 +211,18 @@
             return True
         else:
             return False
+
+    def redfish_valid_boot_state(self, boot_type, state_dict):
+        r"""
+        Validate a given set of states is valid.
+
+        Description of argument(s):
+        boot_type                   Boot type (e.g. off/running/host booted
+                                    etc.)
+        state_dict                  State dictionary.
+        """
+
+        if set(state_dict.values()) in set(REDFISH_VALID_BOOT_STATES[boot_type]):
+            return True
+        else:
+            return False
diff --git a/lib/utils.robot b/lib/utils.robot
index 5a6efde..a73a56c 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -58,6 +58,21 @@
     Should Be Empty     ${stderr}
 
 
+Verify Ping SSH And Redfish Authentication
+    [Documentation]  Verify ping, SSH and redfish authentication.
+
+    ${l_ping}=   Run Keyword And Return Status  Ping Host  ${OPENBMC_HOST}
+    Run Keyword If  '${l_ping}' == '${False}'  Fail   msg=Ping Failed
+
+    ${l_rest}=   Run Keyword And Return Status   Redfish.Login
+    Run Keyword If  '${l_rest}' == '${False}'  Fail   msg=REST Authentication Failed
+
+    # Just to make sure the SSH is working.
+    Open Connection And Log In
+    ${system}   ${stderr}=    Execute Command   hostname   return_stderr=True
+    Should Be Empty     ${stderr}
+
+
 Check If BMC is Up
     [Documentation]  Wait for Host to be online. Checks every X seconds
     ...              interval for Y minutes and fails if timed out.
diff --git a/redfish/extended/test_power_restore.robot b/redfish/extended/test_power_restore.robot
index 981c859..4639400 100644
--- a/redfish/extended/test_power_restore.robot
+++ b/redfish/extended/test_power_restore.robot
@@ -36,7 +36,7 @@
     [Template]  Verify Restore Policy
 
     # Policy                Initial Host State     Expected Host State
-    ${ALWAYS_POWER_OFF}     Off                    Off
+    AlwaysOff               Off                    Off
 
 
 
@@ -46,7 +46,7 @@
     [Template]  Verify Restore Policy
 
     # Policy                Initial Host State     Expected Host State
-    ${ALWAYS_POWER_OFF}     Running                Running
+    AlwaysOff               Running                Running
 
 
 Test Restore Policy ALWAYS_POWER_ON With Host Off
@@ -63,7 +63,7 @@
     [Template]  Verify Restore Policy
 
     # Policy                Initial Host State     Expected Host State
-    ${ALWAYS_POWER_ON}      Off                    Running
+    AlwaysOn                Off                    Running
 
 
 
@@ -73,7 +73,7 @@
     [Template]  Verify Restore Policy
 
     # Policy                Initial Host State     Expected Host State
-    ${ALWAYS_POWER_ON}      Running                Running
+    AlwaysOn                Running                Running
 
 
 
@@ -91,7 +91,7 @@
     [Template]  Verify Restore Policy
 
     # Policy                Initial Host State     Expected Host State
-    ${RESTORE_LAST_STATE}   Running                Running
+    LastState               Running                Running
 
 
 
@@ -101,7 +101,7 @@
     [Template]  Verify Restore Policy
 
     # Policy                Initial Host State     Expected Host State
-    ${RESTORE_LAST_STATE}   Off                    Off
+    LastState               Off                    Off
 
 
 *** Keywords ***
@@ -118,10 +118,11 @@
 
     Set Initial Test State  ${expectedState}
 
-    Set BMC Power Policy  ${policy}
+    Redfish Set Power Restore Policy  ${policy}
 
     Redfish BMC Reset Operation
-    Check If BMC is Up
+    Sleep  20s
+    Wait For BMC Online
 
     Wait Until Keyword Succeeds
     ...  10 min  20 sec  Valid Boot States  ${nextState}
@@ -135,8 +136,8 @@
     # sys_state    system state list
     #              (e.g. "Off", "On", "Reboot", etc.).
 
-    ${current_state}=  Get Boot State
-    Valid Boot State  ${sys_state}  ${current_state}
+    ${current_state}=  Redfish Get States
+    Redfish Valid Boot State  ${sys_state}  ${current_state}
 
 
 Set Initial Test State
@@ -170,6 +171,24 @@
     [Documentation]  Do the post suite teardown.
     # 1. Set policy to default.
 
-    Run Keyword And Ignore Error  Set BMC Power Policy  ${ALWAYS_POWER_OFF}
+    Run Keyword And Ignore Error  Redfish Set Power Restore Policy  AlwaysOff
     Redfish.Logout
 
+
+Wait For BMC Online
+    [Documentation]  Wait for Host to be online. Checks every X seconds
+    ...              interval for Y minutes and fails if timed out.
+    ...              Default MAX timedout is 10 min, interval 10 seconds.
+    [Arguments]      ${max_timeout}=${OPENBMC_REBOOT_TIMEOUT} min
+    ...              ${interval}=10 sec
+
+    # Description of argument(s):
+    # max_timeout   Maximum time to wait.
+    #               This should be expressed in Robot Framework's time format
+    #               (e.g. "10 minutes").
+    # interval      Interval to wait between status checks.
+    #               This should be expressed in Robot Framework's time format
+    #               (e.g. "5 seconds").
+
+    Wait Until Keyword Succeeds
+    ...   ${max_timeout}  ${interval}  Verify Ping SSH And Redfish Authentication