Ignore deleted services in minimum version calculation

When we go to detect the minimum version for a given service, we
should ignore any deleted services. Without this, we will return
the minimum version of all records, including those that have been
deleted with "nova service-delete". This patch filters deleted
services from the query.

Closes-Bug: #1668310
Change-Id: Ic96a5eb3728f97a3c35d2c5121e6fdcd4fd1c70b
(cherry picked from commit c79770e615)
This commit is contained in:
Dan Smith 2017-02-27 07:52:29 -08:00 committed by Matt Riedemann
parent 6087675d1b
commit a1dd547d3b
2 changed files with 5 additions and 0 deletions

View File

@ -481,6 +481,7 @@ def service_get_minimum_version(context, binaries):
models.Service.binary,
func.min(models.Service.version)).\
filter(models.Service.binary.in_(binaries)).\
filter(models.Service.deleted == 0).\
filter(models.Service.forced_down == false()).\
group_by(models.Service.binary)
return dict(min_versions)

View File

@ -3601,6 +3601,10 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin):
self._create_service({'version': 3,
'host': 'host2',
'binary': 'compute'})
self._create_service({'version': 0,
'host': 'host0',
'binary': 'compute',
'deleted': 1})
self.assertEqual({'compute': 2},
db.service_get_minimum_version(self.ctxt,
['compute']))