瀏覽代碼

AMBARI-3875. Ambari Client unit test output should be redirected to a log file like the agent logs (Eugene Chekanskiy via dlysnichenko)

Lisnichenko Dmitro 11 年之前
父節點
當前提交
b8cc8ea55d

+ 6 - 1
ambari-client/src/test/python/TestAmbariClient.py

@@ -24,9 +24,14 @@ from ambari_client.ambari_api import  AmbariClient
 from HttpClientInvoker import HttpClientInvoker
 from ambari_client.model.stack import StackConfigModel, StackComponentModel
 import unittest
+import logging
 
 class TestAmbariClient(unittest.TestCase):
-  
+
+  def setUp(self):
+    http_client_logger = logging.getLogger()
+    http_client_logger.info('Running test:' + self.id())
+
   def create_client(self, http_client_mock = MagicMock()):
     http_client_mock.invoke.side_effect = HttpClientInvoker.http_client_invoke_side_effects
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)

+ 7 - 3
ambari-client/src/test/python/TestClusterModel.py

@@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 '''
-
+import logging
 
 from mock.mock import MagicMock, patch
 from HttpClientInvoker import HttpClientInvoker
@@ -29,7 +29,11 @@ from ambari_client.core.errors import BadRequest
 import unittest
 
 class TestClusterModel(unittest.TestCase):
-  
+
+  def setUp(self):
+    http_client_logger = logging.getLogger()
+    http_client_logger.info('Running test:' + self.id())
+
   def create_cluster(self, http_client_mock = MagicMock()):    
     http_client_mock.invoke.side_effect = HttpClientInvoker.http_client_invoke_side_effects
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)
@@ -80,7 +84,7 @@ class TestClusterModel(unittest.TestCase):
     self.assertEqual(hostlist.to_json_dict(), expected_dict_output)
     self.assertEqual(hostlist[1].host_name, 'dev06.hortonworks.com')
     self.assertEqual(len(hostlist), 2)  
-    
+
   def test_get_host(self):
     """
     Get cluster host

+ 5 - 1
ambari-client/src/test/python/TestComponentModel.py

@@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 '''
-
+import logging
 
 from mock.mock import MagicMock, patch
 from HttpClientInvoker import HttpClientInvoker
@@ -28,6 +28,10 @@ import unittest
 
 class TestClusterModel(unittest.TestCase):
 
+  def setUp(self):
+    http_client_logger = logging.getLogger()
+    http_client_logger.info('Running test:' + self.id())
+
   def create_component(self, http_client_mock = MagicMock()):
     http_client_mock.invoke.side_effect = HttpClientInvoker.http_client_invoke_side_effects
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)

+ 5 - 1
ambari-client/src/test/python/TestHostModel.py

@@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 '''
-
+import logging
 
 from mock.mock import MagicMock, patch
 from HttpClientInvoker import HttpClientInvoker
@@ -28,6 +28,10 @@ import unittest
 
 class TestHostModel(unittest.TestCase):
 
+  def setUp(self):
+    http_client_logger = logging.getLogger()
+    http_client_logger.info('Running test:' + self.id())
+
   def create_host(self, http_client_mock = MagicMock()):
     http_client_mock.invoke.side_effect = HttpClientInvoker.http_client_invoke_side_effects
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)

+ 5 - 1
ambari-client/src/test/python/TestServiceModel.py

@@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 '''
-
+import logging
 
 from mock.mock import MagicMock, patch
 from HttpClientInvoker import HttpClientInvoker
@@ -28,6 +28,10 @@ import unittest
 
 class TestServiceModel(unittest.TestCase):
 
+  def setUp(self):
+    http_client_logger = logging.getLogger()
+    http_client_logger.info('Running test:' + self.id())
+
   def create_service(self, http_client_mock = MagicMock()):
     http_client_mock.invoke.side_effect = HttpClientInvoker.http_client_invoke_side_effects
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)

+ 5 - 1
ambari-client/src/test/python/TestStatusModel.py

@@ -17,7 +17,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 '''
-
+import logging
 
 from ambari_client.model.status import StatusModel
 from mock.mock import MagicMock, patch
@@ -28,6 +28,10 @@ import unittest
 
 class TestStatusModel(unittest.TestCase):
 
+  def setUp(self):
+    http_client_logger = logging.getLogger()
+    http_client_logger.info('Running test:' + self.id())
+
   def create_service(self, http_client_mock = MagicMock()):
     http_client_mock.invoke.side_effect = HttpClientInvoker.http_client_invoke_side_effects
     client = AmbariClient("localhost", 8080, "admin", "admin", version=1, client=http_client_mock)

+ 6 - 1
ambari-client/src/test/python/unitTests.py

@@ -79,7 +79,12 @@ def main():
   logger.info('------------------------------------------------------------------------')
   runner = unittest.TextTestRunner(verbosity=2, stream=sys.stdout)
   suite = all_tests_suite()
-  status = runner.run(suite).wasSuccessful()
+  result = runner.run(suite)
+  for error in result.errors:
+    logger.error('Failed test:' + error[0]._testMethodName + '\n' + error[1])
+  for failure in result.failures:
+    logger.error('Failed test:' + failure[0]._testMethodName + '\n' + failure[1])
+  status = result.wasSuccessful()
 
   if not status:
     logger.error('-----------------------------------------------------------------------')

+ 5 - 2
ambari-client/src/test/python/utils/HttpClientInvoker.py

@@ -1,8 +1,11 @@
+import logging
+import unittest
 class HttpClientInvoker():
   @staticmethod
   def http_client_invoke_side_effects(*args, **kwargs):
-      print locals()
-      
+      localss = locals()
+      logger = logging.getLogger()
+      logger.info(localss)
       http_method = args[0]
       url = args[1]
       payload = kwargs.get("payload",None)