Skip to content

Commit

Permalink
teuthology: Add tests 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 Nov 18, 2024
1 parent 6f1b6b1 commit 824260d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions teuthology/orchestra/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,28 @@ def sh(self, script, **kwargs):
remotes = sorted(self.remotes.keys(), key=lambda rem: rem.name)
return [remote.sh(script, **kwargs) for remote in remotes]

def write_file(self, file_name, content, sudo=False, perms=None, owner=None):
def write_file(self, file_name, content, sudo=False, perms=None, owner=None,
**kwargs):
"""
Write text to a file on each node.
:param file_name: file name
:param content: file content
:param sudo: use sudo
:param perms: file permissions (passed to chmod) ONLY if sudo is True
:param owner: file owner (passed to chmod) ONLY if sudo is True
"""
remotes = sorted(self.remotes.keys(), key=lambda rem: rem.name)
for remote in remotes:
if sudo:
remote.write_file(file_name, content,
sudo=True, mode=perms, owner=owner)
kwargs['sudo'] = True
kwargs['mode'] = perms
kwargs['owner'] = owner
else:
if perms is not None or owner is not None:
raise ValueError("To specify perms or owner, sudo must be True")
remote.write_file(file_name, content)

remote.write_file(file_name, content, **kwargs)

def only(self, *roles):
"""
Expand Down
10 changes: 10 additions & 0 deletions teuthology/orchestra/test/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ def test_fails_with_invalid_owner(self, m_write_file):
def test_with_sudo(self, m_write_file):
self.c.write_file("filename", "content", sudo=True)
m_write_file.assert_called_with("filename", "content", sudo=True, owner=None, mode=None)

@patch("teuthology.orchestra.remote.RemoteShell.write_file")
def test_write_file_offset(self, m_write_file):
self.c.write_file("filename", "content", bs=1, offset=1024)
m_write_file.assert_called_with("filename", "content", bs=1, offset=1024)

@patch("teuthology.orchestra.remote.RemoteShell.write_file")
def test_write_file_sync(self, m_write_file):
self.c.write_file("filename", "content", sync=True)
m_write_file.assert_called_with("filename", "content", sync=True)

0 comments on commit 824260d

Please sign in to comment.