Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use COMPUTE_SAME_HOST_COLD_MIGRATE trait during migrate
This uses the COMPUTE_SAME_HOST_COLD_MIGRATE trait in the API during a cold migration to filter out hosts that cannot support same-host cold migration, which is all of them except for the hosts using the vCenter driver. For any nodes that do not report the trait, we won't know if they don't because they don't support it or if they are not new enough to report it, so the API has a service version check and will fallback to old behavior using the config if the node is old. That compat code can be removed in the next release. As a result of this the FakeDriver capabilities are updated so the FakeDriver no longer supports same-host cold migration and a new fake driver is added to support that scenario for any tests that need it. Change-Id: I7a4b951f3ab324c666ab924e6003d24cc8e539f5 Closes-Bug: #1748697 Related-Bug: #1811235
- Loading branch information
1 parent
9fa3600
commit 4921e82
Showing
10 changed files
with
216 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# 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. | ||
|
||
import mock | ||
|
||
from nova.compute import api as compute_api | ||
from nova import context as nova_context | ||
from nova import objects | ||
from nova import test | ||
from nova.tests.functional import integrated_helpers | ||
from nova.tests.unit import fake_notifier | ||
|
||
|
||
class ColdMigrationDisallowSameHost( | ||
integrated_helpers.ProviderUsageBaseTestCase): | ||
"""Tests cold migrate where the source host does not have the | ||
COMPUTE_SAME_HOST_COLD_MIGRATE trait. | ||
""" | ||
compute_driver = 'fake.MediumFakeDriver' | ||
|
||
def setUp(self): | ||
super(ColdMigrationDisallowSameHost, self).setUp() | ||
# Start one compute service which will use the fake virt driver | ||
# which disallows cold migration to the same host. | ||
self._start_compute('host1') | ||
|
||
def _wait_for_migrate_no_valid_host(self, error='NoValidHost'): | ||
event = fake_notifier.wait_for_versioned_notifications( | ||
'compute_task.migrate_server.error')[0] | ||
self.assertEqual(error, | ||
event['payload']['nova_object.data']['reason'][ | ||
'nova_object.data']['exception']) | ||
|
||
def test_cold_migrate_same_host_not_supported(self): | ||
"""Simple test to show that you cannot cold-migrate to the same host | ||
when the resource provider does not expose the | ||
COMPUTE_SAME_HOST_COLD_MIGRATE trait. | ||
""" | ||
server = self._create_server(networks='none') | ||
# The fake driver does not report COMPUTE_SAME_HOST_COLD_MIGRATE | ||
# so cold migration should fail since we only have one host. | ||
self.api.post_server_action(server['id'], {'migrate': None}) | ||
self._wait_for_migrate_no_valid_host() | ||
|
||
def test_cold_migrate_same_host_old_compute_disallow(self): | ||
"""Upgrade compat test where the resource provider does not report | ||
the COMPUTE_SAME_HOST_COLD_MIGRATE trait but the compute service is | ||
old so the API falls back to the allow_resize_to_same_host config which | ||
defaults to False. | ||
""" | ||
server = self._create_server(networks='none') | ||
# Stub the compute service version check to make the compute service | ||
# appear old. | ||
fake_service = objects.Service() | ||
fake_service.version = ( | ||
compute_api.MIN_COMPUTE_SAME_HOST_COLD_MIGRATE - 1) | ||
with mock.patch('nova.objects.Service.get_by_compute_host', | ||
return_value=fake_service) as mock_get_service: | ||
self.api.post_server_action(server['id'], {'migrate': None}) | ||
mock_get_service.assert_called_once_with( | ||
test.MatchType(nova_context.RequestContext), 'host1') | ||
# Since allow_resize_to_same_host defaults to False scheduling failed | ||
# since there are no other hosts. | ||
self._wait_for_migrate_no_valid_host() | ||
|
||
def test_cold_migrate_same_host_old_compute_allow(self): | ||
"""Upgrade compat test where the resource provider does not report | ||
the COMPUTE_SAME_HOST_COLD_MIGRATE trait but the compute service is | ||
old so the API falls back to the allow_resize_to_same_host config which | ||
in this test is set to True. | ||
""" | ||
self.flags(allow_resize_to_same_host=True) | ||
server = self._create_server(networks='none') | ||
# Stub the compute service version check to make the compute service | ||
# appear old. | ||
fake_service = objects.Service() | ||
fake_service.version = ( | ||
compute_api.MIN_COMPUTE_SAME_HOST_COLD_MIGRATE - 1) | ||
with mock.patch('nova.objects.Service.get_by_compute_host', | ||
return_value=fake_service) as mock_get_service: | ||
self.api.post_server_action(server['id'], {'migrate': None}) | ||
mock_get_service.assert_called_once_with( | ||
test.MatchType(nova_context.RequestContext), 'host1') | ||
# In this case the compute is old so the API falls back to checking | ||
# allow_resize_to_same_host which says same-host cold migrate is | ||
# allowed so the scheduler sends the request to the only compute | ||
# available but the virt driver says same-host cold migrate is not | ||
# supported and raises UnableToMigrateToSelf. A reschedule is sent | ||
# to conductor which results in MaxRetriesExceeded since there are no | ||
# alternative hosts. | ||
self._wait_for_migrate_no_valid_host(error='MaxRetriesExceeded') | ||
|
||
|
||
class ColdMigrationAllowSameHost( | ||
integrated_helpers.ProviderUsageBaseTestCase): | ||
"""Tests cold migrate where the source host has the | ||
COMPUTE_SAME_HOST_COLD_MIGRATE trait. | ||
""" | ||
compute_driver = 'fake.SameHostColdMigrateDriver' | ||
|
||
def setUp(self): | ||
super(ColdMigrationAllowSameHost, self).setUp() | ||
self._start_compute('host1') | ||
|
||
def test_cold_migrate_same_host_supported(self): | ||
"""Simple test to show that you can cold-migrate to the same host | ||
when the resource provider exposes the COMPUTE_SAME_HOST_COLD_MIGRATE | ||
trait. | ||
""" | ||
server = self._create_server(networks='none') | ||
self.api.post_server_action(server['id'], {'migrate': None}) | ||
server = self._wait_for_state_change(server, 'VERIFY_RESIZE') | ||
self.assertEqual('host1', server['OS-EXT-SRV-ATTR:host']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
releasenotes/notes/bug-1748697-COMPUTE_SAME_HOST_COLD_MIGRATE-19ed64bf48bb1fc7.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
fixes: | ||
- | | ||
This release contains a fix for `bug 1748697`_ which distinguishes between | ||
resize and cold migrate such that the ``allow_resize_to_same_host`` config | ||
option is no longer used to determine if a server can be cold migrated to | ||
the same compute service host. Now when requesting a cold migration the | ||
API will check if the source compute node resource provider has the | ||
``COMPUTE_SAME_HOST_COLD_MIGRATE`` trait and if so the scheduler can select | ||
the source host. Note that the only in-tree compute driver that supports | ||
cold migration to the same host is ``VMwareVCDriver``. | ||
To support rolling upgrades with N-1 computes if a node does not report the | ||
trait and is old the API will fallback to the ``allow_resize_to_same_host`` | ||
config option value. That compatibility will be removed in a subsequent | ||
release. | ||
.. _bug 1748697: https://launchpad.net/bugs/1748697 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters