This repository was archived by the owner on Dec 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +56
-3
lines changed Expand file tree Collapse file tree 5 files changed +56
-3
lines changed Original file line number Diff line number Diff line change @@ -317,9 +317,10 @@ def _reboot_sut(self, force: bool = False) -> None:
317
317
else :
318
318
self ._sut .stop (timeout = 360 )
319
319
320
- self ._sut .communicate (
320
+ self ._sut .ensure_communicate (
321
321
timeout = 3600 ,
322
- iobuffer = RedirectStdout (self ._sut ))
322
+ iobuffer = RedirectStdout (self ._sut ),
323
+ force = force )
323
324
324
325
self ._logger .info ("SUT rebooted" )
325
326
Original file line number Diff line number Diff line change @@ -495,7 +495,10 @@ def communicate(
495
495
self ._wait_for ("Password:" , 5 , iobuffer )
496
496
self ._write_stdin (f"{ self ._password } \n " )
497
497
498
+ time .sleep (0.2 )
499
+
498
500
self ._wait_for ("#" , 5 , iobuffer )
501
+ time .sleep (0.2 )
499
502
500
503
self ._write_stdin ("stty -echo; stty cols 1024\n " )
501
504
self ._wait_for ("#" , 5 , None )
Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ def _start_sut(
185
185
186
186
ltp .events .fire ("sut_start" , sut .name )
187
187
188
- sut .communicate (
188
+ sut .ensure_communicate (
189
189
timeout = 3600 ,
190
190
iobuffer = Printer (sut , False ))
191
191
Original file line number Diff line number Diff line change @@ -186,6 +186,44 @@ def fetch_file(
186
186
"""
187
187
raise NotImplementedError ()
188
188
189
+ def ensure_communicate (
190
+ self ,
191
+ timeout : float = 3600 ,
192
+ iobuffer : IOBuffer = None ,
193
+ retries : int = 10 ,
194
+ force : bool = False ) -> None :
195
+ """
196
+ Ensure that `communicate` is completed, retrying as many times we
197
+ want in case of `LTPException` error. After each `communicate` error
198
+ the SUT is stopped and a new communication is tried.
199
+ :param timeout: timeout to complete communication in seconds
200
+ :type timeout: float
201
+ :param iobuffer: buffer used to write SUT stdout
202
+ :type iobuffer: IOBuffer
203
+ :param retries: number of times we retry communicating with SUT
204
+ :type retries: int
205
+ :param force: use `force_stop` instead of `stop` before communicating
206
+ again with the SUT
207
+ :type force: bool
208
+ """
209
+ retries = max (retries , 1 )
210
+
211
+ for retry in range (retries ):
212
+ try :
213
+ self .communicate (
214
+ timeout = timeout ,
215
+ iobuffer = iobuffer )
216
+
217
+ break
218
+ except LTPException as err :
219
+ if retry >= retries - 1 :
220
+ raise err
221
+
222
+ if force :
223
+ self .force_stop (timeout = timeout , iobuffer = iobuffer )
224
+ else :
225
+ self .stop (timeout = timeout , iobuffer = iobuffer )
226
+
189
227
def get_info (self ) -> dict :
190
228
"""
191
229
Return SUT information.
Original file line number Diff line number Diff line change @@ -90,6 +90,17 @@ def test_communicate(self, sut):
90
90
sut .communicate (iobuffer = Printer ())
91
91
sut .stop ()
92
92
93
+ def test_ensure_communicate (self , sut ):
94
+ """
95
+ Test ensure_communicate method.
96
+ """
97
+ sut .ensure_communicate (iobuffer = Printer ())
98
+ with pytest .raises (SUTError ):
99
+ sut .ensure_communicate (iobuffer = Printer (), retries = 1 )
100
+
101
+ sut .ensure_communicate (iobuffer = Printer (), retries = 10 )
102
+ sut .stop ()
103
+
93
104
@pytest .fixture
94
105
def sut_stop_sleep (self , request ):
95
106
"""
You can’t perform that action at this time.
0 commit comments