Added test cases for clock management

What all is added:
    - Added test case to set BMC and HOST Time
        for all good path scenarios
    - Added test case to set BMC and HOST Time
        for all bad path scenarios
    - These TCs are also added in skip list due
        to an existing issue
    - Added keyword to get BMC and HOST time. This
        keyword is used to verify set time operation.
    - Updated minimum cell separator of 2 spaces
    - Updated documentation section
    - All lines are now under 79 characters

Resolves openbmc/openbmc-test-automation#227 and
         openbmc/openbmc-test-automation#271

Change-Id: I15a4915caf1a212272c390f12b949e76748c1664
Signed-off-by: Rahul Maheshwari <rahulmaheshwari@in.ibm.com>
diff --git a/data/variables.py b/data/variables.py
index 1146cab..1a8c84f 100644
--- a/data/variables.py
+++ b/data/variables.py
@@ -15,7 +15,7 @@
 INVENTORY_URI = OPENBMC_BASE_URI + 'inventory/'
 USER_MANAGER_URI = OPENBMC_BASE_URI + 'UserManager/'
 NETWORK_MANAGER_URI = OPENBMC_BASE_URI + 'NetworkManager/'
-
+TIME_MANAGER_URI = OPENBMC_BASE_URI + 'TimeManager/'
 
 '''
   QEMU HTTPS variable:
diff --git a/test_lists/skip_test b/test_lists/skip_test
index 0121958..d2c547b 100644
--- a/test_lists/skip_test
+++ b/test_lists/skip_test
@@ -49,3 +49,7 @@
 -e get_names_org
 #https://github.com/openbmc/openbmc-test-automation/issues/226
 -e Test_BIOS_Version
+#https://github.com/openbmc/openbmc/issues/928
+-e Set_Host_Time_With_Both_And_NTP
+#https://github.com/openbmc/openbmc/issues/901
+-e Set_BMC_Time_With_Split_And_Manual
diff --git a/test_lists/skip_test_palmetto b/test_lists/skip_test_palmetto
index 501b4e4..3f8cbeb 100644
--- a/test_lists/skip_test_palmetto
+++ b/test_lists/skip_test_palmetto
@@ -55,3 +55,7 @@
 -e get_directory_listing
 #https://github.com/openbmc/openbmc-test-automation/issues/90
 -e Verify_System_VPD_Properties
+#https://github.com/openbmc/openbmc/issues/928
+-e Set_Host_Time_With_Both_And_NTP
+#https://github.com/openbmc/openbmc/issues/901
+-e Set_BMC_Time_With_Split_And_Manual
diff --git a/test_lists/skip_test_witherspoon b/test_lists/skip_test_witherspoon
index 56f41d2..f1e3622 100644
--- a/test_lists/skip_test_witherspoon
+++ b/test_lists/skip_test_witherspoon
@@ -56,3 +56,7 @@
 -e get_names_org
 -e bmcreboot
 -e chassisboot
+#https://github.com/openbmc/openbmc/issues/928
+-e Set_Host_Time_With_Both_And_NTP
+#https://github.com/openbmc/openbmc/issues/901
+-e Set_BMC_Time_With_Split_And_Manual
diff --git a/tests/test_time.robot b/tests/test_time.robot
old mode 100755
new mode 100644
index 3c13f49..c91f178
--- a/tests/test_time.robot
+++ b/tests/test_time.robot
@@ -14,170 +14,387 @@
 Test Teardown          Post Test Execution
 
 *** Variables ***
-${SYSTEM_TIME_INVALID}     01/01/1969 00:00:00
-${SYSTEM_TIME_VALID}       02/29/2016 09:10:00
-${ALLOWED_TIME_DIFF}       2
-
-${SETTING_HOST}     ${SETTINGS_URI}host0
+${SYSTEM_TIME_INVALID}      01/01/1969 00:00:00
+${SYSTEM_TIME_VALID}        02/29/2016 09:10:00
+${SYSTEM_TIME_VALID_EPOCH}  1456737000  #Equivalent epoch time for 02/29/2016 09:10:00
+${ALLOWED_TIME_DIFF}        3
+${SETTING_HOST}             ${SETTINGS_URI}host0
 
 *** Test Cases ***
 
 Get System Time
-    [Documentation]   ***GOOD PATH***
-    ...               This test case tries to get system time using IPMI and
-    ...               then tries to cross check with BMC date time.
-    ...               Expectation is that BMC time and ipmi sel time should match.
+    [Documentation]  Get system time using IPMI and verify that it matches
+    ...              with BMC date time.
     [Tags]  Get_System_Time
 
-    ${resp}=    Run IPMI Standard Command    sel time get
-    ${ipmidate}=    Convert Date    ${resp}    date_format=%m/%d/%Y %H:%M:%S    exclude_millis=yes
-    ${bmcdate}=    Get BMC Time And Date
-    ${diff}=    Subtract Date From Date    ${bmcdate}    ${ipmidate}
-    Should Be True      ${diff} < ${ALLOWED_TIME_DIFF}    Open BMC time does not match with IPMI sel time
+    ${resp}=  Run IPMI Standard Command  sel time get
+    ${ipmidate}=  Convert Date  ${resp}  date_format=%m/%d/%Y %H:%M:%S
+    ...  exclude_millis=yes
+    ${bmcdate}=  Get BMC Time Using IPMI
+    ${diff}=  Subtract Date From Date  ${bmcdate}  ${ipmidate}
+    Should Be True  ${diff} < ${ALLOWED_TIME_DIFF}
+    ...  Open BMC time does not match with IPMI sel time
 
 Set Valid System Time
-    [Documentation]   ***GOOD PATH***
-    ...               This test case tries to set system time using IPMI and
-    ...               then tries to cross check if it is correctly set in BMC.
-    ...               Expectation is that BMC time should match with new time.
+    [Documentation]  Set system time using IPMI and verify that it is
+    ...              correctly set in BMC.
     [Tags]  Set_Valid_System_Time
 
-    ${resp}=    Run IPMI Standard Command    sel time set "${SYSTEM_TIME_VALID}"
-    ${setdate}=    Convert Date    ${SYSTEM_TIME_VALID}    date_format=%m/%d/%Y %H:%M:%S    exclude_millis=yes
-    ${bmcdate}=    Get BMC Time And Date
-    ${diff}=    Subtract Date From Date    ${bmcdate}    ${setdate}
-    Should Be True      ${diff} < ${ALLOWED_TIME_DIFF}     Open BMC time does not match with set time
+    ${resp}=  Run IPMI Standard Command  sel time set "${SYSTEM_TIME_VALID}"
+    ${setdate}=  Convert Date  ${SYSTEM_TIME_VALID}
+    ...  date_format=%m/%d/%Y %H:%M:%S  exclude_millis=yes
+    ${bmcdate}=  Get BMC Time Using IPMI
+    ${diff}=  Subtract Date From Date  ${bmcdate}  ${setdate}
+    Should Be True  ${diff} < ${ALLOWED_TIME_DIFF}
+    ...  Open BMC time does not match with set time
 
 Set Invalid System Time
-    [Documentation]   ***BAD PATH***
-    ...               This test case tries to set system time with invalid time using IPMI.
-    ...               Expectation is that it should return error.
+    [Documentation]  Set system time with invalid time using IPMI and verify
+    ...              that it should throw error.
     [Tags]  Set_Invalid_System_Time
 
-    ${msg}=    Run Keyword And Expect Error    *    Run IPMI Standard Command    sel time set "${SYSTEM_TIME_INVALID}"
-    Should Start With    ${msg}    Specified time could not be parsed
+    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
+    ...  sel time set "${SYSTEM_TIME_INVALID}"
+    Should Start With  ${msg}  Specified time could not be parsed
 
 Set System Time with no time
-    [Documentation]   ***BAD PATH***
-    ...               This test case tries to set system time with no time using IPMI.
-    ...               Expectation is that it should return error.
+    [Documentation]  Set system time with no time using IPMI and verify
+    ...              that it should throw error.
     [Tags]  Set_System_Time_with_no_time
 
-    ${msg}=    Run Keyword And Expect Error    *    Run IPMI Standard Command    sel time set ""
-    Should Start With    ${msg}    Specified time could not be parsed
+    ${msg}=  Run Keyword And Expect Error  *  Run IPMI Standard Command
+    ...  sel time set ""
+    Should Start With  ${msg}  Specified time could not be parsed
 
-Set NTP Time Mode
-    [Documentation]   ***GOOD PATH***
-    ...               This testcase is to set time mode as NTP using REST
-    ...               URI and then verify using REST API.\n
-    [Tags]  Set_NTP_Time_Mode
 
-    Set Time Mode   NTP
+Set BMC Time With BMC And Manual
+    #Operation    Owner  Mode    Status  BMC Time  Host Time
+    Set BMC Time  BMC    MANUAL  ok      Set       Change
 
-    ${boot}=   Read Attribute  ${SETTING_HOST}   time_mode
-    Should Be Equal    ${boot}    NTP
+    [Documentation]  Set BMC time when time owner is BMC and time mode is
+    ...              manual.
+    [Tags]  Set_BMC_Time_With_BMC_And_Manual
+    [Template]  Set Time Using REST
 
-Set Manual Time Mode
-    [Documentation]   ***GOOD PATH***
-    ...               This testcase is to set time mode as manual using REST
-    ...               URI and then verify using REST API.\n
-    [Tags]  Set_Manual_Time_Mode
+Set BMC Time With Both And Manual
+    #Operation    Owner  Mode    Status  BMC Time  Host Time
+    Set BMC Time  BOTH   MANUAL  ok      Set       Change
 
-    Set Time Mode   Manual
+    [Documentation]  Set BMC time when time owner is Both and time mode is
+    ...              manual.
+    [Tags]  Set_BMC_Time_With_Both_And_Manual
+    [Template]  Set Time Using REST
 
-    ${boot}=   Read Attribute  ${SETTING_HOST}   time_mode
-    Should Be Equal    ${boot}    Manual
 
-Set Time Owner as BMC
-    [Documentation]   ***GOOD PATH***
-    ...               This testcase is to set time owner as BMC using REST
-    ...               URI and then verify using REST API.\n
-    [Tags]  Set_Time_Owner_as_BMC
+Set BMC Time With Split And Manual
+    #Operation    Owner  Mode    Status  BMC Time  Host Time
+    Set BMC Time  SPLIT  MANUAL  ok      Set       No Change
 
-    Set Time Owner   BMC
+    [Documentation]  Set BMC time when time owner is Split and time mode is
+    ...              manual.
+    [Tags]  Set_BMC_Time_With_Split_And_Manual
+    [Template]  Set Time Using REST
 
-    ${boot}=   Read Attribute  ${SETTING_HOST}   time_owner
-    Should Be Equal    ${boot}    BMC
+Set BMC Time With BMC And NTP
+    #Operation    Owner  Mode    Status  BMC Time  Host Time
+    Set BMC Time  BMC    NTP     error   Not Set   No Change
 
-Set Time Owner as Host
-    [Documentation]   ***GOOD PATH***
-    ...               This testcase is to set time owner as Host using REST
-    ...               URI and then verify using REST API.\n
-    [Tags]  Set_Time_Owner_as_Host
+    [Documentation]  Set BMC time when time owner is BMC and time mode is
+    ...              NTP.
+    [Tags]  Set_BMC_Time_With_BMC_And_NTP
+    [Template]  Set Time Using REST
 
-    Set Time Owner   Host
+Set BMC Time With Host And Manual
+    #Operation    Owner  Mode    Status  BMC Time  Host Time
+    Set BMC Time  HOST   MANUAL  error   Not Set   No Change
+    [Documentation]  Set BMC time when time owner is Host and time mode is
+    ...              Manual.
+    [Tags]  Set_BMC_Time_With_Host_And_Manual
+    [Template]  Set Time Using REST
 
-    ${boot}=   Read Attribute  ${SETTING_HOST}    time_owner
-    Should Be Equal    ${boot}    Host
+Set BMC Time With Both And NTP
+    #Operation    Owner  Mode    Status  BMC Time  Host Time
+    Set BMC Time  BOTH   NTP     error   Not Set   No Change
+
+    [Documentation]  Set BMC time when time owner is Both and time mode is
+    ...              NTP.
+    [Tags]  Set_BMC_Time_With_Both_And_NTP
+    [Template]  Set Time Using REST
+
+Set BMC Time With Split And NTP
+    #Operation    Owner  Mode    Status  BMC Time  Host Time
+    Set BMC Time  SPLIT  NTP     error   Not Set   No Change
+
+    [Documentation]  Set BMC time when time owner is Split and time mode is
+    ...              NTP.
+    [Tags]  Set_BMC_Time_With_Split_And_NTP
+    [Template]  Set Time Using REST
+
+Set Host Time With Host And Manual
+    #Operation     Owner  Mode    Status  BMC Time  Host Time
+    Set Host Time  HOST   MANUAL  ok      Change    Set
+
+    [Documentation]  Set host time when time owner is host and time mode is
+    ...              manual.
+    [Tags]  Set_Host_Time_With_Host_And_Manual
+    [Template]  Set Time Using REST
+
+Set Host Time With Both And Manual
+    #Operation     Owner  Mode    Status  BMC Time  Host Time
+    Set Host Time  BOTH   MANUAL  ok      Change    Set
+
+    [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
+
+Set Host Time With Both And NTP
+    #Operation     Owner  Mode    Status  BMC Time   Host Time
+    Set Host Time  BOTH   NTP     ok      No Change  Set
+
+    [Documentation]  Set host time when time owner is both and time mode is
+    ...              NTP.
+    [Tags]  Set_Host_Time_With_Both_And_NTP
+    [Template]  Set Time Using REST
+
+Set Host Time With Split And Manual
+    #Operation     Owner  Mode    Status  BMC Time   Host Time
+    Set Host Time  SPLIT  MANUAL  ok      No Change  Set
+
+    [Documentation]  Set host time when time owner is split and time mode is
+    ...              manual.
+    [Tags]  Set_Host_Time_With_Split_And_Manual
+    [Template]  Set Time Using REST
+
+Set Host Time With Split And NTP
+    #Operation     Owner  Mode    Status   BMC Time   HOST Time
+    Set Host Time  SPLIT  NTP     ok       No Change  Set
+
+    [Documentation]  Set host time when time owner is split and time mode is
+    ...              NTP.
+    [Tags]  Set_Host_Time_With_Split_And_NTP
+    [Template]  Set Time Using REST
+
+Set Host Time With BMC And Manual
+    #Operation     Owner  Mode    Status   BMC Time   HOST Time
+    Set Host Time  BMC    MANUAL  error    No Change  Not Set
+    [Documentation]  Set host time when time owner is BMC and time mode is
+    ...              Manual.
+    [Tags]  Set_Host_Time_With_BMC_And_Manual
+    [Template]  Set Time Using REST
+
+Set Host Time With BMC Owner NTP
+    #Operation     Owner  Mode    Status   BMC Time   HOST Time
+    Set Host Time  BMC    NTP     error    No Change  Not Set
+    [Documentation]  Set host time when time owner is BMC and time mode is
+    ...              NTP.
+    [Tags]  Set_Host_Time_With_BMC_And_NTP
+    [Template]  Set Time Using REST
 
 Set Invalid Time Mode
-    [Documentation]   ***BAD PATH***
-    ...               This testcase is to verify that invalid value for time
-    ...               mode can not be set and proper error is thrown by
-    ...               REST API for the same.
+    [Documentation]  Set time mode with invalid value using REST and verify
+    ...              that it should throw error.
     [Tags]  Set_Invalid_Time_Mode
 
-    ${resp}=   Set Time Mode   abc
-    Should Be Equal    ${resp}    error
+    ${timemode}=  Set Variable  abc
+    ${valueDict}=  Create Dictionary  data=${timemode}
 
-    ${boot}=   Read Attribute   ${SETTING_HOST}   time_mode
-    Should Not Be Equal    ${boot}    abc
+    ${resp}=  OpenBMC Put Request
+    ...  ${SETTING_HOST}/attr/time_mode  data=${valueDict}
+    ${jsondata}=  to JSON  ${resp.content}
+    Should Be Equal  ${jsondata['status']}  error
+
+    ${mode}=  Read Attribute  ${SETTING_HOST}  time_mode
+    Should Not Be Equal  ${mode}  abc
 
 Set Invalid Time Owner
-    [Documentation]   ***BAD PATH***
-    ...               This testcase is to verify that invalid value for time
-    ...               owner can not be set and proper error is thrown by
-    ...               REST API for the same.
+    [Documentation]  Set time owner with invalid value using REST and verify
+    ...              that it should throw error.
     [Tags]  Set_Invalid_Time_Owner
 
-    ${resp}=   Set Time Owner   xyz
-    Should Be Equal    ${resp}    error
+    ${timeowner}=  Set Variable  xyz
+    ${valueDict}=  Create Dictionary  data=${timeowner}
 
-    ${boot}=   Read Attribute  ${SETTING_HOST}   time_owner
-    Should Not Be Equal    ${boot}    xyz
+    ${resp}=  OpenBMC Put Request
+    ...  ${SETTING_HOST}/attr/time_owner  data=${valueDict}
+    ${jsondata}=  to JSON  ${resp.content}
+    Should Be Equal  ${jsondata['status']}  error
+
+    ${owner}=  Read Attribute  ${SETTING_HOST}  time_owner
+    Should Not Be Equal  ${owner}  xyz
 
 
 *** Keywords ***
 
-Get BMC Time And Date
-    ${stdout}    ${stderr}    ${output}=
-    ...          Execute Command    date "+%m/%d/%Y %H:%M:%S"
-    ...          return_stdout=True    return_stderr= True    return_rc=True
-    Should Be Equal    ${output}    ${0}    msg=${stderr}
+Get BMC Time Using IPMI
+    [Documentation]  Returns BMC time of the system via IPMI
 
-    ${resp}=     Convert Date    ${stdout}     date_format=%m/%d/%Y %H:%M:%S
-    ...          exclude_millis=yes
-    Should Not Be Empty    ${resp}
-    [Return]    ${resp}
+    ${stdout}  ${stderr}  ${output}=
+    ...  Execute Command  date "+%m/%d/%Y %H:%M:%S"
+    ...  return_stdout=True  return_stderr= True  return_rc=True
+    Should Be Equal  ${output}  ${0}  msg=${stderr}
+
+    ${resp}=  Convert Date  ${stdout}  date_format=%m/%d/%Y %H:%M:%S
+    ...  exclude_millis=yes
+    Should Not Be Empty  ${resp}
+    [Return]  ${resp}
 
 Set Time Owner
-    [Arguments]    ${args}
-    ${timeowner}=   Set Variable   ${args}
-    ${valueDict}=   create dictionary   data=${timeowner}
+    [Arguments]  ${args}
+    [Documentation]  Set time owner of the system via REST
 
-    ${resp}=   OpenBMC Put Request
-    ...    ${SETTING_HOST}/attr/time_owner    data=${valueDict}
-    ${jsondata}=    to json    ${resp.content}
-    [Return]    ${jsondata['status']}
+    ${timeowner}=  Set Variable  ${args}
+    ${valueDict}=  Create Dictionary  data=${timeowner}
+
+    ${resp}=  OpenBMC Put Request
+    ...  ${SETTING_HOST}/attr/time_owner  data=${valueDict}
+    ${jsondata}=  to JSON  ${resp.content}
+
+    @{states}=  Create List  BMC_READY  HOST_POWERED_OFF
+    ${bmc_state}=  Get BMC State
+
+    Run Keyword If  '${bmc_state}' in ${states}
+    ...  Log  System is in off state so owner change will get applied.
+    ...  ELSE   Run keyword
+    ...  Initiate Power Off
+
+    ${owner}=  Read Attribute  ${SETTING_HOST}  time_owner
+    Should Be Equal  ${owner}  ${args}
+
+    ${current_mode}=
+    ...  Read Attribute  ${TIME_MANAGER_URI.rstrip("/")}  curr_time_owner
+    Should Be Equal  ${current_mode}  ${args}
+
+    [Return]  ${jsondata['status']}
 
 Set Time Mode
-    [Arguments]    ${args}
-    ${timemode}=   Set Variable   ${args}
-    ${valueDict}=   create dictionary   data=${timemode}
+    [Arguments]  ${args}
+    [Documentation]  Set time mode of the system via REST
 
-    ${resp}=   OpenBMC Put Request
-    ...   ${SETTING_HOST}/attr/time_mode    data=${valueDict}
-    ${jsondata}=    to json    ${resp.content}
-    [Return]    ${jsondata['status']}
+    ${timemode}=  Set Variable  ${args}
+    ${valueDict}=  Create Dictionary  data=${timemode}
+
+    ${resp}=  OpenBMC Put Request
+    ...  ${SETTING_HOST}/attr/time_mode  data=${valueDict}
+    ${jsondata}=  to JSON  ${resp.content}
+    Sleep  5s
+
+    ${mode}=  Read Attribute  ${SETTING_HOST}  time_mode
+    Should Be Equal  ${mode}  ${args}
+
+    ${current_mode}=
+    ...  Read Attribute  ${TIME_MANAGER_URI.rstrip("/")}  curr_time_mode
+    Should Be Equal  ${current_mode}  ${args}
+
+Get BMC Time Using REST
+    [Documentation]  Returns BMC time of the system via REST
+    ...              Time Format : YYYY-MM-DD hh:mm:ss.mil
+    ...              eg. 2016-12-14 07:09:58.000
+
+    @{time_owner}=  Create List  BMC
+    ${data}=  Create Dictionary  data=@{time_owner}
+    ${resp}=  OpenBMC Post Request
+    ...  ${TIME_MANAGER_URI}action/GetTime  data=${data}
+    ${jsondata}=  To JSON  ${resp.content}
+    ${time_epoch}=  Get From List  ${jsondata["data"]}  0
+    ${resp}=  Convert Date
+    ...  ${time_epoch}  date_format=%a %b %d %H:%M:%S %Y %Z
+    [Return]  ${resp}
+
+Get HOST Time Using REST
+    [Documentation]  Returns HOST time of the system via REST
+    ...              Time Format : YYYY-MM-DD hh:mm:ss.mil
+    ...              eg. 2016-12-14 07:09:58.000
+
+    @{time_owner}=  Create List  HOST
+    ${data}=  Create Dictionary  data=@{time_owner}
+    ${resp}=  OpenBMC Post Request
+    ...  ${TIME_MANAGER_URI}action/GetTime  data=${data}
+    ${jsondata}=  To JSON  ${resp.content}
+    ${time_epoch}=  Get From List  ${jsondata["data"]}   0
+    ${resp}=  Convert Date
+    ...  ${time_epoch}  date_format=%a %b %d %H:%M:%S %Y %Z
+    [Return]  ${resp}
+
+Set Time Using REST
+    [Arguments]  ${operation}  ${owner}  ${mode}  ${status}  ${bmc_time}
+    ...  ${host_time}
+    [Documentation]  Set BMC or Host time on system via REST.
+    ...              Description of arguments:
+    ...              operation :  Set BMC/Host time
+    ...              owner: Time owner
+    ...              mode:  Time mode
+    ...              status:   Expected status of set BMC time URI
+    ...              bmc_time:   Status of BMC time after operation
+    ...              host_time:  Status of HOST time after operation
+    ...                Set - Given time is set
+    ...                Not Set - Given time is not set
+    ...                Change - time is change
+    ...                No Change - time is not change
+
+    Set Time Owner  ${owner}
+    Set Time Mode  ${mode}
+
+    ${setdate}=  Convert Date  ${SYSTEM_TIME_VALID}
+    ...  date_format=%m/%d/%Y %H:%M:%S  exclude_millis=yes
+
+    @{bmc_date_list}=  Create List  BMC  ${setdate}
+    @{host_date_list}=  Create List  HOST  ${SYSTEM_TIME_VALID_EPOCH}
+
+    ${time_owner_date}=  Set Variable If
+    ...  '${operation}' == 'Set BMC Time'  ${bmc_date_list}
+    ...  '${operation}' == 'Set Host Time'  ${host_date_list}
+
+    ${old_bmc_time}=  Get BMC Time Using REST
+    ${old_host_time}=  Get HOST Time Using REST
+
+    ${data}=  Create Dictionary  data=${time_owner_date}
+    ${resp}=  OpenBMC Post Request
+    ...  ${TIME_MANAGER_URI}action/SetTime  data=${data}
+    ${jsondata}=  To JSON  ${resp.content}
+    Should Be Equal As Strings  ${jsondata['status']}  ${status}
+
+    ${new_bmc_time}=  Get BMC Time Using REST
+    ${new_host_time}=  Get HOST Time Using REST
+
+    ${bmc_diff_set_new}=
+    ...  Subtract Date From Date  ${setdate}  ${new_bmc_time}
+    ${bmc_diff_set_new}=  Evaluate  abs(${bmc_diff_set_new})
+    ${bmc_diff_old_new}=
+    ...  Subtract Date From Date  ${old_bmc_time}  ${new_bmc_time}
+    ${bmc_diff_old_new}=  Evaluate  abs(${bmc_diff_old_new})
+
+    ${host_diff_set_new}=
+    ...  Subtract Date From Date  ${setdate}  ${new_host_time}
+    ${host_diff_set_new}=  Evaluate  abs(${host_diff_set_new})
+    ${host_diff_old_new}=
+    ...  Subtract Date From Date  ${old_host_time}  ${new_host_time}
+    ${host_diff_old_new}=  Evaluate  abs(${host_diff_old_new})
+
+    Run Keyword If   '${bmc_time}' == 'Not Set'
+    ...    Should Be True  ${bmc_diff_set_new} >= ${ALLOWED_TIME_DIFF}
+    ...  ELSE IF  '${bmc_time}' == 'Set'
+    ...    Should Be True  ${bmc_diff_set_new} <= ${ALLOWED_TIME_DIFF}
+    ...  ELSE IF  '${bmc_time}' == 'No Change'
+    ...    Should Be True  ${bmc_diff_old_new} <= ${ALLOWED_TIME_DIFF}
+    ...  ELSE IF  '${bmc_time}' == 'Change'
+    ...    Should Be True  ${bmc_diff_old_new} >= ${ALLOWED_TIME_DIFF}
+
+    Run Keyword If  '${host_time}' == 'No Change'
+    ...    Should Be True  ${host_diff_old_new} <= ${ALLOWED_TIME_DIFF}
+    ...  ELSE IF  '${host_time}' == 'Change'
+    ...    Should Be True  ${host_diff_old_new} >= ${ALLOWED_TIME_DIFF}
+    ...  ELSE IF  '${host_time}' == 'Not Set'
+    ...    Should Be True  ${host_diff_set_new} >= ${ALLOWED_TIME_DIFF}
+    ...  ELSE IF  '${host_time}' == 'Set'
+    ...    Should Be True  ${host_diff_set_new} <= ${ALLOWED_TIME_DIFF}
 
 
 Post Test Execution
-    [Documentation]  Perform operations after test execution. It first try to
-    ...              capture FFDC in case of test case failure. Later it sets
-    ...              default values for time mode and owner.
+    [Documentation]  Perform operations after test execution. Capture FFDC
+    ...  in case of test case failure and sets default values for time mode
+    ...  and owner.
 
-    Run Keyword If Test Failed    FFDC On Test Case Fail
-
-    Set Time Mode   NTP
-
-    Set Time Owner   BMC
+    Run Keyword If Test Failed  FFDC On Test Case Fail
+    Set Time Owner  BMC
+    Set Time Mode  NTP