Exemple #1
0
    def validate(self):
        try:
            if self.type == 'SECONDARY' and self.masters is None:
                errors = ValidationErrorList()
                e = ValidationError()
                e.path = ['type']
                e.validator = 'required'
                e.validator_value = ['masters']
                e.message = "'masters' is a required property"
                errors.append(e)
                raise exceptions.InvalidObject(
                    "Provided object does not match "
                    "schema", errors=errors, object=self)

            super(Domain, self).validate()
        except exceptions.RelationNotLoaded as ex:
            errors = ValidationErrorList()
            e = ValidationError()
            e.path = ['type']
            e.validator = 'required'
            e.validator_value = [ex.relation]
            e.message = "'%s' is a required property" % ex.relation
            errors.append(e)
            raise exceptions.InvalidObject(
                "Provided object does not match "
                "schema", errors=errors, object=self)
Exemple #2
0
 def _validate_fail(self, errors, msg):
     e = ValidationError()
     e.path = ['recordset', 'type']
     e.validator = 'value'
     e.validator_value = [self.type]
     e.message = msg
     # Add it to the list for later
     errors.append(e)
     raise exceptions.InvalidObject(
         "Provided object does not match "
         "schema", errors=errors, object=self)
Exemple #3
0
    def validate(self):
        if self.type == "SECONDARY" and self.masters is None:
            errors = ValidationErrorList()
            e = ValidationError()
            e.path = ["type"]
            e.validator = "required"
            e.validator_value = ["masters"]
            e.message = "'masters' is a required property"
            errors.append(e)
            raise exceptions.InvalidObject("Provided object does not match " "schema", errors=errors, object=self)

        super(Domain, self).validate()
Exemple #4
0
 def _validate_fail(self, errors, msg):
     e = ValidationError()
     e.path = ['recordset', 'type']
     e.validator = 'value'
     e.validator_value = [self.type]
     e.message = msg
     # Add it to the list for later
     errors.append(e)
     raise exceptions.InvalidObject(
         "Provided object does not match "
         "schema", errors=errors, object=self)
Exemple #5
0
    def validate(self):
        if self.type == 'SECONDARY' and self.masters is None:
            errors = ValidationErrorList()
            e = ValidationError()
            e.path = ['type']
            e.validator = 'required'
            e.validator_value = ['masters']
            e.message = "'masters' is a required property"
            errors.append(e)
            raise exceptions.InvalidObject(
                "Provided object does not match "
                "schema",
                errors=errors,
                object=self)

        super(Domain, self).validate()
Exemple #6
0
    def validate(self):

        LOG.debug("Validating '%(name)s' object with values: %(values)r", {
            'name': self.obj_name(),
            'values': self.to_dict(),
        })
        LOG.debug(list(self.records))

        errors = ValidationErrorList()

        # Get the right classes (e.g. A for Recordsets with type: 'A')
        try:
            record_list_cls = self.obj_cls_from_name('%sList' % self.type)
            record_cls = self.obj_cls_from_name(self.type)
        except (KeyError, ovo_exc.UnsupportedObjectError) as e:
            err_msg = ("'%(type)s' is not a valid record type" % {
                'type': self.type
            })
            self._validate_fail(errors, err_msg)

        if self.type not in cfg.CONF.supported_record_type:
            err_msg = ("'%(type)s' is not a supported record type" % {
                'type': self.type
            })
            self._validate_fail(errors, err_msg)

        # Get any rules that the record type imposes on the record
        changes = record_cls.get_recordset_schema_changes()
        old_fields = {}
        if changes:
            LOG.debug("Record %s is overriding the RecordSet schema with: %s",
                      record_cls.obj_name(), changes)
            old_fields = deepcopy(self.FIELDS)
            self.FIELDS = utils.deep_dict_merge(self.FIELDS, changes)

        error_indexes = []
        # Copy these for safekeeping
        old_records = deepcopy(self.records)

        # Blank the records for this object with the right list type
        self.records = record_list_cls()

        i = 0

        for record in old_records:
            record_obj = record_cls()
            try:
                record_obj._from_string(record.data)
            # The _from_string() method will throw a ValueError if there is not
            # enough data blobs
            except ValueError as e:
                # Something broke in the _from_string() method
                # Fake a correct looking ValidationError() object
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record" % {
                    'data': record.data,
                    'type': self.type
                })
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except TypeError as e:
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record" % {
                    'data': record.data,
                    'type': self.type
                })
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except AttributeError as e:
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record" % {
                    'data': record.data,
                    'type': self.type
                })
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except Exception as e:
                error_message = ('Provided object is not valid. Got a %s error'
                                 ' with message %s' %
                                 (type(e).__name__, six.text_type(e)))
                raise exceptions.InvalidObject(error_message)

            else:
                # Seems to have loaded right - add it to be validated by
                # JSONSchema
                self.records.append(record_obj)
            i += 1

        try:
            # Run the actual validate code
            super(RecordSet, self).validate()

        except exceptions.InvalidObject as e:
            raise e
        else:
            # If JSONSchema passes, but we found parsing errors,
            # raise an exception
            if len(errors) > 0:
                LOG.debug(
                    "Error Validating '%(name)s' object with values: "
                    "%(values)r", {
                        'name': self.obj_name(),
                        'values': self.to_dict(),
                    })
                raise exceptions.InvalidObject(
                    "Provided object does not match "
                    "schema",
                    errors=errors,
                    object=self)
        finally:
            if old_fields:
                self.FIELDS = old_fields

        # Send in the traditional Record objects to central / storage
        self.records = old_records
