-
Notifications
You must be signed in to change notification settings - Fork 199
target: make _get_driver() prioritize drivers named "default" #1163
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
base: master
Are you sure you want to change the base?
target: make _get_driver() prioritize drivers named "default" #1163
Conversation
Implement the same behavior as get_resource() Signed-off-by: Nicolas Labriet <[email protected]>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## master #1163 +/- ##
========================================
- Coverage 62.7% 62.7% -0.1%
========================================
Files 156 159 +3
Lines 11628 11658 +30
========================================
+ Hits 7301 7317 +16
- Misses 4327 4341 +14
☔ View full report in Codecov by Sentry. |
Thanks for your contribution. Can you share an example where this PR simplifies your config and tell us about how your use case (labgrid-client, pytest, labgrid library usage?)? |
Sure! My boards each have a BeagleBone Black connected to emulate a USB key. My exporter configuration is:
I will create a python script to interact with the BeagleBones and will explicitly name the driver there. Without default, I always need to pass the
With this patch, I no longer need to pass the
I am considering extending the default to select the resources/drivers with no name. That will further simplify the environment file:
What do you think of this? Should it replace name = "default"? Also, the environment file supports List, but the exporter configuration doesn't I will probably look into this if you don't mind. |
Hm, I don't understand why the resource name needs to be set in the exporter configuration. I'd probably use something like..
..and use
I'd suggest using multiple targets in your environment config, describe every DUT and every BBB separately and create separate places for each device. You should still be able to use labgrid-client with this if you use the RemotePlace resource for each target. With this, you should not need to have multiple ModbusCoilDrivers and DigitalOutputPowerDrivers, right?
You mean unnamed resources should be the default? In #1112, we decided to make this explicit by naming the default resource "default".
What's your use case for list support in the exporter configuration? |
Right, I overlooked the
The thing is DUT and BBB are linked together and it might be error-prone if they are each a separate place. Also this will mean having a way to identify which BBB to acquire in my python script based on the acquired DUT.
OK, so no other change to this PR.
In my current setup (naming resources in the exporter), without list support I can't have 2 resources with the same name (like "default"). But I also have 2 NetworkSerialPort to manage. Thank you for your feedback! |
I changed my configuration to remove names from the exporter and set them in the coordinator with
I tested using the (name, class) tuple as key and it solves my issue. |
If you maintain a single DUT and its corresponding BBB per config file, you can use
That's a bug. My understanding is that you should be able to use a resource named "default" per resource class. Thanks for pointing this out. I've opened #1173 for this.
I haven't looked into the consequences of that change, but yeah, something along those lines. |
I am pretty happy with using drivers and resources names (I need this PR and the fix for #1173). It's convenient for a user and my provisioning script is clear. Thanks for your comments. |
I think I lost you somewhere in the discussion: Could you outline once again what this PR allows you to do, that does not work without it? |
It allows me to interact with my main board as if there were no other equipment using the same driver.
My environment file becomes (notice there is no binding on the first DigitalOutputPowerDriver, as the default
I have updated this PR with another test that may more clearly show how this is useful. |
With #1176, but without this PR the following is already possible: $ # place configuration
$ labgrid-client --place bst-test show
Place 'bst-test':
matches:
fixed/f-10/NetworkSerialPort -> default
fixed/f-15/NetworkSerialPort -> secondary
fixed/g-1/NetworkPowerPort -> default
fixed/g-2/NetworkPowerPort -> secondary
acquired: mymachine/bst
acquired resources:
fixed/f-10/NetworkSerialPort/NetworkSerialPort -> default
fixed/f-15/NetworkSerialPort/NetworkSerialPort -> secondary
fixed/g-1/NetworkPowerPort/NetworkPowerPort -> default
fixed/g-2/NetworkPowerPort/NetworkPowerPort -> secondary
created: 2023-01-20 13:57:20.318184
changed: 2023-05-12 14:18:53.294179
Acquired resource 'default' (fixed/f-10/NetworkSerialPort/NetworkSerialPort):
{'acquired': 'bst-test',
'avail': True,
'cls': 'NetworkSerialPort',
'params': {'extra': {'proxy': 'labgrid1',
'proxy_required': False},
'host': 'moxa1',
'port': 4010}}
Acquired resource 'secondary' (fixed/f-15/NetworkSerialPort/NetworkSerialPort):
{'acquired': 'bst-test',
'avail': True,
'cls': 'NetworkSerialPort',
'params': {'extra': {'proxy': 'labgrid1',
'proxy_required': False},
'host': 'moxa1',
'port': 4015}}
Acquired resource 'default' (fixed/g-1/NetworkPowerPort/NetworkPowerPort):
{'acquired': 'bst-test',
'avail': True,
'cls': 'NetworkPowerPort',
'params': {'extra': {'proxy': 'labgrid1',
'proxy_required': False},
'host': 'netio11',
'index': 1,
'model': 'netio'}}
Acquired resource 'secondary' (fixed/g-2/NetworkPowerPort/NetworkPowerPort):
{'acquired': 'bst-test',
'avail': True,
'cls': 'NetworkPowerPort',
'params': {'extra': {'proxy': 'labgrid1',
'proxy_required': False},
'host': 'netio11',
'index': 2,
'model': 'netio'}}
$ # environment config
$ cat env.yaml
targets:
main:
resources:
RemotePlace:
name: "bst-test"
drivers:
- NetworkPowerDriver:
bindings:
port: default
- NetworkPowerDriver:
bindings:
port: secondary
- SerialDriver:
bindings:
port: default
- SerialDriver:
bindings:
port: secondary
$ # switch power of "default" and "secondary" power resources
$ labgrid-client --place bst-test --config env.yaml power on
$ labgrid-client --place bst-test --config env.yaml power on --name secondary
$ # connect to serial console of "default" and "secondary" serial resources
$ labgrid-client --place bst-test --config env.yaml console
$ labgrid-client --place bst-test --config env.yaml console secondary I don't really see how omitting the binding (and thereby leaving the resource-driver relation implicit) makes things simpler. Am I missing something? |
Yes, he is using the |
Right, I didn't get it, but the issue I faced was that
I agree, the driver-driver relation can be implicit, but it doesn't hurt to keep the binding to default. I will update the test_environment test accordingly. |
Signed-off-by: Nicolas Labriet <[email protected]>
c345c21
to
3d6b03f
Compare
Well, it's actually more complicated. When using the library (like it is in the tests), only |
We already have some implicit behavior in the driver selection:
This behavior is useful, as it allows overriding a fallback implementation (i.e. reset via power cycle) with a better/more specific driver. When looking at default handling, it is relatively clear what should happen when requesting a specific class, instead of a protocol, as all of them have the same priorities. It's much less clear when you request a protocol for which multiple active drivers exist, possibly with different priorities or activation states. So as long as we don't have a clear description of expected behavior for these complex cases, which also matches the intuition, I'm against adding more implicit driver selection. For complex place setups, I'd instead prefer to have an explicit configuration, even if it's more verbose. One aspect of your issue is that Taking a step back, I think your configs would be a lot simpler if you had separate places for the DUT and your BBB, as this avoids the underlying cause for having multiple resources and drivers of the same classes. In the simplest case, these places could just have the same place name prefix to indicate that they belong together. That's also what we have done in the few cases where a test setup involved multiple devices. In the future, if this is a common case, we could think about how relationships between places could be described in the coordinator (perhaps tags, perhaps a special property for linking places). |
Right, in my case and to follow Bastian-Krause example, I will need to have a
I think we misunderstood each other on this. I am always using an environment file, I use the But I don't have the broader picture and hopefully we can discuss it here so I get a better understanding. As pointed out, I will create places for the BBB, it's less practical for my team (as now acquiring a BBB can fail, even if the board is acquired), but makes the coordinator configuration and environment file clearer by separating the DUT from these on-the-side hardware.
Place relationships could help, but a prefix seems enough for me right now. Thanks |
Description
Implement the same behavior as
get_resource()
This make writing configuration files easier when having multiple drivers.
I updated the tests and they run OK. I my setup this feature runs as expected.
Checklist
In doc/configuration.rst
Tests updated
I added a description of the "default" value for the name property
No impact on man pages