Fix db query for service cleanup.
Instead of getting all services, fetch topic related entries from db during service cleanup. Related-bug: #1990839 Depends-on: I8b71c4c27ff8fcb25616a95a5ed8362a7f4ffc61 Change-Id: I9e911021bd144b76d39193e5480d5ca88973973e
This commit is contained in:
parent
98be6376b2
commit
ce42bd9e1a
@ -323,15 +323,14 @@ class Service(service.Service):
|
|||||||
"""Remove the stopped services of same topic from the datastore."""
|
"""Remove the stopped services of same topic from the datastore."""
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
try:
|
try:
|
||||||
services = db.service_get_all(ctxt, self.topic)
|
services = db.service_get_all_by_topic(ctxt, self.topic)
|
||||||
except exception.NotFound:
|
except exception.NotFound:
|
||||||
LOG.debug('The service database object disappeared,'
|
LOG.debug('The service database object disappeared,'
|
||||||
'Exiting from cleanup.')
|
'Exiting from cleanup.')
|
||||||
return
|
return
|
||||||
|
|
||||||
for svc in services:
|
for svc in services:
|
||||||
if (svc['topic'] == self.topic and
|
if (svc['state'] == 'stopped' and
|
||||||
svc['state'] == 'stopped' and
|
|
||||||
not utils.service_is_up(svc)):
|
not utils.service_is_up(svc)):
|
||||||
db.service_destroy(ctxt, svc['id'])
|
db.service_destroy(ctxt, svc['id'])
|
||||||
|
|
||||||
|
@ -303,7 +303,8 @@ class ServiceTestCase(test.TestCase):
|
|||||||
datetime.utcnow() - timedelta(minutes=10))
|
datetime.utcnow() - timedelta(minutes=10))
|
||||||
else:
|
else:
|
||||||
service_ref_stopped['updated_at'] = datetime.utcnow()
|
service_ref_stopped['updated_at'] = datetime.utcnow()
|
||||||
mock_db.service_get_all.return_value = [service_ref_stopped]
|
mock_db.service_get_all_by_topic.return_value = [
|
||||||
|
service_ref_stopped]
|
||||||
serv.stop()
|
serv.stop()
|
||||||
serv.cleanup_services()
|
serv.cleanup_services()
|
||||||
if cleanup_interval_done:
|
if cleanup_interval_done:
|
||||||
|
Loading…
Reference in New Issue
Block a user