Merge "Restrict magnum service name"
This commit is contained in:
commit
5f78e2f33a
|
@ -28,7 +28,7 @@ class MagnumService(base.APIBase):
|
|||
host = wtypes.StringType(min_length=1, max_length=255)
|
||||
"""Name of the host """
|
||||
|
||||
binary = wtypes.StringType(min_length=1, max_length=255)
|
||||
binary = wtypes.Enum(str, *fields.MagnumServiceBinary.ALL)
|
||||
"""Name of the binary"""
|
||||
|
||||
state = wtypes.Enum(str, *fields.MagnumServiceState.ALL)
|
||||
|
|
|
@ -95,6 +95,18 @@ class MagnumServiceState(fields.Enum):
|
|||
valid_values=MagnumServiceState.ALL)
|
||||
|
||||
|
||||
class MagnumServiceBinary(fields.Enum):
|
||||
ALL = (
|
||||
magnum_conductor
|
||||
) = (
|
||||
'magnum-conductor',
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
super(MagnumServiceBinary, self).__init__(
|
||||
valid_values=MagnumServiceBinary.ALL)
|
||||
|
||||
|
||||
class ListOfDictsField(fields.AutoTypedField):
|
||||
AUTO_TYPE = fields.List(fields.Dict(fields.FieldType()))
|
||||
|
||||
|
@ -107,6 +119,10 @@ class MagnumServiceField(fields.BaseEnumField):
|
|||
AUTO_TYPE = MagnumServiceState()
|
||||
|
||||
|
||||
class MagnumServiceBinaryField(fields.BaseEnumField):
|
||||
AUTO_TYPE = MagnumServiceBinary()
|
||||
|
||||
|
||||
class ContainerStatusField(fields.BaseEnumField):
|
||||
AUTO_TYPE = ContainerStatus()
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ def mservice_get_data(**kw):
|
|||
"""Simulate what the RPC layer will get from DB """
|
||||
faketime = datetime.datetime(2001, 1, 1, tzinfo=pytz.UTC)
|
||||
return {
|
||||
'binary': kw.get('binary', 'fake-binary'),
|
||||
'binary': kw.get('binary', 'magnum-conductor'),
|
||||
'host': kw.get('host', 'fake-host'),
|
||||
'id': kw.get('id', 13),
|
||||
'report_count': kw.get('report_count', 13),
|
||||
|
|
|
@ -89,3 +89,21 @@ class TestClusterType(test_fields.TestField):
|
|||
|
||||
def test_stringify_invalid(self):
|
||||
self.assertRaises(ValueError, self.field.stringify, 'invalid')
|
||||
|
||||
|
||||
class TestMagnumServiceBinary(test_fields.TestField):
|
||||
def setUp(self):
|
||||
super(TestMagnumServiceBinary, self).setUp()
|
||||
self.field = fields.MagnumServiceBinaryField()
|
||||
self.coerce_good_values = [('magnum-conductor', 'magnum-conductor')]
|
||||
self.coerce_bad_values = ['invalid']
|
||||
|
||||
self.to_primitive_values = self.coerce_good_values[0:1]
|
||||
self.from_primitive_values = self.coerce_good_values[0:1]
|
||||
|
||||
def test_stringify(self):
|
||||
self.assertEqual("'magnum-conductor'",
|
||||
self.field.stringify('magnum-conductor'))
|
||||
|
||||
def test_stringify_invalid(self):
|
||||
self.assertRaises(ValueError, self.field.stringify, 'invalid')
|
||||
|
|
Loading…
Reference in New Issue