зеркало из https://github.com/microsoft/lisa.git
node: propagate log to parent logger.
This commit is contained in:
Родитель
e43b9aa57a
Коммит
b28279d4f6
|
@ -194,8 +194,6 @@ class Environment(ContextMixin, InitializableMixin):
|
|||
for node_runbook in runbook.nodes:
|
||||
self.create_node_from_exists(
|
||||
node_runbook=node_runbook,
|
||||
environment_name=self.name,
|
||||
base_log_path=self.log_path,
|
||||
)
|
||||
|
||||
has_default_node = self.__validate_single_default(
|
||||
|
@ -273,14 +271,12 @@ class Environment(ContextMixin, InitializableMixin):
|
|||
def create_node_from_exists(
|
||||
self,
|
||||
node_runbook: schema.Node,
|
||||
environment_name: str,
|
||||
base_log_path: Optional[Path] = None,
|
||||
) -> Node:
|
||||
node = Node.create(
|
||||
index=len(self.nodes),
|
||||
runbook=node_runbook,
|
||||
logger_name=environment_name,
|
||||
base_log_path=base_log_path,
|
||||
base_log_path=self.log_path,
|
||||
parent_logger=self._log,
|
||||
)
|
||||
self.nodes.append(node)
|
||||
|
||||
|
@ -289,8 +285,6 @@ class Environment(ContextMixin, InitializableMixin):
|
|||
def create_node_from_requirement(
|
||||
self,
|
||||
node_requirement: schema.NodeSpace,
|
||||
environment_name: str,
|
||||
base_log_path: Optional[Path] = None,
|
||||
) -> Node:
|
||||
min_requirement = cast(
|
||||
schema.Capability,
|
||||
|
@ -310,8 +304,8 @@ class Environment(ContextMixin, InitializableMixin):
|
|||
node = Node.create(
|
||||
index=len(self.nodes),
|
||||
runbook=mock_runbook,
|
||||
logger_name=environment_name,
|
||||
base_log_path=base_log_path,
|
||||
base_log_path=self.log_path,
|
||||
parent_logger=self._log,
|
||||
)
|
||||
self.nodes.append(node)
|
||||
|
||||
|
|
20
lisa/node.py
20
lisa/node.py
|
@ -20,7 +20,7 @@ from lisa.util import (
|
|||
fields_to_dict,
|
||||
subclasses,
|
||||
)
|
||||
from lisa.util.logger import get_logger
|
||||
from lisa.util.logger import Logger, get_logger
|
||||
from lisa.util.process import ExecutableResult, Process
|
||||
from lisa.util.shell import ConnectionInfo, LocalShell, Shell, SshShell
|
||||
|
||||
|
@ -36,6 +36,7 @@ class Node(subclasses.BaseClassWithRunbookMixin, ContextMixin, InitializableMixi
|
|||
index: int,
|
||||
logger_name: str,
|
||||
base_log_path: Optional[Path] = None,
|
||||
parent_logger: Optional[Logger] = None,
|
||||
) -> None:
|
||||
super().__init__(runbook=runbook)
|
||||
self.is_default = runbook.is_default
|
||||
|
@ -50,7 +51,7 @@ class Node(subclasses.BaseClassWithRunbookMixin, ContextMixin, InitializableMixi
|
|||
self.tools = Tools(self)
|
||||
# the path uses remotely
|
||||
node_id = str(self.index) if self.index >= 0 else ""
|
||||
self.log = get_logger(logger_name, node_id)
|
||||
self.log = get_logger(logger_name, node_id, parent=parent_logger)
|
||||
|
||||
# The working path will be created in remote node, when it's used.
|
||||
self._working_path: Optional[PurePath] = None
|
||||
|
@ -141,6 +142,7 @@ class Node(subclasses.BaseClassWithRunbookMixin, ContextMixin, InitializableMixi
|
|||
runbook: schema.Node,
|
||||
logger_name: str = "node",
|
||||
base_log_path: Optional[Path] = None,
|
||||
parent_logger: Optional[Logger] = None,
|
||||
) -> Node:
|
||||
if not cls._factory:
|
||||
cls._factory = subclasses.Factory[Node](Node)
|
||||
|
@ -150,6 +152,7 @@ class Node(subclasses.BaseClassWithRunbookMixin, ContextMixin, InitializableMixi
|
|||
runbook=runbook,
|
||||
logger_name=logger_name,
|
||||
base_log_path=base_log_path,
|
||||
parent_logger=parent_logger,
|
||||
)
|
||||
|
||||
node.log.debug(
|
||||
|
@ -384,12 +387,14 @@ class LocalNode(Node):
|
|||
index: int,
|
||||
logger_name: str,
|
||||
base_log_path: Optional[Path],
|
||||
parent_logger: Optional[Logger] = None,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
index=index,
|
||||
runbook=runbook,
|
||||
logger_name=logger_name,
|
||||
base_log_path=base_log_path,
|
||||
parent_logger=parent_logger,
|
||||
)
|
||||
|
||||
self._shell = LocalShell()
|
||||
|
@ -475,11 +480,18 @@ class Nodes:
|
|||
self._list.append(node)
|
||||
|
||||
|
||||
def quick_connect(runbook: schema.Node, logger_name: str = "", index: int = -1) -> Node:
|
||||
def quick_connect(
|
||||
runbook: schema.Node,
|
||||
logger_name: str = "",
|
||||
index: int = -1,
|
||||
parent_logger: Optional[Logger] = None,
|
||||
) -> Node:
|
||||
"""
|
||||
setup node information and initialize connection.
|
||||
"""
|
||||
node = Node.create(index, runbook, logger_name=logger_name)
|
||||
node = Node.create(
|
||||
index, runbook, logger_name=logger_name, parent_logger=parent_logger
|
||||
)
|
||||
if isinstance(node, RemoteNode):
|
||||
node.set_connection_info_by_runbook()
|
||||
node.initialize()
|
||||
|
|
|
@ -869,8 +869,6 @@ class AzurePlatform(Platform):
|
|||
# init node
|
||||
node = environment.create_node_from_requirement(
|
||||
node_space,
|
||||
environment_name=environment.name,
|
||||
base_log_path=environment.log_path,
|
||||
)
|
||||
if not azure_node_runbook.name:
|
||||
azure_node_runbook.name = f"node-{len(nodes_parameters)}"
|
||||
|
|
|
@ -14,6 +14,7 @@ from lisa import node, schema, search_space
|
|||
from lisa.environment import load_environments
|
||||
from lisa.testsuite import simple_requirement
|
||||
from lisa.util import constants
|
||||
from lisa.util.logger import Logger
|
||||
|
||||
CUSTOM_LOCAL = "custom_local"
|
||||
CUSTOM_REMOTE = "custom_remote"
|
||||
|
@ -40,12 +41,14 @@ class CustomLocalNode(node.LocalNode):
|
|||
runbook: CustomLocalNodeSchema,
|
||||
logger_name: str,
|
||||
base_log_path: Optional[Path] = None,
|
||||
parent_logger: Optional[Logger] = None,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
index=index,
|
||||
runbook=runbook,
|
||||
logger_name=logger_name,
|
||||
base_log_path=base_log_path,
|
||||
parent_logger=parent_logger,
|
||||
)
|
||||
self.custom_local_field = runbook.custom_local_field
|
||||
assert (
|
||||
|
@ -82,12 +85,14 @@ class CustomRemoteNode(node.RemoteNode):
|
|||
runbook: CustomRemoteNodeSchema,
|
||||
logger_name: str,
|
||||
base_log_path: Optional[Path] = None,
|
||||
parent_logger: Optional[Logger] = None,
|
||||
) -> None:
|
||||
super().__init__(
|
||||
index=index,
|
||||
runbook=runbook,
|
||||
logger_name=logger_name,
|
||||
base_log_path=base_log_path,
|
||||
parent_logger=parent_logger,
|
||||
)
|
||||
self.custom_remote_field = runbook.custom_remote_field
|
||||
assert (
|
||||
|
|
|
@ -91,9 +91,7 @@ class MockPlatform(Platform):
|
|||
if self._mock_runbook.return_prepared and environment.runbook.nodes_requirement:
|
||||
requirements = environment.runbook.nodes_requirement
|
||||
for node_space in requirements:
|
||||
environment.create_node_from_requirement(
|
||||
node_requirement=node_space, environment_name=environment.name
|
||||
)
|
||||
environment.create_node_from_requirement(node_requirement=node_space)
|
||||
for node in environment.nodes.list():
|
||||
node._is_initialized = True
|
||||
self.test_data.deployed_envs.append(environment.name)
|
||||
|
|
Загрузка…
Ссылка в новой задаче