implement sample console notifier

This commit is contained in:
Chi Song 2020-09-28 17:27:26 +08:00
Родитель c0d361e930
Коммит 98ef17cf58
3 изменённых файлов: 41 добавлений и 0 удалений

Просмотреть файл

@ -5,6 +5,8 @@ environment:
environments: environments:
- nodes: - nodes:
- type: local - type: local
notifier:
- type: console
testcase: testcase:
- criteria: - criteria:
area: demo area: demo

Просмотреть файл

39
lisa/notifiers/console.py Normal file
Просмотреть файл

@ -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]