From 824260d53f442319c060f44a0a2b13f1477d1be5 Mon Sep 17 00:00:00 2001 From: Christopher Hoffman Date: Mon, 18 Nov 2024 15:30:10 +0000 Subject: [PATCH] teuthology: Add tests for seek and sync in write_file Signed-off-by: Christopher Hoffman --- teuthology/orchestra/cluster.py | 12 ++++++++---- teuthology/orchestra/test/test_cluster.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/teuthology/orchestra/cluster.py b/teuthology/orchestra/cluster.py index 654ef0c3de..5e4bba45cc 100644 --- a/teuthology/orchestra/cluster.py +++ b/teuthology/orchestra/cluster.py @@ -102,7 +102,8 @@ 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. @@ -110,16 +111,19 @@ def write_file(self, file_name, content, sudo=False, perms=None, owner=None): :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): """ diff --git a/teuthology/orchestra/test/test_cluster.py b/teuthology/orchestra/test/test_cluster.py index 27bef8b831..147b654b38 100644 --- a/teuthology/orchestra/test/test_cluster.py +++ b/teuthology/orchestra/test/test_cluster.py @@ -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)