From 6406a1ecc8cfc7370c099c9a29d39874827902c8 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Wed, 4 Sep 2013 11:02:56 -0500 Subject: [PATCH] Add Cluster.write_file() --- teuthology/orchestra/cluster.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/teuthology/orchestra/cluster.py b/teuthology/orchestra/cluster.py index df97d7a52..7c55fa0ff 100644 --- a/teuthology/orchestra/cluster.py +++ b/teuthology/orchestra/cluster.py @@ -1,3 +1,5 @@ +import teuthology.misc + class Cluster(object): """ Manage SSH connections to a cluster of machines. @@ -51,6 +53,24 @@ class Cluster(object): remotes = sorted(self.remotes.iterkeys(), key=lambda rem: rem.name) return [remote.run(**kwargs) for remote in remotes] + def write_file(self, file_name, content, sudo=False, perms=None): + """ + 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 + """ + remotes = sorted(self.remotes.iterkeys(), key=lambda rem: rem.name) + for remote in remotes: + if sudo: + teuthology.misc.sudo_write_file(remote, file_name, content, perms) + else: + if perms is not None: + raise ValueError("To specify perms, sudo must be True") + teuthology.misc.write_file(remote, file_name, content, perms) + def only(self, *roles): """ Return a cluster with only the remotes that have all of given roles. -- 2.47.3