From 737c957c8a0e4aa2263c485e5e8007a8bfc3783f Mon Sep 17 00:00:00 2001 From: jichenjc Date: Wed, 26 Aug 2015 17:13:52 +0800 Subject: [PATCH] Remove duplicate VALID_NAME_REGEX VALID_NAME_REGEX was defined in api/openstack/common and compute/flavors, remove the duplicate definitions. Change-Id: I37175cc3ba11777d9a7508d757433c3dbff0b1a2 Related-Bug: 1431932 --- nova/api/openstack/common.py | 3 --- nova/api/openstack/compute/legacy_v2/contrib/server_groups.py | 3 ++- nova/api/validation/parameter_types.py | 3 +++ nova/compute/flavors.py | 3 +-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 925b0918f1..00693efbf0 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -27,7 +27,6 @@ import six.moves.urllib.parse as urlparse import webob from webob import exc -from nova.api.validation import parameter_types from nova.compute import task_states from nova.compute import utils as compute_utils from nova.compute import vm_states @@ -59,8 +58,6 @@ QUOTAS = quota.QUOTAS CONF.import_opt('enable', 'nova.cells.opts', group='cells') -VALID_NAME_REGEX = re.compile(parameter_types.valid_name_regex, re.UNICODE) - XML_NS_V11 = 'http://docs.openstack.org/compute/api/v1.1' diff --git a/nova/api/openstack/compute/legacy_v2/contrib/server_groups.py b/nova/api/openstack/compute/legacy_v2/contrib/server_groups.py index 553f946c71..88bf573d05 100644 --- a/nova/api/openstack/compute/legacy_v2/contrib/server_groups.py +++ b/nova/api/openstack/compute/legacy_v2/contrib/server_groups.py @@ -22,6 +22,7 @@ from webob import exc from nova.api.openstack import common from nova.api.openstack import extensions from nova.api.openstack import wsgi +from nova.api.validation import parameter_types import nova.exception from nova.i18n import _ from nova.i18n import _LE @@ -109,7 +110,7 @@ class ServerGroupController(wsgi.Controller): if field == 'name': utils.check_string_length(value, field, min_length=1, max_length=255) - if not common.VALID_NAME_REGEX.search(value): + if not parameter_types.valid_name_regex_obj.search(value): msg = _("Invalid format for name: '%s'") % value raise nova.exception.InvalidInput(reason=msg) elif field == 'policies': diff --git a/nova/api/validation/parameter_types.py b/nova/api/validation/parameter_types.py index 01facad978..1e55df42a6 100644 --- a/nova/api/validation/parameter_types.py +++ b/nova/api/validation/parameter_types.py @@ -100,6 +100,9 @@ valid_name_leading_trailing_spaces_regex = ( 'no_ws': re.escape(_get_printable_no_ws())}) +valid_name_regex_obj = re.compile(valid_name_regex, re.UNICODE) + + boolean = { 'type': ['boolean', 'string'], 'enum': [True, 'True', 'TRUE', 'true', '1', 'ON', 'On', 'on', diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py index 3ea9c6158d..36e0179191 100644 --- a/nova/compute/flavors.py +++ b/nova/compute/flavors.py @@ -51,7 +51,6 @@ LOG = logging.getLogger(__name__) # create flavor names in locales that use them, however flavor IDs are limited # to ascii characters. VALID_ID_REGEX = re.compile("^[\w\.\- ]*$") -VALID_NAME_REGEX = re.compile(parameter_types.valid_name_regex, re.UNICODE) # NOTE(dosaboy): This is supposed to represent the maximum value that we can # place into a SQL single precision float so that we can check whether values @@ -111,7 +110,7 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None, utils.check_string_length(name, 'name', min_length=1, max_length=255) # ensure name does not contain any special characters - valid_name = VALID_NAME_REGEX.search(name) + 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.")