From b9955569acd44e0f1938745cf252544d03935f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Nussbaumer?= <rn@google.com> Date: Tue, 14 Dec 2010 17:14:55 +0100 Subject: [PATCH] QA: Allow upload of string data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: RenΓ© Nussbaumer <rn@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- qa/qa_utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/qa/qa_utils.py b/qa/qa_utils.py index 6a8ed18e3..6fa949a98 100644 --- a/qa/qa_utils.py +++ b/qa/qa_utils.py @@ -218,6 +218,32 @@ def UploadFile(node, src): f.close() +def UploadData(node, data, mode=0600, filename=None): + """Uploads data to a node and returns the filename. + + Caller needs to remove the returned file on the node when it's not needed + anymore. + + """ + if filename: + tmp = "tmp=%s" % utils.ShellQuote(filename) + else: + tmp = "tmp=$(tempfile --mode %o --prefix gnt)" % mode + cmd = ("%s && " + "[[ -f \"${tmp}\" ]] && " + "cat > \"${tmp}\" && " + "echo \"${tmp}\"") % tmp + + p = subprocess.Popen(GetSSHCommand(node, cmd), shell=False, + stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p.stdin.write(data) + p.stdin.close() + AssertEqual(p.wait(), 0) + + # Return temporary filename + return p.stdout.read().strip() + + def BackupFile(node, path): """Creates a backup of a file on the node and returns the filename. -- GitLab