@@ -1119,13 +1119,18 @@ def fast_track_able(task):
11191119def value_within_timeout (value , timeout ):
11201120 """Checks if the time is within the previous timeout seconds from now.
11211121
1122- :param value: a string representing date and time or None.
1122+ :param value: a datetime or string representing date and time or None.
11231123 :param timeout: timeout in seconds.
11241124 """
11251125 # use native datetime objects for conversion and compare
11261126 # slightly odd because py2 compatability :(
1127- last = datetime .datetime .strptime (value or '1970-01-01T00:00:00.000000' ,
1128- "%Y-%m-%dT%H:%M:%S.%f" )
1127+ if isinstance (value , datetime .datetime ):
1128+ # Converts to a offset-naive datetime(as created by timeutils.utcnow())
1129+ last = value .replace (tzinfo = None )
1130+ else :
1131+ defaultdt = '1970-01-01T00:00:00.000000'
1132+ last = datetime .datetime .strptime (value or defaultdt ,
1133+ '%Y-%m-%dT%H:%M:%S.%f' )
11291134 # If we found nothing, we assume that the time is essentially epoch.
11301135 time_delta = datetime .timedelta (seconds = timeout )
11311136 last_valid = timeutils .utcnow () - time_delta
@@ -1142,14 +1147,20 @@ def agent_is_alive(node, timeout=None):
11421147 :param node: A node object.
11431148 :param timeout: Heartbeat timeout, defaults to `fast_track_timeout`.
11441149 """
1150+
1151+ timeout = timeout or CONF .deploy .fast_track_timeout
1152+ if node .power_state == states .POWER_ON and \
1153+ node .inspection_finished_at and \
1154+ value_within_timeout (node .inspection_finished_at , timeout ):
1155+ return True
1156+
11451157 # If no agent_url is present then we have powered down since the
11461158 # last agent heartbeat
11471159 if not node .driver_internal_info .get ('agent_url' ):
11481160 return False
11491161
11501162 return value_within_timeout (
1151- node .driver_internal_info .get ('agent_last_heartbeat' ),
1152- timeout or CONF .deploy .fast_track_timeout )
1163+ node .driver_internal_info .get ('agent_last_heartbeat' ), timeout )
11531164
11541165
11551166def is_fast_track (task ):
0 commit comments