test code working
diff --git a/wally/node.py b/wally/node.py
index 2a57c65..6624bdc 100644
--- a/wally/node.py
+++ b/wally/node.py
@@ -164,12 +164,12 @@
return str(self)
def get_file_content(self, path: str) -> bytes:
- logger.debug("GET %s", path)
- res = self.conn.fs.get_file(path, expanduser=True)
- logger.debug("Receive %s bytes from %s", len(res), path)
+ logger.debug("GET %s from %s", path, self.info)
+ res = self.conn.fs.get_file(self.conn.fs.expanduser(path))
+ logger.debug("Download %s bytes from remote file %s from %s", len(res), path, self.info)
return res
- def run(self, cmd: str, timeout: int = 60, nolog: bool = False) -> str:
+ def run(self, cmd: str, timeout: int = 60, nolog: bool = False, check_timeout: float = 0.01) -> str:
if not nolog:
logger.debug("Node %s - run %s", self.info.node_id(), cmd)
@@ -182,7 +182,7 @@
out += outb.decode("utf8")
if code is not None:
break
- time.sleep(0.01)
+ time.sleep(check_timeout)
if code != 0:
templ = "Node {} - cmd {!r} failed with code {}. Output: {!r}."
@@ -190,15 +190,15 @@
return out
- def copy_file(self, local_path: str, remote_path: str = None, expand_user: bool = False) -> str:
+ def copy_file(self, local_path: str, remote_path: str = None) -> str:
data = open(local_path, 'rb').read()
- return self.put_to_file(remote_path, data, expand_user)
+ return self.put_to_file(remote_path, data)
- def put_to_file(self, path: Optional[str], content: bytes, expand_user: bool = False) -> str:
- return self.conn.fs.store_file(path, content, expand_user)
+ def put_to_file(self, path: Optional[str], content: bytes) -> str:
+ return self.conn.fs.store_file(path, content)
- def stat_file(self, path: str, expand_user: bool = False) -> Dict[str, int]:
- return self.conn.fs.file_stat(path, expand_user)
+ def stat_file(self, path: str) -> Dict[str, int]:
+ return self.conn.fs.file_stat(path)
def __exit__(self, x, y, z) -> bool:
self.disconnect(stop=True)
@@ -217,6 +217,23 @@
self.conn = None
+def get_node_python_27(node: ISSHHost) -> Optional[str]:
+ python_cmd = None # type: Optional[str]
+ try:
+ python_cmd = node.run('which python2.7').strip()
+ except Exception as exc:
+ pass
+
+ if python_cmd is None:
+ try:
+ if '2.7' in node.run('python --version'):
+ python_cmd = node.run('which python').strip()
+ except Exception as exc:
+ pass
+
+ return python_cmd
+
+
def setup_rpc(node: ISSHHost,
rpc_server_code: bytes,
plugins: Dict[str, bytes] = None,
@@ -224,19 +241,27 @@
log_level: str = None) -> IRPCNode:
logger.debug("Setting up RPC connection to {}".format(node.info))
+ python_cmd = get_node_python_27(node)
+ if python_cmd:
+ logger.debug("python2.7 on node {} path is {}".format(node.info, python_cmd))
+ else:
+ logger.error(("Can't find python2.7 on node {}. " +
+ "Install python2.7 and rerun test").format(node.info))
+ raise ValueError("Python not found")
+
code_file = node.put_to_file(None, rpc_server_code)
ip = node.info.ssh_creds.addr.host
log_file = None # type: Optional[str]
if log_level:
log_file = node.run("mktemp", nolog=True).strip()
- cmd = "python {} --log-level={} server --listen-addr={}:{} --daemon --show-settings"
- cmd = cmd.format(code_file, log_level, ip, port) + " --stdout-file={}".format(log_file)
+ cmd = "{} {} --log-level={} server --listen-addr={}:{} --daemon --show-settings"
+ cmd = cmd.format(python_cmd, code_file, log_level, ip, port) + " --stdout-file={}".format(log_file)
logger.info("Agent logs for node {} stored on node in file {}. Log level is {}".format(
node.info.node_id(), log_file, log_level))
else:
- cmd = "python {} --log-level=CRITICAL server --listen-addr={}:{} --daemon --show-settings"
- cmd = cmd.format(code_file, ip, port)
+ cmd = "{} {} --log-level=CRITICAL server --listen-addr={}:{} --daemon --show-settings"
+ cmd = cmd.format(python_cmd, code_file, ip, port)
params_js = node.run(cmd).strip()
params = json.loads(params_js)