Fix to handle "403 Forbidden error" while setting time

This fix is to handle limitation of fw issue - openbmc/openbmc#3459

Change-Id: Ie692c295080b5ac6645690c318af0f92fe43209a
Signed-off-by: Rahul Maheshwari <rahulmaheshwari@in.ibm.com>
diff --git a/tests/test_time.robot b/tests/test_time.robot
index 01d56c1..5ced93a 100644
--- a/tests/test_time.robot
+++ b/tests/test_time.robot
@@ -38,6 +38,7 @@
     Should Be True  ${diff} < ${ALLOWED_TIME_DIFF}
     ...  Open BMC time does not match with IPMI sel time
 
+
 Set Valid System Time
     [Documentation]  Set system time using IPMI and verify that it is
     ...              correctly set in BMC.
@@ -58,6 +59,7 @@
     Should Be True  ${diff} < ${ALLOWED_TIME_DIFF}
     ...  Open BMC time does not match with set time
 
+
 Set Invalid System Time
     [Documentation]  Set system time with invalid time using IPMI and verify
     ...              that it should throw error.
@@ -173,16 +175,6 @@
     Set Host Time  ${HOST_OWNER}  ${MANUAL_MODE}  ok      Change    Set
 
 
-Set Host Time With Both And Manual
-    [Documentation]  Set host time when time owner is both and time mode is
-    ...              manual.
-    [Tags]  Set_Host_Time_With_Both_And_Manual
-    [Template]  Set Time Using REST
-
-    #Operation     Owner          Mode            Status  BMC Time  Host Time
-    Set Host Time  ${BOTH_OWNER}  ${MANUAL_MODE}  ok      Change    Set
-
-
 Set Host Time With Both And NTP
     [Documentation]  Set host time when time owner is both and time mode is
     ...              NTP.
@@ -243,6 +235,16 @@
     Set Host Time  ${HOST_OWNER}   ${NTP_MODE}     error   Not Change  No Set
 
 
+Set Host Time With Both And Manual
+    [Documentation]  Set host time when time owner is both and time mode is
+    ...              manual.
+    [Tags]  Set_Host_Time_With_Both_And_Manual
+    [Template]  Set Time Using REST
+
+    #Operation     Owner          Mode            Status  BMC Time  Host Time
+    Set Host Time  ${BOTH_OWNER}  ${MANUAL_MODE}  ok      Change    Set
+
+
 Set Invalid Time Mode
     [Documentation]  Set time mode with invalid value using REST and verify
     ...              that it should throw error.
@@ -293,6 +295,25 @@
     Should Not Be Empty  ${resp}
     [Return]  ${resp}
 
+
+Verify Set Time Via REST
+    [Documentation]  Verify set time via REST.
+    [Arguments]  ${target}  ${expected_status}
+    # Description of argument(s):
+    # target           The target of the set time operation: "bmc" or "host".
+    # expected_status  Expected status of set time operation
+
+    ${time_owner_url}=  Set Variable  ${TIME_MANAGER_URI}${target}
+
+    ${args}=  Create Dictionary  data=${SYSTEM_TIME_VALID_EPOCH}
+    ${resp}=  OpenBMC Put Request
+    ...  ${time_owner_url}/attr/Elapsed  data=${args}
+    ${jsondata}=  to Json  ${resp.content}
+    Run Keyword If  "${expected_status}" == "ok"
+    ...  Should Not Be Equal As Strings  ${jsondata['message']}  403 Forbidden
+    Should Be Equal As Strings  ${jsondata['status']}  ${expected_status}
+
+
 Set Time Owner
     [Arguments]  ${args}
     [Documentation]  Set time owner of the system via REST
@@ -372,20 +393,18 @@
 
     ${setdate}=  Set Variable  ${SYSTEM_TIME_VALID_EPOCH}
 
-    ${time_owner_url}=  Set Variable If
-    ...  '${operation}' == 'Set BMC Time'  ${TIME_MANAGER_URI}bmc
-    ...  '${operation}' == 'Set Host Time'  ${TIME_MANAGER_URI}host
-
     ${start_time}=  Get Current Date
 
     ${old_bmc_time}=  Get BMC Time Using REST
     ${old_host_time}=  Get HOST Time Using REST
 
-    ${valueDict}=  Create Dictionary  data=${SYSTEM_TIME_VALID_EPOCH}
-    ${resp}=  OpenBMC Put Request
-    ...  ${time_owner_url}/attr/Elapsed  data=${valueDict}
-    ${jsondata}=  to JSON  ${resp.content}
-    Should Be Equal As Strings  ${jsondata['status']}  ${status}
+    Run Keyword If  '${operation}' == 'Set BMC Time'
+    ...  Wait Until Keyword Succeeds  1 min  20 sec  Verify Set Time Via REST
+    ...  bmc  ${status}
+    ...  ELSE IF  '${operation}' == 'Set Host Time'
+    ...  Wait Until Keyword Succeeds  1 min  20 sec  Verify Set Time Via REST
+    ...  host  ${status}
+
 
     ${new_bmc_time}=  Get BMC Time Using REST
     ${new_host_time}=  Get HOST Time Using REST
@@ -453,6 +472,7 @@
 
     [Return]  ${date}
 
+
 Post Test Case Execution
     [Documentation]  Do the post test teardown.
     ...  1. Capture FFDC on test failure.