juju_verify.verifiers.result module

Juju-verify verification result.

class juju_verify.verifiers.result.Partial(severity: Severity, message: str)

Bases: object

Class representing partial result.

Generally, instances of this class are used in Result class to represent (partial) results of individual checks ran during the whole verification process.

class juju_verify.verifiers.result.Result(severity: Severity = Severity.OK, message: str = '')

Bases: object

Convenience class that represents result of the check.

Each juju-verify check should return Result instance with at least one partial result in self.partials. Multiple partial result are good idea if, for example, the check runs against multiple units.

VERBOSE_MAP = {Severity.OK: 'OK (All checks passed)', Severity.WARN: 'OK (Checks passed with warnings)', Severity.UNSUPPORTED: 'Failed (Targeted charms are not supported)', Severity.FAIL: 'Failed'}
add_partial_result(severity: Severity, message: str) None

Add partial result to this instance.

property empty: bool

Return True if result does not contain any partial results.

property success: bool

Return overall Result’s success.

The success is calculated based on the highest Severity value from all the partial results in self.partials. Following is the map for overall success:

Highest severity is OK -> Overall success is True Highest severity is WARN -> Overall success is True Highest severity is UNSUPPORTED -> Overall success is False Highest severity is FAIL -> Overall success is False

Note: If the Result instance has no Partial results in self.partials, overall success will be True.

class juju_verify.verifiers.result.Severity(value)

Bases: Enum

Collection of possible Result’s severities.

FAIL = 40
OK = 10
UNSUPPORTED = 30
WARN = 20
juju_verify.verifiers.result.checks_executor(*checks: Union[Callable, Tuple[Callable, Dict[str, Any]]]) Result

Executor that aggregates checks and captures errors.

This executor will accept checks as a callable function or as a tuple with first object callable (check) and second as a dictionary containing parameters for performing the check. The executor’s output aggregates all check results into one result, while the order is preserved. If the check does not return any input, then the default value is used in the form: Result(OK, “<check .__ name __> check successful”). At the same time, if the check fails on one of the following errors (JujuActionFailed, CharmException, KeyError, JSONDecodeError), it will be marked as failed with the result in the form: `Result(FAIL, f”{check.__name__} check failed with error: {error}”.

Examples of use:

def check_without_parameter_1():

return Result(Severity.OK, “check 1 passed”)

def check_without_parameter_2():

return Result(Severity.OK, “check 2 passed”)

def check_with_parameter(resources=None):
if resources is None:

return Result(Severity.FAIL, “check 3 failed”)

return Result(Severity.OK, f”check 3 passed ({resources})”)

result_1 = checks_executor(check_without_parameter_1,

check_without_parameter_2, (check_with_parameter, dict(resources=”DHCP”)))

print(result_1) Checks: [OK] check 1 passed [OK] check 2 passed [OK] check 3 passed (DHCP)

Overall result: OK (All checks passed)

result_2 = checks_executor(check_without_parameter_1,

check_without_parameter_2, check_with_parameter)

print(result_2) Checks: [OK] check 1 passed [OK] check 2 passed [FAIL] check 3 failed

Overall result: Failed

juju_verify.verifiers.result.set_stop_on_failure(stop: bool = False) None

Set stop on failure.

juju_verify.verifiers.result.stop_on_failure() bool

Get the configuration to stop on failure.