diff options
author | lmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4> | 2011-03-10 19:50:29 +0000 |
---|---|---|
committer | lmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4> | 2011-03-10 19:50:29 +0000 |
commit | 3d9ef8a26dd893be5cf2b26cb17f984f217fb4d7 (patch) | |
tree | 799fdadca4fa83e7b3b2e6525a0fdce31d0c7b9e /scheduler | |
parent | b6317a104e1e08a54f6d1f696b534132a8b63714 (diff) |
scheduler: Prevent the scheduler from logging the stdout return
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 <gps@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@5277 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'scheduler')
-rw-r--r-- | scheduler/drones.py | 14 | ||||
-rwxr-xr-x | scheduler/drones_unittest.py | 54 |
2 files changed, 63 insertions, 5 deletions
diff --git a/scheduler/drones.py b/scheduler/drones.py index b742b55b..effde182 100644 --- a/scheduler/drones.py +++ b/scheduler/drones.py @@ -122,6 +122,12 @@ class _RemoteDrone(_AbstractDrone): 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 @@ class _RemoteDrone(_AbstractDrone): 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 diff --git a/scheduler/drones_unittest.py b/scheduler/drones_unittest.py new file mode 100755 index 00000000..0713d52e --- /dev/null +++ b/scheduler/drones_unittest.py @@ -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() |