Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver/resources: use consistent logger names #1293

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1b93339
driver/common: add logger to Driver base class
Bastian-Krause Jul 28, 2023
a387ffe
driver/bareboxdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
0f4136f
driver/dediprogflashdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
aab1536
driver/dockerdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
6a21f77
driver/externalconsoledriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
8ba8345
driver/fake: use logger from Driver base class
Bastian-Krause Jul 28, 2023
e422eda
driver/flashromdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
36a19d8
driver/flashscriptdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
15195fc
driver/openocddriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
42aa9c2
driver/qemudriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
4667eed
driver/quartushpsdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
c776c61
driver/serialdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
f2aba57
driver/shelldriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
1b99825
driver/sigrokdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
2d5fb2d
driver/sshdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
0e34328
driver/ubootdriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
932b991
driver/usbaudiodriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
57e5e08
driver/usbstoragedriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
e41f684
driver/usbvideodriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
7edac83
driver/xenadriver: use logger from Driver base class
Bastian-Krause Jul 28, 2023
96bbe61
resource/common: add logger to Resource/ResourceManager
Bastian-Krause Jul 28, 2023
7600343
resource/docker: use logger from Resource(Manager)
Bastian-Krause Jul 28, 2023
71c5589
resource/ethernetport: use logger from ResourceManager
Bastian-Krause Jul 28, 2023
be3cc7e
resource/lxaiobus: use logger from ResourceManager
Bastian-Krause Jul 28, 2023
26dffe4
resource/mqtt: use logger from ResourceManager
Bastian-Krause Jul 28, 2023
ee2cfbe
resource/remote: use logger from ResourceManager
Bastian-Krause Jul 28, 2023
3d156a1
resource/udev: use logger from ResourceManager
Bastian-Krause Jul 28, 2023
2a095c2
util/qmp: drop colon from logger name
Bastian-Krause Jul 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions labgrid/driver/bareboxdriver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import shlex

import attr
Expand Down Expand Up @@ -40,7 +39,6 @@ class BareboxDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}:{self.target}")
self._status = 0
# barebox' default log level, used as fallback if no log level can be saved
self.saved_log_level = 7
Expand Down
6 changes: 6 additions & 0 deletions labgrid/driver/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import subprocess
import attr

Expand Down Expand Up @@ -25,6 +26,11 @@ def __attrs_post_init__(self):
if self.target is None:
raise BindingError("Drivers can only be created on a valid target")

logger_name = f"{self.__class__.__name__}({self.target.name})"
if self.name:
logger_name += f":{self.name}"
self.logger = logging.getLogger(logger_name)

def get_priority(self, protocol):
"""Retrieve the priority for a given protocol

Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/dediprogflashdriver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os.path
import logging
import attr

from ..resource import NetworkDediprogFlasher
Expand All @@ -24,7 +23,6 @@ class DediprogFlashDriver(Driver):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f'{self}')
if self.target.env:
self.tool = self.target.env.config.get_tool('dpcmd')
else:
Expand Down
4 changes: 0 additions & 4 deletions labgrid/driver/dockerdriver.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
Class for connecting to a docker daemon running on the host machine.
"""

import logging

import attr

from labgrid.factory import target_factory
Expand Down Expand Up @@ -62,7 +59,6 @@ class DockerDriver(PowerProtocol, Driver):
attr.validators.instance_of(list)))

def __attrs_post_init__(self):
self.logger = logging.getLogger(f"{self}({self.target})")
super().__attrs_post_init__()
self._client = None
self._container = None
Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/externalconsoledriver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fcntl
import logging
import os
import select
import shlex
Expand All @@ -25,7 +24,6 @@ class ExternalConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}({self.target})")
self.status = 0
self._child = None

Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/fake.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# pylint: disable=arguments-differ
import logging
import re

import attr
Expand All @@ -18,7 +17,6 @@ class FakeConsoleDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}({self.target})")
self.rxq = []
self.txq = []

Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/flashromdriver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os.path
import logging
import attr

from ..resource import NetworkFlashrom
Expand All @@ -24,7 +23,6 @@ class FlashromDriver(Driver, BootstrapProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f'{self}')
if self.target.env:
self.tool = self.target.env.config.get_tool('flashrom')
else:
Expand Down
5 changes: 0 additions & 5 deletions labgrid/driver/flashscriptdriver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import attr

from ..factory import target_factory
Expand Down Expand Up @@ -27,10 +26,6 @@ class FlashScriptDriver(Driver):
validator=attr.validators.optional(attr.validators.instance_of(list)),
)

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}:{self.target}")

