Test to verify IPMI chassis power restore policy settings.

TC verifies whether the change of power policy setting through REST API
is reflected in the IPMI chassis status power restore policy settings.

Change-Id: If51c531660c2a3f0771e53c5ba00faec9466a15c
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/extended/test_power_restore.robot b/extended/test_power_restore.robot
index 38da2c6..87df8c0 100644
--- a/extended/test_power_restore.robot
+++ b/extended/test_power_restore.robot
@@ -17,7 +17,7 @@
 Force Tags      chassisboot  bmcreboot
 
 *** Variables ***
-${HOST_SETTING}    ${OPENBMC_BASE_URI}settings/host0
+${HOST_SETTING}    ${SETTINGS_URI}host0
 
 *** Test Cases ***
 
@@ -48,7 +48,7 @@
 Set Restore Policy
     [Arguments]    ${policy}   ${expectedState}   ${nextState}
 
-    Set Policy Setting   ${policy}
+    Set BMC Power Policy    ${policy}
 
     ${currentState}=
     ...   Read Attribute   ${HOST_SETTING}   system_state
@@ -70,16 +70,6 @@
     ...   5 min   10 sec   System State  ${nextState}
 
 
-Set Policy Setting
-    [Documentation]   Set the given test policy
-    [Arguments]   ${policy}
-
-    ${valueDict}=     create dictionary  data=${policy}
-    Write Attribute    ${HOST_SETTING}    power_policy   data=${valueDict}
-    ${currentPolicy}=  Read Attribute     ${HOST_SETTING}   power_policy
-    Should Be Equal    ${currentPolicy}   ${policy}
-
-
 Set Initial Test State
     [Documentation]   Poweron if ON expected, Poweroff if OFF expected
     ...               to initial state of the test.
diff --git a/lib/utils.robot b/lib/utils.robot
index 63c7cae..66b51d6 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -18,14 +18,15 @@
 #${dbuscmdString}=  string:"xyz.openbmc_project.settings.Host" string:
 ${dbuscmdString}=   string:"org.openbmc.settings.Host" string:
 
-
 # Assign default value to QUIET for programs which may not define it.
 ${QUIET}  ${0}
 ${bmc_mem_free_cmd}=   free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f4
 ${bmc_mem_total_cmd}=   free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f2
 ${bmc_cpu_usage_cmd}=   top -n 1  | grep CPU: | cut -c 7-9
+${HOST_SETTING}    ${SETTINGS_URI}host0
 
 *** Keywords ***
+
 Wait For Host To Ping
     [Arguments]  ${host}  ${timeout}=${OPENBMC_REBOOT_TIMEOUT}min
     ...          ${interval}=5 sec
@@ -508,6 +509,7 @@
     ${resp}=   Get Matches   ${list}   regexp=^.*[0-9a-z_].${endpoint}[0-9]*$
     [Return]   ${resp}
 
+
 Check Zombie Process
     [Documentation]    Check if any defunct process exist or not on BMC
     ${count}  ${stderr}  ${rc}=  Execute Command  ps -o stat | grep Z | wc -l
@@ -532,3 +534,12 @@
 
     Should Be Equal  ${rc}  ${0}  msg=${stderr}
     Should Contain   ${stderr}  Vacuuming done
+
+Set BMC Power Policy
+    [Documentation]   Set the given BMC power policy.
+    [arguments]   ${policy}
+
+    ${valueDict}=     create dictionary  data=${policy}
+    Write Attribute    ${HOST_SETTING}    power_policy   data=${valueDict}
+    ${currentPolicy}=  Read Attribute     ${HOST_SETTING}   power_policy
+    Should Be Equal    ${currentPolicy}   ${policy}
diff --git a/test_lists/skip_test b/test_lists/skip_test
index 146ebe8..0121958 100644
--- a/test_lists/skip_test
+++ b/test_lists/skip_test
@@ -41,6 +41,7 @@
 -e Set_System_Time_with_no_time
 -e IPMI_Chassis_Status_On
 -e IPMI_Chassis_Status_Off
+-e IPMI_Chassis_Restore_Power_Policy
 #https://github.com/openbmc/openbmc/issues/830
 -e Good_connection_for_testing
 -e get_directory_listing
diff --git a/test_lists/skip_test_palmetto b/test_lists/skip_test_palmetto
index 71ae7f0..501b4e4 100644
--- a/test_lists/skip_test_palmetto
+++ b/test_lists/skip_test_palmetto
@@ -49,6 +49,7 @@
 -e Set_System_Time_with_no_time
 -e IPMI_Chassis_Status_On
 -e IPMI_Chassis_Status_Off
