From 7e7bcc4f080c824c94c41485e29e365473661fa3 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Mon, 14 Jan 2013 02:06:39 +0000 Subject: Fix uses of service_get_all_compute_by_host There should never be more than 1 service entry for the same topic and host, however this method returns a list of services. All callers of this method except for 1 already account for there being only 1 service entry for a particular 'compute' host and only use the first entry in the return list. This patch renames the DB API call to be 'service_get_by_compute_host' and returns a single entry. All uses of the old method are adjusted accordingly. Change-Id: I0e0ef62f5d2e71efe756940d9fdd98aa02fef216 --- nova/db/api.py | 9 ++++++--- nova/db/sqlalchemy/api.py | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'nova/db') diff --git a/nova/db/api.py b/nova/db/api.py index b1552b480..d7d9bd0d2 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -151,9 +151,12 @@ def service_get_all_by_host(context, host): return IMPL.service_get_all_by_host(context, host) -def service_get_all_compute_by_host(context, host): - """Get all compute services for a given host.""" - return IMPL.service_get_all_compute_by_host(context, host) +def service_get_by_compute_host(context, host): + """Get the service entry for a given compute host. + + Returns the service entry joined with the compute_node entry. + """ + return IMPL.service_get_by_compute_host(context, host) def service_get_all_compute_sorted(context): diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 8930f6ccc..e51d7b685 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -370,12 +370,12 @@ def service_get_all_by_host(context, host): @require_admin_context -def service_get_all_compute_by_host(context, host): +def service_get_by_compute_host(context, host): result = model_query(context, models.Service, read_deleted="no").\ options(joinedload('compute_node')).\ filter_by(host=host).\ filter_by(topic=CONF.compute_topic).\ - all() + first() if not result: raise exception.ComputeHostNotFound(host=host) -- cgit