Merge pull request #38073 from doublescoring/2016.11

2016.11
This commit is contained in:
Mike Place 2016-12-20 07:51:10 -07:00 committed by GitHub
commit 530f495955
2 changed files with 10 additions and 1 deletions

View file

@ -1954,7 +1954,10 @@ def sftp_file(dest_path, contents=None, kwargs=None, local_file=None):
if contents is not None:
try:
tmpfd, file_to_upload = tempfile.mkstemp()
os.write(tmpfd, contents)
if isinstance(contents, str):
os.write(tmpfd, contents.encode(__salt_system_encoding__))
else:
os.write(tmpfd, contents)
finally:
try:
os.close(tmpfd)

View file

@ -118,6 +118,12 @@ class CloudUtilsTestCase(TestCase):
'fake_username')
self.assertEqual(pw_in_keyring, 'fake_password_c8231')
def test_sftp_file_with_content_under_python3(self):
with self.assertRaises(Exception) as context:
cloud.sftp_file("/tmp/test", "ТЕСТ test content")
# we successful pass the place with os.write(tmpfd, ...
self.assertNotEqual("a bytes-like object is required, not 'str'", str(context.exception))
if __name__ == '__main__':
from integration import run_tests
run_tests(CloudUtilsTestCase, needs_daemon=False)