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
This commit is contained in:
Kevin_Zheng 2018-07-19 19:09:31 +08:00
parent afe4512bf6
commit 0f4e5c442c
2 changed files with 15 additions and 1 deletions

View File

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

View File

@ -74,16 +74,19 @@ class MemcachedServiceGroupTestCase(test.NoDBTestCase):
'updated_at': updated_at_time.replace(tzinfo=iso8601.UTC)
}
# If no record returned from the mc, return record from DB
self.mc_client.get.return_value = None
self.assertEqual(service_ref['updated_at'],
self.servicegroup_api.get_updated_time(service_ref))
self.mc_client.get.assert_called_once_with('compute:fake-host')
# If the record in mc is newer than DB, return record from mc
self.mc_client.reset_mock()
retval = timeutils.utcnow()
self.mc_client.get.return_value = retval
self.assertEqual(retval.replace(tzinfo=iso8601.UTC),
self.servicegroup_api.get_updated_time(service_ref))
self.mc_client.get.assert_called_once_with('compute:fake-host')
# If the record in DB is newer than mc, return record from DB
self.mc_client.reset_mock()
service_ref['updated_at'] = \
retval.replace(tzinfo=iso8601.UTC)
@ -91,3 +94,10 @@ class MemcachedServiceGroupTestCase(test.NoDBTestCase):
self.assertEqual(service_ref['updated_at'],
self.servicegroup_api.get_updated_time(service_ref))
self.mc_client.get.assert_called_once_with('compute:fake-host')
# If no record returned from the DB, return the record from mc
self.mc_client.reset_mock()
service_ref['updated_at'] = None
self.mc_client.get.return_value = updated_at_time
self.assertEqual(updated_at_time.replace(tzinfo=iso8601.UTC),
self.servicegroup_api.get_updated_time(service_ref))
self.mc_client.get.assert_called_once_with('compute:fake-host')