Forráskód Böngészése

AMBARI-10109. Improve logging of RMF (aonishuk)

Andrew Onishuk 10 éve
szülő
commit
c34b474108

+ 3 - 3
ambari-agent/src/test/python/resource_management/TestDirectoryResource.py

@@ -111,7 +111,7 @@ class TestDirectoryResource(TestCase):
         )
       self.fail("Must fail because parent directory /a/b/c doesn't exist")
     except Fail as e:
-      self.assertEqual('Applying u"Directory[\'/a/b/c/d\']" failed, parent directory /a/b/c doesn\'t exist',
+      self.assertEqual('Applying Directory[\'/a/b/c/d\'] failed, parent directory /a/b/c doesn\'t exist',
                        str(e))
 
   @patch.object(sudo, "path_exists")
@@ -130,7 +130,7 @@ class TestDirectoryResource(TestCase):
         )
       self.fail("Must fail because file /a/b/c/d already exists")
     except Fail as e:
-      self.assertEqual('Applying u"Directory[\'/a/b/c/d\']" failed, file /a/b/c/d already exists',
+      self.assertEqual('Applying Directory[\'/a/b/c/d\'] failed, file /a/b/c/d already exists',
                        str(e))
   
   @patch.object(sudo, "rmtree")
@@ -170,5 +170,5 @@ class TestDirectoryResource(TestCase):
         )
       self.fail("Must fail because /a/b/c/d is not a directory")
     except Fail as e:
-      self.assertEqual('Applying u"Directory[\'/a/b/c/d\']" failed, /a/b/c/d is not a directory',
+      self.assertEqual('Applying Directory[\'/a/b/c/d\'] failed, /a/b/c/d is not a directory',
                        str(e))

+ 1 - 1
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]),
-                       'u"Execute[\'path -kt keytab principal\']"')
+                       '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,

+ 2 - 2
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 u"File[\'/existent_directory\']" failed, directory with name /existent_directory exists',
+      self.assertEqual('Applying 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 u"File[\'/non_existent_directory/file\']" failed, parent directory /non_existent_directory doesn\'t exist',
+        'Applying File[\'/non_existent_directory/file\'] failed, parent directory /non_existent_directory doesn\'t exist',
         str(e))
     self.assertTrue(dirname_mock.called)
 

+ 2 - 2
ambari-agent/src/test/python/resource_management/TestLinkResource.py

@@ -110,7 +110,7 @@ class TestLinkResource(TestCase):
         )  
         self.fail("Must fail when target directory do doenst exist")
       except Fail as e:
-        self.assertEqual('Failed to apply u"Link[\'/some_path\']", linking to nonexistent location /a/b/link_to_path',
+        self.assertEqual('Failed to apply Link[\'/some_path\'], linking to nonexistent location /a/b/link_to_path',
                        str(e))
         
   @patch.object(sudo, "path_isdir") 
@@ -130,7 +130,7 @@ class TestLinkResource(TestCase):
         )  
         self.fail("Must fail when hardlinking to directory")
       except Fail as e:
