Skip to content

Commit f209948

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 f209948

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

labgrid/driver/usbstoragedriver.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,26 @@ class USBStorageDriver(Driver):
3939
"NetworkUSBSDWireDevice",
4040
},
4141
}
42+
43+
def __attrs_post_init__(self):
44+
super().__attrs_post_init__()
45+
self._expect = PtxExpect(self)
46+
4247
image = attr.ib(
4348
default=None,
4449
validator=attr.validators.optional(attr.validators.instance_of(str))
4550
)
46-
WAIT_FOR_MEDIUM_TIMEOUT = 10.0 # s
51+
timeout = attr.ib(default=0.0, validator=attr.validators.instance_of(float))
52+
default=10.0,
53+
validator=attr.validators.instance_of(float))
54+
)
55+
4756
WAIT_FOR_MEDIUM_SLEEP = 0.5 # s
4857
MOUNT_RETRIES = 5
4958

5059
def __attrs_post_init__(self):
60+
if self.timeout < 0.0:
61+
raise ValueError("timeout must be positive")
5162
super().__attrs_post_init__()
5263
self.wrapper = None
5364
self.proxy = None
@@ -208,7 +219,7 @@ def _get_devpath(self, partition):
208219

209220
@Driver.check_active
210221
def _wait_for_medium(self, partition):
211-
timeout = Timeout(self.WAIT_FOR_MEDIUM_TIMEOUT)
222+
timeout = Timeout(self.timeout)
212223
while not timeout.expired:
213224
if self.get_size(partition) > 0:
214225
break

0 commit comments

Comments
 (0)