From 81110e55cebbd470217639c13b3b17bd5230fcec Mon Sep 17 00:00:00 2001 From: twangboy Date: Thu, 13 Jun 2019 18:12:09 -0600 Subject: [PATCH] Fix test_file_copy_make_dirs that was failing on Linux I wasn't running sudo, but now it tells you that And verifies that the user is added and the state is run successfully before continuing with the test --- salt/log/setup.py | 13 ++++++++----- tests/integration/states/test_file.py | 12 +++++++----- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/salt/log/setup.py b/salt/log/setup.py index 2f1b1b03d4..7405d456c2 100644 --- a/salt/log/setup.py +++ b/salt/log/setup.py @@ -362,11 +362,14 @@ class SaltLoggingClass(six.with_metaclass(LoggingMixInMeta, LOGGING_LOGGER_CLASS extra = None # Let's try to make every logging message unicode - salt_system_encoding = __salt_system_encoding__ - if salt_system_encoding == 'ascii': - # Encoding detection most likely failed, let's use the utf-8 - # value which we defaulted before __salt_system_encoding__ was - # implemented + try: + salt_system_encoding = __salt_system_encoding__ + if salt_system_encoding == 'ascii': + # Encoding detection most likely failed, let's use the utf-8 + # value which we defaulted before __salt_system_encoding__ was + # implemented + salt_system_encoding = 'utf-8' + except NameError: salt_system_encoding = 'utf-8' if isinstance(msg, six.string_types) \ diff --git a/tests/integration/states/test_file.py b/tests/integration/states/test_file.py index 6c0044fd27..5ab620787e 100644 --- a/tests/integration/states/test_file.py +++ b/tests/integration/states/test_file.py @@ -1764,7 +1764,7 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin): with salt.utils.files.fopen(path_test, 'rb') as fp_: serialized_file = salt.utils.stringutils.to_unicode(fp_.read()) - # The JSON serializer uses LF even on OSes where os.path.sep is CRLF. + # The JSON serializer uses LF even on OSes where os.sep is CRLF. expected_file = '\n'.join([ '{', ' "a_list": [', @@ -2609,15 +2609,17 @@ class FileTest(ModuleCase, SaltReturnAssertsMixin): user = 'salt' mode = '0644' - self.run_function('user.add', [user]) + ret = self.run_function('user.add', [user]) + self.assertTrue(ret, 'Failed to add user. Are you running as sudo?') ret = self.run_state('file.copy', name=dest, source=source, user=user, - makedirs=True, mode=mode) + makedirs=True, mode=mode) + self.assertSaltTrueReturn(ret) file_checks = [dest, os.path.join(TMP, 'dir1'), os.path.join(TMP, 'dir1', 'dir2')] for check in file_checks: user_check = self.run_function('file.get_user', [check]) mode_check = self.run_function('file.get_mode', [check]) - assert user_check == user - assert salt.utils.files.normalize_mode(mode_check) == mode + self.assertEqual(user_check, user) + self.assertEqual(salt.utils.files.normalize_mode(mode_check), mode) def test_contents_pillar_with_pillar_list(self): '''