Skip to content

Commit 0aff8fb

Browse files
author
Kyr Shatskyy
committed
teuthology-node-cleanup: use same timezone as local
Fixes: https://tracker.ceph.com/issues/72773 Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@clyso.com>
1 parent 3ae1592 commit 0aff8fb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

teuthology/lock/query.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ def node_active_job(name: str, status: Union[dict, None] = None, grace_time: int
156156
return "node description does not contained scheduled job info"
157157
url = f"{config.results_server}/runs/{run_name}/jobs/{job_id}/"
158158
job_status = ""
159+
# suppose results' server is in the same timezone as we are here
160+
tzhere = datetime.now().astimezone().tzinfo
159161
active = True
160162
with safe_while(
161163
sleep=1, increment=0.5, action='node_is_active') as proceed:
@@ -171,7 +173,8 @@ def node_active_job(name: str, status: Union[dict, None] = None, grace_time: int
171173
if not grace_time:
172174
break
173175
try:
174-
delta = datetime.datetime.now(datetime.timezone.utc) - parse_timestamp(job_updated)
176+
now = datetime.datetime.now(datetime.timezone.utc)
177+
delta = now - parse_timestamp(job_updated, tzhere)
175178
active = active or delta < datetime.timedelta(minutes=grace_time)
176179
except Exception:
177180
log.exception(f"{run_name}/{job_id} updated={job_updated}")

teuthology/util/time.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import re
22

33
from datetime import datetime, timedelta, timezone
4+
from typing import Optional
45

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

8-
def parse_timestamp(timestamp: str) -> datetime:
9+
def parse_timestamp(timestamp: str, tz: Optional[timezone] = timezone.utc) -> datetime:
910
"""
1011
timestamp: A string either in ISO 8601 format or TIMESTAMP_FMT.
1112
If no timezone is specified, UTC is assumed.
1213
1314
:returns: a datetime object
1415
"""
16+
tzhere = datetime.now().astimezone().tzinfo
1517
try:
1618
dt = datetime.fromisoformat(timestamp)
1719
except ValueError:
1820
dt = datetime.strptime(timestamp, TIMESTAMP_FMT)
1921
if dt.tzinfo is None:
20-
dt = dt.replace(tzinfo=timezone.utc)
22+
dt = dt.replace(tzinfo=tz)
2123
return dt
2224

2325
def parse_offset(offset: str) -> timedelta:

0 commit comments

Comments
 (0)