mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
commit
530f495955
2 changed files with 10 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue