Alex Miller | 6ee996f | 2013-02-28 13:53:52 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 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', |
Prashanth B | 3ef8213 | 2014-07-08 23:38:53 +0000 | [diff] [blame] | 36 | 'mock-drone-utility-path') |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 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( |
Prashanth B | 3ef8213 | 2014-07-08 23:38:53 +0000 | [diff] [blame] | 43 | 'python mock-drone-utility-path', |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 44 | stdin=cPickle.dumps(mock_calls), stdout_tee=None, |
| 45 | connect_timeout=mock.is_instance_comparator(int)).and_return( |
| 46 | mock_result) |
Prashanth B | 3ef8213 | 2014-07-08 23:38:53 +0000 | [diff] [blame] | 47 | |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 48 | drone = drones._RemoteDrone('fakehost') |
| 49 | self.assertEqual('mock return', drone._execute_calls_impl(mock_calls)) |
| 50 | self.god.check_playback() |
| 51 | |
| 52 | |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 53 | if __name__ == '__main__': |
| 54 | unittest.main() |