Skip to content

Commit

Permalink
Improve the liveness checking for services
Browse files Browse the repository at this point in the history
With this modification both nova-manage and scheduler use the flag
service_down_time and check positive and negative values in a
correct way.
Fixes bug: 867674.

Change-Id: I15c48d80cafa2089cd228c09c61b0a1e513730e8
  • Loading branch information
David Subiros authored and viraptor committed Oct 21, 2011
1 parent 75a3fbb commit ad74424
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/nova-manage
Expand Up @@ -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']:
Expand Down
6 changes: 2 additions & 4 deletions nova/scheduler/driver.py
Expand Up @@ -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
Expand Down Expand Up @@ -143,8 +141,8 @@ def service_is_up(service):
"""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."""
Expand Down
9 changes: 9 additions & 0 deletions nova/utils.py
Expand Up @@ -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

0 comments on commit ad74424

Please sign in to comment.