def _validate_portinfo(self, profile): key_specs = { 'datapath_id': { 'type:string': None, 'required': True }, 'port_no': { 'type:non_negative': None, 'required': True, 'convert_to': attrs.convert_to_int } } msg = attrs._validate_dict_or_empty(profile, key_specs=key_specs) if msg: raise n_exc.InvalidInput(error_message=msg) datapath_id = profile.get('datapath_id') port_no = profile.get('port_no') try: dpid = int(datapath_id, 16) except ValueError: raise nexc.ProfilePortInfoInvalidDataPathId() if dpid > 0xffffffffffffffffL: raise nexc.ProfilePortInfoInvalidDataPathId() # Make sure dpid is a hex string beginning with 0x. dpid = hex(dpid) if int(port_no) > 65535: raise nexc.ProfilePortInfoInvalidPortNo() return {'datapath_id': dpid, 'port_no': port_no}
def _validate_portinfo(self, profile): key_specs = { 'portinfo:datapath_id': {'type:string': None, 'required': True}, 'portinfo:port_no': {'type:non_negative': None, 'required': True, 'convert_to': attrs.convert_to_int} } msg = attrs._validate_dict_or_empty(profile, key_specs=key_specs) if msg: raise q_exc.InvalidInput(error_message=msg) datapath_id = profile.get('portinfo:datapath_id') port_no = profile.get('portinfo:port_no') try: dpid = int(datapath_id, 16) except ValueError: raise nexc.ProfilePortInfoInvalidDataPathId() if dpid > 0xffffffffffffffffL: raise nexc.ProfilePortInfoInvalidDataPathId() # Make sure dpid is a hex string beginning with 0x. dpid = hex(dpid) if int(port_no) > 65535: raise nexc.ProfilePortInfoInvalidPortNo() return {'datapath_id': dpid, 'port_no': port_no}
def _validate_service_context_list(data, valid_values=None): if not isinstance(data, list): msg = _("invalid data format for service context list: '%s'") % data LOG.debug(msg) return msg key_specs = { 'network_id': { 'type:uuid': None }, 'subnet_id': { 'type:uuid': None }, 'port_id': { 'type:uuid': None }, 'router_id': { 'type:uuid': None }, 'role': { 'type:string': None }, 'index': { 'type:non_negative': None, 'convert_to': attr.convert_to_int }, } for sc_entry in data: msg = attr._validate_dict_or_empty(sc_entry, key_specs=key_specs) if msg: LOG.debug(msg) return msg
def test_validate_dict_or_empty(self): dictionary, constraints = self._construct_dict_and_constraints() # Check whether an empty dictionary is valid. msg = attributes._validate_dict_or_empty({}, constraints) self.assertIsNone(msg, 'Validation of a None dictionary failed.') # Check validation of a regular dictionary. msg = attributes._validate_dict_or_none(dictionary, constraints) self.assertIsNone(msg, 'Validation of a valid dictionary failed.') self.assertIsNone(msg, 'Validation of a valid dictionary failed.')
def _validate_service_context_list(data, valid_values=None): if not isinstance(data, list): msg = _("invalid data format for service context list: '%s'") % data LOG.debug(msg) return msg key_specs = { 'network_id': {'type:uuid': None}, 'subnet_id': {'type:uuid': None}, 'port_id': {'type:uuid': None}, 'router_id': {'type:uuid': None}, 'role': {'type:string': None}, 'index': {'type:non_negative': None, 'convert_to': attr.convert_to_int}, } for sc_entry in data: msg = attr._validate_dict_or_empty(sc_entry, key_specs=key_specs) if msg: LOG.debug(msg) return msg
def _validate_portinfo(self, profile): key_specs = { "datapath_id": {"type:string": None, "required": True}, "port_no": {"type:non_negative": None, "required": True, "convert_to": attrs.convert_to_int}, } msg = attrs._validate_dict_or_empty(profile, key_specs=key_specs) if msg: raise n_exc.InvalidInput(error_message=msg) datapath_id = profile.get("datapath_id") port_no = profile.get("port_no") try: dpid = int(datapath_id, 16) except ValueError: raise nexc.ProfilePortInfoInvalidDataPathId() if dpid > 0xFFFFFFFFFFFFFFFFL: raise nexc.ProfilePortInfoInvalidDataPathId() # Make sure dpid is a hex string beginning with 0x. dpid = hex(dpid) if int(port_no) > 65535: raise nexc.ProfilePortInfoInvalidPortNo() return {"datapath_id": dpid, "port_no": port_no}