summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-08-08 14:46:16 +0000
committerGerrit Code Review <review@openstack.org>2019-08-08 14:46:17 +0000
commit94f5f3fe25f2e824aa3b20828e3336c7ba644d4c (patch)
treedb287a5dbbbbe8cbb7d970d0bbcee0f62ce96ac0
parent04173f583830d670db31608e67b02c506e0bf85a (diff)
parentc5d417927470f12426a0f1b95991a688b7c8dec3 (diff)
downloadheat-94f5f3fe25f2e824aa3b20828e3336c7ba644d4c.tar.gz
Merge "Show an engine as down if service record is not updated twice" into stable/queens
-rw-r--r--heat/common/service_utils.py12
-rw-r--r--heat/tests/test_common_service_utils.py12
2 files changed, 10 insertions, 14 deletions
diff --git a/heat/common/service_utils.py b/heat/common/service_utils.py
index b5cf00485..a59fef8e8 100644
--- a/heat/common/service_utils.py
+++ b/heat/common/service_utils.py
@@ -51,14 +51,10 @@ def format_service(service):
return
status = 'down'
- if service.updated_at is not None:
- if ((timeutils.utcnow() - service.updated_at).total_seconds()
- <= service.report_interval):
- status = 'up'
- else:
- if ((timeutils.utcnow() - service.created_at).total_seconds()
- <= service.report_interval):
- status = 'up'
+ last_updated = service.updated_at or service.created_at
+ check_interval = (timeutils.utcnow() - last_updated).total_seconds()
+ if check_interval <= 2 * service.report_interval:
+ status = 'up'
result = {
SERVICE_ID: service.id,
diff --git a/heat/tests/test_common_service_utils.py b/heat/tests/test_common_service_utils.py
index 6bad2a83d..0745e8f85 100644
--- a/heat/tests/test_common_service_utils.py
+++ b/heat/tests/test_common_service_utils.py
@@ -51,23 +51,23 @@ class TestServiceUtils(common.HeatTestCase):
self.assertEqual(service_dict['status'], 'up')
- # check again within first report_interval time (60)
+ # check again within first report_interval time
service_dict = service_utils.format_service(service)
self.assertEqual(service_dict['status'], 'up')
- # check update not happen within report_interval time (60+)
+ # check update not happen within 2*report_interval time
service.created_at = (timeutils.utcnow() -
- datetime.timedelta(0, 70))
+ datetime.timedelta(0, 130))
service_dict = service_utils.format_service(service)
self.assertEqual(service_dict['status'], 'down')
- # check update happened after report_interval time (60+)
+ # check update happened after 2* report_interval time
service.updated_at = (timeutils.utcnow() -
- datetime.timedelta(0, 70))
+ datetime.timedelta(0, 130))
service_dict = service_utils.format_service(service)
self.assertEqual(service_dict['status'], 'down')
- # check update happened within report_interval time (60)
+ # check update happened within report_interval time
service.updated_at = (timeutils.utcnow() -
datetime.timedelta(0, 50))
service_dict = service_utils.format_service(service)