Skip to content

Commit

Permalink
fup: Move _migrate_stub into LibvirtMigrationMixin
Browse files Browse the repository at this point in the history
Change-Id: I70efe60995568d71d184eadd27adf8918d1909e2
  • Loading branch information
lyarwood committed Aug 20, 2021
1 parent ce12879 commit 78cace1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
25 changes: 25 additions & 0 deletions nova/tests/functional/libvirt/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,31 @@ def _start_compute(hostname, host_info):
return hostname


class LibvirtMigrationMixin(object):
"""A simple mixin to facilliate successful libvirt live migrations
Requires that the test class set self.server for the specific test instnace
and self.{src,dest} to indicate the direction of the migration. For any
scenarios more complex than this they should override _migrate_stub with
their own implementation.
"""
def setUp(self):
super().setUp()
self.useFixture(fixtures.MonkeyPatch(
'nova.tests.fixtures.libvirt.Domain.migrateToURI3',
self._migrate_stub))
self.migrate_stub_ran = False

def _migrate_stub(self, domain, destination, params, flags):
self.dest.driver._host.get_connection().createXML(
params['destination_xml'],
'fake-createXML-doesnt-care-about-flags')
conn = self.src.driver._host.get_connection()
dom = conn.lookupByUUIDString(self.server['id'])
dom.complete_job()
self.migrate_stub_ran = True


class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
"""A custom variant of the stock neutron fixture with more networks.
Expand Down
24 changes: 12 additions & 12 deletions nova/tests/functional/libvirt/test_numa_live_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from nova.compute import resource_tracker as rt
from nova import context
from nova import objects
from nova import test
from nova.tests.fixtures import libvirt as fakelibvirt
from nova.tests.functional import integrated_helpers
from nova.tests.functional.libvirt import base
Expand All @@ -32,8 +31,11 @@
LOG = logging.getLogger(__name__)


class NUMALiveMigrationBase(base.ServersTestBase,
integrated_helpers.InstanceHelperMixin):
class NUMALiveMigrationBase(
base.LibvirtMigrationMixin,
base.ServersTestBase,
integrated_helpers.InstanceHelperMixin
):
"""Base for all the test classes here. Gives us the NUMATopologyFilter and
small helper methods.
"""
Expand Down Expand Up @@ -64,11 +66,6 @@ def setUp(self):
'_live_migration_cleanup_flags',
lambda *args, **kwargs: (True, True)))

def _migrate_stub(self, domain, destination, params, flags):
raise test.TestingException('_migrate_stub() must be implemented in '
' tests that expect the live migration '
' to start.')

def get_host(self, server_id):
server = self.api.get_server(server_id)
return server['OS-EXT-SRV-ATTR:host']
Expand Down Expand Up @@ -104,10 +101,6 @@ class NUMALiveMigrationPositiveBase(NUMALiveMigrationBase):

def setUp(self):
super(NUMALiveMigrationPositiveBase, self).setUp()
self.useFixture(fixtures.MonkeyPatch(
'nova.tests.fixtures.libvirt.Domain.migrateToURI3',
self._migrate_stub))
self.migrate_stub_ran = False

def start_computes_and_servers(self):
# Start 2 computes
Expand Down Expand Up @@ -469,6 +462,11 @@ def _test(self, pin_source, pin_cond, expect_success=True):
hostname='dest',
host_info=fakelibvirt.HostInfo())

# This duplication is required to let the LibvirtMigrationMixin know
# which host is which in terms of the migration.
self.src = self.computes['source']
self.dest = self.computes['dest']

ctxt = context.get_admin_context()
src_mgr = self.computes['source'].manager
cond_mgr = self.conductor.manager.compute_task_mgr
Expand Down Expand Up @@ -507,8 +505,10 @@ def _test(self, pin_source, pin_cond, expect_success=True):
server2 = self._create_server(flavor_id=flavor, networks='none')
if self.get_host(server1['id']) == 'source':
self.migrating_server = server1
self.server = server1
else:
self.migrating_server = server2
self.server = server2
self.api.post_server_action(
self.migrating_server['id'],
{'os-migrateLive': {'host': 'dest',
Expand Down
20 changes: 3 additions & 17 deletions nova/tests/functional/regressions/test_bug_1939545.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import fixtures

from oslo_serialization import jsonutils

from nova import context
Expand All @@ -24,6 +22,7 @@


class TestLiveMigrateUpdateDevicePath(
base.LibvirtMigrationMixin,
base.ServersTestBase,
integrated_helpers.InstanceHelperMixin
):
Expand All @@ -43,12 +42,6 @@ class TestLiveMigrateUpdateDevicePath(
def setUp(self):
super().setUp()

# TODO(lyarwood): Move into base.ServersTestBase to allow live
# migrations to pass without changes by the test classes.
self.useFixture(fixtures.MonkeyPatch(
'nova.tests.fixtures.libvirt.Domain.migrateToURI3',
self._migrate_stub))

self.start_compute(
hostname='src',
host_info=fakelibvirt.HostInfo(
Expand All @@ -58,15 +51,8 @@ def setUp(self):
host_info=fakelibvirt.HostInfo(
cpu_nodes=1, cpu_sockets=1, cpu_cores=4, cpu_threads=1))

def _migrate_stub(self, domain, destination, params, flags):
dest = self.computes['dest']
dest.driver._host.get_connection().createXML(
params['destination_xml'],
'fake-createXML-doesnt-care-about-flags')
source = self.computes['src']
conn = source.driver._host.get_connection()
dom = conn.lookupByUUIDString(self.server['id'])
dom.complete_job()
self.src = self.computes['src']
self.dest = self.computes['dest']

def test_live_migrate_update_device_path(self):
self.server = self._create_server(host='src', networks='none')
Expand Down

0 comments on commit 78cace1

Please sign in to comment.