Merge "xenapi: refactor get_all_vdis_in_sr"
This commit is contained in:
commit
686da61dd3
@ -1593,6 +1593,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):
|
||||
|
@ -1845,11 +1845,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):
|
||||
|
Loading…
Reference in New Issue
Block a user