|
25 | 25 | from unittest import mock
|
26 | 26 |
|
27 | 27 | from castellan import key_manager
|
| 28 | +from cinderclient import exceptions as cinder_exception |
28 | 29 | import ddt
|
| 30 | +from keystoneclient import exceptions as keystone_exception |
29 | 31 | from neutronclient.common import exceptions as neutron_exceptions
|
30 | 32 | from oslo_log import log as logging
|
31 | 33 | import oslo_messaging as messaging
|
@@ -1495,6 +1497,43 @@ def _test__delete_dangling_bdms(
|
1495 | 1497 |
|
1496 | 1498 | return mock_destroy, mock_attachment_delete
|
1497 | 1499 |
|
| 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 | + |
1498 | 1537 | def test_dangling_bdms_nothing_to_delete(self):
|
1499 | 1538 | """no bdm, no attachments"""
|
1500 | 1539 | instance = self._create_fake_instance_obj()
|
@@ -1588,13 +1627,15 @@ def test_dangling_bdms_delete_cinder_attachments(self):
|
1588 | 1627 |
|
1589 | 1628 | cinder_attachments = [
|
1590 | 1629 | {'id': uuids.fake_attachment_1},
|
1591 |
| - {'id': 2}, |
| 1630 | + {'id': uuids.not_in_nova_bdms}, |
1592 | 1631 | ]
|
1593 | 1632 | _, mock_attachment_delete = self._test__delete_dangling_bdms(
|
1594 | 1633 | instance, bdms, cinder_attachments, True)
|
1595 | 1634 |
|
1596 | 1635 | 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) |
1598 | 1639 | self.assertEqual(len(bdms), 1)
|
1599 | 1640 |
|
1600 | 1641 |
|
|
0 commit comments