diff --git a/nova/tests/virt/xenapi/test_vm_utils.py b/nova/tests/virt/xenapi/test_vm_utils.py index 10d24e82617e..c3d909534ab4 100644 --- a/nova/tests/virt/xenapi/test_vm_utils.py +++ b/nova/tests/virt/xenapi/test_vm_utils.py @@ -1523,6 +1523,24 @@ class GetAllVdiForVMTestCase(VMUtilsTestBase): self.assertEqual(expected, list(result)) +class GetAllVdisTestCase(VMUtilsTestBase): + def test_get_all_vdis_in_sr(self): + + def fake_get_rec(record_type, ref): + if ref == "2": + return "vdi_rec_2" + + session = mock.Mock() + session.call_xenapi.return_value = ["1", "2"] + session.get_rec.side_effect = fake_get_rec + + sr_ref = "sr_ref" + actual = list(vm_utils._get_all_vdis_in_sr(session, sr_ref)) + self.assertEqual(actual, [('2', 'vdi_rec_2')]) + + session.call_xenapi.assert_called_once_with("SR.get_VDIs", sr_ref) + + class SnapshotAttachedHereTestCase(VMUtilsTestBase): @mock.patch.object(vm_utils, '_snapshot_attached_here_impl') def test_snapshot_attached_here(self, mock_impl): diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index f902243199f3..1ac055b101ac 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -1820,11 +1820,11 @@ def _get_rrd(server, vm_uuid): def _get_all_vdis_in_sr(session, sr_ref): for vdi_ref in session.call_xenapi('SR.get_VDIs', sr_ref): - try: - vdi_rec = session.call_xenapi('VDI.get_record', vdi_ref) + vdi_rec = session.get_rec('VDI', vdi_ref) + # Check to make sure the record still exists. It may have + # been deleted between the get_all call and get_rec call + if vdi_rec: yield vdi_ref, vdi_rec - except session.XenAPI.Failure: - continue def get_instance_vdis_for_sr(session, vm_ref, sr_ref):