]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/remotehost.py
2 # Copyright (c) 2016, Qualcomm Atheros, Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
11 logger
= logging
.getLogger()
13 def remote_compatible(func
):
14 func
.remote_compatible
= True
17 def execute_thread(command
, reply
):
18 cmd
= ' '.join(command
)
19 logger
.debug("thread run: " + cmd
)
22 buf
= subprocess
.check_output(command
, stderr
=subprocess
.STDOUT
)
23 except subprocess
.CalledProcessError
as e
:
27 logger
.debug("thread cmd: " + cmd
)
28 logger
.debug("thread exit status: " + str(status
))
29 logger
.debug("thread exit buf: " + str(buf
))
34 def __init__(self
, host
=None, ifname
=None, port
=None, name
="", user
="root"):
39 self
.monitor_thread
= None
44 if self
.name
== "" and host
!= None:
47 def local_execute(self
, command
):
48 logger
.debug("execute: " + str(command
))
51 buf
= subprocess
.check_output(command
, stderr
=subprocess
.STDOUT
)
52 except subprocess
.CalledProcessError
as e
:
56 logger
.debug("status: " + str(status
))
57 logger
.debug("buf: " + str(buf
))
60 def execute(self
, command
):
62 return self
.local_execute(command
)
64 cmd
= ["ssh", self
.user
+ "@" + self
.host
, ' '.join(command
)]
65 _cmd
= self
.name
+ " execute: " + ' '.join(cmd
)
69 buf
= subprocess
.check_output(cmd
, stderr
=subprocess
.STDOUT
)
70 except subprocess
.CalledProcessError
as e
:
74 logger
.debug(self
.name
+ " status: " + str(status
))
75 logger
.debug(self
.name
+ " buf: " + str(buf
))
79 def execute_run(self
, command
, res
):
83 cmd
= ["ssh", self
.user
+ "@" + self
.host
, ' '.join(command
)]
84 _cmd
= self
.name
+ " execute_run: " + ' '.join(cmd
)
86 t
= threading
.Thread(target
= execute_thread
, args
=(cmd
, res
))
90 def wait_execute_complete(self
, t
, wait
=None):
94 wait_str
= str(wait
) + "s"
96 logger
.debug(self
.name
+ " wait_execute_complete(" + wait_str
+ "): ")
100 def add_log(self
, log_file
):
101 self
.logs
.append(log_file
)
103 def get_logs(self
, local_log_dir
=None):
104 for log
in self
.logs
:
106 self
.local_execute(["scp", self
.user
+ "@[" + self
.host
+ "]:" + log
, local_log_dir
])
107 self
.execute(["rm", log
])