def show(self, context, image_id):
return {'size': 2 * units.GiB,
'disk_format': 'raw',
- 'container_format': 'bare'}
+ 'container_format': 'bare',
+ 'status': 'active'}
class BaseVolumeTestCase(test.TestCase):
def show(self, context, image_id):
return {'size': 2 * units.GiB + 1,
'disk_format': 'raw',
- 'container_format': 'bare'}
+ 'container_format': 'bare',
+ 'status': 'active'}
volume_api = cinder.volume.api.API(image_service=
_ModifiedFakeImageService())
return {'size': 2 * units.GiB,
'disk_format': 'raw',
'container_format': 'bare',
- 'min_disk': 5}
+ 'min_disk': 5,
+ 'status': 'active'}
+
+ volume_api = cinder.volume.api.API(image_service=
+ _ModifiedFakeImageService())
+
+ self.assertRaises(exception.InvalidInput,
+ volume_api.create,
+ self.context, 2,
+ 'name', 'description', image_id=1)
+
+ def test_create_volume_with_deleted_imaged(self):
+ """Verify create volume from image will cause an error."""
+ class _ModifiedFakeImageService(FakeImageService):
+ def show(self, context, image_id):
+ return {'size': 2 * units.GiB,
+ 'disk_format': 'raw',
+ 'container_format': 'bare',
+ 'min_disk': 5,
+ 'status': 'deleted'}
volume_api = cinder.volume.api.API(image_service=
_ModifiedFakeImageService())
# exist, this is expected as it signals that the image_id is missing.
image_meta = self.image_service.show(context, image_id)
+ #check whether image is active
+ if image_meta['status'] != 'active':
+ msg = _('Image %(image_id)s is not active.')\
+ % {'image_id': image_id}
+ raise exception.InvalidInput(reason=msg)
+
# Check image size is not larger than volume size.
image_size = utils.as_int(image_meta['size'], quiet=False)
image_size_in_gb = (image_size + GB - 1) / GB