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

teuthology: Add support for seek and sync in write_file #2010

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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):
Comment on lines +105 to +106
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated directly to write_file. To keep PR simple if you really need seek and sync in cluster wide call, maybe create another PR.

"""
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)
Comment on lines +233 to +242
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are test not for the remote.write_file but for cluster.remote_write, I guess there should be new tests added to test/test_remote.py module instead.