summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-02-22 17:02:42 +0000
committerGerrit Code Review <review@openstack.org>2018-02-22 17:02:42 +0000
commita4a53bfa31e22bf1c377dca539ee1c7c7c05847c (patch)
tree24075da4a011fa1994c374c740ce4a5d503db50f
parentc716600f8ed0e834d794e1129a5c872fc2ecad88 (diff)
parent58af9ba39bda8753bb9d86d3587e2529911843f9 (diff)
Merge "Ensure attachment_id always exists for block device mapping" into stable/queens17.0.0.0rc3stable/queens
-rw-r--r--nova/compute/api.py7
-rw-r--r--nova/tests/functional/wsgi/test_servers.py5
-rw-r--r--nova/tests/unit/compute/test_compute_api.py40
3 files changed, 48 insertions, 4 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 622eecc..9e7387b 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1346,6 +1346,13 @@ class API(base.Base):
1346 # compatibility can be removed after Ocata EOL. 1346 # compatibility can be removed after Ocata EOL.
1347 self._check_attach(context, volume, instance) 1347 self._check_attach(context, volume, instance)
1348 bdm.volume_size = volume.get('size') 1348 bdm.volume_size = volume.get('size')
1349
1350 # NOTE(mnaser): If we end up reserving the volume, it will
1351 # not have an attachment_id which is needed
1352 # for cleanups. This can be removed once
1353 # all calls to reserve_volume are gone.
1354 if 'attachment_id' not in bdm:
1355 bdm.attachment_id = None
1349 except (exception.CinderConnectionFailed, 1356 except (exception.CinderConnectionFailed,
1350 exception.InvalidVolume, 1357 exception.InvalidVolume,
1351 exception.MultiattachNotSupportedOldMicroversion, 1358 exception.MultiattachNotSupportedOldMicroversion,
diff --git a/nova/tests/functional/wsgi/test_servers.py b/nova/tests/functional/wsgi/test_servers.py
index b0a6999..3c2aea7 100644
--- a/nova/tests/functional/wsgi/test_servers.py
+++ b/nova/tests/functional/wsgi/test_servers.py
@@ -276,10 +276,7 @@ class ServersPreSchedulingTestCase(test.TestCase,
276 276
277 # The volume should no longer have any attachments as instance delete 277 # The volume should no longer have any attachments as instance delete
278 # should have removed them. 278 # should have removed them.
279 # self.assertNotIn(volume_id, cinder.reserved_volumes) 279 self.assertNotIn(volume_id, cinder.reserved_volumes)
280 # FIXME(mnaser): This is part of bug 1750666 where the BDMs aren't
281 # properly deleted because they don't exist in the database.
282 self.assertIn(volume_id, cinder.reserved_volumes)
283 280
284 def test_bfv_delete_build_request_pre_scheduling(self): 281 def test_bfv_delete_build_request_pre_scheduling(self):
285 cinder = self.useFixture( 282 cinder = self.useFixture(
diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py
index a00c0a0..ad7e032 100644
--- a/nova/tests/unit/compute/test_compute_api.py
+++ b/nova/tests/unit/compute/test_compute_api.py
@@ -4010,6 +4010,46 @@ class _ComputeAPIUnitTestMixIn(object):
4010 @mock.patch.object(objects.Service, 'get_minimum_version', 4010 @mock.patch.object(objects.Service, 'get_minimum_version',
4011 return_value=17) 4011 return_value=17)
4012 @mock.patch.object(cinder.API, 'get') 4012 @mock.patch.object(cinder.API, 'get')
4013 @mock.patch.object(cinder.API, 'reserve_volume')
4014 def test_validate_bdm_returns_attachment_id(self, mock_reserve_volume,
4015 mock_get, mock_get_min_ver,
4016 mock_get_min_ver_all):
4017 # Tests that bdm validation *always* returns an attachment_id even if
4018 # it's None.
4019 instance = self._create_instance_obj()
4020 instance_type = self._create_flavor()
4021 volume_id = 'e856840e-9f5b-4894-8bde-58c6e29ac1e8'
4022 volume_info = {'status': 'available',
4023 'attach_status': 'detached',
4024 'id': volume_id,
4025 'multiattach': False}
4026 mock_get.return_value = volume_info
4027
4028 # NOTE(mnaser): We use the AnonFakeDbBlockDeviceDict to make sure that
4029 # the attachment_id field does not get any defaults to
4030 # properly test this function.
4031 bdms = [objects.BlockDeviceMapping(
4032 **fake_block_device.AnonFakeDbBlockDeviceDict(
4033 {
4034 'boot_index': 0,
4035 'volume_id': volume_id,
4036 'source_type': 'volume',
4037 'destination_type': 'volume',
4038 'device_name': 'vda',
4039 }))]
4040 self.compute_api._validate_bdm(self.context, instance, instance_type,
4041 bdms)
4042 self.assertIsNone(bdms[0].attachment_id)
4043
4044 mock_get.assert_called_once_with(self.context, volume_id)
4045 mock_reserve_volume.assert_called_once_with(
4046 self.context, volume_id)
4047
4048 @mock.patch.object(objects.service, 'get_minimum_version_all_cells',
4049 return_value=17)
4050 @mock.patch.object(objects.Service, 'get_minimum_version',
4051 return_value=17)
4052 @mock.patch.object(cinder.API, 'get')
4013 @mock.patch.object(cinder.API, 'reserve_volume', 4053 @mock.patch.object(cinder.API, 'reserve_volume',
4014 side_effect=exception.InvalidInput(reason='error')) 4054 side_effect=exception.InvalidInput(reason='error'))
4015 def test_validate_bdm_with_error_volume(self, mock_reserve_volume, 4055 def test_validate_bdm_with_error_volume(self, mock_reserve_volume,