Add Live Migration Mixin

Mixin does a live migration and checks if old host is different
from destination host.

Mixin is used in test_cluster.py and test_vnuma.py.

Change-Id: Ia647b78b24feeba4e6b74ed08a21e8ac0955920d
This commit is contained in:
Alexandru Muresan 2017-07-18 11:53:08 +03:00
parent 377943cb0d
commit 11f87904b2
4 changed files with 69 additions and 5 deletions

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from tempest.common import waiters
import testtools
from oswin_tempest_plugin import config
@ -43,3 +44,64 @@ class _MigrateMixin(object):
server_tuple = self._create_server()
self._migrate_server(server_tuple)
self._check_server_connectivity(server_tuple)
class _LiveMigrateMixin(object):
"""Live migration mixin.
This mixin will add a live migration test. It will perform the
following operations:
* Spawn instance.
* Live migrate the instance.
* Check the server connectivity.
"""
# TODO(amuresan): Different mixins may be used at the same time.
# Each of them may override some fields such as
# 'max_microversion'. This has to be sorted out.
max_microversion = '2.24'
def _live_migrate_server(self, server_tuple, destination_host=None,
state='ACTIVE', volume_backed=False):
server = server_tuple.server
admin_server = self._get_server_as_admin(server)
current_host = admin_server['OS-EXT-SRV-ATTR:host']
block_migration = (CONF.compute_feature_enabled.
block_migration_for_live_migration and
not volume_backed)
self.admin_servers_client.live_migrate_server(
server['id'],
host=destination_host,
block_migration=block_migration,
disk_over_commit=False)
waiters.wait_for_server_status(self.admin_servers_client, server['id'],
state)
admin_server = self._get_server_as_admin(server)
after_migration_host = admin_server['OS-EXT-SRV-ATTR:host']
migration_list = (self.admin_migrations_client.list_migrations()
['migrations'])
msg = ("Live Migration failed. Migrations list for Instance "
"%s: [" % server['id'])
for live_migration in migration_list:
if live_migration['instance_uuid'] == server['id']:
msg += "\n%s" % live_migration
msg += "]"
if destination_host:
self.assertEqual(destination_host, after_migration_host, msg)
else:
self.assertNotEqual(current_host, after_migration_host, msg)
@testtools.skipUnless(CONF.compute_feature_enabled.live_migration,
'Live migration option enabled.')
def test_live_migration(self):
server_tuple = self._create_server()
self._live_migrate_server(server_tuple)
self._check_server_connectivity(server_tuple)

View File

@ -31,6 +31,7 @@ LOG = logging.getLogger(__name__)
class HyperVClusterTest(test_base.TestBase,
migrate._MigrateMixin,
migrate._LiveMigrateMixin,
resize._ResizeMixin):
"""The test suite for the Hyper-V Cluster.
@ -134,11 +135,6 @@ class HyperVClusterTest(test_base.TestBase,
res_type='hypervisor')
return hypervisor[0]
def _get_server_as_admin(self, server):
# only admins have access to certain instance properties.
return self.admin_servers_client.show_server(
server['id'])['server']
def _create_server(self):
server_tuple = super(HyperVClusterTest, self)._create_server()
server = server_tuple.server

View File

@ -21,6 +21,7 @@ from oswin_tempest_plugin.tests import test_base
class HyperVvNumaTestCase(test_base.TestBase,
migrate._MigrateMixin,
migrate._LiveMigrateMixin,
optional_feature._OptionalFeatureMixin,
resize._ResizeMixin):
"""Hyper-V vNUMA test suite.

View File

@ -186,6 +186,11 @@ class TestBase(tempest.test.BaseTestCase):
return server_tuple
def _get_server_as_admin(self, server):
# only admins have access to certain instance properties.
return self.admin_servers_client.show_server(
server['id'])['server']
def _create_security_group(self):
sg_name = data_utils.rand_name(self.__class__.__name__)
sg_desc = sg_name + " description"