re-Allow adding computes with no ComputeNodes to aggregates

After the cellification of the Aggregates API, we introduced a requirement
that the service must have a HostMapping record, so that we know which
cell the service is in. This is normally fine, but for weird drivers such
as ironic, there may be valid cases (i.e. during setup) where no ironic
nodes are present, thus one or more services may not have any compute node
records, and thus cannot be added to aggregates.

This adds a cell scan, only if necessary, to find the desired service so
that the operation may proceed as it did before. To do this, we refactor
the _find_service() helper to a more generic utility and use that if we
don't find a HostMapping during the add operation.

Change-Id: Idc97126d63684e7d638b974d7226ff210c744404
Closes-Bug: #1686744
This commit is contained in:
Dan Smith 2017-04-27 07:55:40 -07:00
parent c2b2e9ca8c
commit c398d6a2ce
1 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,41 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova.tests.functional import integrated_helpers
class AggregatesTest(integrated_helpers._IntegratedTestBase):
api_major_version = 'v2'
ADMIN_API = True
def _add_hosts_to_aggregate(self):
"""List all compute services and add them all to an aggregate."""
compute_services = [s for s in self.api.get_services()
if s['binary'] == 'nova-compute']
agg = {'aggregate': {'name': 'test-aggregate'}}
agg = self.api.post_aggregate(agg)
for service in compute_services:
self.api.add_host_to_aggregate(agg['id'], service['host'])
return len(compute_services)
def test_add_hosts(self):
# Default case with one compute, mapped for us
self.assertEqual(1, self._add_hosts_to_aggregate())
def test_add_unmapped_host(self):
"""Ensure that hosts without mappings are still found and added"""
# Add another compute, but nuke its HostMapping
self.start_service('compute', host='compute2')
self.host_mappings['compute2'].destroy()
self.assertEqual(2, self._add_hosts_to_aggregate())