Skip to content

Commit 68b2131

Browse files
SeanMooneyauniyal61
authored andcommitted
only attempt to clean up dangling bdm if cinder is installed
This change ensure we only try to clean up dangling bdms if cinder is installed and reachable. Closes-Bug: #2033752 Change-Id: I0ada59d8901f8620fd1f3dc20d6be303aa7dabca
1 parent 88c73e2 commit 68b2131

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

nova/compute/manager.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4185,9 +4185,21 @@ def _delete_dangling_bdms(self, context, instance, bdms):
41854185

41864186
:param context: The nova request context.
41874187
:param instance: instance object.
4188-
:param instance: BlockDeviceMappingList list object.
4188+
:param bdms: BlockDeviceMappingList list object.
41894189
"""
41904190

4191+
try:
4192+
cinder_attachments = self.volume_api.attachment_get_all(
4193+
context, instance.uuid)
4194+
except (keystone_exception.EndpointNotFound,
4195+
cinder_exception.ClientException):
4196+
# if cinder is not deployed we never need to check for
4197+
# attachments as there cannot be dangling bdms.
4198+
# if we cannot connect to cinder we cannot check for dangling
4199+
# bdms so we skip the check. Intermittent connection issues
4200+
# to cinder should not cause instance reboot to fail.
4201+
return
4202+
41914203
# attachments present in nova DB, ones nova knows about
41924204
nova_attachments = []
41934205
bdms_to_delete = []
@@ -4206,8 +4218,6 @@ def _delete_dangling_bdms(self, context, instance, bdms):
42064218
else:
42074219
nova_attachments.append(bdm.attachment_id)
42084220

4209-
cinder_attachments = self.volume_api.attachment_get_all(
4210-
context, instance.uuid)
42114221
cinder_attachments = [each['id'] for each in cinder_attachments]
42124222

42134223
if len(set(cinder_attachments) - set(nova_attachments)):

nova/tests/unit/compute/test_compute.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
from unittest import mock
2626

2727
from castellan import key_manager
28+
from cinderclient import exceptions as cinder_exception
2829
import ddt
30+
from keystoneclient import exceptions as keystone_exception
2931
from neutronclient.common import exceptions as neutron_exceptions
3032
from oslo_log import log as logging
3133
import oslo_messaging as messaging
@@ -1495,6 +1497,43 @@ def _test__delete_dangling_bdms(
14951497

14961498
return mock_destroy, mock_attachment_delete
14971499

1500+
def _test_delete_dangling_bdms_cinder_error(self):
1501+
instance = self._create_fake_instance_obj()
1502+
bdms = objects.BlockDeviceMappingList(objects=[
1503+
objects.BlockDeviceMapping(
1504+
**fake_block_device.AnonFakeDbBlockDeviceDict(
1505+
{
1506+
'instance_uuid': instance.uuid,
1507+
'volume_id': uuids.fake_vol1,
1508+
'attachment_id': uuids.fake_attachment_1,
1509+
'source_type': 'volume',
1510+
'destination_type': 'volume'})),
1511+
objects.BlockDeviceMapping(
1512+
**fake_block_device.AnonFakeDbBlockDeviceDict(
1513+
{
1514+
'instance_uuid': instance.uuid,
1515+
'volume_id': uuids.fake_vol2,
1516+
'attachment_id': uuids.fake_attachment_2,
1517+
'source_type': 'image',
1518+
'destination_type': 'volume'}))
1519+
])
1520+
1521+
expected = bdms.obj_to_primitive()
1522+
self.compute._delete_dangling_bdms(self.context, instance, bdms)
1523+
self.assertEqual(expected, bdms.obj_to_primitive())
1524+
1525+
@mock.patch.object(
1526+
cinder.API, 'attachment_get_all',
1527+
new=mock.Mock(side_effect=keystone_exception.EndpointNotFound()))
1528+
def test_delete_dangling_bdms_cinder_not_found(self):
1529+
self._test_delete_dangling_bdms_cinder_error()
1530+
1531+
@mock.patch.object(
1532+
cinder.API, 'attachment_get_all',
1533+
new=mock.Mock(side_effect=cinder_exception.ClientException(500)))
1534+
def test_delete_dangling_bdms_cinder_client_error(self):
1535+
self._test_delete_dangling_bdms_cinder_error()
1536+
14981537
def test_dangling_bdms_nothing_to_delete(self):
14991538
"""no bdm, no attachments"""
15001539
instance = self._create_fake_instance_obj()
@@ -1588,13 +1627,15 @@ def test_dangling_bdms_delete_cinder_attachments(self):
15881627

15891628
cinder_attachments = [
15901629
{'id': uuids.fake_attachment_1},
1591-
{'id': 2},
1630+
{'id': uuids.not_in_nova_bdms},
15921631
]
15931632
_, mock_attachment_delete = self._test__delete_dangling_bdms(
15941633
instance, bdms, cinder_attachments, True)
15951634

15961635
self.assertTrue(mock_attachment_delete.call_count, 1)
1597-
self.assertEqual(mock_attachment_delete.call_args_list[0][0][1], 2)
1636+
self.assertEqual(
1637+
mock_attachment_delete.call_args_list[0][0][1],
1638+
uuids.not_in_nova_bdms)
15981639
self.assertEqual(len(bdms), 1)
15991640

16001641

0 commit comments

Comments
 (0)