diff options
author | Kaifeng Wang <kaifeng.w@gmail.com> | 2023-05-07 15:09:50 +0800 |
---|---|---|
committer | Kaifeng Wang <kaifeng.w@gmail.com> | 2023-05-07 15:09:50 +0800 |
commit | b48dfd44c7dedd5e55f27d3692db82ce89c35b97 (patch) | |
tree | 90086a49fa31e6630e27c04cc263672dd9089425 | |
parent | 7f281392c219decdfc1a34dc672a86e360230ac9 (diff) | |
download | ironic-b48dfd44c7dedd5e55f27d3692db82ce89c35b97.tar.gz |
Use monotonic time for hashring reset
hashring use time.time() to calculate intervals, replace with
monotonic so it will not be affected by system time jump.
Change-Id: I17569359f4d2c0f2f24ca8b50773c4d210ed8deb
-rw-r--r-- | ironic/common/hash_ring.py | 4 | ||||
-rw-r--r-- | ironic/tests/unit/common/test_hash_ring.py | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/ironic/common/hash_ring.py b/ironic/common/hash_ring.py index 1f1107008..8986d5bd2 100644 --- a/ironic/common/hash_ring.py +++ b/ironic/common/hash_ring.py @@ -40,7 +40,7 @@ class HashRingManager(object): @property def ring(self): interval = CONF.hash_ring_reset_interval - limit = time.time() - interval + limit = time.monotonic() - interval if not self.cache: return self._load_hash_rings() @@ -56,7 +56,7 @@ class HashRingManager(object): if hash_rings is None or updated_at < limit: LOG.debug('Rebuilding cached hash rings') hash_rings = self._load_hash_rings() - self.__class__._hash_rings = hash_rings, time.time() + self.__class__._hash_rings = hash_rings, time.monotonic() LOG.debug('Finished rebuilding hash rings, available drivers ' 'are %s', ', '.join(hash_rings)) return hash_rings diff --git a/ironic/tests/unit/common/test_hash_ring.py b/ironic/tests/unit/common/test_hash_ring.py index 9ecf34562..a84b9ffcf 100644 --- a/ironic/tests/unit/common/test_hash_ring.py +++ b/ironic/tests/unit/common/test_hash_ring.py @@ -129,7 +129,7 @@ class HashRingManagerTestCase(db_base.DbTestCase): self.ring_manager.__class__._hash_rings = ( self.ring_manager.__class__._hash_rings[0], - time.time() - 31 + time.monotonic() - 31 ) ring = self.ring_manager.get_ring('hardware-type', '') self.assertEqual(2, len(ring)) |