diff --git a/examples/runbook/hello_world.yml b/examples/runbook/hello_world.yml index d5fcfeffb..15c981189 100644 --- a/examples/runbook/hello_world.yml +++ b/examples/runbook/hello_world.yml @@ -5,6 +5,8 @@ environment: environments: - nodes: - type: local +notifier: + - type: console testcase: - criteria: area: demo diff --git a/lisa/notifiers/__init__.py b/lisa/notifiers/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/lisa/notifiers/console.py b/lisa/notifiers/console.py new file mode 100644 index 000000000..060defc3b --- /dev/null +++ b/lisa/notifiers/console.py @@ -0,0 +1,39 @@ +import logging +from dataclasses import dataclass +from typing import List, Type, cast + +from dataclasses_json import LetterCase, dataclass_json # type: ignore + +from lisa import notifier, schema +from lisa.testsuite import TestResultMessage + + +@dataclass_json(letter_case=LetterCase.CAMEL) +@dataclass +class ConsoleSchema(schema.TypedSchema): + log_level: str = logging.getLevelName(logging.DEBUG) + + +class Console(notifier.Notifier): + """ + It's a sample notifier, output subscribed message to console. + It can be used to troubleshooting what kind of message received. + """ + + @classmethod + def type_name(cls) -> str: + return "console" + + @classmethod + def type_schema(cls) -> Type[schema.TypedSchema]: + return ConsoleSchema + + def _received_message(self, message: notifier.MessageBase) -> None: + runbook = cast(ConsoleSchema, self._runbook) + self._log.log( + getattr(logging, runbook.log_level), + f"received message [{message.type}]: {message}", + ) + + def _subscribed_message_type(self) -> List[Type[notifier.MessageBase]]: + return [TestResultMessage]