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

USBStorageDriver cleanup remote resource #1588

Closed
Closed
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions labgrid/driver/usbstoragedriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ def write_files(self, sources, target, partition, target_is_directory=True):
target_path = str(pathlib.PurePath(mount_path) / target_rel)

copied_sources = []
files = [ManagedFile(f, self.storage) for f in sources]

for f in sources:
mf = ManagedFile(f, self.storage)
for mf in files:
mf.sync_to_resource()
copied_sources.append(mf.get_remote_path())

Expand All @@ -114,6 +114,10 @@ def write_files(self, sources, target, partition, target_is_directory=True):
args = ["cp", "-T", copied_sources[0], target_path]

processwrapper.check_output(self.storage.command_prefix + args)

for mf in files:
mf.cleanup_resource()

self.proxy.unmount(self.devpath)
except:
# We are going to die with an exception anyway, so no point in waiting
Expand Down Expand Up @@ -201,6 +205,8 @@ def write_image(self, filename=None, mode=Mode.DD, partition=None, skip=0, seek=
print_on_silent_log=True
)

mf.cleanup_resource()

def _get_devpath(self, partition):
partition = "" if partition is None else partition
# simple concatenation is sufficient for USB mass storage
Expand Down
15 changes: 15 additions & 0 deletions labgrid/util/managedfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ def sync_to_resource(self, symlink=None):
# --symbolic --force --no-dereference
conn.run_check(f"ln -sfn {self.rpath}{os.path.basename(self.local_path)} {symlink}")

def cleanup_resource(self, symlink=None):
if isinstance(self.resource, NetworkResource):
host = self.resource.host
conn = sshmanager.open(host)

if self._on_nfs(conn):
pass
else:
self.rpath = f"{self.get_user_cache_path()}/{self.get_hash()}/"
self.logger.info("Removing %s on %s", self.local_path, host)
conn.run_check(f"rm -rf {self.rpath}")

if symlink is not None:
self.logger.info("Removing symlink {symlink}")
conn.run_check(f"rm -f {symlink}")

def _on_nfs(self, conn):
if self._on_nfs_cached is not None:
Expand Down