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:
Kiran Pawar 2023-02-24 11:10:23 +00:00
parent 98be6376b2
commit ce42bd9e1a
2 changed files with 4 additions and 4 deletions

View File

@ -323,15 +323,14 @@ class Service(service.Service):
"""Remove the stopped services of same topic from the datastore."""
ctxt = context.get_admin_context()
try:
services = db.service_get_all(ctxt, self.topic)
services = db.service_get_all_by_topic(ctxt, self.topic)
except exception.NotFound:
LOG.debug('The service database object disappeared,'
'Exiting from cleanup.')
return
for svc in services:
if (svc['topic'] == self.topic and
svc['state'] == 'stopped' and
if (svc['state'] == 'stopped' and
not utils.service_is_up(svc)):
db.service_destroy(ctxt, svc['id'])

View File

@ -303,7 +303,8 @@ class ServiceTestCase(test.TestCase):
datetime.utcnow() - timedelta(minutes=10))
else:
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.cleanup_services()
if cleanup_interval_done: