From 8b5e7725ac9668f360343f0797677b9231fe55ac Mon Sep 17 00:00:00 2001 From: Christopher Hoffman Date: Fri, 25 Oct 2024 15:50:59 +0000 Subject: [PATCH] teuthology: Add support for seek and sync in write_file Signed-off-by: Christopher Hoffman --- teuthology/misc.py | 7 +++++-- teuthology/orchestra/remote.py | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/teuthology/misc.py b/teuthology/misc.py index 97521895a..5fbe3c848 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -512,15 +512,18 @@ def gen_addresses(): return fsid -def write_file(remote, path, data): +def write_file(remote, path, data, bs=None, offset=None, sync=False): """ Write data to a remote file :param remote: Remote site. :param path: Path on the remote being written to. :param data: Data to be written. + :param bs: The block size to be used. + :param offset: The number of bytes to seek to in file. + :param sync: Sync file. """ - remote.write_file(path, data) + remote.write_file(path, data, bs=bs, offset=offset, sync=sync) def sudo_write_file(remote, path, data, perms=None, owner=None): diff --git a/teuthology/orchestra/remote.py b/teuthology/orchestra/remote.py index ce77a519c..2212db786 100644 --- a/teuthology/orchestra/remote.py +++ b/teuthology/orchestra/remote.py @@ -265,7 +265,8 @@ def read_file(self, path, sudo=False, stdout=None, def write_file(self, path, data, sudo=False, mode=None, owner=None, - mkdir=False, append=False): + mkdir=False, append=False, bs=None, + offset=None, sync=False): """ Write data to remote file @@ -276,11 +277,20 @@ def write_file(self, path, data, sudo=False, mode=None, owner=None, :param owner: set file owner if provided :param mkdir: preliminary create the file directory, defaults False :param append: append data to the file, defaults False + :param bs: block size + :param offset: number of bytes to seek to in file + :param sync: sync file """ dd = 'sudo dd' if sudo else 'dd' args = dd + ' of=' + path if append: args += ' conv=notrunc oflag=append' + if bs: + args += ' bs=' + str(bs) + if offset: + args += ' seek=' + str(offset) + if sync: + args += ' conv=sync' if mkdir: mkdirp = 'sudo mkdir -p' if sudo else 'mkdir -p' dirpath = os.path.dirname(path)