volume = body['volume']
- def as_int(s):
- try:
- return int(s)
- except ValueError:
- return s
-
- # NOTE(eglynn): we're tolerant of non-int sizes here, as type
- # integrity is enforced later in the creation codepath
- size = as_int(volume['size'])
+ size = volume['size']
LOG.audit(_("Create volume of %s GB"), size, context=context)
self.stubs.Set(volume_api.API, 'get', fakes.stub_volume_get)
self.stubs.Set(volume_api.API, 'delete', fakes.stub_volume_delete)
- def _do_test_volume_create(self, size):
+ def test_volume_create(self):
self.stubs.Set(volume_api.API, "create", fakes.stub_volume_create)
- vol = {"size": size,
+ vol = {"size": 100,
"display_name": "Volume Test Name",
"display_description": "Volume Test Desc",
"availability_zone": "zone1:host1"}
'size': 100}}
self.assertEqual(res_dict, expected)
- def test_volume_create_int_size(self):
- self._do_test_volume_create(100)
-
- def test_volume_create_str_size(self):
- self._do_test_volume_create('100')
-
def test_volume_creation_fails_with_bad_size(self):
vol = {"size": '',
"display_name": "Volume Test Name",
'metadata': {},
'id': '1',
'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
- 'size': 1}
+ 'size': '1'}
}
body = {"volume": vol}
req = fakes.HTTPRequest.blank('/v1/volumes')
from cinder.openstack.common import importutils
from cinder.openstack.common import rpc
import cinder.policy
+from cinder import quota
from cinder import test
import cinder.volume.api
db.volume_destroy(self.context, volume_id)
os.unlink(dst_path)
+ def _do_test_create_volume_with_size(self, size):
+ def fake_allowed_volumes(context, requested_volumes, size):
+ return requested_volumes
+
+ self.stubs.Set(quota, 'allowed_volumes', fake_allowed_volumes)
+
+ volume_api = cinder.volume.api.API()
+
+ volume = volume_api.create(self.context,
+ size,
+ 'name',
+ 'description')
+ self.assertEquals(volume['size'], int(size))
+
+ def test_create_volume_int_size(self):
+ """Test volume creation with int size."""
+ self._do_test_create_volume_with_size(2)
+
+ def test_create_volume_string_size(self):
+ """Test volume creation with string size."""
+ self._do_test_create_volume_with_size('2')
+
+ def test_create_volume_with_bad_size(self):
+ def fake_allowed_volumes(context, requested_volumes, size):
+ return requested_volumes
+
+ self.stubs.Set(quota, 'allowed_volumes', fake_allowed_volumes)
+
+ volume_api = cinder.volume.api.API()
+
+ self.assertRaises(exception.InvalidInput,
+ volume_api.create,
+ self.context,
+ '2Gb',
+ 'name',
+ 'description')
+
class DriverTestCase(test.TestCase):
"""Base Test class for Drivers."""
snapshot_id = snapshot['id']
else:
snapshot_id = None
+
+ def as_int(s):
+ try:
+ return int(s)
+ except ValueError:
+ return s
+
+ # tolerate size as stringified int
+ size = as_int(size)
+
if not isinstance(size, int) or size <= 0:
- msg = _('Volume size must be an integer and greater than 0')
+ msg = (_("Volume size '%s' must be an integer and greater than 0")
+ % size)
raise exception.InvalidInput(reason=msg)
if quota.allowed_volumes(context, 1, size) < 1:
pid = context.project_id