Exemple #7
0
    def validate(self):

        LOG.debug("Validating '%(name)s' object with values: %(values)r", {
            'name': self.obj_name(),
            'values': self.to_dict(),
        })

        errors = ValidationErrorList()

        # Get the right classes (e.g. A for Recordsets with type: 'A')
        try:
            record_list_cls = self.obj_cls_from_name('%sList' % self.type)
            record_cls = self.obj_cls_from_name(self.type)
        except KeyError as e:
            e = ValidationError()
            e.path = ['recordset', 'type']
            e.validator = 'value'
            e.validator_value = [self.type]
            e.message = ("'%(type)s' is not a supported Record type"
                         % {'type': self.type})
            # Add it to the list for later
            errors.append(e)
            raise exceptions.InvalidObject(
                "Provided object does not match "
                "schema", errors=errors, object=self)

        # Get any rules that the record type imposes on the record
        changes = record_cls.get_recordset_schema_changes()
        old_fields = {}
        if changes:
            LOG.debug("Record %s is overriding the RecordSet schema with: %s" %
                      (record_cls.obj_name(), changes))
            old_fields = deepcopy(self.FIELDS)
            self.FIELDS = utils.deep_dict_merge(self.FIELDS, changes)

        error_indexes = []
        # Copy these for safekeeping
        old_records = deepcopy(self.records)

        # Blank the records for this object with the right list type
        self.records = record_list_cls()

        i = 0

        for record in old_records:
            record_obj = record_cls()
            try:
                record_obj._from_string(record.data)
            # The _from_string() method will throw a ValueError if there is not
            # enough data blobs
            except ValueError as e:
                # Something broke in the _from_string() method
                # Fake a correct looking ValidationError() object
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record"
                             % {'data': record.data, 'type': self.type})
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except TypeError as e:
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record"
                             % {'data': record.data, 'type': self.type})
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except AttributeError as e:
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record"
                             % {'data': record.data, 'type': self.type})
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except Exception as e:
                error_message = str.format(
                    'Provided object is not valid. '
                    'Got a %s error with message %s' %
                    (type(e).__name__, six.text_type(e)))
                raise exceptions.InvalidObject(error_message)

            else:
                # Seems to have loaded right - add it to be validated by
                # JSONSchema
                self.records.append(record_obj)
            i += 1

        try:
            # Run the actual validate code
            super(RecordSet, self).validate()

        except exceptions.InvalidObject as e:
            # Something is wrong according to JSONSchema - append our errors
            increment = 0
            # This code below is to make sure we have the index for the record
            # list correct. JSONSchema may be missing some of the objects due
            # to validation above, so this re - inserts them, and makes sure
            # the index is right
            for error in e.errors:
                if len(error.path) > 1 and isinstance(error.path[1], int):
                    error.path[1] += increment
                    while error.path[1] in error_indexes:
                        increment += 1
                        error.path[1] += 1
            # Add the list from above
            e.errors.extend(errors)
            # Raise the exception
            raise e
        else:
            # If JSONSchema passes, but we found parsing errors,
            # raise an exception
            if len(errors) > 0:
                LOG.debug(
                    "Error Validating '%(name)s' object with values: "
                    "%(values)r", {
                        'name': self.obj_name(),
                        'values': self.to_dict(),
                    }
                )
                raise exceptions.InvalidObject(
                    "Provided object does not match "
                    "schema", errors=errors, object=self)
        finally:
            if old_fields:
                self.FIELDS = old_fields
        # Send in the traditional Record objects to central / storage
        self.records = old_records
