test_monitor_command: mock LOG so we don't output error 71/37471/2
authorRoss Brattain <ross.b.brattain@intel.com>
Fri, 14 Jul 2017 06:14:07 +0000 (23:14 -0700)
committerRoss Brattain <ross.b.brattain@intel.com>
Fri, 14 Jul 2017 06:25:42 +0000 (23:25 -0700)
Don't print fake tracebacks to the unittest logs

Change-Id: I8a468b8c6566f02be88a9dd222567c14c66b0956
Signed-off-by: Ross Brattain <ross.b.brattain@intel.com>
tests/unit/benchmark/scenarios/availability/test_monitor_command.py
yardstick/benchmark/scenarios/availability/monitor/monitor_command.py

index 2ed4be7..6a9b3b1 100644 (file)
@@ -30,12 +30,14 @@ class ExecuteShellTestCase(unittest.TestCase):
         exitcode, output = monitor_command._execute_shell_command(cmd)
         self.assertEqual(exitcode, 0)
 
-    def test__fun_execute_shell_command_fail_cmd_exception(self,
+    @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG')
+    def test__fun_execute_shell_command_fail_cmd_exception(self, mock_log,
                                                            mock_subprocess):
         cmd = "env"
         mock_subprocess.check_output.side_effect = RuntimeError
         exitcode, output = monitor_command._execute_shell_command(cmd)
         self.assertEqual(exitcode, -1)
+        mock_log.error.assert_called_once()
 
 
 @mock.patch(
@@ -67,13 +69,15 @@ class MonitorOpenstackCmdTestCase(unittest.TestCase):
         instance._result = {"outage_time": 0}
         instance.verify_SLA()
 
-    def test__monitor_command_monitor_func_failure(self, mock_subprocess):
+    @mock.patch('yardstick.benchmark.scenarios.availability.monitor.monitor_command.LOG')
+    def test__monitor_command_monitor_func_failure(self, mock_log, mock_subprocess):
         mock_subprocess.check_output.return_value = (1, 'unittest')
         instance = monitor_command.MonitorOpenstackCmd(self.config, None, {"nova-api": 10})
         instance.setup()
         mock_subprocess.check_output.side_effect = RuntimeError
         ret = instance.monitor_func()
         self.assertEqual(ret, False)
+        mock_log.error.assert_called_once()
         instance._result = {"outage_time": 10}
         instance.verify_SLA()
 
index a0777f9..a9488cc 100644 (file)
@@ -11,7 +11,6 @@ from __future__ import absolute_import
 import os
 import logging
 import subprocess
-import traceback
 
 import yardstick.ssh as ssh
 from yardstick.benchmark.scenarios.availability.monitor import basemonitor
@@ -27,9 +26,7 @@ def _execute_shell_command(command):
         output = subprocess.check_output(command, shell=True)
     except Exception:
         exitcode = -1
-        output = traceback.format_exc()
-        LOG.error("exec command '%s' error:\n ", command)
-        LOG.error(traceback.format_exc())
+        LOG.error("exec command '%s' error:\n ", command, exc_info=True)
 
     return exitcode, output