summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-05-09 16:37:58 +0000
committerGerrit Code Review <review@openstack.org>2023-05-09 16:37:58 +0000
commitf70053f2aaa8b8d46690c94530bb2fb5f908347c (patch)
tree1d3ca00edea5b638ab5fdfe189c536e0d08854af
parentf194b33bd3a8b9e6255f6dad74b1d09b0d74ff13 (diff)
parent437d2d96393b616c306a7886ce13d9220ca95207 (diff)
downloaddesignate-f70053f2aaa8b8d46690c94530bb2fb5f908347c.tar.gz
Merge "Use monotonic time to protect from system time jumps"
-rwxr-xr-xdesignate/backend/impl_dynect.py4
-rw-r--r--designate/dnsutils.py4
-rw-r--r--designate/tests/__init__.py8
-rw-r--r--designate/worker/processing.py4
4 files changed, 10 insertions, 10 deletions
diff --git a/designate/backend/impl_dynect.py b/designate/backend/impl_dynect.py
index 19f586f5..7e30443c 100755
--- a/designate/backend/impl_dynect.py
+++ b/designate/backend/impl_dynect.py
@@ -202,11 +202,11 @@ class DynClient(object):
self._http_log_req(method, url, kwargs)
if self.timings:
- start_time = time.time()
+ start_time = time.monotonic()
resp = self.http.request(method, url, **kwargs)
if self.timings:
self.times.append(("%s %s" % (method, url),
- start_time, time.time()))
+ start_time, time.monotonic()))
self._http_log_resp(resp)
if resp.status_code >= 400:
diff --git a/designate/dnsutils.py b/designate/dnsutils.py
index 81df8409..43c45dff 100644
--- a/designate/dnsutils.py
+++ b/designate/dnsutils.py
@@ -203,12 +203,12 @@ class ZoneLock(object):
with self.lock:
# If no one holds the lock for the zone, grant it
if zone not in self.data:
- self.data[zone] = time.time()
+ self.data[zone] = time.monotonic()
return True
# Otherwise, get the time that it was locked
locktime = self.data[zone]
- now = time.time()
+ now = time.monotonic()
period = now - locktime
diff --git a/designate/tests/__init__.py b/designate/tests/__init__.py
index d65ef2bf..ac371ab7 100644
--- a/designate/tests/__init__.py
+++ b/designate/tests/__init__.py
@@ -820,7 +820,7 @@ class TestCase(base.BaseTestCase):
Zone imports spawn a thread to parse the zone file and
insert the data. This waits for this process before continuing
"""
- start_time = time.time()
+ start_time = time.monotonic()
while True:
# Retrieve it, and ensure it's the same
zone_import = self.central_service.get_zone_import(
@@ -835,7 +835,7 @@ class TestCase(base.BaseTestCase):
if error_is_ok and zone_import.status != 'PENDING':
break
- if (time.time() - start_time) > max_wait:
+ if (time.monotonic() - start_time) > max_wait:
break
time.sleep(0.5)
@@ -870,8 +870,8 @@ class TestCase(base.BaseTestCase):
Poll every `interval` seconds. `condition` can be a callable.
(Caution: some mocks behave both as values and callables.)
"""
- t_max = time.time() + timeout
- while time.time() < t_max:
+ t_max = time.monotonic() + timeout
+ while time.monotonic() < t_max:
if callable(condition):
result = condition()
else:
diff --git a/designate/worker/processing.py b/designate/worker/processing.py
index 59f8fcbe..cf280033 100644
--- a/designate/worker/processing.py
+++ b/designate/worker/processing.py
@@ -70,9 +70,9 @@ class Executor(object):
if callable(tasks):
tasks = [tasks]
- start_time = time.time()
+ start_time = time.monotonic()
results = [r for r in self._executor.map(self.do, tasks)]
- elapsed_time = time.time() - start_time
+ elapsed_time = time.monotonic() - start_time
LOG.debug(
'Finished Task(s): %(tasks)s in %(time)fs',