From c19c3d976019027586080cf0958aff41a373f701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=9F=E5=B0=8F=E5=90=9B?= Date: Wed, 20 Feb 2019 21:21:27 +0800 Subject: [PATCH] Remove flavor id and name validation code Remove flavor id and name validation code because of jsonschema validation.The jsonschema validation was added with Ieba96718264ad2ddfba63b65425f7e5bbb8606a9. Closes-Bug: #1816755 Change-Id: Id6702180a4af6f9f7851a2b912e6d6adeccf90df --- nova/compute/flavors.py | 31 ------------- .../openstack/compute/test_flavor_manage.py | 4 ++ nova/tests/unit/test_flavors.py | 43 ------------------- 3 files changed, 4 insertions(+), 74 deletions(-) diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py index 3319947d651c..4f66bef86a6d 100644 --- a/nova/compute/flavors.py +++ b/nova/compute/flavors.py @@ -24,7 +24,6 @@ from oslo_utils import strutils from oslo_utils import uuidutils import six -from nova.api.validation import parameter_types import nova.conf from nova import context from nova.db import api as db @@ -35,11 +34,6 @@ from nova import utils CONF = nova.conf.CONF -# NOTE(luisg): Flavor names can include non-ascii characters so that users can -# create flavor names in locales that use them, however flavor IDs are limited -# to ascii characters. -VALID_ID_REGEX = re.compile("^[\w\.\- ]*$") - # Validate extra specs key names. VALID_EXTRASPEC_NAME_REGEX = re.compile(r"[\w\.\- :]+$", re.UNICODE) @@ -86,36 +80,11 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None, if isinstance(name, six.string_types): name = name.strip() - # ensure name do not exceed 255 characters - utils.check_string_length(name, 'name', min_length=1, max_length=255) - - # ensure name does not contain any special characters - valid_name = parameter_types.valid_name_regex_obj.search(name) - if not valid_name: - msg = _("Flavor names can only contain printable characters " - "and horizontal spaces.") - raise exception.InvalidInput(reason=msg) # NOTE(vish): Internally, flavorid is stored as a string but it comes # in through json as an integer, so we convert it here. flavorid = six.text_type(flavorid) - # ensure leading/trailing whitespaces not present. - if flavorid.strip() != flavorid: - msg = _("id cannot contain leading and/or trailing whitespace(s)") - raise exception.InvalidInput(reason=msg) - - # ensure flavor id does not exceed 255 characters - utils.check_string_length(flavorid, 'id', min_length=1, - max_length=255) - - # ensure flavor id does not contain any special characters - valid_flavor_id = VALID_ID_REGEX.search(flavorid) - if not valid_flavor_id: - msg = _("Flavor id can only contain letters from A-Z (both cases), " - "periods, dashes, underscores and spaces.") - raise exception.InvalidInput(reason=msg) - # NOTE(wangbo): validate attributes of the creating flavor. # ram and vcpus should be positive ( > 0) integers. # disk, ephemeral and swap should be non-negative ( >= 0) integers. diff --git a/nova/tests/unit/api/openstack/compute/test_flavor_manage.py b/nova/tests/unit/api/openstack/compute/test_flavor_manage.py index 2b333f5174eb..2d4ca97a2a88 100644 --- a/nova/tests/unit/api/openstack/compute/test_flavor_manage.py +++ b/nova/tests/unit/api/openstack/compute/test_flavor_manage.py @@ -172,6 +172,10 @@ class FlavorManageTestV21(test.NoDBTestCase): self.request_body['flavor']['name'] = 'a' * 256 self._create_flavor_bad_request_case(self.request_body) + def test_create_with_short_name(self): + self.request_body['flavor']['name'] = '' + self._create_flavor_bad_request_case(self.request_body) + def test_create_with_name_leading_trailing_spaces(self): self.request_body['flavor']['name'] = ' test ' self._create_flavor_bad_request_case(self.request_body) diff --git a/nova/tests/unit/test_flavors.py b/nova/tests/unit/test_flavors.py index d237e3d2147d..df9fb62478ad 100644 --- a/nova/tests/unit/test_flavors.py +++ b/nova/tests/unit/test_flavors.py @@ -172,49 +172,6 @@ class CreateInstanceTypeTest(test.TestCase): self.assertRaises(exception.InvalidInput, flavors.create, *create_args, **create_kwargs) - def test_create_with_valid_name(self): - # Names can contain alphanumeric and [_.- ] - flavors.create('azAZ09. -_', 64, 1, 120) - # And they are not limited to ascii characters - # E.g.: m1.huge in simplified Chinese - flavors.create(u'm1.\u5DE8\u5927', 6400, 100, 12000) - - def test_name_with_special_characters(self): - # Names can contain all printable characters - flavors.create('_foo.bar-123', 64, 1, 120) - - # Ensure instance types raises InvalidInput for invalid characters. - self.assertInvalidInput('foobar\x00', 64, 1, 120) - - def test_name_with_non_printable_characters(self): - # Names cannot contain non printable characters - self.assertInvalidInput(u'm1.\u0C77 #', 64, 1, 120) - - def test_name_length_checks(self): - MAX_LEN = 255 - - # Flavor name with 255 characters or less is valid. - flavors.create('a' * MAX_LEN, 64, 1, 120) - - # Flavor name which is more than 255 characters will cause error. - self.assertInvalidInput('a' * (MAX_LEN + 1), 64, 1, 120) - - # Flavor name which is empty should cause an error - self.assertInvalidInput('', 64, 1, 120) - - def test_all_whitespace_flavor_names_rejected(self): - self.assertInvalidInput(' ', 64, 1, 120) - - def test_flavorid_with_invalid_characters(self): - # Ensure Flavor ID can only contain [a-zA-Z0-9_.- ] - self.assertInvalidInput('a', 64, 1, 120, flavorid=u'\u2605') - self.assertInvalidInput('a', 64, 1, 120, flavorid='%%$%$@#$#@$@#$^%') - - def test_flavorid_length_checks(self): - MAX_LEN = 255 - # Flavor ID which is more than 255 characters will cause error. - self.assertInvalidInput('a', 64, 1, 120, flavorid='a' * (MAX_LEN + 1)) - def test_memory_must_be_positive_db_integer(self): self.assertInvalidInput('flavor1', 'foo', 1, 120) self.assertInvalidInput('flavor1', -1, 1, 120)