Move user_data max length check to schema

We've had a hard-coded limit on the size of user_data
since 4d350dc82e in Folsom.

This simply moves that check to the request API schema
where it belongs.

Change-Id: I2b8371a5ec99997626121a00ecf83f04b67bbdd9
This commit is contained in:
Matt Riedemann 2017-10-09 18:22:17 -04:00
parent 083ca83401
commit d43d1d6734
6 changed files with 16 additions and 41 deletions

View File

@ -12,18 +12,22 @@
# License for the specific language governing permissions and limitations
# under the License.
common_user_data = {
'type': 'string',
'format': 'base64',
'maxLength': 65535
}
server_create = {
'user_data': {
'type': 'string',
'format': 'base64'
},
'user_data': common_user_data
}
server_create_v20 = {
'user_data': {
'oneOf': [
{'type': 'string', 'format': 'base64'},
common_user_data,
{'type': 'null'},
],
},

View File

@ -584,7 +584,6 @@ class ServersController(wsgi.Controller):
exception.MultiplePortsNotApplicable,
exception.InvalidFixedIpAndMaxCountRequest,
exception.InstanceUserDataMalformed,
exception.InstanceUserDataTooLarge,
exception.PortNotFound,
exception.FixedIpAlreadyInUse,
exception.SecurityGroupNotFound,

View File

@ -95,7 +95,6 @@ wrap_exception = functools.partial(exception_wrapper.wrap_exception,
binary='nova-api')
CONF = nova.conf.CONF
MAX_USERDATA_SIZE = 65535
RO_SECURITY_GROUPS = ['default']
AGGREGATE_ACTION_UPDATE = 'Update'
@ -770,13 +769,6 @@ class API(base.Base):
raise exception.FlavorNotFound(flavor_id=instance_type['id'])
if user_data:
l = len(user_data)
if l > MAX_USERDATA_SIZE:
# NOTE(mikal): user_data is stored in a text column, and
# the database might silently truncate if its over length.
raise exception.InstanceUserDataTooLarge(
length=l, maxsize=MAX_USERDATA_SIZE)
try:
base64utils.decode_as_bytes(user_data)
except (base64.binascii.Error, TypeError):

View File

@ -1520,12 +1520,6 @@ class InterfaceDetachFailed(Invalid):
"%(instance_uuid)s")
class InstanceUserDataTooLarge(NovaException):
msg_fmt = _("User data too large. User data must be no larger than "
"%(maxsize)s bytes once base64 encoded. Your data is "
"%(length)d bytes")
class InstanceUserDataMalformed(NovaException):
msg_fmt = _("User data needs to be valid base 64.")

View File

@ -2885,14 +2885,13 @@ class ServersControllerCreateTest(test.TestCase):
self.assertRaises(webob.exc.HTTPBadRequest,
self._test_create_extra, params)
@mock.patch.object(compute_api.API, 'create')
def test_create_instance_raise_user_data_too_large(self, mock_create):
mock_create.side_effect = exception.InstanceUserDataTooLarge(
maxsize=1, length=2)
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create,
self.req, body=self.body)
def test_create_instance_raise_user_data_too_large(self):
self.body['server']['user_data'] = (b'1' * 65536)
ex = self.assertRaises(exception.ValidationError,
self.controller.create,
self.req, body=self.body)
# Make sure the failure was about user_data and not something else.
self.assertIn('user_data', six.text_type(ex))
def test_create_instance_with_network_with_no_subnet(self):
network = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'

View File

@ -8261,19 +8261,6 @@ class ComputeAPITestCase(BaseTestCase):
self.assertEqual(pre_build_len,
len(db.instance_get_all(self.context)))
def test_create_with_large_user_data(self):
# Test an instance type with too much user data.
inst_type = flavors.get_default_flavor()
self.fake_image['min_ram'] = 2
self.stub_out('nova.tests.unit.image.fake._FakeImageService.show',
self.fake_show)
self.assertRaises(exception.InstanceUserDataTooLarge,
self.compute_api.create, self.context, inst_type,
self.fake_image['id'], user_data=(b'1' * 65536))
def test_create_with_malformed_user_data(self):
# Test an instance type with malformed user data.