labgrid icon indicating copy to clipboard operation
labgrid copied to clipboard

Drivers name and binding from env file are not taken into consideration

Open ElenaGrigore opened this issue 4 years ago • 1 comments

Hi,

I was reading the docs and the examples , but maybe I missed something. Are the name and bindings options from drivers sections taken into consideration at target creation ? Or the comment from target.py bind_driver " Currently, we only support binding all suppliers at once." means just that: all the resources/drivers of that type will be matched ignoring name and binding ?

My case is that I want to have a SerialDriver for the board itself and a SerialDriver for a controller that is linked to that board (this second one will be part of a PowerDriver, but now is just its serial that I'am interested in ). Also I configured for this board to have multiple consoles available.

Board resources:

(venv) testlabgrid@<workstation-hostname>:~/test-bindings/labgrid-tests$ labgrid-client -p DESK--MX8QM_mek--1 show
Place 'DESK--MX8QM_mek--1':
  comment: temporary-ghost-board
  matches:
    <workstation-hostname>/DESK--MX8QM_mek--1/*
    <workstation-hostname>/DESK--MX8QM_mek--1-console-0/NetworkSerialPort -> 0
    <workstation-hostname>/DESK--MX8QM_mek--1-console-1/NetworkSerialPort -> 1
    <workstation-hostname>/DESK--MX8QM_mek--1-console-2/NetworkSerialPort -> 2
    <workstation-hostname>/DESK--MX8QM_mek--1-console-3/NetworkSerialPort -> 3
  acquired: <workstation-hostname>/testlabgrid
  acquired resources:
    <workstation-hostname>/DESK--MX8QM_mek--1/NetworkSerialPort/ControllerPort
    <workstation-hostname>/DESK--MX8QM_mek--1/NetworkSerialPort/USBSerialPort
    <workstation-hostname>/DESK--MX8QM_mek--1/NetworkService/NetworkService
    <workstation-hostname>/DESK--MX8QM_mek--1-console-0/NetworkSerialPort/USBSerialPort -> 0
    <workstation-hostname>/DESK--MX8QM_mek--1-console-1/NetworkSerialPort/USBSerialPort -> 1
    <workstation-hostname>/DESK--MX8QM_mek--1-console-2/NetworkSerialPort/USBSerialPort -> 2
    <workstation-hostname>/DESK--MX8QM_mek--1-console-3/NetworkSerialPort/USBSerialPort -> 3
  created: 2020-07-08 15:59:13.247768
  changed: 2020-07-13 18:22:18.416482
Acquired resource 'ControllerPort' (<workstation-hostname>/DESK--MX8QM_mek--1/NetworkSerialPort/ControllerPort):
  {'acquired': 'DESK--MX8QM_mek--1',
   'avail': True,
   'cls': 'NetworkSerialPort',
   'params': {'extra': {'path': '/dev/ttyUSB0',
                        'proxy': '<workstation-hostname>',
                        'proxy_required': False},
              'host': '<workstation-hostname>.domain.net',
              'port': 55793}}
Acquired resource 'USBSerialPort' (<workstation-hostname>/DESK--MX8QM_mek--1/NetworkSerialPort/USBSerialPort):
  {'acquired': 'DESK--MX8QM_mek--1',
   'avail': True,
   'cls': 'NetworkSerialPort',
   'params': {'extra': {'path': '/dev/ttyUSB1',
                        'proxy': '<workstation-hostname>',
                        'proxy_required': False},
              'host': '<workstation-hostname>.domain.net',
              'port': 58474}}
Acquired resource 'NetworkService' (<workstation-hostname>/DESK--MX8QM_mek--1/NetworkService/NetworkService):
  {'acquired': 'DESK--MX8QM_mek--1',
   'avail': True,
   'cls': 'NetworkService',
   'params': {'address': '192.168.99.55', 'username': 'bamboo'}}
Acquired resource '0' (<workstation-hostname>/DESK--MX8QM_mek--1-console-0/NetworkSerialPort/USBSerialPort):
  {'acquired': 'DESK--MX8QM_mek--1',
   'avail': True,
   'cls': 'NetworkSerialPort',
   'params': {'extra': {'path': '/dev/ttyUSB1',
                        'proxy': '<workstation-hostname>',
                        'proxy_required': False},
              'host': '<workstation-hostname>.domain.net',
              'port': 47004}}
Acquired resource '1' (<workstation-hostname>/DESK--MX8QM_mek--1-console-1/NetworkSerialPort/USBSerialPort):
  {'acquired': 'DESK--MX8QM_mek--1',
   'avail': True,
   'cls': 'NetworkSerialPort',
   'params': {'extra': {'path': '/dev/ttyUSB2',
                        'proxy': '<workstation-hostname>',
                        'proxy_required': False},
              'host': '<workstation-hostname>.domain.net',
              'port': 54307}}
Acquired resource '2' (<workstation-hostname>/DESK--MX8QM_mek--1-console-2/NetworkSerialPort/USBSerialPort):
  {'acquired': 'DESK--MX8QM_mek--1',
   'avail': True,
   'cls': 'NetworkSerialPort',
   'params': {'extra': {'path': '/dev/ttyUSB3',
                        'proxy': '<workstation-hostname>',
                        'proxy_required': False},
              'host': '<workstation-hostname>.domain.net',
              'port': 60409}}
Acquired resource '3' (<workstation-hostname>/DESK--MX8QM_mek--1-console-3/NetworkSerialPort/USBSerialPort):
  {'acquired': 'DESK--MX8QM_mek--1',
   'avail': True,
   'cls': 'NetworkSerialPort',
   'params': {'extra': {'path': '/dev/ttyUSB4',
                        'proxy': '<workstation-hostname>',
                        'proxy_required': False},
              'host': '<workstation-hostname>.domain.net',
              'port': 52541}}

Environment file - I tried to assign name and bindings to every driver, to avoid confusion:

(venv) testlabgrid@<workstation-hostname>:~/test-bindings/labgrid-tests$ cat labgrid-config/boards/DESK--MX8QM_mek--1_remote.yaml
features:
 - console
 - network
 - baseboard
 - CPU
 - recipe B
 - CAN
 - bt-wifi
 - MURATA
 - audiocard
 - display
 - LVDS-HDMI
 - MIPI-DSI
 - camera
 - CSI-OV5640
targets:
  main:
    resources:
      RemotePlace:
        name: 'DESK--MX8QM_mek--1'
    drivers:
      SerialDriver:
        name: 'ControllerSerial'
        bindings: { port : 'ControllerPort'}
      UUUDriver:
        image: 'cmd_file'
      SerialDriver:
        name: 'BoardSerial'
        bindings: { port : 'USBSerialPort'}
      ShellDriver:
        bindings: { console: 'BoardSerial'}
        prompt: 'root@\w+:[^ ]+ '
        login_prompt: ' login: '
        username: 'root'
      UUUDriver: {}
      UUUStrategy: {}
tools:
    uuu: "/tftpboot/uuu-DESK--MX8QM_mek--1"
images:
    cmd_file: "DESK--MX8QM_mek--1_cmd.txt"
imports:
- ../../uuustrategy.py
options:
    nfs_server: '192.168.99.55'
    tftp_dir: '/tftpboot'
    nfs_dir: '/nfsroot'
    emmc: '80'
    sd: '30'
    qspi: '18'
    usb: '20'

Trying to access a function from labgrid-client that uses target = self._get_target(place) which with a configuration file as parameter will access self.env.get_target(self.role) (where self.role is "main" in this case) it will fail, first with multiple resources of the same type (NetworkSerialPort) and then (if a create one of the SerialDrivers outside the env file) it will fail with multiple drivers matching ConsoleProtocol.

(venv) testlabgrid@<workstation-hostname>:~/test-bindings/labgrid-tests$ labgrid-client -p DESK--MX8QM_mek--1 -c labgrid-config/boards/DESK--MX8QM_mek--1_remote.yaml  power on
Selected role main from configuration file
Traceback (most recent call last):
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/remote/client.py", line 1930, in main
    args.func(session)
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/remote/client.py", line 699, in power
    target = self._get_target(place)
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/remote/client.py", line 677, in _get_target
    target = self.env.get_target(self.role)
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/environment.py", line 48, in get_target
    target = target_factory.make_target(role, config, env=self)
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/factory.py", line 152, in make_target
    self.make_driver(target, driver, name, args)
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/factory.py", line 130, in make_driver
    d = cls(target, name, **args)
  File "<attrs generated init labgrid.driver.serialdriver.SerialDriver>", line 9, in __init__
    self.__attrs_post_init__()
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/driver/serialdriver.py", line 39, in __attrs_post_init__
    super().__attrs_post_init__()
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/driver/consoleexpectmixin.py", line 17, in __attrs_post_init__
    super().__attrs_post_init__()
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/driver/common.py", line 24, in __attrs_post_init__
    super().__attrs_post_init__()
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/binding.py", line 54, in __attrs_post_init__
    target.bind(self)
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/target.py", line 396, in bind
    return self.bind_driver(bindable)
  File "/home/testlabgrid/test-bindings/labgrid-tests/venv/lib/python3.5/site-packages/labgrid-0.0.0-py3.5.egg/labgrid/target.py", line 347, in bind_driver
    requirements=requirements, target=self, errors=errors)
labgrid.exceptions.NoSupplierFoundError: no supplier matching {'SerialPort', 'NetworkSerialPort'} found in Target(name='main', env=Environment(config_file='labgrid-config/boards/DESK--MX8QM_mek--1_remote.yaml')) (errors: [NoResourceFoundError(msg="no <class 'labgrid.resource.base.SerialPort'> resource found in Target(name='main', env=Environment(config_file='labgrid-config/boards/DESK--MX8QM_mek--1_remote.yaml'))", filter=None), NoResourceFoundError(msg="multiple resources matching <class 'labgrid.resource.serialport.NetworkSerialPort'> found in Target(name='main', env=Environment(config_file='labgrid-config/boards/DESK--MX8QM_mek--1_remote.yaml'))", filter=None)])

ElenaGrigore avatar Jul 16 '20 12:07 ElenaGrigore

Looking at the resources for the remoteplace:

    <workstation-hostname>/DESK--MX8QM_mek--1/NetworkSerialPort/ControllerPort
    <workstation-hostname>/DESK--MX8QM_mek--1/NetworkSerialPort/USBSerialPort
    <workstation-hostname>/DESK--MX8QM_mek--1/NetworkService/NetworkService
    <workstation-hostname>/DESK--MX8QM_mek--1-console-0/NetworkSerialPort/USBSerialPort -> 0
    <workstation-hostname>/DESK--MX8QM_mek--1-console-1/NetworkSerialPort/USBSerialPort -> 1
    <workstation-hostname>/DESK--MX8QM_mek--1-console-2/NetworkSerialPort/USBSerialPort -> 2
    <workstation-hostname>/DESK--MX8QM_mek--1-console-3/NetworkSerialPort/USBSerialPort -> 3

You have six NetworkSerialPorts available, of which four are set up with add-named-match and are thus resolvable by the named binding mechanism. However these two:

    <workstation-hostname>/DESK--MX8QM_mek--1/NetworkSerialPort/ControllerPort
    <workstation-hostname>/DESK--MX8QM_mek--1/NetworkSerialPort/USBSerialPort

do not have a named binding setup. You'll need to remove the * match and setup separate named bindings for each port. The ControllerPort is also none standard and not supported by upstream Labgrid, why did you add this new resource?

Emantor avatar Oct 26 '20 07:10 Emantor