tests: remotehost: Extend proc API
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@gmail.com>
This commit is contained in:
parent
c24453dd93
commit
2342d95821
1 changed files with 17 additions and 4 deletions
|
@ -161,8 +161,8 @@ class Host():
|
||||||
if t.is_alive():
|
if t.is_alive():
|
||||||
t.join(wait)
|
t.join(wait)
|
||||||
|
|
||||||
def pending(self, s, timeout=0):
|
def proc_pending(self, proc, timeout=0):
|
||||||
[r, w, e] = select.select([s], [], [], timeout)
|
[r, w, e] = select.select([proc.stdout], [], [], timeout)
|
||||||
if r:
|
if r:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -194,7 +194,7 @@ class Host():
|
||||||
start = os.times()[4]
|
start = os.times()[4]
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
while self.pending(proc.stdout):
|
while self.proc_pending(proc):
|
||||||
line = proc.stdout.readline()
|
line = proc.stdout.readline()
|
||||||
if not line:
|
if not line:
|
||||||
return None
|
return None
|
||||||
|
@ -207,13 +207,26 @@ class Host():
|
||||||
remaining = start + timeout - now
|
remaining = start + timeout - now
|
||||||
if remaining <= 0:
|
if remaining <= 0:
|
||||||
break
|
break
|
||||||
if not self.pending(proc.stdout, timeout=remaining):
|
if not self.proc_pending(proc, timeout=remaining):
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
logger.debug(traceback.format_exc())
|
logger.debug(traceback.format_exc())
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def proc_write(self, proc, cmd):
|
||||||
|
return proc.stdout.write(cmd)
|
||||||
|
|
||||||
|
def proc_read(self, proc, timeout=0):
|
||||||
|
if not self.proc_pending(proc):
|
||||||
|
return None
|
||||||
|
res = proc.stdout.read(4094).decode()
|
||||||
|
try:
|
||||||
|
r = str(res)
|
||||||
|
except UnicodeDecodeError as e:
|
||||||
|
r = res
|
||||||
|
return r
|
||||||
|
|
||||||
def proc_stop(self, proc):
|
def proc_stop(self, proc):
|
||||||
if not proc:
|
if not proc:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue