Expand valid server group name character set
Names requested for a server group should use the same validation checking as names in the other APIS. Right now it will not allow any non alphanumeric characters. Change this to allow all printable and horizontal whitespace unicode characters. This is the same check that is done for flavor names, as well as names in v2.1 APIs. Closes-Bug: #1434335 Change-Id: I6c675fb6c2f40e83499a41ecdccec58d99501433
This commit is contained in:
@@ -25,6 +25,7 @@ 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
|
||||
@@ -54,10 +55,8 @@ QUOTAS = quota.QUOTAS
|
||||
|
||||
CONF.import_opt('enable', 'nova.cells.opts', group='cells')
|
||||
|
||||
# NOTE(cyeoh): A common regexp for acceptable names (user supplied)
|
||||
# that we want all new extensions to conform to unless there is a very
|
||||
# good reason not to.
|
||||
VALID_NAME_REGEX = re.compile("^(?! )[\w. _-]+(?<! )$", re.UNICODE)
|
||||
VALID_NAME_REGEX = re.compile(parameter_types.valid_name_regex, re.UNICODE)
|
||||
|
||||
|
||||
XML_NS_V11 = 'http://docs.openstack.org/compute/api/v1.1'
|
||||
|
||||
|
||||
@@ -152,6 +152,17 @@ class ServerGroupTestV21(test.TestCase):
|
||||
self.assertEqual(1, len(result_members))
|
||||
self.assertIn(instances[0].uuid, result_members)
|
||||
|
||||
def test_create_server_group_with_non_alphanumeric_in_name(self):
|
||||
# The fix for bug #1434335 expanded the allowable character set
|
||||
# for server group names to include non-alphanumeric characters
|
||||
# if they are printable.
|
||||
|
||||
sgroup = server_group_template(name='good* $%name',
|
||||
policies=['affinity'])
|
||||
res_dict = self.controller.create(self.req,
|
||||
body={'server_group': sgroup})
|
||||
self.assertEqual(res_dict['server_group']['name'], 'good* $%name')
|
||||
|
||||
def test_create_server_group_with_illegal_name(self):
|
||||
# blank name
|
||||
sgroup = server_group_template(name='', policies=['test_policy'])
|
||||
@@ -187,6 +198,18 @@ class ServerGroupTestV21(test.TestCase):
|
||||
self.assertRaises(self.validation_error, self.controller.create,
|
||||
self.req, body={'server_group': sgroup})
|
||||
|
||||
# name with unprintable character
|
||||
sgroup = server_group_template(name='bad\x00name',
|
||||
policies=['test_policy'])
|
||||
self.assertRaises(self.validation_error, self.controller.create,
|
||||
self.req, body={'server_group': sgroup})
|
||||
|
||||
# name with out of range char U0001F4A9
|
||||
sgroup = server_group_template(name=u"\U0001F4A9",
|
||||
policies=['affinity'])
|
||||
self.assertRaises(self.validation_error, self.controller.create,
|
||||
self.req, body={'server_group': sgroup})
|
||||
|
||||
def test_create_server_group_with_illegal_policies(self):
|
||||
# blank policy
|
||||
sgroup = server_group_template(name='fake-name', policies='')
|
||||
|
||||
Reference in New Issue
Block a user