Exemple #8
0
    def validate(self):

        LOG.debug("Validating '%(name)s' object with values: %(values)r", {
            'name': self.obj_name(),
            'values': self.to_dict(),
        })
        LOG.debug(list(self.records))

        errors = ValidationErrorList()

        # Get the right classes (e.g. A for Recordsets with type: 'A')
        try:
            record_list_cls = self.obj_cls_from_name('%sList' % self.type)
            record_cls = self.obj_cls_from_name(self.type)
        except (KeyError, ovo_exc.UnsupportedObjectError) as e:
            err_msg = ("'%(type)s' is not a valid record type"
                       % {'type': self.type})
            self._validate_fail(errors, err_msg)

        if self.type not in cfg.CONF.supported_record_type:
            err_msg = ("'%(type)s' is not a supported record type"
                       % {'type': self.type})
            self._validate_fail(errors, err_msg)

        # Get any rules that the record type imposes on the record
        changes = record_cls.get_recordset_schema_changes()
        old_fields = {}
        if changes:
            LOG.debug("Record %s is overriding the RecordSet schema with: %s",
                      record_cls.obj_name(), changes)
            old_fields = deepcopy(self.FIELDS)
            self.FIELDS = utils.deep_dict_merge(self.FIELDS, changes)

        error_indexes = []
        # Copy these for safekeeping
        old_records = deepcopy(self.records)

        # Blank the records for this object with the right list type
        self.records = record_list_cls()

        i = 0

        for record in old_records:
            record_obj = record_cls()
            try:
                record_obj._from_string(record.data)
            # The _from_string() method will throw a ValueError if there is not
            # enough data blobs
            except ValueError as e:
                # Something broke in the _from_string() method
                # Fake a correct looking ValidationError() object
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record"
                             % {'data': record.data, 'type': self.type})
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except TypeError as e:
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record"
                             % {'data': record.data, 'type': self.type})
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except AttributeError as e:
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record"
                             % {'data': record.data, 'type': self.type})
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except Exception as e:
                error_message = str.format(
                    'Provided object is not valid. '
                    'Got a %s error with message %s' %
                    (type(e).__name__, six.text_type(e)))
                raise exceptions.InvalidObject(error_message)

            else:
                # Seems to have loaded right - add it to be validated by
                # JSONSchema
                self.records.append(record_obj)
            i += 1

        try:
            # Run the actual validate code
            super(RecordSet, self).validate()

        except exceptions.InvalidObject as e:
            raise e
        else:
            # If JSONSchema passes, but we found parsing errors,
            # raise an exception
            if len(errors) > 0:
                LOG.debug(
                    "Error Validating '%(name)s' object with values: "
                    "%(values)r", {
                        'name': self.obj_name(),
                        'values': self.to_dict(),
                    }
                )
                raise exceptions.InvalidObject(
                    "Provided object does not match "
                    "schema", errors=errors, object=self)
        finally:
            if old_fields:
                self.FIELDS = old_fields

        # Send in the traditional Record objects to central / storage
        self.records = old_records
Exemple #9
0
    def validate(self):
        errors = ValidationErrorList()

        if self.type == 'PRIMARY':
            if self.obj_attr_is_set('masters') and len(self.masters) != 0:
                e = ValidationError()
                e.path = ['type']
                e.validator = 'maxItems'
                e.validator_value = ['masters']
                e.message = "'masters' has more items than allowed"
                errors.append(e)
            if self.email is None:
                e = ValidationError()
                e.path = ['type']
                e.validator = 'required'
                e.validator_value = 'email'
                e.message = "'email' is a required property"
                errors.append(e)
            self._raise(errors)

        try:
            if self.type == 'SECONDARY':
                if self.masters is None or len(self.masters) == 0:
                    e = ValidationError()
                    e.path = ['type']
                    e.validator = 'required'
                    e.validator_value = ['masters']
                    e.message = "'masters' is a required property"
                    errors.append(e)

                for i in ['email', 'ttl']:
                    if i in self.obj_what_changed():
                        e = ValidationError()
                        e.path = ['type']
                        e.validator = 'not_allowed'
                        e.validator_value = i
                        e.message = "'%s' can't be specified when type is " \
                            "SECONDARY" % i
                        errors.append(e)
                self._raise(errors)

            super(Zone, self).validate()
        except exceptions.RelationNotLoaded as ex:
            errors = ValidationErrorList()
            e = ValidationError()
            e.path = ['type']
            e.validator = 'required'
            e.validator_value = [ex.relation]
            e.message = "'%s' is a required property" % ex.relation
            errors.append(e)
            self._raise(errors)
