Skip to content

Commit ecb0d50

Browse files
committed
usbstoragedriver: Allow to define a different waiting medium timeout
Nice to have a way to define a timeout for usb storage driver if it used after a usb switch. This will make this code more simpler mux_driver = target.get_driver('LXAUSBMuxDriver') mux_driver.set_links(['host-device']) time.sleep(3) <-- avoid to use a new sleep here usb = target.get_driver('USBStorageDriver') assert usb.get_size() > 0 Signed-off-by: Michael Trimarchi <[email protected]>
1 parent 0ba0f75 commit ecb0d50

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

labgrid/driver/usbstoragedriver.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,22 @@ class USBStorageDriver(Driver):
3939
"NetworkUSBSDWireDevice",
4040
},
4141
}
42+
4243
image = attr.ib(
4344
default=None,
4445
validator=attr.validators.optional(attr.validators.instance_of(str))
4546
)
46-
WAIT_FOR_MEDIUM_TIMEOUT = 10.0 # s
47+
timeout = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
48+
default=10.0,
49+
validator=attr.validators.instance_of(float))
50+
)
51+
4752
WAIT_FOR_MEDIUM_SLEEP = 0.5 # s
4853
MOUNT_RETRIES = 5
4954

5055
def __attrs_post_init__(self):
56+
if self.timeout < 0.0:
57+
raise ValueError("timeout must be positive")
5158
super().__attrs_post_init__()
5259
self.wrapper = None
5360
self.proxy = None
@@ -208,7 +215,7 @@ def _get_devpath(self, partition):
208215

209216
@Driver.check_active
210217
def _wait_for_medium(self, partition):
211-
timeout = Timeout(self.WAIT_FOR_MEDIUM_TIMEOUT)
218+
timeout = Timeout(self.timeout)
212219
while not timeout.expired:
213220
if self.get_size(partition) > 0:
214221
break

0 commit comments

Comments
 (0)