def on_activate(self):
pass

Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/openocddriver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
from itertools import chain
import attr

Expand Down Expand Up @@ -47,7 +46,6 @@ class OpenOCDDriver(Driver, BootstrapProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}:{self.target}")

# FIXME make sure we always have an environment or config
if self.target.env:
Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/qemudriver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""The QEMUDriver implements a driver to use a QEMU target"""
import atexit
import logging
import select
import shlex
import shutil
Expand Down Expand Up @@ -89,7 +88,6 @@ class QEMUDriver(ConsoleExpectMixin, Driver, PowerProtocol, ConsoleProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}:")
self.status = 0
self.txdelay = None
self._child = None
Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/quartushpsdriver.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import subprocess
import re
import time
import logging

import attr

Expand All @@ -28,7 +27,6 @@ class QuartusHPSDriver(Driver):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}({self.target})")

# FIXME make sure we always have an environment or config
if self.target.env:
Expand Down
3 changes: 0 additions & 3 deletions labgrid/driver/serialdriver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

import attr
from pexpect import TIMEOUT
import serial
Expand All @@ -26,7 +24,6 @@ class SerialDriver(ConsoleExpectMixin, Driver, ConsoleProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}({self.target})")
if isinstance(self.port, SerialPort):
self.serial = serial.Serial()
else:
Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/shelldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""The ShellDriver provides the CommandProtocol, ConsoleProtocol and
InfoProtocol on top of a SerialPort."""
import io
import logging
import re
import shlex
import ipaddress
Expand Down Expand Up @@ -58,7 +57,6 @@ class ShellDriver(CommandMixin, Driver, CommandProtocol, FileTransferProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}:{self.target}")
self._status = 0

self._xmodem_cached_rx_cmd = ""
Expand Down
26 changes: 12 additions & 14 deletions labgrid/driver/sigrokdriver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import os.path
import re
import subprocess
Expand Down Expand Up @@ -37,7 +36,6 @@ def __attrs_post_init__(self):
) or 'sigrok-cli'
else:
self.tool = 'sigrok-cli'
self.log = logging.getLogger("SigrokDriver")
self._running = False

