Disallow specifying too long description for meter-label

Change-Id: Ifece06cb7d041b155296cee04f794601736d6952
Closes-Bug: #1609727
This commit is contained in:
hobo.kengo 2016-08-05 05:25:03 +00:00
parent 1a4cce9f34
commit ae09911c01
2 changed files with 15 additions and 0 deletions

View File

@ -51,6 +51,8 @@ RESOURCE_ATTRIBUTE_MAP = {
'name': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': ''},
'description': {'allow_post': True, 'allow_put': False,
'validate': {
'type:string': attr.LONG_DESCRIPTION_MAX_LEN},
'is_visible': True, 'default': ''},
'tenant_id': {'allow_post': True, 'allow_put': False,
'required_by_policy': True,

View File

@ -18,6 +18,7 @@ from neutron_lib import constants as n_consts
import webob.exc
from neutron.api import extensions
from neutron.api.v2 import attributes as attr
from neutron.common import config
from neutron import context
import neutron.extensions
@ -32,6 +33,8 @@ DB_METERING_PLUGIN_KLASS = (
)
extensions_path = ':'.join(neutron.extensions.__path__)
_long_description_ok = 'x' * (attr.LONG_DESCRIPTION_MAX_LEN)
_long_description_ng = 'x' * (attr.LONG_DESCRIPTION_MAX_LEN + 1)
class MeteringPluginDbTestCaseMixin(object):
@ -155,6 +158,16 @@ class TestMetering(MeteringPluginDbTestCase):
for k, v, in keys:
self.assertEqual(metering_label['metering_label'][k], v)
def test_create_metering_label_with_max_description_length(self):
res = self._create_metering_label(self.fmt, 'my label',
_long_description_ok)
self.assertEqual(webob.exc.HTTPCreated.code, res.status_int)
def test_create_metering_label_with_too_long_description(self):
res = self._create_metering_label(self.fmt, 'my label',
_long_description_ng)
self.assertEqual(webob.exc.HTTPBadRequest.code, res.status_int)
def test_update_metering_label(self):
name = 'my label'
description = 'my metering label'