Prevent the scheduler from logging the large pickled stdout return value of drone_utility in the scheduler debug logs. Adds a unittest.
Signed-off-by: Gregory Smith <g...@google.com> --- autotest/scheduler/drones.py 2010-10-29 15:37:05.000000000 -0700 +++ autotest/scheduler/drones.py 2011-01-27 16:51:47.000000000 -0800 @@ -122,6 +122,12 @@ self._autotest_install_dir = AUTOTEST_INSTALL_DIR + @property + def _drone_utility_path(self): + return os.path.join(self._autotest_install_dir, + 'scheduler', 'drone_utility.py') + + def set_autotest_install_dir(self, path): self._autotest_install_dir = path @@ -133,11 +139,9 @@ def _execute_calls_impl(self, calls): logging.info("Running drone_utility on %s", self.hostname) - drone_utility_path = os.path.join(self._autotest_install_dir, - 'scheduler', 'drone_utility.py') - result = self._host.run('python %s' % drone_utility_path, - stdin=cPickle.dumps(calls), connect_timeout=300) - + result = self._host.run('python %s' % self._drone_utility_path, + stdin=cPickle.dumps(calls), stdout_tee=None, + connect_timeout=300) try: return cPickle.loads(result.stdout) except Exception: # cPickle.loads can throw all kinds of exceptions ==== (added) //depot/google_vendor_src_branch/autotest/scheduler/drones_unittest.py#1 ==== --- /dev/null 2011-02-15 18:13:29.172335531 -0800 +++ autotest/scheduler/drones_unittest.py 2011-01-27 16:51:47.000000000 -0800 @@ -0,0 +1,54 @@ +#!/usr/bin/python2.4 + +"""Tests for autotest_lib.scheduler.drones.""" + +import cPickle + +import common +from autotest_lib.client.common_lib import utils +from autotest_lib.client.common_lib.test_utils import mock, unittest +from autotest_lib.scheduler import drones +from autotest_lib.server.hosts import ssh_host + + +class RemoteDroneTest(unittest.TestCase): + def setUp(self): + self.god = mock.mock_god() + self._mock_host = self.god.create_mock_class(ssh_host.SSHHost, + 'mock SSHHost') + self.god.stub_function(drones.drone_utility, 'create_host') + + + def tearDown(self): + self.god.unstub_all() + + + def test_unreachable(self): + drones.drone_utility.create_host.expect_call('fakehost').and_return( + self._mock_host) + self._mock_host.is_up.expect_call().and_return(False) + self.assertRaises(drones.DroneUnreachable, + drones._RemoteDrone, 'fakehost') + + + def test_execute_calls_impl(self): + self.god.stub_with(drones._RemoteDrone, '_drone_utility_path', + 'mock-drone-utility-path') + drones.drone_utility.create_host.expect_call('fakehost').and_return( + self._mock_host) + self._mock_host.is_up.expect_call().and_return(True) + mock_calls = ('foo',) + mock_result = utils.CmdResult(stdout=cPickle.dumps('mock return')) + self._mock_host.run.expect_call( + 'python mock-drone-utility-path', + stdin=cPickle.dumps(mock_calls), stdout_tee=None, + connect_timeout=mock.is_instance_comparator(int)).and_return( + mock_result) + + drone = drones._RemoteDrone('fakehost') + self.assertEqual('mock return', drone._execute_calls_impl(mock_calls)) + self.god.check_playback() + + +if __name__ == '__main__': + unittest.main() _______________________________________________ Autotest mailing list Autotest@test.kernel.org http://test.kernel.org/cgi-bin/mailman/listinfo/autotest