nova/nova/tests/functional/test_scheduler.py
Matt Riedemann a05ef30fb9 Make API always RPC cast to conductor for resize/migrate
This is a follow up to [1] to make the API behave consistently
by always asynchronously casting to conductor during resize
and cold migration regardless of same-cell or cross-cell
migration.

From the end user point of view, not much changes besides
the possibility of some exceptions occurring during scheduling
which would have resulted in a 400 BadRequest error.
The user still gets a 202 response, must poll the server status
until the server goes to VERIFY_RESIZE status or times out, and
can check the instance actions if the resize/migrate fails.

The specific errors that can occur are not really an API contract
and as such end user applications should not be building logic
around, for example, getting a NoValidHost error. It should be
noted, however, that by default non-admin users cannot see
the instance action event traceback that would contain the
error, e.g. NoValidHost.

The only exception types removed from handling in the API are
(1) AllocationMoveFailed which can be raised when the conductor
MigrationTask runs replace_allocation_with_migration and
(2) NoValidHost when the scheduler is called to select destinations.

Because of this, quite a few functional negative tests have to be
adjusted since the API no longer returns a 400 for NoValidHost and
other errors that can happen during scheduling.

Finally, the do_cast kwarg is left on the conductor API method since
the compute service calls it during same-cell reschedule as a
synchronous RPC call and has error handling if rescheduling in
conductor fails.

[1] I098f91d8c498e5a85266e193ad37c08aca4792b2

Change-Id: I711e56bcb4b72605253fa63be230a68e03e45b84
2019-11-13 10:19:53 -05:00

101 lines
4.2 KiB
Python

# 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.compute import instance_actions
from nova import test
from nova.tests import fixtures as nova_fixtures
from nova.tests.functional import fixtures as func_fixtures
from nova.tests.functional import integrated_helpers
from nova.tests.unit import fake_network
import nova.tests.unit.image.fake as fake_image
from nova.tests.unit import policy_fixture
CELL1_NAME = 'cell1'
CELL2_NAME = 'cell2'
class MultiCellSchedulerTestCase(test.TestCase,
integrated_helpers.InstanceHelperMixin):
NUMBER_OF_CELLS = 2
def setUp(self):
super(MultiCellSchedulerTestCase, self).setUp()
self.useFixture(policy_fixture.RealPolicyFixture())
self.useFixture(nova_fixtures.NeutronFixture(self))
self.useFixture(nova_fixtures.AllServicesCurrent())
self.useFixture(func_fixtures.PlacementFixture())
api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
api_version='v2.1'))
self.api = api_fixture.api
self.admin_api = api_fixture.admin_api
fake_network.set_stub_network_methods(self)
self.flags(allow_resize_to_same_host=False)
self.flags(enabled_filters=['AllHostsFilter'],
group='filter_scheduler')
self.start_service('conductor')
self.start_service('scheduler')
fake_image.stub_out_image_service(self)
self.addCleanup(fake_image.FakeImageService_reset)
def _test_create_and_migrate(self, expected_status, az=None):
server = self._build_minimal_create_server_request(self.api,
'some-server',
az=az)
post = {'server': server}
# If forcing the server onto a host we have to use the admin API.
api = self.admin_api if az else self.api
created_server = api.post_server(post)
# Wait for it to finish being created
found_server = self._wait_for_state_change(
self.admin_api, created_server, 'ACTIVE')
return self.admin_api.api_post(
'/servers/%s/action' % found_server['id'],
{'migrate': None},
check_response_status=[expected_status]), found_server
def test_migrate_between_cells(self):
"""Verify that migrating between cells is not allowed.
Right now, we can't migrate between cells. So, create two computes
in different cells and make sure that migration fails with NoValidHost.
"""
# Hosts in different cells
self.start_service('compute', host='compute1', cell=CELL1_NAME)
self.start_service('compute', host='compute2', cell=CELL2_NAME)
_, server = self._test_create_and_migrate(expected_status=202)
# The instance action should have failed with details.
self._assert_resize_migrate_action_fail(
server, instance_actions.MIGRATE, 'NoValidHost')
def test_migrate_within_cell(self):
"""Verify that migrating within cells is allowed.
Create two computes in the same cell and validate that the same
migration is allowed.
"""
# Hosts in the same cell
self.start_service('compute', host='compute1', cell=CELL1_NAME)
self.start_service('compute', host='compute2', cell=CELL1_NAME)
# Create another host just so it looks like we have hosts in
# both cells
self.start_service('compute', host='compute3', cell=CELL2_NAME)
# Force the server onto compute1 in cell1 so we do not accidentally
# land on compute3 in cell2 and fail to migrate.
self._test_create_and_migrate(expected_status=202,
az='nova:compute1')