diff options
author | Lee Yarwood <lyarwood@redhat.com> | 2021-08-11 10:51:33 +0100 |
---|---|---|
committer | Lee Yarwood <lyarwood@redhat.com> | 2021-08-11 19:51:19 +0100 |
commit | 268b7169554f871d3813d78e79861934d086484d (patch) | |
tree | aa808efbfcdc4595b729fd68721bfdd152c51a07 /nova/tests/functional/regressions | |
parent | d102b751b743b5315557cac0997198152c0cac74 (diff) | |
download | nova-268b7169554f871d3813d78e79861934d086484d.tar.gz |
Add a regression test for bug 1939545
Assert the behaviour of the libvirt driver during pre_live_migration
with instances that have block based volumes attached.
Bug #1939545 covering the case where the returned path from os-brick
isn't being saved into the connection_info of the associated bdm in
Nova.
The cinder fixture is extended as part of this change to offer
connection_info listing the iscsi volume type in order to correctly
assert the behaviour of the associated libvirt volume driver.
Related-Bug: #1939545
Change-Id: I3f1073d70e4332737e33f3c9c00cf129d0ef76b4
Diffstat (limited to 'nova/tests/functional/regressions')
-rw-r--r-- | nova/tests/functional/regressions/test_bug_1939545.py | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/nova/tests/functional/regressions/test_bug_1939545.py b/nova/tests/functional/regressions/test_bug_1939545.py new file mode 100644 index 0000000000..1c0827cf54 --- /dev/null +++ b/nova/tests/functional/regressions/test_bug_1939545.py @@ -0,0 +1,110 @@ +# Copyright 2021, Red Hat, Inc. All Rights Reserved. +# +# 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 fixtures +import mock + +from oslo_serialization import jsonutils + +from nova import context +from nova import objects +from nova.tests import fixtures as nova_fixtures +from nova.tests.fixtures import libvirt as fakelibvirt +from nova.tests.functional import integrated_helpers +from nova.tests.functional.libvirt import base + + +class TestLiveMigrateUpdateDevicePath( + base.ServersTestBase, + integrated_helpers.InstanceHelperMixin +): + """Regression test for bug 1939545 + + Assert the behaviour of the libvirt driver during pre_live_migration with + instances that have block based volumes attached. + + Bug #1939545 covering the case where the returned path from os-brick + isn't being saved into the connection_info of the associated bdm in Nova. + """ + + api_major_version = 'v2.1' + microversion = 'latest' + ADMIN_API = True + + def setUp(self): + super().setUp() + + # TODO(lyarwood): Move into base.ServersTestBase + self.useFixture(nova_fixtures.OSBrickFixture()) + + # 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( + cpu_nodes=1, cpu_sockets=1, cpu_cores=4, cpu_threads=1)) + self.start_compute( + hostname='dest', + 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() + + # TODO(lyarwood): Move this into the os-brick fixture and repeat for all + # provided connectors at runtime. + @mock.patch( + 'os_brick.initiator.connectors.iscsi.ISCSIConnector.connect_volume') + @mock.patch( + 'os_brick.initiator.connectors.iscsi.ISCSIConnector.disconnect_volume') + def test_live_migrate_update_device_path( + self, mock_disconnect_volume, mock_connect_volume + ): + self.server = self._create_server(host='src', networks='none') + volume_id = self.cinder.ISCSI_BACKED_VOL + + # TODO(lyarwood): As above, move this into the os-brick fixture. + mock_connect_volume.return_value = {'path': '/dev/sda'} + + self.api.post_server_volume( + self.server['id'], {'volumeAttachment': {'volumeId': volume_id}}) + + # Get the volume bdm and assert that the connection_info is set with + # device_path from the volume driver. + ctxt = context.get_admin_context() + bdm = objects.BlockDeviceMapping.get_by_volume_and_instance( + ctxt, volume_id, self.server['id']) + connection_info = jsonutils.loads(bdm.connection_info) + self.assertIn('device_path', connection_info.get('data')) + + # Live migrate the instance to another host + self._live_migrate(self.server) + + # FIXME(lyarwood): This is bug #1939545, again get the volume bdm and + # assert that the saved connection_info doesn't contain device_path. + bdm = objects.BlockDeviceMapping.get_by_volume_and_instance( + ctxt, volume_id, self.server['id']) + connection_info = jsonutils.loads(bdm.connection_info) + self.assertNotIn('device_path', connection_info.get('data')) |