Merge "Enable non-ascii characters in flavor names"
This commit is contained in:
commit
5a810e80e3
|
@ -51,7 +51,11 @@ CONF.register_opts(flavor_opts)
|
|||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
VALID_NAME_OR_ID_REGEX = re.compile("^[\w\.\- ]*$")
|
||||
# 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\.\- ]*$")
|
||||
VALID_NAME_REGEX = re.compile("^[\w\.\- ]*$", re.UNICODE)
|
||||
|
||||
|
||||
def _int_or_none(val):
|
||||
|
@ -94,9 +98,10 @@ 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_OR_ID_REGEX.search(name)
|
||||
valid_name = VALID_NAME_REGEX.search(name)
|
||||
if not valid_name:
|
||||
msg = _("names can only contain [a-zA-Z0-9_.- ]")
|
||||
msg = _("Flavor names can only contain alphanumeric characters, "
|
||||
"periods, dashes, underscores and spaces.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
# NOTE(vish): Internally, flavorid is stored as a string but it comes
|
||||
|
@ -113,9 +118,10 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
|
|||
max_length=255)
|
||||
|
||||
# ensure flavor id does not contain any special characters
|
||||
valid_flavor_id = VALID_NAME_OR_ID_REGEX.search(flavorid)
|
||||
valid_flavor_id = VALID_ID_REGEX.search(flavorid)
|
||||
if not valid_flavor_id:
|
||||
msg = _("id can only contain [a-zA-Z0-9_.- ]")
|
||||
msg = _("Flavor id can only contain letters from A-Z (both cases), "
|
||||
"periods, dashes, underscores and spaces.")
|
||||
raise exception.InvalidInput(reason=msg)
|
||||
|
||||
# Some attributes are positive ( > 0) integers
|
||||
|
|
|
@ -393,16 +393,22 @@ class CreateInstanceTypeTest(test.TestCase):
|
|||
*create_args, **create_kwargs)
|
||||
|
||||
def test_create_with_valid_name(self):
|
||||
# Names can contain [a-zA-Z0-9_.- ]
|
||||
# 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 [a-zA-Z0-9_.- ]
|
||||
# Names can contain alphanumeric and [_.- ]
|
||||
flavors.create('_foo.bar-123', 64, 1, 120)
|
||||
|
||||
# Ensure instance types raises InvalidInput for invalid characters.
|
||||
self.assertInvalidInput('foobar#', 64, 1, 120)
|
||||
|
||||
def test_non_ascii_name_with_special_characters(self):
|
||||
self.assertInvalidInput(u'm1.\u5DE8\u5927 #', 64, 1, 120)
|
||||
|
||||
def test_name_length_checks(self):
|
||||
MAX_LEN = 255
|
||||
|
||||
|
|
Loading…
Reference in New Issue