Browse Source

Fix service list for disabled compute using MC driver

In 0df91a7f79 a comparison
between ``updated_at`` field from services table and update time
from memcache was added if the servergroup_driver is set to be
mc.

This could be problematic if servergroup_driver=mc and
``[DEFAULT]/enable_new_services`` option in /etc/nova/nova.conf
is set to be ``False`` at the same time, as the ``updated_at``
field will always be ``Null`` in services record.

This patch fixes the bug by returning ``updated_time_in_mc`` instead
under the above mentioned scenario.

Closes-Bug: #1781880

Change-Id: I27160140cbccf3e6914aed2dcff54d547e446c1f
tags/19.0.0.0rc1
Kevin_Zheng 1 year ago
parent
commit
0f4e5c442c

+ 5
- 1
nova/servicegroup/drivers/mc.py View File

@@ -78,7 +78,11 @@ class MemcachedDriver(base.Driver):
78 78
             # Change mc time to offset-aware time
79 79
             updated_time_in_mc = \
80 80
                 updated_time_in_mc.replace(tzinfo=iso8601.UTC)
81
-            if updated_time_in_db <= updated_time_in_mc:
81
+            # If [DEFAULT]/enable_new_services is set to be false, the
82
+            # ``updated_time_in_db`` will be None, in this case, use
83
+            # ``updated_time_in_mc`` instead.
84
+            if (not updated_time_in_db or
85
+                    updated_time_in_db <= updated_time_in_mc):
82 86
                 return updated_time_in_mc
83 87
 
84 88
         return updated_time_in_db

+ 10
- 0
nova/tests/unit/servicegroup/test_mc_servicegroup.py View File

@@ -74,16 +74,19 @@ class MemcachedServiceGroupTestCase(test.NoDBTestCase):
74 74
             'updated_at': updated_at_time.replace(tzinfo=iso8601.UTC)
75 75
         }
76 76
 
77
+        # If no record returned from the mc, return record from DB
77 78
         self.mc_client.get.return_value = None
78 79
         self.assertEqual(service_ref['updated_at'],
79 80
                          self.servicegroup_api.get_updated_time(service_ref))
80 81
         self.mc_client.get.assert_called_once_with('compute:fake-host')
82
+        # If the record in mc is newer than DB, return record from mc
81 83
         self.mc_client.reset_mock()
82 84
         retval = timeutils.utcnow()
83 85
         self.mc_client.get.return_value = retval
84 86
         self.assertEqual(retval.replace(tzinfo=iso8601.UTC),
85 87
                          self.servicegroup_api.get_updated_time(service_ref))
86 88
         self.mc_client.get.assert_called_once_with('compute:fake-host')
89
+        # If the record in DB is newer than mc, return record from DB
87 90
         self.mc_client.reset_mock()
88 91
         service_ref['updated_at'] = \
89 92
             retval.replace(tzinfo=iso8601.UTC)
@@ -91,3 +94,10 @@ class MemcachedServiceGroupTestCase(test.NoDBTestCase):
91 94
         self.assertEqual(service_ref['updated_at'],
92 95
                          self.servicegroup_api.get_updated_time(service_ref))
93 96
         self.mc_client.get.assert_called_once_with('compute:fake-host')
97
+        # If no record returned from the DB, return the record from mc
98
+        self.mc_client.reset_mock()
99
+        service_ref['updated_at'] = None
100
+        self.mc_client.get.return_value = updated_at_time
101
+        self.assertEqual(updated_at_time.replace(tzinfo=iso8601.UTC),
102
+                         self.servicegroup_api.get_updated_time(service_ref))
103
+        self.mc_client.get.assert_called_once_with('compute:fake-host')

Loading…
Cancel
Save