Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sshdriver: log verbose scp output #1285

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 26 additions & 18 deletions labgrid/driver/sshdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def scp(self, *, src, dst):
complete_cmd = ["scp",
"-F", "none",
"-o", f"ControlPath={self.control.replace('%', '%%')}",
"-v",
src, dst,
]

Expand All @@ -366,10 +367,11 @@ def scp(self, *, src, dst):
complete_cmd.insert(1, "-O")

self.logger.info("Running command: %s", complete_cmd)
sub = subprocess.Popen(
complete_cmd,
)
return sub.wait()
result = subprocess.run(complete_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout = result.stdout.split(b"\n")
for line in stdout:
self.logger.info("scp: %s", line.rstrip().decode(encoding="utf-8", errors="replace"))
return result.returncode

@Driver.check_active
@step(args=['src', 'dst', 'extra'])
Expand Down Expand Up @@ -469,6 +471,7 @@ def put(self, filename, remotepath=''):
*self.ssh_prefix,
"-P", str(self.networkservice.port),
"-r",
"-v",
filename,
f"{self.networkservice.username}@{self.networkservice.address}:{remotepath}"
]
Expand All @@ -479,14 +482,16 @@ def put(self, filename, remotepath=''):
transfer_cmd.insert(1, "-O")

try:
sub = subprocess.call(
transfer_cmd
) #, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except:
raise ExecutionError(
f"error executing command: {transfer_cmd}"
subprocess.run(
transfer_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=True
)
if sub != 0:
except subprocess.CalledProcessError as e:
stdout = e.stdout.split(b"\n")
for line in stdout:
self.logger.warning("scp: %s", line.rstrip().decode(encoding="utf-8", errors="replace"))
raise ExecutionError(
f"error executing command: {transfer_cmd}"
)
Expand All @@ -499,6 +504,7 @@ def get(self, filename, destination="."):
*self.ssh_prefix,
"-P", str(self.networkservice.port),
"-r",
"-v",
f"{self.networkservice.username}@{self.networkservice.address}:{filename}",
destination
]
Expand All @@ -509,14 +515,16 @@ def get(self, filename, destination="."):
transfer_cmd.insert(1, "-O")

try:
sub = subprocess.call(
transfer_cmd
) #, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except:
raise ExecutionError(
f"error executing command: {transfer_cmd}"
subprocess.run(
transfer_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=True
)
if sub != 0:
except subprocess.CalledProcessError as e:
stdout = e.stdout.split(b"\n")
for line in stdout:
self.logger.warning("scp: %s", line.rstrip().decode(encoding="utf-8", errors="replace"))
raise ExecutionError(
f"error executing command: {transfer_cmd}"
)
Expand Down