From 7a4aea6b4d27d9d6f6b3beb91e31ae1f5f922a2b Mon Sep 17 00:00:00 2001 From: pcarlton Date: Fri, 4 Mar 2016 08:46:03 +0000 Subject: [PATCH] Add include_disabled parameter to service_get_all_by_binary The database query service_get_all_by_binary should return a list of services with the specified binary but it currently excludes disabled hosts. This change adds a name parameter called 'include_disabled' which provides the caller with the option of having disabled hosts returned too. This query is used by the scheduler to retrieve the list of available hosts. The initial list should include disabled hosts. The ComputeFilter removes disabled hosts so inclusion of this filter is the proper way to exclude disabled hosts. Excluding disabled hosts from the initial list prevents the forcehost feature from being used to place an instance on a disabled host. The query is only used in objects.ServiceList.get_by_binary which is only called in one other place, in cells/state.py by CellStateManager._get_compute_hosts. Adding the named parameter to the get_by_binary method of the ServiceList class means the behaviour of CellStateManager._get_compute_hosts will not be impacted. Change-Id: I05c2716da45119e6e6aa272b0701be9ae098842c Closes-Bug: #1553099 --- nova/db/api.py | 10 +++++++--- nova/db/sqlalchemy/api.py | 11 ++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/nova/db/api.py b/nova/db/api.py index f793bfe03..7cd9e7aed 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -141,9 +141,13 @@ def service_get_all_by_topic(context, topic): return IMPL.service_get_all_by_topic(context, topic) -def service_get_all_by_binary(context, binary): - """Get all services for a given binary.""" - return IMPL.service_get_all_by_binary(context, binary) +def service_get_all_by_binary(context, binary, include_disabled=False): + """Get services for a given binary. + + Includes disabled services if 'include_disabled' parameter is True + """ + return IMPL.service_get_all_by_binary(context, binary, + include_disabled=include_disabled) def service_get_all_by_host(context, host): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index ec33279e0..0d52636b4 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -545,11 +545,12 @@ def service_get_by_host_and_topic(context, host, topic): @pick_context_manager_reader -def service_get_all_by_binary(context, binary): - return model_query(context, models.Service, read_deleted="no").\ - filter_by(disabled=False).\ - filter_by(binary=binary).\ - all() +def service_get_all_by_binary(context, binary, include_disabled=False): + query = model_query(context, models.Service, read_deleted="no").\ + filter_by(binary=binary) + if not include_disabled: + query = query.filter_by(disabled=False) + return query.all() @pick_context_manager_reader