From 5affc9b982f6314fc6d1c63fb687acee20f5144b Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Thu, 12 Jul 2018 14:49:04 +0200 Subject: [PATCH] Create helper function to upload to temp file upload_temp_contents() generates a temporary file on the remote side and uploads content to that temporary file. The file name is returned. Signed-off-by: Christian Heimes Reviewed-By: Alexander Bokovoy --- ipatests/pytest_plugins/integration/tasks.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ipatests/pytest_plugins/integration/tasks.py b/ipatests/pytest_plugins/integration/tasks.py index 54c12bf78..31e66bdae 100644 --- a/ipatests/pytest_plugins/integration/tasks.py +++ b/ipatests/pytest_plugins/integration/tasks.py @@ -1313,6 +1313,20 @@ def run_certutil(host, args, reqdir, dbtype=None, stdin_text=stdin) +def upload_temp_contents(host, contents, encoding='utf-8'): + """Upload contents to a temporary file + + :param host: Remote host instance + :param contents: file content (str, bytes) + :param encoding: file encoding + :return: Temporary file name + """ + result = host.run_command(['mktemp']) + tmpname = result.stdout_text.strip() + host.put_file_contents(tmpname, contents, encoding=encoding) + return tmpname + + def assert_error(result, stderr_text, returncode=None): "Assert that `result` command failed and its stderr contains `stderr_text`" assert stderr_text in result.stderr_text, result.stderr_text