Skip to content

Commit 10b1dc8

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "fup: Move _migrate_stub into LibvirtMigrationMixin"
2 parents a2fee52 + 78cace1 commit 10b1dc8

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

nova/tests/functional/libvirt/base.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,31 @@ def _start_compute(hostname, host_info):
160160
return hostname
161161

162162

163+
class LibvirtMigrationMixin(object):
164+
"""A simple mixin to facilliate successful libvirt live migrations
165+
166+
Requires that the test class set self.server for the specific test instnace
167+
and self.{src,dest} to indicate the direction of the migration. For any
168+
scenarios more complex than this they should override _migrate_stub with
169+
their own implementation.
170+
"""
171+
def setUp(self):
172+
super().setUp()
173+
self.useFixture(fixtures.MonkeyPatch(
174+
'nova.tests.fixtures.libvirt.Domain.migrateToURI3',
175+
self._migrate_stub))
176+
self.migrate_stub_ran = False
177+
178+
def _migrate_stub(self, domain, destination, params, flags):
179+
self.dest.driver._host.get_connection().createXML(
180+
params['destination_xml'],
181+
'fake-createXML-doesnt-care-about-flags')
182+
conn = self.src.driver._host.get_connection()
183+
dom = conn.lookupByUUIDString(self.server['id'])
184+
dom.complete_job()
185+
self.migrate_stub_ran = True
186+
187+
163188
class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
164189
"""A custom variant of the stock neutron fixture with more networks.
165190

nova/tests/functional/libvirt/test_numa_live_migration.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from nova.compute import resource_tracker as rt
2323
from nova import context
2424
from nova import objects
25-
from nova import test
2625
from nova.tests.fixtures import libvirt as fakelibvirt
2726
from nova.tests.functional import integrated_helpers
2827
from nova.tests.functional.libvirt import base
@@ -32,8 +31,11 @@
3231
LOG = logging.getLogger(__name__)
3332

3433

35-
class NUMALiveMigrationBase(base.ServersTestBase,
36-
integrated_helpers.InstanceHelperMixin):
34+
class NUMALiveMigrationBase(
35+
base.LibvirtMigrationMixin,
36+
base.ServersTestBase,
37+
integrated_helpers.InstanceHelperMixin
38+
):
3739
"""Base for all the test classes here. Gives us the NUMATopologyFilter and
3840
small helper methods.
3941
"""
@@ -64,11 +66,6 @@ def setUp(self):
6466
'_live_migration_cleanup_flags',
6567
lambda *args, **kwargs: (True, True)))
6668

67-
def _migrate_stub(self, domain, destination, params, flags):
68-
raise test.TestingException('_migrate_stub() must be implemented in '
69-
' tests that expect the live migration '
70-
' to start.')
71-
7269
def get_host(self, server_id):
7370
server = self.api.get_server(server_id)
7471
return server['OS-EXT-SRV-ATTR:host']
@@ -104,10 +101,6 @@ class NUMALiveMigrationPositiveBase(NUMALiveMigrationBase):
104101

105102
def setUp(self):
106103
super(NUMALiveMigrationPositiveBase, self).setUp()
107-
self.useFixture(fixtures.MonkeyPatch(
108-
'nova.tests.fixtures.libvirt.Domain.migrateToURI3',
109-
self._migrate_stub))
110-
self.migrate_stub_ran = False
111104

112105
def start_computes_and_servers(self):
113106
# Start 2 computes
@@ -469,6 +462,11 @@ def _test(self, pin_source, pin_cond, expect_success=True):
469462
hostname='dest',
470463
host_info=fakelibvirt.HostInfo())
471464

465+
# This duplication is required to let the LibvirtMigrationMixin know
466+
# which host is which in terms of the migration.
467+
self.src = self.computes['source']
468+
self.dest = self.computes['dest']
469+
472470
ctxt = context.get_admin_context()
473471
src_mgr = self.computes['source'].manager
474472
cond_mgr = self.conductor.manager.compute_task_mgr
@@ -507,8 +505,10 @@ def _test(self, pin_source, pin_cond, expect_success=True):
507505
server2 = self._create_server(flavor_id=flavor, networks='none')
508506
if self.get_host(server1['id']) == 'source':
509507
self.migrating_server = server1
508+
self.server = server1
510509
else:
511510
self.migrating_server = server2
511+
self.server = server2
512512
self.api.post_server_action(
513513
self.migrating_server['id'],
514514
{'os-migrateLive': {'host': 'dest',

nova/tests/functional/regressions/test_bug_1939545.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
import fixtures
16-
1715
from oslo_serialization import jsonutils
1816

1917
from nova import context
@@ -24,6 +22,7 @@
2422

2523

2624
class TestLiveMigrateUpdateDevicePath(
25+
base.LibvirtMigrationMixin,
2726
base.ServersTestBase,
2827
integrated_helpers.InstanceHelperMixin
2928
):
@@ -43,12 +42,6 @@ class TestLiveMigrateUpdateDevicePath(
4342
def setUp(self):
4443
super().setUp()
4544

46-
# TODO(lyarwood): Move into base.ServersTestBase to allow live
47-
# migrations to pass without changes by the test classes.
48-
self.useFixture(fixtures.MonkeyPatch(
49-
'nova.tests.fixtures.libvirt.Domain.migrateToURI3',
50-
self._migrate_stub))
51-
5245
self.start_compute(
5346
hostname='src',
5447
host_info=fakelibvirt.HostInfo(
@@ -58,15 +51,8 @@ def setUp(self):
5851
host_info=fakelibvirt.HostInfo(
5952
cpu_nodes=1, cpu_sockets=1, cpu_cores=4, cpu_threads=1))
6053

61-
def _migrate_stub(self, domain, destination, params, flags):
62-
dest = self.computes['dest']
63-
dest.driver._host.get_connection().createXML(
64-
params['destination_xml'],
65-
'fake-createXML-doesnt-care-about-flags')
66-
source = self.computes['src']
67-
conn = source.driver._host.get_connection()
68-
dom = conn.lookupByUUIDString(self.server['id'])
69-
dom.complete_job()
54+
self.src = self.computes['src']
55+
self.dest = self.computes['dest']
7056

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

0 commit comments

Comments
 (0)