Merge "Add scenario test case to verivy Nova servers migration"

This commit is contained in:
Zuul 2021-05-03 14:05:43 +00:00 committed by Gerrit Code Review
commit 7eb10f7d11

View File

@ -18,10 +18,12 @@ import testtools
import tobiko
from tobiko import config
from tobiko.openstack import stacks
from tobiko.openstack import keystone
from tobiko.openstack import neutron
from tobiko.openstack import nova
from tobiko.openstack import stacks
from tobiko.openstack import tests
from tobiko.shell import ping
class ServerStackResourcesTest(testtools.TestCase):
@ -64,3 +66,63 @@ class ServerCreationTest(testtools.TestCase):
def test_servers_creation(self):
tests.test_servers_creation()
class MigrateServerStack(stacks.CirrosServerStackFixture):
pass
@keystone.skip_unless_has_keystone_credentials()
@nova.skip_if_missing_hypervisors(count=2)
class MigrateServerTest(testtools.TestCase):
stack = tobiko.required_setup_fixture(MigrateServerStack)
def test_migrate_server(self):
"""Tests cold migration actually changes hypervisor
"""
server = self.setup_server()
initial_hypervisor = nova.get_server_hypervisor(server)
server = self.migrate_server(server)
final_hypervisor = nova.get_server_hypervisor(server)
self.assertNotEqual(initial_hypervisor, final_hypervisor)
def test_migrate_server_with_host(self):
"""Tests cold migration actually ends on target hypervisor
"""
server = self.setup_server()
initial_hypervisor = nova.get_server_hypervisor(server)
for hypervisor in nova.list_hypervisors(status='enabled', state='up'):
if initial_hypervisor != hypervisor.hypervisor_hostname:
target_hypervisor = hypervisor.hypervisor_hostname
break
else:
self.skipTest("Cannot find a valid hypervisor host to migrate "
"server to")
server = self.migrate_server(server=server, host=target_hypervisor)
final_hypervisor = nova.get_server_hypervisor(server)
self.assertEqual(target_hypervisor, final_hypervisor)
def setup_server(self):
server = self.stack.ensure_server_status('ACTIVE')
self.assertEqual('ACTIVE', server.status)
return server
def migrate_server(self, server, **params):
self.assertEqual('ACTIVE', server.status)
nova.migrate_server(server, **params)
server = nova.wait_for_server_status(server, 'VERIFY_RESIZE')
self.assertEqual('VERIFY_RESIZE', server.status)
nova.confirm_resize(server)
server = nova.wait_for_server_status(
server, 'ACTIVE', transient_status={'VERIFY_RESIZE'})
self.assertEqual('ACTIVE', server.status)
ping.ping_until_received(self.stack.ip_address).assert_replied()
return server