+-e IPMI_Chassis_Restore_Power_Policy
 #https://github.com/openbmc/openbmc/issues/830
 -e Good_connection_for_testing
 -e get_directory_listing
diff --git a/test_lists/skip_test_witherspoon b/test_lists/skip_test_witherspoon
index c290289..56f41d2 100644
--- a/test_lists/skip_test_witherspoon
+++ b/test_lists/skip_test_witherspoon
@@ -41,6 +41,7 @@
 -e Set_System_Time_with_no_time
 -e IPMI_Chassis_Status_On
 -e IPMI_Chassis_Status_Off
+-e IPMI_Chassis_Restore_Power_Policy
 #Pre bringup list
 -e Repeated_Testing
 -e power_on_test
diff --git a/tests/ipmi/test_chassis.robot b/tests/ipmi/test_chassis.robot
old mode 100644
new mode 100755
index ccf6b88..5cccc6c
--- a/tests/ipmi/test_chassis.robot
+++ b/tests/ipmi/test_chassis.robot
@@ -5,31 +5,73 @@
 Resource               ../../lib/ipmi_client.robot
 Resource               ../../lib/openbmc_ffdc.robot
 Resource               ../../lib/utils.robot
+Resource               ../../lib/resource.txt
 
 Suite Setup            Open Connection And Log In
 Suite Teardown         Close All Connections
-Test Teardown          FFDC On Test Case Fail
+Test Teardown          Test Exit Logs
+
+*** Variables ***
+${HOST_SETTING}  ${SETTINGS_URI}host0
 
 *** Test Cases ***
 
 IPMI Chassis Status On
-    [Documentation]   This test case verfies system power on status
-    ...               using IPMI Get Chassis status command
+    [Documentation]  This test case verfies system power on status
+    ...               using IPMI Get Chassis status command.
     [Tags]  IPMI_Chassis_Status_On
 
     Initiate Power On
-    ${resp}=    Run IPMI Standard Command    chassis status
-    ${power_status}=    Get Lines Containing String    ${resp}    System Power
-    Should Contain    ${power_status}    on
+    ${resp}=  Run IPMI Standard Command  chassis status
+    ${power_status}=  Get Lines Containing String  ${resp}  System Power
+    Should Contain  ${power_status}  on
 
 IPMI Chassis Status Off
-    [Documentation]   This test case verfies system power off status
-    ...               using IPMI Get Chassis status command
+    [Documentation]  This test case verfies system power off status
+    ...               using IPMI Get Chassis status command.
     [Tags]  IPMI_Chassis_Status_Off
 
     Initiate Power Off
-    ${resp}=    Run IPMI Standard Command    chassis status
-    ${power_status}=    Get Lines Containing String    ${resp}    System Power
-    Should Contain    ${power_status}    off
+    ${resp}=  Run IPMI Standard Command  chassis status
+    ${power_status}=  Get Lines Containing String  ${resp}  System Power
+    Should Contain  ${power_status}    off
 
+IPMI Chassis Restore Power Policy
+     [Documentation]  Verfy IPMI chassis restore power policy.
 
+     [Tags]  IPMI_Chassis_Restore_Power_Policy
+
+     ${initial_power_policy}=  Read Attribute  ${HOST_SETTING}  power_policy
+
+     Set BMC Power Policy  ALWAYS_POWER_ON
+     ${resp}=  Run IPMI Standard Command  chassis status
+     ${power_status}=
+     ...  Get Lines Containing String  ${resp}  Power Restore Policy
+     Should Contain  ${power_status}  always-on
+
+     Set BMC Power Policy  RESTORE_LAST_STATE
+     ${resp}=  Run IPMI Standard Command  chassis status
+     ${power_status}=
+     ...  Get Lines Containing String  ${resp}  Power Restore Policy
+     Should Contain  ${power_status}  previous
+
+     Set BMC Power Policy  LEAVE_OFF
+     ${resp}=    Run IPMI Standard Command  chassis status
+     ${power_status}=
+     ...  Get Lines Containing String  ${resp}  Power Restore Policy
+     Should Contain  ${power_status}    always-off
+
+     Set BMC Power Policy  ${initial_power_policy}
+     ${power_policy}=  Read Attribute  ${HOST_SETTING}  power_policy
+     Should Be Equal  ${power_policy}  ${initial_power_policy}
+
+*** Keywords ***
+
+Test Exit Logs
+    [Documentation]    Log FFDC if test failed.
+
+    Set BMC Power Policy  RESTORE_LAST_STATE
+    ${power_policy}=  Read Attribute  ${HOST_SETTING}  power_policy
+    Should Be Equal  ${power_policy}  RESTORE_LAST_STATE
+
+    FFDC On Test Case Fail