Disallow specifying too long name for meter-label
Change-Id: Id916192f0ae38434de7d86790e056e48764b0916
Closes-Bug: #1609725
diff --git a/neutron/tests/tempest/api/test_metering_extensions.py b/neutron/tests/tempest/api/test_metering_extensions.py
index 756cd5a..7b03386 100644
--- a/neutron/tests/tempest/api/test_metering_extensions.py
+++ b/neutron/tests/tempest/api/test_metering_extensions.py
@@ -15,8 +15,11 @@
from tempest.lib.common.utils import data_utils
from tempest import test
+from neutron.api.v2 import attributes as attr
from neutron.tests.tempest.api import base
+LONG_NAME_OK = 'x' * (attr.NAME_MAX_LEN)
+
class MeteringTestJSON(base.BaseAdminNetworkTest):
@@ -81,6 +84,17 @@
id=metering_label['id']))
self.assertEqual(len(labels['metering_labels']), 1)
+ @test.idempotent_id('46608f8d-2e27-4eb6-a0b4-dbe405144c4d')
+ def test_create_delete_metering_label_with_name_max_length(self):
+ name = LONG_NAME_OK
+ body = self.admin_client.create_metering_label(name=name)
+ metering_label = body['metering_label']
+ self.addCleanup(self._delete_metering_label,
+ metering_label['id'])
+ labels = (self.admin_client.list_metering_labels(
+ id=metering_label['id']))
+ self.assertEqual(len(labels['metering_labels']), 1)
+
@test.idempotent_id('cfc500d9-9de6-4847-8803-62889c097d45')
def test_show_metering_label(self):
# Verifies the details of a label
diff --git a/neutron/tests/tempest/api/test_metering_negative.py b/neutron/tests/tempest/api/test_metering_negative.py
new file mode 100644
index 0000000..39fdae8
--- /dev/null
+++ b/neutron/tests/tempest/api/test_metering_negative.py
@@ -0,0 +1,36 @@
+# Copyright 2016 FUJITSU LIMITED
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from tempest.lib import exceptions as lib_exc
+from tempest import test
+
+from neutron.api.v2 import attributes as attr
+from neutron.tests.tempest.api import base
+
+LONG_NAME_NG = 'x' * (attr.NAME_MAX_LEN + 1)
+
+
+class MeteringNegativeTestJSON(base.BaseAdminNetworkTest):
+
+ @classmethod
+ @test.requires_ext(extension="metering", service="network")
+ def resource_setup(cls):
+ super(MeteringNegativeTestJSON, cls).resource_setup()
+
+ @test.attr(type='negative')
+ @test.idempotent_id('8b3f7c84-9d37-4771-8681-bfd2c07f3c2d')
+ def test_create_metering_label_with_too_long_name(self):
+ self.assertRaises(lib_exc.BadRequest,
+ self.admin_client.create_metering_label,
+ name=LONG_NAME_NG)