Exemple #10
0
    def validate(self):

        LOG.debug("Validating '%(name)s' object with values: %(values)r", {
            'name': self.obj_name(),
            'values': self.to_dict(),
        })

        errors = ValidationErrorList()

        # Get the right classes (e.g. A for Recordsets with type: 'A')
        try:
            record_list_cls = self.obj_cls_from_name('%sList' % self.type)
            record_cls = self.obj_cls_from_name(self.type)
        except KeyError as e:
            e = ValidationError()
            e.path = ['recordset', 'type']
            e.validator = 'value'
            e.validator_value = [self.type]
            e.message = ("'%(type)s' is not a supported Record type" % {
                'type': self.type
            })
            # Add it to the list for later
            errors.append(e)
            raise exceptions.InvalidObject(
                "Provided object does not match "
                "schema",
                errors=errors,
                object=self)

        # Get any rules that the record type imposes on the record
        changes = record_cls.get_recordset_schema_changes()
        old_fields = {}
        if changes:
            LOG.debug("Record %s is overriding the RecordSet schema with: %s" %
                      (record_cls.obj_name(), changes))
            old_fields = deepcopy(self.FIELDS)
            self.FIELDS = utils.deep_dict_merge(self.FIELDS, changes)

        error_indexes = []
        # Copy these for safekeeping
        old_records = deepcopy(self.records)

        # Blank the records for this object with the right list type
        self.records = record_list_cls()

        i = 0

        for record in old_records:
            record_obj = record_cls()
            try:
                record_obj._from_string(record.data)
            # The _from_string() method will throw a ValueError if there is not
            # enough data blobs
            except ValueError as e:
                # Something broke in the _from_string() method
                # Fake a correct looking ValidationError() object
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record" % {
                    'data': record.data,
                    'type': self.type
                })
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except TypeError as e:
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record" % {
                    'data': record.data,
                    'type': self.type
                })
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except AttributeError as e:
                e = ValidationError()
                e.path = ['records', i]
                e.validator = 'format'
                e.validator_value = [self.type]
                e.message = ("'%(data)s' is not a '%(type)s' Record" % {
                    'data': record.data,
                    'type': self.type
                })
                # Add it to the list for later
                errors.append(e)
                error_indexes.append(i)

            except Exception as e:
                error_message = str.format(
                    'Provided object is not valid. '
                    'Got a %s error with message %s' %
                    (type(e).__name__, six.text_type(e)))
                raise exceptions.InvalidObject(error_message)

            else:
                # Seems to have loaded right - add it to be validated by
                # JSONSchema
                self.records.append(record_obj)
            i += 1

        try:
            # Run the actual validate code
            super(RecordSet, self).validate()

        except exceptions.InvalidObject as e:
            # Something is wrong according to JSONSchema - append our errors
            increment = 0
            # This code below is to make sure we have the index for the record
            # list correct. JSONSchema may be missing some of the objects due
            # to validation above, so this re - inserts them, and makes sure
            # the index is right
            for error in e.errors:
                if len(error.path) > 1 and isinstance(error.path[1], int):
                    error.path[1] += increment
                    while error.path[1] in error_indexes:
                        increment += 1
                        error.path[1] += 1
            # Add the list from above
            e.errors.extend(errors)
            # Raise the exception
            raise e
        else:
            # If JSONSchema passes, but we found parsing errors,
            # raise an exception
            if len(errors) > 0:
                LOG.debug(
                    "Error Validating '%(name)s' object with values: "
                    "%(values)r", {
                        'name': self.obj_name(),
                        'values': self.to_dict(),
                    })
                raise exceptions.InvalidObject(
                    "Provided object does not match "
                    "schema",
                    errors=errors,
                    object=self)
        finally:
            if old_fields:
                self.FIELDS = old_fields
        # Send in the traditional Record objects to central / storage
        self.records = old_records
Exemple #11
0
    def validate(self):
        errors = ValidationErrorList()

        if self.type == 'PRIMARY':
            if self.obj_attr_is_set('masters') and len(self.masters) != 0:
                e = ValidationError()
                e.path = ['type']
                e.validator = 'maxItems'
                e.validator_value = ['masters']
                e.message = "'masters' has more items than allowed"
                errors.append(e)
            if self.email is None:
                e = ValidationError()
                e.path = ['type']
                e.validator = 'required'
                e.validator_value = 'email'
                e.message = "'email' is a required property"
                errors.append(e)
            self._raise(errors)

        try:
            if self.type == 'SECONDARY':
                if self.masters is None or len(self.masters) == 0:
                    e = ValidationError()
                    e.path = ['type']
                    e.validator = 'required'
                    e.validator_value = ['masters']
                    e.message = "'masters' is a required property"
                    errors.append(e)

                for i in ['email', 'ttl']:
                    if i in self.obj_what_changed():
                        e = ValidationError()
                        e.path = ['type']
                        e.validator = 'not_allowed'
                        e.validator_value = i
                        e.message = "'%s' can't be specified when type is " \
                            "SECONDARY" % i
                        errors.append(e)
                self._raise(errors)

            super(Zone, self).validate()
        except exceptions.RelationNotLoaded as ex:
            errors = ValidationErrorList()
            e = ValidationError()
            e.path = ['type']
            e.validator = 'required'
            e.validator_value = [ex.relation]
            e.message = "'%s' is a required property" % ex.relation
            errors.append(e)
            self._raise(errors)