Skip to content

Commit

Permalink
Merge pull request ceph#2010 from chrisphoffman/wip-dd-syncseek
Browse files Browse the repository at this point in the history
teuthology: Add support for seek and sync in write_file
  • Loading branch information
kshtsk authored Jan 7, 2025
2 parents 07120e2 + 0e0d40a commit d407041
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion teuthology/orchestra/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,22 +265,34 @@ 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
The data written in 512-byte blocks, provide `bs` to use bigger blocks.
:param path: file path on remote host
:param data: str, binary or fileobj to be written
:param sudo: use sudo to write file, defaults False
:param mode: set file mode bits if provided
: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: write up to N bytes at a time if provided, default is 512 in `dd`
:param offset: number of bs blocks to seek to in file, defaults 0
:param sync: sync file after write is complete if provided
"""
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
12 changes: 12 additions & 0 deletions teuthology/orchestra/test/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,15 @@ def test_is_container(self):
rem2 = remote.Remote(name='[email protected]', ssh=self.m_ssh)
rem2._runner = m_run
assert not rem2.is_container

@patch("teuthology.orchestra.remote.Remote.run")
def test_write_file(self, m_run):
file = "fakefile"
contents = "fakecontents"
rem = remote.Remote(name='[email protected]', ssh=self.m_ssh)

remote.Remote.write_file(rem, file, contents, bs=1, offset=1024)
m_run.assert_called_with(args=f"set -ex\ndd of={file} bs=1 seek=1024", stdin=contents, quiet=True)

remote.Remote.write_file(rem, file, contents, sync=True)
m_run.assert_called_with(args=f"set -ex\ndd of={file} conv=sync", stdin=contents, quiet=True)

0 comments on commit d407041

Please sign in to comment.