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:
317317 else :
318318 self ._sut .stop (timeout = 360 )
319319
320- self ._sut .communicate (
320+ self ._sut .ensure_communicate (
321321 timeout = 3600 ,
322- iobuffer = RedirectStdout (self ._sut ))
322+ iobuffer = RedirectStdout (self ._sut ),
323+ force = force )
323324
324325 self ._logger .info ("SUT rebooted" )
325326
Original file line number Diff line number Diff line change @@ -495,7 +495,10 @@ def communicate(
495495 self ._wait_for ("Password:" , 5 , iobuffer )
496496 self ._write_stdin (f"{ self ._password } \n " )
497497
498+ time .sleep (0.2 )
499+
498500 self ._wait_for ("#" , 5 , iobuffer )
501+ time .sleep (0.2 )
499502
500503 self ._write_stdin ("stty -echo; stty cols 1024\n " )
501504 self ._wait_for ("#" , 5 , None )
Original file line number Diff line number Diff line change @@ -185,7 +185,7 @@ def _start_sut(
185185
186186 ltp .events .fire ("sut_start" , sut .name )
187187
188- sut .communicate (
188+ sut .ensure_communicate (
189189 timeout = 3600 ,
190190 iobuffer = Printer (sut , False ))
191191
Original file line number Diff line number Diff line change @@ -186,6 +186,44 @@ def fetch_file(
186186 """
187187 raise NotImplementedError ()
188188
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+
189227 def get_info (self ) -> dict :
190228 """
191229 Return SUT information.
Original file line number Diff line number Diff line change @@ -90,6 +90,17 @@ def test_communicate(self, sut):
9090 sut .communicate (iobuffer = Printer ())
9191 sut .stop ()
9292
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+
93104 @pytest .fixture
94105 def sut_stop_sleep (self , request ):
95106 """
You can’t perform that action at this time.
0 commit comments