Example #1
0
    def validate(self, val):
        if val is None:
            return self.on_missing(self)
        if self.validation_regex and not self.validation_pattern.match(val):
            raise declarative.DynamicPollsterDefinitionException(
                "Pollster %s [%s] does not match [%s]."
                % (self.name, val, self.validation_regex))

        if self.validator:
            self.validator(val)

        return val
    def validate_pollster_definition(self):
        missing_required_fields = \
            [field for field in self.REQUIRED_POLLSTER_FIELDS
             if field not in self.pollster_definitions]

        if missing_required_fields:
            raise declarative.DynamicPollsterDefinitionException(
                "Required fields %s not specified." % missing_required_fields,
                self.pollster_definitions)

        sample_type = self.pollster_definitions['sample_type']
        if sample_type not in sample.TYPES:
            raise declarative.DynamicPollsterDefinitionException(
                "Invalid sample type [%s]. Valid ones are [%s]." %
                (sample_type, sample.TYPES), self.pollster_definitions)

        for definition_key in self.pollster_definitions:
            if definition_key not in self.ALL_POLLSTER_FIELDS:
                LOG.warning(
                    "Field [%s] defined in [%s] is unknown "
                    "and will be ignored. Valid fields are [%s].",
                    definition_key, self.pollster_definitions,
                    self.ALL_POLLSTER_FIELDS)
Example #3
0
    def validate_missing(self):
        required_configurations = map(lambda fdf: fdf.name,
                                      filter(lambda df: df.required,
                                             self.definitions.values()))

        missing = list(filter(
            lambda rf: rf not in map(lambda f: f[0],
                                     filter(lambda f: f[1],
                                            self.configurations.items())),
            required_configurations))

        if missing:
            raise declarative.DynamicPollsterDefinitionException(
                "Required fields %s not specified."
                % missing, self.configurations)
Example #4
0
 def operate_value(self, keys_and_operations, value):
     # We do not have operations to be executed against the value extracted
     if len(keys_and_operations) < 2:
         return value
     for operation in keys_and_operations[1::]:
         # The operation must be performed onto the 'value' variable
         if 'value' not in operation:
             raise declarative.DynamicPollsterDefinitionException(
                 "The attribute field operation [%s] must use the ["
                 "value] variable." % operation,
                 self.definitions.configurations)
         LOG.debug("Executing operation [%s] against value [%s].",
                   operation, value)
         value = eval(operation.strip())
         LOG.debug("Result [%s] of operation [%s].",
                   value, operation)
     return value
Example #5
0
    def build_definitions(self, configurations):
        supported_definitions = []
        for definition in self.definitions:
            if definition.is_field_applicable_to_definition(configurations):
                supported_definitions.append(definition)

        if not supported_definitions:
            raise declarative.DynamicPollsterDefinitionException(
                "Your configurations do not fit any type of DynamicPollsters, "
                "please recheck them. Used configurations = [%s]." %
                configurations)

        definition_name = self.join_supported_definitions_names(
            supported_definitions)

        definition_parents = tuple(supported_definitions)
        definition_attribs = {'extra_definitions': reduce(
            lambda d1, d2: d1 + d2, map(lambda df: df.extra_definitions,
                                        supported_definitions))}
        definition_type = type(definition_name, definition_parents,
                               definition_attribs)
        return definition_type(configurations)
Example #6
0
def validate_sample_type(sample_type):
    if sample_type not in ceilometer_sample.TYPES:
        raise declarative.DynamicPollsterDefinitionException(
            "Invalid sample type [%s]. Valid ones are [%s]."
            % (sample_type, ceilometer_sample.TYPES))