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 <cheimes@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
Christian Heimes
2018-07-12 18:19:34 +02:00
parent 10de2f37a2
commit 5affc9b982
@@ -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