diff options
| author | Russell King (Oracle) <[email protected]> | 2024-06-10 12:03:21 +0100 |
|---|---|---|
| committer | Russell King (Oracle) <[email protected]> | 2024-06-10 12:03:21 +0100 |
| commit | 594ce0b8a998aa4d05827cd7c0d0dcec9a1e3ae2 (patch) | |
| tree | 070bd60a8fda15e5f47339d3f6888a0fe2ca6fe9 /tools/testing/selftests/drivers/net/lib/py/remote_ssh.py | |
| parent | 616501eccb58615f8f352a29239ea6c6fc5e6546 (diff) | |
| parent | e3cf20e5c68df604315ab30bdbe15dc8a5da556b (diff) | |
Merge topic branches 'clkdev' and 'fixes' into for-linus
Diffstat (limited to 'tools/testing/selftests/drivers/net/lib/py/remote_ssh.py')
| -rw-r--r-- | tools/testing/selftests/drivers/net/lib/py/remote_ssh.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/testing/selftests/drivers/net/lib/py/remote_ssh.py b/tools/testing/selftests/drivers/net/lib/py/remote_ssh.py new file mode 100644 index 000000000000..924addde19a3 --- /dev/null +++ b/tools/testing/selftests/drivers/net/lib/py/remote_ssh.py @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: GPL-2.0 + +import os +import string +import subprocess +import random + +from lib.py import cmd + + +class Remote: + def __init__(self, name, dir_path): + self.name = name + self.dir_path = dir_path + self._tmpdir = None + + def __del__(self): + if self._tmpdir: + cmd("rm -rf " + self._tmpdir, host=self) + self._tmpdir = None + + def cmd(self, comm): + return subprocess.Popen(["ssh", "-q", self.name, comm], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + def _mktmp(self): + return ''.join(random.choice(string.ascii_lowercase) for _ in range(8)) + + def deploy(self, what): + if not self._tmpdir: + self._tmpdir = "/tmp/" + self._mktmp() + cmd("mkdir " + self._tmpdir, host=self) + file_name = self._tmpdir + "/" + self._mktmp() + os.path.basename(what) + + if not os.path.isabs(what): + what = os.path.abspath(self.dir_path + "/" + what) + + cmd(f"scp {what} {self.name}:{file_name}") + return file_name |