diff options
| author | Chris Behrens <cbehrens@codestud.com> | 2013-01-14 02:06:39 +0000 |
|---|---|---|
| committer | Chris Behrens <cbehrens@codestud.com> | 2013-01-14 18:28:37 +0000 |
| commit | 7e7bcc4f080c824c94c41485e29e365473661fa3 (patch) | |
| tree | 40659e8a41af38e7304234f5a03b7639a2a04226 /nova/compute | |
| parent | ca4b1303804e94f10f0e4e6c4a9e09c049efd1ee (diff) | |
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
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/api.py | 24 | ||||
| -rw-r--r-- | nova/compute/manager.py | 4 | ||||
| -rw-r--r-- | nova/compute/resource_tracker.py | 3 |
3 files changed, 12 insertions, 19 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index d0a039644..1ad9e2aee 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -954,19 +954,16 @@ class API(base.Base): host=src_host, cast=False, reservations=downsize_reservations) - # NOTE(jogo): db allows for multiple compute services per host + is_up = False try: - services = self.db.service_get_all_compute_by_host( + service = self.db.service_get_by_compute_host( context.elevated(), instance['host']) - except exception.ComputeHostNotFound: - services = [] - - is_up = False - for service in services: if self.servicegroup_api.service_is_up(service): is_up = True cb(context, instance, bdms) - break + except exception.ComputeHostNotFound: + pass + if not is_up: # If compute node isn't up, just delete from DB self._local_delete(context, instance, bdms) @@ -2238,9 +2235,8 @@ class HostAPI(base.Base): """ # Getting compute node info and related instances info try: - compute_ref = self.db.service_get_all_compute_by_host(context, - host_name) - compute_ref = compute_ref[0] + compute_ref = self.db.service_get_by_compute_host(context, + host_name) except exception.ComputeHostNotFound: raise exception.HostNotFound(host=host_name) instance_refs = self.db.instance_get_all_by_host(context, @@ -2360,8 +2356,7 @@ class AggregateAPI(base.Base): def add_host_to_aggregate(self, context, aggregate_id, host_name): """Adds the host to an aggregate.""" # validates the host; ComputeHostNotFound is raised if invalid - service = self.db.service_get_all_compute_by_host( - context, host_name)[0] + self.db.service_get_by_compute_host(context, host_name) aggregate = self.db.aggregate_get(context, aggregate_id) self.db.aggregate_host_add(context, aggregate_id, host_name) #NOTE(jogo): Send message to host to support resource pools @@ -2372,8 +2367,7 @@ class AggregateAPI(base.Base): def remove_host_from_aggregate(self, context, aggregate_id, host_name): """Removes host from the aggregate.""" # validates the host; ComputeHostNotFound is raised if invalid - service = self.db.service_get_all_compute_by_host( - context, host_name)[0] + self.db.service_get_by_compute_host(context, host_name) aggregate = self.db.aggregate_get(context, aggregate_id) self.db.aggregate_host_delete(context, aggregate_id, host_name) self.compute_rpcapi.remove_aggregate_host(context, diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 85942541f..d8021ac7d 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -2592,10 +2592,10 @@ class ComputeManager(manager.SchedulerDependentManager): pass def _get_compute_info(self, context, host): - compute_node_ref = self.conductor_api.service_get_all_compute_by_host( + compute_node_ref = self.conductor_api.service_get_by_compute_host( context, host) try: - return compute_node_ref[0]['compute_node'][0] + return compute_node_ref['compute_node'][0] except IndexError: raise exception.NotFound(_("Host %(host)s not found") % locals()) diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index 075d59ec8..d2afcaa27 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -308,8 +308,7 @@ class ResourceTracker(object): def _get_service(self, context): try: - return db.service_get_all_compute_by_host(context, - self.host)[0] + return db.service_get_by_compute_host(context, self.host) except exception.NotFound: LOG.warn(_("No service record for host %s"), self.host) |