def _create_tmpdir(self):
Expand All @@ -46,26 +44,26 @@ def _create_tmpdir(self):
command = self.sigrok.command_prefix + [
'mkdir', '-p', self._tmpdir
]
self.log.debug("Tmpdir command: %s", command)
self.logger.debug("Tmpdir command: %s", command)
subprocess.call(
command,
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
self.log.debug("Created tmpdir: %s", self._tmpdir)
self.logger.debug("Created tmpdir: %s", self._tmpdir)
self._local_tmpdir = tempfile.mkdtemp(prefix="labgrid-sigrok-")
self.log.debug("Created local tmpdir: %s", self._local_tmpdir)
self.logger.debug("Created local tmpdir: %s", self._local_tmpdir)
else:
self._tmpdir = tempfile.mkdtemp(prefix="labgrid-sigrok-")
self.log.debug("created tmpdir: %s", self._tmpdir)
self.logger.debug("created tmpdir: %s", self._tmpdir)

def _delete_tmpdir(self):
if isinstance(self.sigrok, NetworkSigrokUSBDevice):
command = self.sigrok.command_prefix + [
'rm', '-r', self._tmpdir
]
self.log.debug("Tmpdir command: %s", command)
self.logger.debug("Tmpdir command: %s", command)
subprocess.call(
command,
stdin=subprocess.DEVNULL,
Expand Down Expand Up @@ -98,7 +96,7 @@ def _get_sigrok_prefix(self):
@step(title='call', args=['args'])
def _call_with_driver(self, *args):
combined = self._get_sigrok_prefix() + list(args)
self.log.debug("Combined command: %s", " ".join(combined))
self.logger.debug("Combined command: %s", " ".join(combined))
self._process = subprocess.Popen(
combined,
stdout=subprocess.PIPE,
Expand All @@ -113,7 +111,7 @@ def _call(self, *args):
if self.sigrok.channels:
combined += ["-C", self.sigrok.channels]
combined += list(args)
self.log.debug("Combined command: %s", combined)
self.logger.debug("Combined command: %s", combined)
self._process = subprocess.Popen(
combined,
stdout=subprocess.PIPE,
Expand All @@ -138,7 +136,7 @@ class SigrokDriver(SigrokCommon):
def capture(self, filename, samplerate="200k"):
self._filename = filename
self._basename = os.path.basename(self._filename)
self.log.debug(
self.logger.debug(
"Saving to: %s with basename: %s", self._filename, self._basename
)
cmd = [
Expand Down Expand Up @@ -166,7 +164,7 @@ def stop(self):
self._process.send_signal(signal.SIGINT)
stdout, stderr = self._process.communicate()
self._process.wait()
self.log.debug("stdout:\n %s\n ----- \n stderr:\n %s", stdout, stderr)
self.logger.debug("stdout:\n %s\n ----- \n stderr:\n %s", stdout, stderr)

# Convert from .sr to .csv
cmd = [
Expand All @@ -177,7 +175,7 @@ def stop(self):
self._call(*cmd)
self._process.wait()
stdout, stderr = self._process.communicate()
self.log.debug("stdout:\n %s\n ----- \n stderr:\n %s", stdout, stderr)
self.logger.debug("stdout:\n %s\n ----- \n stderr:\n %s", stdout, stderr)
if isinstance(self.sigrok, NetworkSigrokUSBDevice):
subprocess.call([
'scp', f'{self.sigrok.host}:{os.path.join(self._tmpdir, self._basename)}',
Expand Down Expand Up @@ -411,7 +409,7 @@ def stop(self):
time.sleep(0.1)
else:
# process did not finish in time
self.log.info("sigrok-cli did not finish in time, increase timeout?")
self.logger.info("sigrok-cli did not finish in time, increase timeout?")
self._process.kill()

res = []
Expand All @@ -428,7 +426,7 @@ def stop(self):
# all other lines are actual values
res.append(float(line))
_, stderr = self._process.communicate()
self.log.debug("stderr: %s", stderr)
self.logger.debug("stderr: %s", stderr)

self._running = False
return unit, res
Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/sshdriver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""The SSHDriver uses SSH as a transport to implement CommandProtocol and FileTransferProtocol"""
import contextlib
import logging
import os
import re
import stat
Expand Down Expand Up @@ -39,7 +38,6 @@ class SSHDriver(CommandMixin, Driver, CommandProtocol, FileTransferProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}({self.target})")
self._keepalive = None

def on_activate(self):
Expand Down
3 changes: 0 additions & 3 deletions labgrid/driver/ubootdriver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""The U-Boot Module contains the UBootDriver"""
import logging

import attr
from pexpect import TIMEOUT

Expand Down Expand Up @@ -48,7 +46,6 @@ class UBootDriver(CommandMixin, Driver, CommandProtocol, LinuxBootProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}:{self.target}")
self._status = 0

if self.boot_expression:
Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/usbaudiodriver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import subprocess
import attr

Expand Down Expand Up @@ -28,7 +27,6 @@ class USBAudioInputDriver(Driver):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}")
self._prepared = False

def _get_pipeline(self):
Expand Down
5 changes: 0 additions & 5 deletions labgrid/driver/usbstoragedriver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import enum
import logging
import os
import time
import subprocess
Expand Down Expand Up @@ -42,10 +41,6 @@ class USBStorageDriver(Driver):
validator=attr.validators.optional(attr.validators.instance_of(str))
)

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}:{self.target}")

def on_activate(self):
pass

Expand Down
2 changes: 0 additions & 2 deletions labgrid/driver/usbvideodriver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
import subprocess

import attr
Expand All @@ -18,7 +17,6 @@ class USBVideoDriver(Driver, VideoProtocol):

def __attrs_post_init__(self):
super().__attrs_post_init__()
self.logger = logging.getLogger(f"{self}")
self._prepared = False

def get_qualities(self):
Expand Down
4 changes: 1 addition & 3 deletions labgrid/driver/xenadriver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import logging
from importlib import import_module
import attr

Expand All @@ -17,11 +16,10 @@ def __attrs_post_init__(self):
super().__attrs_post_init__()
self._xena_app = import_module('xenavalkyrie.xena_app')
self._tgn_utils = import_module('trafficgenerator.tgn_utils')
self._logger = logging.getLogger(f"{self}")
self._xm = None

def on_activate(self):
self._xm = self._xena_app.init_xena(self._tgn_utils.ApiType.socket, self._logger, 'labgrid')
self._xm = self._xena_app.init_xena(self._tgn_utils.ApiType.socket, self.logger, 'labgrid')
self._xm.session.add_chassis(self.xena_manager.hostname)

def on_deactivate(self):
Expand Down
Loading