Repository: ambari Updated Branches: refs/heads/trunk 1d01d35a6 -> 06277ee15
AMBARI-9283. Python logging fails with non-ascii characters in Mysql password (dlysnichenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/06277ee1 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/06277ee1 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/06277ee1 Branch: refs/heads/trunk Commit: 06277ee15a9fb451147237873f28371d1c0ab3c4 Parents: 1d01d35 Author: Lisnichenko Dmitro <dlysniche...@hortonworks.com> Authored: Thu Jan 22 23:18:42 2015 +0200 Committer: Lisnichenko Dmitro <dlysniche...@hortonworks.com> Committed: Thu Jan 22 23:18:42 2015 +0200 ---------------------------------------------------------------------- .../TestDirectoryResource.py | 6 +++--- .../TestExecuteHadoopResource.py | 2 +- .../resource_management/TestFileResource.py | 4 ++-- .../resource_management/TestLinkResource.py | 4 ++-- .../TestMonitorWebserverResource.py | 22 +++++++++++--------- .../python/resource_management/TestScript.py | 2 +- .../resource_management/TestUserResource.py | 1 + .../python/resource_management/core/base.py | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/06277ee1/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py b/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py index 0705922..fe64400 100644 --- a/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py +++ b/ambari-agent/src/test/python/resource_management/TestDirectoryResource.py @@ -112,7 +112,7 @@ class TestDirectoryResource(TestCase): ) self.fail("Must fail because parent directory /a/b/c doesn't exist") except Fail as e: - self.assertEqual("Applying Directory['/a/b/c/d'] failed, parent directory /a/b/c doesn't exist", + self.assertEqual('Applying u"Directory[\'/a/b/c/d\']" failed, parent directory /a/b/c doesn\'t exist', str(e)) @patch.object(os.path, "exists") @@ -131,7 +131,7 @@ class TestDirectoryResource(TestCase): ) self.fail("Must fail because file /a/b/c/d already exists") except Fail as e: - self.assertEqual("Applying Directory['/a/b/c/d'] failed, file /a/b/c/d already exists", + self.assertEqual('Applying u"Directory[\'/a/b/c/d\']" failed, file /a/b/c/d already exists', str(e)) @patch.object(shutil, "rmtree") @@ -171,5 +171,5 @@ class TestDirectoryResource(TestCase): ) self.fail("Must fail because /a/b/c/d is not a directory") except Fail as e: - self.assertEqual("Applying Directory['/a/b/c/d'] failed, /a/b/c/d is not a directory", + self.assertEqual('Applying u"Directory[\'/a/b/c/d\']" failed, /a/b/c/d is not a directory', str(e)) \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/06277ee1/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py b/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py index 6ca6f36..a368e5d 100644 --- a/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py +++ b/ambari-agent/src/test/python/resource_management/TestExecuteHadoopResource.py @@ -176,7 +176,7 @@ class TestExecuteHadoopResource(TestCase): ) self.assertEqual(execute_mock.call_count, 2) self.assertEqual(str(execute_mock.call_args_list[0][0][0]), - "Execute['path -kt keytab principal']") + 'u"Execute[\'path -kt keytab principal\']"') self.assertEqual(execute_mock.call_args_list[0][0][0].command, 'path -kt keytab principal') self.assertEqual(execute_mock.call_args_list[0][0][0].arguments, http://git-wip-us.apache.org/repos/asf/ambari/blob/06277ee1/ambari-agent/src/test/python/resource_management/TestFileResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestFileResource.py b/ambari-agent/src/test/python/resource_management/TestFileResource.py index 063de19..28fa610 100644 --- a/ambari-agent/src/test/python/resource_management/TestFileResource.py +++ b/ambari-agent/src/test/python/resource_management/TestFileResource.py @@ -48,7 +48,7 @@ class TestFileResource(TestCase): self.fail("Must fail when directory with name 'path' exist") except Fail as e: - self.assertEqual("Applying File['/existent_directory'] failed, directory with name /existent_directory exists", + self.assertEqual('Applying u"File[\'/existent_directory\']" failed, directory with name /existent_directory exists', str(e)) self.assertFalse(dirname_mock.called) @@ -72,7 +72,7 @@ class TestFileResource(TestCase): self.fail('Must fail on non existent parent directory') except Fail as e: self.assertEqual( - "Applying File['/non_existent_directory/file'] failed, parent directory /non_existent_directory doesn't exist", + 'Applying u"File[\'/non_existent_directory/file\']" failed, parent directory /non_existent_directory doesn\'t exist', str(e)) self.assertTrue(dirname_mock.called) http://git-wip-us.apache.org/repos/asf/ambari/blob/06277ee1/ambari-agent/src/test/python/resource_management/TestLinkResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestLinkResource.py b/ambari-agent/src/test/python/resource_management/TestLinkResource.py index 6a428b6..cdb6061 100644 --- a/ambari-agent/src/test/python/resource_management/TestLinkResource.py +++ b/ambari-agent/src/test/python/resource_management/TestLinkResource.py @@ -112,7 +112,7 @@ class TestLinkResource(TestCase): ) self.fail("Must fail when target directory do doenst exist") except Fail as e: - self.assertEqual("Failed to apply Link['/some_path'], linking to nonexistent location /a/b/link_to_path", + self.assertEqual('Failed to apply u"Link[\'/some_path\']", linking to nonexistent location /a/b/link_to_path', str(e)) @patch.object(os.path, "isdir") @@ -132,7 +132,7 @@ class TestLinkResource(TestCase): ) self.fail("Must fail when hardlinking to directory") except Fail as e: - self.assertEqual("Failed to apply Link['/some_path'], cannot create hard link to a directory (/a/b/link_to_path)", + self.assertEqual('Failed to apply u"Link[\'/some_path\']", cannot create hard link to a directory (/a/b/link_to_path)', str(e)) @patch.object(sudo, "unlink") http://git-wip-us.apache.org/repos/asf/ambari/blob/06277ee1/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py b/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py index 65ada42..26c2ef7 100644 --- a/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py +++ b/ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py @@ -31,9 +31,11 @@ class TestMonitorWebserverResource(TestCase): with Environment(test_mode=True) as env: MonitorWebserverProvider(MonitorWebserver("start")).action_start() defined_resources = env.resource_list - expected_resources = "[MonitorWebserver['start'], Execute['grep -E 'KeepAlive (On|Off)' /etc/httpd/conf/httpd.conf && " \ - "/usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E sed -i 's/KeepAlive Off/KeepAlive On/' /etc/httpd/conf/httpd.conf || " \ - "echo 'KeepAlive On' | /usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/httpd/conf/httpd.conf > /dev/null'], Execute['('/etc/init.d/httpd', 'start')']]" + expected_resources = '[u"MonitorWebserver[\'start\']", u"Execute[\'grep -E \'KeepAlive (On|Off)\' ' \ + '/etc/httpd/conf/httpd.conf && /usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E sed -i ' \ + '\'s/KeepAlive Off/KeepAlive On/\' /etc/httpd/conf/httpd.conf || echo \'KeepAlive On\' ' \ + '| /usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/httpd/conf/httpd.conf > /dev/null\']"' \ + ', u"Execute[\'(\'/etc/init.d/httpd\', \'start\')\']"]' self.assertEqual(str(defined_resources), expected_resources) @patch.object(System, "os_family", new='suse') @@ -41,9 +43,11 @@ class TestMonitorWebserverResource(TestCase): with Environment(test_mode=True) as env: MonitorWebserverProvider(MonitorWebserver("start")).action_start() defined_resources = env.resource_list - expected_resources = "[MonitorWebserver['start'], Execute['grep -E 'KeepAlive (On|Off)' /etc/apache2/httpd.conf && /usr/bin/sudo [RMF_ENV_PLACEHOLDER] " \ - "-H -E sed -i 's/KeepAlive Off/KeepAlive On/' /etc/apache2/httpd.conf || echo 'KeepAlive On' | " \ - "/usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/apache2/httpd.conf > /dev/null'], Execute['('/etc/init.d/apache2', 'start')']]" + expected_resources = '[u"MonitorWebserver[\'start\']", u"Execute[\'grep -E \'KeepAlive (On|Off)\' ' \ + '/etc/apache2/httpd.conf && /usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E sed -i ' \ + '\'s/KeepAlive Off/KeepAlive On/\' /etc/apache2/httpd.conf || echo \'KeepAlive On\' ' \ + '| /usr/bin/sudo [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/apache2/httpd.conf > /dev/null\']",' \ + ' u"Execute[\'(\'/etc/init.d/apache2\', \'start\')\']"]' self.assertEqual(str(defined_resources), expected_resources) @patch.object(System, "os_family", new='redhat') @@ -51,8 +55,7 @@ class TestMonitorWebserverResource(TestCase): with Environment(test_mode=True) as env: MonitorWebserverProvider(MonitorWebserver("stop")).action_stop() defined_resources = env.resource_list - expected_resources = "[MonitorWebserver['stop'], " \ - "Execute['('/etc/init.d/httpd', 'stop')']]" + expected_resources = '[u"MonitorWebserver[\'stop\']", u"Execute[\'(\'/etc/init.d/httpd\', \'stop\')\']"]' self.assertEqual(str(defined_resources), expected_resources) @patch.object(System, "os_family", new='suse') @@ -60,6 +63,5 @@ class TestMonitorWebserverResource(TestCase): with Environment(test_mode=True) as env: MonitorWebserverProvider(MonitorWebserver("stop")).action_stop() defined_resources = env.resource_list - expected_resources = "[MonitorWebserver['stop'], " \ - "Execute['('/etc/init.d/apache2', 'stop')']]" + expected_resources = '[u"MonitorWebserver[\'stop\']", u"Execute[\'(\'/etc/init.d/apache2\', \'stop\')\']"]' self.assertEqual(str(defined_resources), expected_resources) http://git-wip-us.apache.org/repos/asf/ambari/blob/06277ee1/ambari-agent/src/test/python/resource_management/TestScript.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestScript.py b/ambari-agent/src/test/python/resource_management/TestScript.py index 9afaa39..1d112d8 100644 --- a/ambari-agent/src/test/python/resource_management/TestScript.py +++ b/ambari-agent/src/test/python/resource_management/TestScript.py @@ -89,7 +89,7 @@ class TestScript(TestCase): Script.config = dummy_config script.install_packages("env") resource_dump = pprint.pformat(env.resource_list) - self.assertEqual(resource_dump, "[Package['hbase'], Package['yet-another-package']]") + self.assertEqual(resource_dump, '[u"Package[\'hbase\']", u"Package[\'yet-another-package\']"]') @patch("__builtin__.open") def test_structured_out(self, open_mock): http://git-wip-us.apache.org/repos/asf/ambari/blob/06277ee1/ambari-agent/src/test/python/resource_management/TestUserResource.py ---------------------------------------------------------------------- diff --git a/ambari-agent/src/test/python/resource_management/TestUserResource.py b/ambari-agent/src/test/python/resource_management/TestUserResource.py index f66b738..dad2828 100644 --- a/ambari-agent/src/test/python/resource_management/TestUserResource.py +++ b/ambari-agent/src/test/python/resource_management/TestUserResource.py @@ -196,3 +196,4 @@ class TestUserResource(TestCase): popen_mock.assert_called_with(['/bin/bash', '--login', '--noprofile', '-c', "/usr/bin/sudo PATH=/bin -H -E useradd -m mapred"], shell=False, preexec_fn=None, stderr=-2, stdout=-1, env={'PATH': '/bin'}, cwd=None) self.assertEqual(popen_mock.call_count, 1) + http://git-wip-us.apache.org/repos/asf/ambari/blob/06277ee1/ambari-common/src/main/python/resource_management/core/base.py ---------------------------------------------------------------------- diff --git a/ambari-common/src/main/python/resource_management/core/base.py b/ambari-common/src/main/python/resource_management/core/base.py index 52f1dff..cc5f111 100644 --- a/ambari-common/src/main/python/resource_management/core/base.py +++ b/ambari-common/src/main/python/resource_management/core/base.py @@ -151,7 +151,7 @@ class Resource(object): pass def __repr__(self): - return "%s['%s']" % (self.__class__.__name__, self.name) + return repr(unicode(self)) def __unicode__(self): return u"%s['%s']" % (self.__class__.__name__, self.name)