Merge "Convert ContainerName type to NameType"
This commit is contained in:
commit
1bb474dad3
@ -23,7 +23,7 @@ from zun.common.i18n import _
|
||||
from zun.common.i18n import _LE
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
container_pattern = re.compile(r'[a-zA-Z0-9][a-zA-Z0-9_.-]')
|
||||
name_pattern = re.compile(r'[a-zA-Z0-9][a-zA-Z0-9_.-]')
|
||||
MIN_MEMORY_SIZE = 4194304
|
||||
VALID_UNITS = {
|
||||
'b': 1,
|
||||
@ -70,10 +70,10 @@ class String(object):
|
||||
return value
|
||||
|
||||
|
||||
class ContainerName(String):
|
||||
type_name = 'ContainerName'
|
||||
class NameType(String):
|
||||
type_name = 'NameType'
|
||||
|
||||
# Container name allows to be None or a string matches pattern
|
||||
# NameType allows to be None or a string matches pattern
|
||||
# `[a-zA-Z0-9][a-zA-Z0-9_.-].` with minimum length is 2 and maximum length
|
||||
# 255 string type.
|
||||
|
||||
@ -81,8 +81,8 @@ class ContainerName(String):
|
||||
def validate(cls, value):
|
||||
if value is None:
|
||||
return value
|
||||
super(ContainerName, cls).validate(value, min_length=2, max_length=255)
|
||||
match = container_pattern.match(value)
|
||||
super(NameType, cls).validate(value, min_length=2, max_length=255)
|
||||
match = name_pattern.match(value)
|
||||
if match:
|
||||
return value
|
||||
else:
|
||||
|
@ -61,7 +61,7 @@ class Container(base.APIBase):
|
||||
'validate': types.Uuid.validate,
|
||||
},
|
||||
'name': {
|
||||
'validate': types.ContainerName.validate,
|
||||
'validate': types.NameType.validate,
|
||||
},
|
||||
'image': {
|
||||
'validate': types.String.validate,
|
||||
|
@ -172,14 +172,14 @@ class TestTypes(test_base.BaseTestCase):
|
||||
self.assertIsInstance(value[0], TestAPI)
|
||||
self.assertEqual({'test': 'test_value'}, value[0].as_dict())
|
||||
|
||||
def test_container_name_type(self):
|
||||
def test_name_type(self):
|
||||
test_value = '***'
|
||||
self.assertRaises(exception.InvalidValue,
|
||||
types.ContainerName.validate, test_value)
|
||||
types.NameType.validate, test_value)
|
||||
|
||||
test_value = '*' * 256
|
||||
self.assertRaises(exception.InvalidValue,
|
||||
types.ContainerName.validate, test_value)
|
||||
types.NameType.validate, test_value)
|
||||
|
||||
def test_container_memory_type(self):
|
||||
test_value = '4m'
|
||||
|
Loading…
Reference in New Issue
Block a user