Skip to content

Commit

Permalink
teuthology: Add support for seek and sync in write_file
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Hoffman <[email protected]>
  • Loading branch information
chrisphoffman committed Oct 25, 2024
1 parent 1d957a3 commit 8b5e772
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
7 changes: 5 additions & 2 deletions teuthology/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 11 additions & 1 deletion teuthology/orchestra/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 8b5e772

Please sign in to comment.