Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion teuthology/lock/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def node_active_job(name: str, status: Union[dict, None] = None, grace_time: int
return "node description does not contained scheduled job info"
url = f"{config.results_server}/runs/{run_name}/jobs/{job_id}/"
job_status = ""
# suppose results' server is in the same timezone as we are here
tzhere = datetime.datetime.now().astimezone().tzinfo
active = True
with safe_while(
sleep=1, increment=0.5, action='node_is_active') as proceed:
Expand All @@ -171,7 +173,8 @@ def node_active_job(name: str, status: Union[dict, None] = None, grace_time: int
if not grace_time:
break
try:
delta = datetime.datetime.now(datetime.timezone.utc) - parse_timestamp(job_updated)
now = datetime.datetime.now(datetime.timezone.utc)
delta = now - parse_timestamp(job_updated, tzhere)
active = active or delta < datetime.timedelta(minutes=grace_time)
except Exception:
log.exception(f"{run_name}/{job_id} updated={job_updated}")
Expand Down
5 changes: 3 additions & 2 deletions teuthology/util/time.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import re

from datetime import datetime, timedelta, timezone
from typing import Optional

# When we're not using ISO format, we're using this
TIMESTAMP_FMT = "%Y-%m-%d_%H:%M:%S"

def parse_timestamp(timestamp: str) -> datetime:
def parse_timestamp(timestamp: str, tz: Optional[timezone] = timezone.utc) -> datetime:
"""
timestamp: A string either in ISO 8601 format or TIMESTAMP_FMT.
If no timezone is specified, UTC is assumed.
Expand All @@ -17,7 +18,7 @@ def parse_timestamp(timestamp: str) -> datetime:
except ValueError:
dt = datetime.strptime(timestamp, TIMESTAMP_FMT)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=timezone.utc)
dt = dt.replace(tzinfo=tz)
return dt

def parse_offset(offset: str) -> timedelta:
Expand Down
Loading