Add volume create schema enforcement unit tests

This increases test coverage with the volume create call to verify calls
using microversions < 3.53 allow extra parameters to be passed and calls
starting with microversion 3.53 will raise a schema validation error for
unexpected values.

Partial-bug: #1786054

Change-Id: Ib532eb9d4fe0bd597724b734d2e8a7c6daf7c4f1
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2018-08-08 09:50:08 -05:00
parent a27d0eb32a
commit 3a5f83be2d
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
1 changed files with 30 additions and 1 deletions

View File

@ -508,7 +508,14 @@ class VolumeApiTest(test.TestCase):
(mv.get_prior_version(mv.GROUP_VOLUME),
{'name': ' test name ',
'description': ' test desc ',
'size': 1}))
'size': 1}),
('3.0',
{'name': 'test name',
'description': 'test desc',
'size': 1,
'user_id': 'teapot',
'project_id': 'kettle',
'status': 'confused'}))
@ddt.unpack
def test_volume_create(self, max_ver, volume_body):
self.mock_object(volume_api.API, 'get', v2_fakes.fake_volume_get)
@ -530,6 +537,28 @@ class VolumeApiTest(test.TestCase):
self.assertEqual(ex['volume']['description'],
res_dict['volume']['description'])
def test_volume_create_extra_params(self):
self.mock_object(volume_api.API, 'get', v2_fakes.fake_volume_get)
self.mock_object(volume_api.API, "create",
v2_fakes.fake_volume_api_create)
self.mock_object(db.sqlalchemy.api, '_volume_type_get_full',
v2_fakes.fake_volume_type_get)
req = fakes.HTTPRequest.blank('/v3/volumes')
req.api_version_request = mv.get_api_version(
mv.SUPPORT_VOLUME_SCHEMA_CHANGES)
body = {'volume': {
'name': 'test name',
'description': 'test desc',
'size': 1,
'user_id': 'teapot',
'project_id': 'kettle',
'status': 'confused'}}
self.assertRaises(exception.ValidationError,
self.controller.create,
req, body=body)
@ddt.data(mv.get_prior_version(mv.VOLUME_DELETE_FORCE),
mv.VOLUME_DELETE_FORCE)
@mock.patch('cinder.context.RequestContext.authorize')