Merge "Fix is_volume_backed_instance() for unset image_ref"
This commit is contained in:
commit
802d320236
@ -3241,13 +3241,12 @@ class API(base.Base):
|
|||||||
return bdms.root_bdm()
|
return bdms.root_bdm()
|
||||||
|
|
||||||
def is_volume_backed_instance(self, context, instance, bdms=None):
|
def is_volume_backed_instance(self, context, instance, bdms=None):
|
||||||
if not instance.image_ref:
|
|
||||||
return True
|
|
||||||
|
|
||||||
root_bdm = self._get_root_bdm(context, instance, bdms)
|
root_bdm = self._get_root_bdm(context, instance, bdms)
|
||||||
if not root_bdm:
|
if root_bdm is not None:
|
||||||
return False
|
return root_bdm.is_volume
|
||||||
return root_bdm.is_volume
|
# in case we hit a very old instance without root bdm, we _assume_ that
|
||||||
|
# instance is backed by a volume, if and only if image_ref is not set
|
||||||
|
return not instance.image_ref
|
||||||
|
|
||||||
@check_instance_lock
|
@check_instance_lock
|
||||||
@check_instance_cell
|
@check_instance_cell
|
||||||
|
@ -8956,24 +8956,30 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
self.assertIsNone(
|
self.assertIsNone(
|
||||||
self.compute_api._volume_size(inst_type, blank_bdm))
|
self.compute_api._volume_size(inst_type, blank_bdm))
|
||||||
|
|
||||||
def test_is_volume_backed_instance_no_image(self):
|
def test_is_volume_backed_instance_no_bdm_no_image(self):
|
||||||
ctxt = self.context
|
ctxt = self.context
|
||||||
|
|
||||||
instance = self._create_fake_instance_obj({'image_ref': ''})
|
instance = self._create_fake_instance_obj({'image_ref': ''})
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
self.compute_api.is_volume_backed_instance(ctxt, instance, None))
|
self.compute_api.is_volume_backed_instance(ctxt, instance, None))
|
||||||
|
|
||||||
def test_is_volume_backed_instance_no_bdm(self):
|
def test_is_volume_backed_instance_empty_bdm_with_image(self):
|
||||||
ctxt = self.context
|
ctxt = self.context
|
||||||
instance = self._create_fake_instance_obj({'root_device_name': 'vda'})
|
instance = self._create_fake_instance_obj({
|
||||||
|
'root_device_name': 'vda',
|
||||||
|
'image_ref': FAKE_IMAGE_REF
|
||||||
|
})
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
self.compute_api.is_volume_backed_instance(
|
self.compute_api.is_volume_backed_instance(
|
||||||
ctxt, instance,
|
ctxt, instance,
|
||||||
block_device_obj.block_device_make_list(ctxt, [])))
|
block_device_obj.block_device_make_list(ctxt, [])))
|
||||||
|
|
||||||
def test_is_volume_backed_instance_bdm_volume(self):
|
def test_is_volume_backed_instance_bdm_volume_no_image(self):
|
||||||
ctxt = self.context
|
ctxt = self.context
|
||||||
instance = self._create_fake_instance_obj({'root_device_name': 'vda'})
|
instance = self._create_fake_instance_obj({
|
||||||
|
'root_device_name': 'vda',
|
||||||
|
'image_ref': ''
|
||||||
|
})
|
||||||
bdms = block_device_obj.block_device_make_list(ctxt,
|
bdms = block_device_obj.block_device_make_list(ctxt,
|
||||||
[fake_block_device.FakeDbBlockDeviceDict(
|
[fake_block_device.FakeDbBlockDeviceDict(
|
||||||
{'source_type': 'volume',
|
{'source_type': 'volume',
|
||||||
@ -8985,9 +8991,14 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
self.compute_api.is_volume_backed_instance(ctxt, instance, bdms))
|
self.compute_api.is_volume_backed_instance(ctxt, instance, bdms))
|
||||||
|
|
||||||
def test_is_volume_backed_instance_bdm_local(self):
|
def test_is_volume_backed_instance_bdm_local_no_image(self):
|
||||||
|
# if the root device is local the instance is not volume backed, even
|
||||||
|
# if no image_ref is set.
|
||||||
ctxt = self.context
|
ctxt = self.context
|
||||||
instance = self._create_fake_instance_obj({'root_device_name': 'vda'})
|
instance = self._create_fake_instance_obj({
|
||||||
|
'root_device_name': 'vda',
|
||||||
|
'image_ref': ''
|
||||||
|
})
|
||||||
bdms = block_device_obj.block_device_make_list(ctxt,
|
bdms = block_device_obj.block_device_make_list(ctxt,
|
||||||
[fake_block_device.FakeDbBlockDeviceDict(
|
[fake_block_device.FakeDbBlockDeviceDict(
|
||||||
{'source_type': 'volume',
|
{'source_type': 'volume',
|
||||||
@ -9008,6 +9019,22 @@ class ComputeAPITestCase(BaseTestCase):
|
|||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
self.compute_api.is_volume_backed_instance(ctxt, instance, bdms))
|
self.compute_api.is_volume_backed_instance(ctxt, instance, bdms))
|
||||||
|
|
||||||
|
def test_is_volume_backed_instance_bdm_volume_with_image(self):
|
||||||
|
ctxt = self.context
|
||||||
|
instance = self._create_fake_instance_obj({
|
||||||
|
'root_device_name': 'vda',
|
||||||
|
'image_ref': FAKE_IMAGE_REF
|
||||||
|
})
|
||||||
|
bdms = block_device_obj.block_device_make_list(ctxt,
|
||||||
|
[fake_block_device.FakeDbBlockDeviceDict(
|
||||||
|
{'source_type': 'volume',
|
||||||
|
'device_name': '/dev/vda',
|
||||||
|
'volume_id': 'fake_volume_id',
|
||||||
|
'boot_index': 0,
|
||||||
|
'destination_type': 'volume'})])
|
||||||
|
self.assertTrue(
|
||||||
|
self.compute_api.is_volume_backed_instance(ctxt, instance, bdms))
|
||||||
|
|
||||||
def test_is_volume_backed_instance_bdm_snapshot(self):
|
def test_is_volume_backed_instance_bdm_snapshot(self):
|
||||||
ctxt = self.context
|
ctxt = self.context
|
||||||
instance = self._create_fake_instance_obj({'root_device_name': 'vda'})
|
instance = self._create_fake_instance_obj({'root_device_name': 'vda'})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user