diff options
author | Jenkins <jenkins@review.openstack.org> | 2011-10-26 01:01:00 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2011-10-26 01:01:00 +0000 |
commit | 7cd3d73bc8729c00b739166e92050b659dd4602e (patch) | |
tree | 873afac2ddcb39ab8a0a41a1c29525ddc71d613d | |
parent | ace2628dfa6048a8e8b7757daefffc1987cfad3f (diff) | |
parent | ad74424768463cd6ad02dd9d6fdf64fc7b3bbafb (diff) | |
download | nova-7cd3d73bc8729c00b739166e92050b659dd4602e.tar.gz nova-7cd3d73bc8729c00b739166e92050b659dd4602e.tar.xz nova-7cd3d73bc8729c00b739166e92050b659dd4602e.zip |
Merge "Improve the liveness checking for services"
-rwxr-xr-x | bin/nova-manage | 2 | ||||
-rw-r--r-- | nova/scheduler/driver.py | 6 | ||||
-rw-r--r-- | nova/utils.py | 9 |
3 files changed, 12 insertions, 5 deletions
diff --git a/bin/nova-manage b/bin/nova-manage index acaf05216..244c11869 100755 --- a/bin/nova-manage +++ b/bin/nova-manage @@ -1021,7 +1021,7 @@ class ServiceCommands(object): _('Updated_At')) for svc in services: delta = now - (svc['updated_at'] or svc['created_at']) - alive = (delta.seconds <= 15) + alive = abs(utils.total_seconds(delta)) <= FLAGS.service_down_time art = (alive and ":-)") or "XXX" active = 'enabled' if svc['disabled']: diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 7bf26cfdf..577503cd8 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -21,8 +21,6 @@ Scheduler base class that all Schedulers should inherit from """ -import datetime - from nova import db from nova import exception from nova import flags @@ -143,8 +141,8 @@ class Scheduler(object): """Check whether a service is up based on last heartbeat.""" last_heartbeat = service['updated_at'] or service['created_at'] # Timestamps in DB are UTC. - elapsed = utils.utcnow() - last_heartbeat - return elapsed < datetime.timedelta(seconds=FLAGS.service_down_time) + elapsed = utils.total_seconds(utils.utcnow() - last_heartbeat) + return abs(elapsed) <= FLAGS.service_down_time def hosts_up(self, context, topic): """Return the list of hosts that have a running service for topic.""" diff --git a/nova/utils.py b/nova/utils.py index 7d34a87d8..ad585ba1c 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -1009,3 +1009,12 @@ def make_dev_path(dev, partition=None, base='/dev'): if partition: path += str(partition) return path + + +def total_seconds(td): + """Local total_seconds implementation for compatibility with python 2.6""" + if hasattr(td, 'total_seconds'): + return td.total_seconds() + else: + return ((td.days * 86400 + td.seconds) * 10 ** 6 + + td.microseconds) / 10.0 ** 6 |