Skip to content

Commit 75767cd

Browse files
committed
driver: rawnetworkinterfacedriver: Add managed attribute
Adds an attribute that controls if the driver fully manages the network interface, which causes it to setup and teardown the interface on activate and deactivate. This allows users to disable this behavior if they are externally managing the interface. Closes: #1728 Signed-off-by: Joshua Watt <[email protected]>
1 parent e9e43aa commit 75767cd

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

doc/configuration.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3393,7 +3393,9 @@ network interface to the user, including:
33933393
Address Autoconfiguration) and Neighbor Discovery
33943394
- disabling Generic Receive Offload (GRO)
33953395

3396-
This might change in the future.
3396+
This might change in the future. If you do not want the driver to automatically
3397+
manage the interface (e.g. you are managing it externally), set
3398+
``manage_interface`` to ``False``.
33973399

33983400
Binds to:
33993401
iface:
@@ -3405,7 +3407,9 @@ Implements:
34053407
- None yet
34063408

34073409
Arguments:
3408-
- None
3410+
- manage_interface (bool): optional, if True this driver will
3411+
setup/teardown the interface on activate/deactivate. Set this to
3412+
False if you are managing the interface externally.
34093413

34103414
.. _conf-strategies:
34113415

labgrid/driver/rawnetworkinterfacedriver.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,34 @@
1818
@target_factory.reg_driver
1919
@attr.s(eq=False)
2020
class RawNetworkInterfaceDriver(Driver):
21+
"""RawNetworkInterface - Manage a network interface and interact with it at a low level
22+
RawNetworkInterface binds to a NetworkInterface, RemoteNetworkInterface, or USBNetworkInterface
23+
24+
Args:
25+
manage_interface (bool): optional, if True this driver will
26+
setup/teardown the interface on activate/deactivate. Set this to
27+
False if you are managing the interface externally.
28+
"""
29+
2130
bindings = {
2231
"iface": {"NetworkInterface", "RemoteNetworkInterface", "USBNetworkInterface"},
2332
}
33+
manage_interface = attr.ib(default=True, validator=attr.validators.instance_of(bool))
2434

2535
def __attrs_post_init__(self):
2636
super().__attrs_post_init__()
2737
self._record_handle = None
2838
self._replay_handle = None
2939

3040
def on_activate(self):
31-
self._set_interface("up")
32-
self._wait_state("up")
41+
if self.manage_inteface:
42+
self._set_interface("up")
43+
self._wait_state("up")
3344

3445
def on_deactivate(self):
35-
self._set_interface("down")
36-
self._wait_state("down")
46+
if self.manage_interface:
47+
self._set_interface("down")
48+
self._wait_state("down")
3749

3850
def _wrap_command(self, args):
3951
wrapper = ["sudo", "labgrid-raw-interface"]

0 commit comments

Comments
 (0)