-        self.assertEqual('Failed to apply u"Link[\'/some_path\']", cannot create hard link to a directory (/a/b/link_to_path)',
+        self.assertEqual('Failed to apply Link[\'/some_path\'], cannot create hard link to a directory (/a/b/link_to_path)',
                        str(e)) 
         
   @patch.object(sudo, "unlink")

+ 8 - 8
ambari-agent/src/test/python/resource_management/TestMonitorWebserverResource.py

@@ -31,11 +31,11 @@ class TestMonitorWebserverResource(TestCase):
     with Environment(test_mode=True) as env:
       MonitorWebserverProvider(MonitorWebserver("start")).action_start()
     defined_resources = env.resource_list
-    expected_resources = '[u"MonitorWebserver[\'start\']", u"Execute[\'grep -E \'KeepAlive (On|Off)\' ' \
+    expected_resources = '[MonitorWebserver[\'start\'], Execute[\'grep -E \'KeepAlive (On|Off)\' ' \
                          '/etc/httpd/conf/httpd.conf && ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E sed -i ' \
                          '\'s/KeepAlive Off/KeepAlive On/\' /etc/httpd/conf/httpd.conf || echo \'KeepAlive On\' ' \
-                         '| ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/httpd/conf/httpd.conf > /dev/null\']"' \
-                         ', u"Execute[\'(\'/etc/init.d/httpd\', \'start\')\']"]'
+                         '| ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/httpd/conf/httpd.conf > /dev/null\']' \
+                         ', Execute[\'(\'/etc/init.d/httpd\', \'start\')\']]'
     self.assertEqual(str(defined_resources), expected_resources)
 
   @patch.object(System, "os_family", new='suse')
@@ -43,11 +43,11 @@ class TestMonitorWebserverResource(TestCase):
     with Environment(test_mode=True) as env:
       MonitorWebserverProvider(MonitorWebserver("start")).action_start()
     defined_resources = env.resource_list
-    expected_resources = '[u"MonitorWebserver[\'start\']", u"Execute[\'grep -E \'KeepAlive (On|Off)\' ' \
+    expected_resources = '[MonitorWebserver[\'start\'], Execute[\'grep -E \'KeepAlive (On|Off)\' ' \
                          '/etc/apache2/httpd.conf && ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E sed -i ' \
                          '\'s/KeepAlive Off/KeepAlive On/\' /etc/apache2/httpd.conf || echo \'KeepAlive On\' ' \
-                         '| ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/apache2/httpd.conf > /dev/null\']",' \
-                         ' u"Execute[\'(\'/etc/init.d/apache2\', \'start\')\']"]'
+                         '| ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E tee --append /etc/apache2/httpd.conf > /dev/null\'],' \
+                         ' Execute[\'(\'/etc/init.d/apache2\', \'start\')\']]'
     self.assertEqual(str(defined_resources), expected_resources)
 
   @patch.object(System, "os_family", new='redhat')
@@ -55,7 +55,7 @@ class TestMonitorWebserverResource(TestCase):
     with Environment(test_mode=True) as env:
       MonitorWebserverProvider(MonitorWebserver("stop")).action_stop()
     defined_resources = env.resource_list
-    expected_resources = '[u"MonitorWebserver[\'stop\']", u"Execute[\'(\'/etc/init.d/httpd\', \'stop\')\']"]'
+    expected_resources = '[MonitorWebserver[\'stop\'], Execute[\'(\'/etc/init.d/httpd\', \'stop\')\']]'
     self.assertEqual(str(defined_resources), expected_resources)
 
   @patch.object(System, "os_family", new='suse')
@@ -63,5 +63,5 @@ class TestMonitorWebserverResource(TestCase):
     with Environment(test_mode=True) as env:
       MonitorWebserverProvider(MonitorWebserver("stop")).action_stop()
     defined_resources = env.resource_list
-    expected_resources = '[u"MonitorWebserver[\'stop\']", u"Execute[\'(\'/etc/init.d/apache2\', \'stop\')\']"]'
+    expected_resources = '[MonitorWebserver[\'stop\'], Execute[\'(\'/etc/init.d/apache2\', \'stop\')\']]'
     self.assertEqual(str(defined_resources), expected_resources)

+ 2 - 2
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, '[u"Package[\'hbase\']", u"Package[\'yet-another-package\']"]')
+    self.assertEqual(resource_dump, '[Package[\'hbase\'], Package[\'yet-another-package\']]')
 
   @patch("__builtin__.open")
   def test_structured_out(self, open_mock):
@@ -130,7 +130,7 @@ class TestScript(TestCase):
       Script.config = good_config
       script.set_version()
     resource_dump = pprint.pformat(env.resource_list)
-    self.assertEquals(resource_dump, '[u"Execute[\'(\'/usr/bin/hdp-select\', \'set\', \'kafka-broker\', \'2.2.0.0-2041\')\']"]')
+    self.assertEquals(resource_dump, '[Execute[\'(\'/usr/bin/hdp-select\', \'set\', \'kafka-broker\', \'2.2.0.0-2041\')\']]')
 
     # Component does not provide mapping
     get_stack_to_component_mock.return_value = {}

+ 1 - 1
ambari-common/src/main/python/resource_management/core/base.py

@@ -151,7 +151,7 @@ class Resource(object):
     pass
 
   def __repr__(self):
-    return repr(unicode(self))
+    return unicode(self)
 
   def __unicode__(self):
     return u"%s['%s']" % (self.__class__.__name__, self.name)

+ 7 - 1
ambari-common/src/main/python/resource_management/core/shell.py

@@ -66,7 +66,13 @@ def log_function_call(function):
       ('logoutput' in kwargs and kwargs['logoutput']==None and Logger.logger.isEnabledFor(logging.DEBUG)) or \
       (not 'logoutput' in kwargs and not is_internal_call and Logger.logger.isEnabledFor(logging.DEBUG))
        
-    return function(command, **kwargs)
+    result = function(command, **kwargs)
+    
+    if quiet == False or (quiet == None and not is_internal_call):
+      log_msg = "{0} returned {1}".format(function.__name__, result)
+      Logger.info(log_msg)
+      
+    return result
     
   return inner
 

+ 1 - 1
ambari-common/src/main/python/resource_management/libraries/functions/version_select_util.py

@@ -57,7 +57,7 @@ def get_component_version(stack_name, component_name):
       if code != 0 or out is None:
         raise Exception("Code is nonzero or output is empty")
 
-      Logger.info("Command: %s\nOutput: %s" % (get_hdp_comp_version_cmd, str(out)))
+      Logger.debug("Command: %s\nOutput: %s" % (get_hdp_comp_version_cmd, str(out)))
       matches = re.findall(r"([\d\.]+\-\d+)", out)
       version = matches[0] if matches and len(matches) > 0 else None
     except Exception, e: