specs_matcher

oslo_utils.specs_matcher.make_grammar()

Creates the grammar to be used by a spec matcher.

The grammar created supports the following operations.

Numerical values:
  • =  : equal to or greater than. This is equivalent to >= and is supported for legacy reasons

  • != : Float/integer value not equal

  • <= : Float/integer value less than or equal

  • <  : Float/integer value less than

  • == : Float/integer value equal

  • >= : Float/integer value greater than or equal

  • >  : Float/integer value greater

String operations:
  • s!= : Not equal

  • s<  : Less than

  • s<= : Less than or equal

  • s== : Equal

  • s>  : Greater than

  • s>= : Greater than or equal

Other operations:
  • <all-in>  : All items ‘in’ value

  • <in>      : Item ‘in’ value, like a substring in a string.

  • <or>      : Logical ‘or’

  • <range-in>: Range tester with customizable boundary conditions, tests

    whether value is in the range, boundary condition could be inclusve ‘[’ or exclusive ‘(‘.

If no operator is specified the default is s== (string equality comparison)

Example operations:
  • ">= 60" Is the numerical value greater than or equal to 60

  • "<or> spam <or> eggs" Does the value contain spam or eggs

  • "s== 2.1.0" Is the string value equal to 2.1.0

  • "<in> gcc" Is the string gcc contained in the value string

  • "<all-in> aes mmx" Are both aes and mmx in the value

  • "<range-in> [ 10 20 ]" float(value) >= 10 and float(value) <= 20

  • "<range-in> ( 10 20 ]" float(value) > 10 and float(value) <= 20

  • "<range-in> ( 10 20 )" float(value) > 10 and float(value) < 20

Returns:

A pyparsing.MatchFirst object. See https://pythonhosted.org/pyparsing/ for details on pyparsing.

oslo_utils.specs_matcher.match(cmp_value, spec)

Match a given value to a given spec DSL.

This uses the grammar defined by make_grammar()

Parameters:
  • cmp_value – Value to be checked for match.

  • spec – The comparison specification string, for example ">= 70" or "s== string_value". See make_grammar() for examples of a specification string.

Returns:

True if cmp_value is a match for spec. False otherwise.