Browse Source

Merge "Show an engine as down if service record is not updated twice" into stable/queens

changes/96/677396/1
Zuul 1 month ago
parent
commit
94f5f3fe25
2 changed files with 10 additions and 14 deletions
  1. 4
    8
      heat/common/service_utils.py
  2. 6
    6
      heat/tests/test_common_service_utils.py

+ 4
- 8
heat/common/service_utils.py View File

@@ -51,14 +51,10 @@ def format_service(service):
51 51
         return
52 52
 
53 53
     status = 'down'
54
-    if service.updated_at is not None:
55
-        if ((timeutils.utcnow() - service.updated_at).total_seconds()
56
-                <= service.report_interval):
57
-            status = 'up'
58
-    else:
59
-        if ((timeutils.utcnow() - service.created_at).total_seconds()
60
-                <= service.report_interval):
61
-            status = 'up'
54
+    last_updated = service.updated_at or service.created_at
55
+    check_interval = (timeutils.utcnow() - last_updated).total_seconds()
56
+    if check_interval <= 2 * service.report_interval:
57
+        status = 'up'
62 58
 
63 59
     result = {
64 60
         SERVICE_ID: service.id,

+ 6
- 6
heat/tests/test_common_service_utils.py View File

@@ -51,23 +51,23 @@ class TestServiceUtils(common.HeatTestCase):
51 51
 
52 52
         self.assertEqual(service_dict['status'], 'up')
53 53
 
54
-        # check again within first report_interval time (60)
54
+        # check again within first report_interval time
55 55
         service_dict = service_utils.format_service(service)
56 56
         self.assertEqual(service_dict['status'], 'up')
57 57
 
58
-        # check update not happen within report_interval time (60+)
58
+        # check update not happen within 2*report_interval time
59 59
         service.created_at = (timeutils.utcnow() -
60
-                              datetime.timedelta(0, 70))
60
+                              datetime.timedelta(0, 130))
61 61
         service_dict = service_utils.format_service(service)
62 62
         self.assertEqual(service_dict['status'], 'down')
63 63
 
64
-        # check update happened after report_interval time (60+)
64
+        # check update happened after 2* report_interval time
65 65
         service.updated_at = (timeutils.utcnow() -
66
-                              datetime.timedelta(0, 70))
66
+                              datetime.timedelta(0, 130))
67 67
         service_dict = service_utils.format_service(service)
68 68
         self.assertEqual(service_dict['status'], 'down')
69 69
 
70
-        # check update happened within report_interval time (60)
70
+        # check update happened within report_interval time
71 71
         service.updated_at = (timeutils.utcnow() -
72 72
                               datetime.timedelta(0, 50))
73 73
         service_dict = service_utils.format_service(service)

Loading…
Cancel
Save