From c79770e615799cd4457ac603dcad4fb3452fe2bc Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 27 Feb 2017 07:52:29 -0800 Subject: [PATCH] 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 --- nova/db/sqlalchemy/api.py | 1 + nova/tests/unit/db/test_db_api.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 0d976315fcc8..b11157d33989 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -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) diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index b541194fbbda..77ce6ab42d90 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -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']))