OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 |
| 3 """Tests for autotest_lib.scheduler.drones.""" |
| 4 |
| 5 import cPickle |
| 6 |
| 7 import common |
| 8 from autotest_lib.client.common_lib import utils |
| 9 from autotest_lib.client.common_lib.test_utils import mock, unittest |
| 10 from autotest_lib.scheduler import drones |
| 11 from autotest_lib.server.hosts import ssh_host |
| 12 |
| 13 |
| 14 class RemoteDroneTest(unittest.TestCase): |
| 15 def setUp(self): |
| 16 self.god = mock.mock_god() |
| 17 self._mock_host = self.god.create_mock_class(ssh_host.SSHHost, |
| 18 'mock SSHHost') |
| 19 self.god.stub_function(drones.drone_utility, 'create_host') |
| 20 |
| 21 |
| 22 def tearDown(self): |
| 23 self.god.unstub_all() |
| 24 |
| 25 |
| 26 def test_unreachable(self): |
| 27 drones.drone_utility.create_host.expect_call('fakehost').and_return( |
| 28 self._mock_host) |
| 29 self._mock_host.is_up.expect_call().and_return(False) |
| 30 self.assertRaises(drones.DroneUnreachable, |
| 31 drones._RemoteDrone, 'fakehost') |
| 32 |
| 33 |
| 34 def test_execute_calls_impl(self): |
| 35 self.god.stub_with(drones._RemoteDrone, '_drone_utility_path', |
| 36 'mock-drone-utility-path') |
| 37 drones.drone_utility.create_host.expect_call('fakehost').and_return( |
| 38 self._mock_host) |
| 39 self._mock_host.is_up.expect_call().and_return(True) |
| 40 mock_calls = ('foo',) |
| 41 mock_result = utils.CmdResult(stdout=cPickle.dumps('mock return')) |
| 42 self._mock_host.run.expect_call( |
| 43 'python mock-drone-utility-path', |
| 44 stdin=cPickle.dumps(mock_calls), stdout_tee=None, |
| 45 connect_timeout=mock.is_instance_comparator(int)).and_return( |
| 46 mock_result) |
| 47 |
| 48 drone = drones._RemoteDrone('fakehost') |
| 49 self.assertEqual('mock return', drone._execute_calls_impl(mock_calls)) |
| 50 self.god.check_playback() |
| 51 |
| 52 |
| 53 if __name__ == '__main__': |
| 54 unittest.main() |
OLD | NEW |