本文整理汇总了Python中neutron.api.v2.attributes._validate_dict函数的典型用法代码示例。如果您正苦于以下问题:Python _validate_dict函数的具体用法?Python _validate_dict怎么用?Python _validate_dict使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_validate_dict函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_validate_dict_without_constraints
def test_validate_dict_without_constraints(self):
msg = attributes._validate_dict({})
self.assertIsNone(msg)
# Validate a dictionary without constraints.
msg = attributes._validate_dict({'key': 'value'})
self.assertIsNone(msg)
开发者ID:glove747,项目名称:liberty-neutron,代码行数:7,代码来源:test_attributes.py
示例2: validate_gwdevice_list
def validate_gwdevice_list(data, valid_values=None):
"""Validate the list of devices."""
if not data:
# Devices must be provided
msg = _("Cannot create a gateway with an empty device list")
return msg
if len(data) > 1:
# The number of devices must be exactly one
msg = _("Exactly one device must be specified to create a gateway")
return msg
try:
for device in data:
err_msg = attributes._validate_dict(device, None)
if err_msg:
return err_msg
device_id = device.get('device_id')
if not device_id:
msg = _("Cannot create a gateway with an empty device_id")
return msg
# Don't accept any interface. However, when supporting HW VTEPs
# this must be supported.
# TODO(RYU): Allow setting segmentation ID in some way
if device.get('interfaces'):
msg = _("Interfaces are not allowed in MidoNet L2GW")
return msg
device['interfaces'] = []
except TypeError:
return (_("%s: provided data are not iterable") %
validate_gwdevice_list.__name__)
开发者ID:Prabhat2015,项目名称:networking-midonet,代码行数:34,代码来源:l2gw_midonet_validators.py
示例3: _validate_device_list
def _validate_device_list(data, valid_values=None):
"""Validate the list of service definitions."""
if not data:
# Devices must be provided
msg = _("Cannot create a gateway with an empty device list")
return msg
try:
for device in data:
key_specs = {DEVICE_ID_ATTR:
{'type:regex': attributes.UUID_PATTERN,
'required': True},
IFACE_NAME_ATTR:
{'type:string': None,
'required': False}}
err_msg = attributes._validate_dict(
device, key_specs=key_specs)
if err_msg:
return err_msg
unexpected_keys = [key for key in device if key not in key_specs]
if unexpected_keys:
err_msg = (_("Unexpected keys found in device description:%s")
% ",".join(unexpected_keys))
return err_msg
except TypeError:
return (_("%s: provided data are not iterable") %
_validate_device_list.__name__)
开发者ID:50infivedays,项目名称:neutron,代码行数:26,代码来源:networkgw.py
示例4: test_subdictionary
def test_subdictionary(self):
dictionary, constraints = self._construct_dict_and_constraints()
del dictionary['key3']['k4']
dictionary['key3']['k5'] = 'a string value'
msg = attributes._validate_dict(dictionary, constraints)
self.assertIn('Expected keys:', msg)
开发者ID:glove747,项目名称:liberty-neutron,代码行数:7,代码来源:test_attributes.py
示例5: test_validate_dict_not_required_keys
def test_validate_dict_not_required_keys(self):
dictionary, constraints = self._construct_dict_and_constraints()
del dictionary['key2']
msg = attributes._validate_dict(dictionary, constraints)
self.assertIsNone(msg, 'Field that was not required by the specs was'
'required by the validator.')
开发者ID:glove747,项目名称:liberty-neutron,代码行数:7,代码来源:test_attributes.py
示例6: _validate_list_of_dict_or_none
def _validate_list_of_dict_or_none(data, key_specs=None):
if data is not None:
if not isinstance(data, list):
raise ExtraDhcpOptBadData(data=data)
for d in data:
msg = attr._validate_dict(d, key_specs)
if msg:
raise ExtraDhcpOptBadData(data=msg)
开发者ID:afori,项目名称:neutron,代码行数:8,代码来源:extra_dhcp_opt.py
示例7: test_validate_dict_convert_boolean
def test_validate_dict_convert_boolean(self):
dictionary, constraints = self._construct_dict_and_constraints()
constraints["key_bool"] = {"type:boolean": None, "required": False, "convert_to": attributes.convert_to_boolean}
dictionary["key_bool"] = "true"
msg = attributes._validate_dict(dictionary, constraints)
self.assertIsNone(msg)
# Explicitly comparing with literal 'True' as assertTrue
# succeeds also for 'true'
self.assertIs(True, dictionary["key_bool"])
开发者ID:manjeetbhatia,项目名称:test_l3,代码行数:10,代码来源:test_attributes.py
示例8: _validate_extra_dhcp_opt
def _validate_extra_dhcp_opt(data, key_specs=None):
if data is not None:
if not isinstance(data, list):
raise ExtraDhcpOptBadData(data=data)
for d in data:
if d["opt_name"] in VALID_BLANK_EXTRA_DHCP_OPTS:
msg = attr._validate_string_or_none(d["opt_value"], DHCP_OPT_VALUE_MAX_LEN)
else:
msg = attr._validate_dict(d, key_specs)
if msg:
raise ExtraDhcpOptBadData(data=msg)
开发者ID:leftyLin,项目名称:neutron,代码行数:11,代码来源:extra_dhcp_opt.py
示例9: validate_gwdevice_list
def validate_gwdevice_list(data, valid_values=None):
"""Validate the list of devices."""
if not data:
# Devices must be provided
msg = _("Cannot create a gateway with an empty device list")
return msg
try:
for device in data:
interface_data = device.get(constants.IFACE_NAME_ATTR)
device_name = device.get(constants.DEVICE_ID_ATTR)
device_ip = device.get(constants.DEVICE_IP_ATTR)
if device_ip and not netaddr.valid_ipv4(device_ip):
msg = _("Cannot create a gateway with an invalid device IP")
return msg
if not device_ip:
msg = _("Cannot create a gateway with an empty device IP")
return msg
if not device_name:
msg = _("Cannot create a gateway with an empty device_name")
return msg
if not interface_data:
msg = _("Cannot create a gateway with an empty interface")
return msg
for int_dict in interface_data:
err_msg = attributes._validate_dict(int_dict, None)
if not int_dict.get('name'):
msg = _("Cannot create a gateway with an empty"
"interface name")
return msg
if not constants.SEG_ID in int_dict:
msg = _("Cannot create a gateway with an empty "
"segmentation ID")
return msg
else:
seg_id_list = int_dict.get(constants.SEG_ID)
if seg_id_list and type(seg_id_list) is not list:
msg = _("segmentation_id type should be of list type")
return msg
if len(seg_id_list) > 1:
msg = _("Only one segmentation_id per interface is "
"allowed")
return msg
if not seg_id_list:
msg = _("segmentation_id_list should not be empty")
return msg
for seg_id in seg_id_list:
is_valid_vlan_id(seg_id)
if err_msg:
return err_msg
except TypeError:
return (_("%s: provided data are not iterable") %
validate_gwdevice_list.__name__)
开发者ID:InamTaj,项目名称:networking-plumgrid,代码行数:52,代码来源:l2gw_validators.py
示例10: test_validate_dict_convert_boolean
def test_validate_dict_convert_boolean(self):
dictionary, constraints = self._construct_dict_and_constraints()
constraints['key_bool'] = {
'type:boolean': None,
'required': False,
'convert_to': attributes.convert_to_boolean}
dictionary['key_bool'] = 'true'
msg = attributes._validate_dict(dictionary, constraints)
self.assertIsNone(msg)
# Explicitly comparing with literal 'True' as assertTrue
# succeeds also for 'true'
self.assertIs(True, dictionary['key_bool'])
开发者ID:glove747,项目名称:liberty-neutron,代码行数:13,代码来源:test_attributes.py
示例11: _validate_service_type_list
def _validate_service_type_list(data, valid_values=None):
if not isinstance(data, list):
msg = _("invalid data format for service list: '%s'") % data
LOG.debug(msg)
return msg
if not data:
msg = _("empty list is not allowed for service list. '%s'") % data
LOG.debug(msg)
return msg
key_specs = {
'service_type': {
'type:string': None,
}
}
for service in data:
msg = attr._validate_dict(service, key_specs)
if msg:
LOG.debug(msg)
return msg
开发者ID:CingHu,项目名称:neutron-ustack,代码行数:19,代码来源:servicevm.py
示例12: test_validate_dict_wrong_values
def test_validate_dict_wrong_values(self):
dictionary, constraints = self._construct_dict_and_constraints()
dictionary['key1'] = 'UNSUPPORTED'
msg = attributes._validate_dict(dictionary, constraints)
self.assertIsNotNone(msg)
开发者ID:glove747,项目名称:liberty-neutron,代码行数:6,代码来源:test_attributes.py
示例13: test_validate_dict_required_keys
def test_validate_dict_required_keys(self):
dictionary, constraints = self._construct_dict_and_constraints()
del dictionary['key1']
msg = attributes._validate_dict(dictionary, constraints)
self.assertIn('Expected keys:', msg)
开发者ID:glove747,项目名称:liberty-neutron,代码行数:6,代码来源:test_attributes.py
示例14: test_validate_dict_with_invalid_validator
def test_validate_dict_with_invalid_validator(self):
dictionary, constraints = self._construct_dict_and_constraints()
constraints['key1'] = {'type:unsupported': None, 'required': True}
msg = attributes._validate_dict(dictionary, constraints)
self.assertEqual("Validator 'type:unsupported' does not exist.", msg)
开发者ID:glove747,项目名称:liberty-neutron,代码行数:6,代码来源:test_attributes.py
示例15: test_validate_a_valid_dict_with_constraints
def test_validate_a_valid_dict_with_constraints(self):
dictionary, constraints = self._construct_dict_and_constraints()
msg = attributes._validate_dict(dictionary, constraints)
self.assertIsNone(msg, 'Validation of a valid dictionary failed.')
开发者ID:glove747,项目名称:liberty-neutron,代码行数:5,代码来源:test_attributes.py
示例16: test_validate_dict_type
def test_validate_dict_type(self):
for value in (None, True, '1', []):
self.assertEqual("'%s' is not a dictionary" % value,
attributes._validate_dict(value))
开发者ID:glove747,项目名称:liberty-neutron,代码行数:4,代码来源:test_attributes.py
示例17: test_validate_dict_with_invalid_validator
def test_validate_dict_with_invalid_validator(self):
dictionary, constraints = self._construct_dict_and_constraints()
constraints["key1"] = {"type:unsupported": None, "required": True}
msg = attributes._validate_dict(dictionary, constraints)
self.assertEqual(msg, "Validator 'type:unsupported' does not exist.")
开发者ID:ZelinIO,项目名称:neutron,代码行数:6,代码来源:test_attributes.py
注:本文中的neutron.api.v2.attributes._validate_dict函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论