|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import mock |
| 14 | + |
| 15 | +from nova import test |
| 16 | +from nova.tests import fixtures as nova_fixtures |
| 17 | +from nova.tests.functional import integrated_helpers |
| 18 | + |
| 19 | + |
| 20 | +class TestVolAttachmentsDuringPreLiveMigration( |
| 21 | + integrated_helpers._IntegratedTestBase |
| 22 | +): |
| 23 | + """Regression test for bug 1889108. |
| 24 | +
|
| 25 | + This regression test asserts that the original source volume attachments |
| 26 | + are incorrectly removed during the rollback from pre_live_migration |
| 27 | + failures on the destination. |
| 28 | + """ |
| 29 | + |
| 30 | + # Default self.api to the self.admin_api as live migration is admin only |
| 31 | + ADMIN_API = True |
| 32 | + microversion = 'latest' |
| 33 | + |
| 34 | + def setUp(self): |
| 35 | + super().setUp() |
| 36 | + self.cinder = self.useFixture(nova_fixtures.CinderFixture(self)) |
| 37 | + |
| 38 | + def _setup_compute_service(self): |
| 39 | + self._start_compute('src') |
| 40 | + self._start_compute('dest') |
| 41 | + |
| 42 | + @mock.patch('nova.virt.fake.FakeDriver.pre_live_migration', |
| 43 | + side_effect=test.TestingException) |
| 44 | + def test_vol_attachments_during_driver_pre_live_mig_failure( |
| 45 | + self, mock_plm): |
| 46 | + """Assert that the src attachment is incorrectly removed |
| 47 | +
|
| 48 | + * Mock pre_live_migration to always fail within the virt driver |
| 49 | + * Launch a boot from volume instance |
| 50 | + * Assert that the volume is attached correctly to the instance. |
| 51 | + * Live migrate the instance to another host invoking the mocked |
| 52 | + pre_live_migration |
| 53 | + * Assert that the instance is still on the source host |
| 54 | + * Assert that both the original source host volume attachment and |
| 55 | + new destination volume attachment have been removed |
| 56 | + """ |
| 57 | + volume_id = nova_fixtures.CinderFixture.IMAGE_BACKED_VOL |
| 58 | + server = self._build_server( |
| 59 | + name='test_bfv_pre_live_migration_failure', image_uuid='', |
| 60 | + networks='none' |
| 61 | + ) |
| 62 | + server['block_device_mapping_v2'] = [{ |
| 63 | + 'source_type': 'volume', |
| 64 | + 'destination_type': 'volume', |
| 65 | + 'boot_index': 0, |
| 66 | + 'uuid': volume_id |
| 67 | + }] |
| 68 | + server = self.api.post_server({'server': server}) |
| 69 | + self._wait_for_state_change(server, 'ACTIVE') |
| 70 | + |
| 71 | + # Fetch the source host for use later |
| 72 | + server = self.api.get_server(server['id']) |
| 73 | + src_host = server['OS-EXT-SRV-ATTR:host'] |
| 74 | + |
| 75 | + # Assert that the volume is connected to the instance |
| 76 | + self.assertIn( |
| 77 | + volume_id, self.cinder.volume_ids_for_instance(server['id'])) |
| 78 | + |
| 79 | + # Assert that we have an active attachment in the fixture |
| 80 | + attachments = self.cinder.volume_to_attachment.get(volume_id) |
| 81 | + self.assertEqual(1, len(attachments)) |
| 82 | + |
| 83 | + # Fetch the attachment_id for use later once we have migrated |
| 84 | + src_attachment_id = list(attachments.keys())[0] |
| 85 | + |
| 86 | + # Migrate the instance and wait until the migration errors out thanks |
| 87 | + # to our mocked version of pre_live_migration raising |
| 88 | + # test.TestingException |
| 89 | + self._live_migrate(server, 'error') |
| 90 | + |
| 91 | + # Assert that we called the fake pre_live_migration method |
| 92 | + mock_plm.assert_called_once() |
| 93 | + |
| 94 | + # Assert that the instance is listed on the source |
| 95 | + server = self.api.get_server(server['id']) |
| 96 | + self.assertEqual(src_host, server['OS-EXT-SRV-ATTR:host']) |
| 97 | + |
| 98 | + # FIXME(lyarwood): Assert that both the src and dest attachments have |
| 99 | + # been removed. Only the dest attachment should be removed during the |
| 100 | + # rollback of a pre_live_migration failure. |
| 101 | + attachments = self.cinder.volume_to_attachment.get(volume_id) |
| 102 | + self.assertNotIn(src_attachment_id, attachments.keys()) |
| 103 | + self.assertEqual(0, len(attachments)) |
0 commit comments