blob: a3c3953862ed43ce657f3346cb26c848f2f2321c [file] [log] [blame]
Alex Miller6ee996f2013-02-28 13:53:52 -08001#!/usr/bin/python
Prashanth B340fd1e2014-06-22 12:44:10 -07002#pylint: disable-msg=C0111
Eric Lid656d562011-04-20 11:48:29 -07003
4"""Tests for autotest_lib.scheduler.drones."""
5
6import cPickle
7
8import common
9from autotest_lib.client.common_lib import utils
10from autotest_lib.client.common_lib.test_utils import mock, unittest
11from autotest_lib.scheduler import drones
12from autotest_lib.server.hosts import ssh_host
13
14
15class RemoteDroneTest(unittest.TestCase):
Prashanth B340fd1e2014-06-22 12:44:10 -070016
Eric Lid656d562011-04-20 11:48:29 -070017 def setUp(self):
18 self.god = mock.mock_god()
19 self._mock_host = self.god.create_mock_class(ssh_host.SSHHost,
20 'mock SSHHost')
21 self.god.stub_function(drones.drone_utility, 'create_host')
Prashanth B340fd1e2014-06-22 12:44:10 -070022 self.drone_utility_path = 'mock-drone-utility-path'
Eric Lid656d562011-04-20 11:48:29 -070023
24
25 def tearDown(self):
26 self.god.unstub_all()
27
28
29 def test_unreachable(self):
30 drones.drone_utility.create_host.expect_call('fakehost').and_return(
31 self._mock_host)
32 self._mock_host.is_up.expect_call().and_return(False)
33 self.assertRaises(drones.DroneUnreachable,
34 drones._RemoteDrone, 'fakehost')
35
36
37 def test_execute_calls_impl(self):
38 self.god.stub_with(drones._RemoteDrone, '_drone_utility_path',
Prashanth B340fd1e2014-06-22 12:44:10 -070039 self.drone_utility_path)
Eric Lid656d562011-04-20 11:48:29 -070040 drones.drone_utility.create_host.expect_call('fakehost').and_return(
41 self._mock_host)
42 self._mock_host.is_up.expect_call().and_return(True)
43 mock_calls = ('foo',)
44 mock_result = utils.CmdResult(stdout=cPickle.dumps('mock return'))
45 self._mock_host.run.expect_call(
Prashanth B340fd1e2014-06-22 12:44:10 -070046 'python %s' % self.drone_utility_path,
Eric Lid656d562011-04-20 11:48:29 -070047 stdin=cPickle.dumps(mock_calls), stdout_tee=None,
48 connect_timeout=mock.is_instance_comparator(int)).and_return(
49 mock_result)
Eric Lid656d562011-04-20 11:48:29 -070050 drone = drones._RemoteDrone('fakehost')
51 self.assertEqual('mock return', drone._execute_calls_impl(mock_calls))
52 self.god.check_playback()
53
54
Prashanth B340fd1e2014-06-22 12:44:10 -070055 def test_execute_queued_calls(self):
56 self.god.stub_with(drones._RemoteDrone, '_drone_utility_path',
57 self.drone_utility_path)
58 drones.drone_utility.create_host.expect_call('fakehost').and_return(
59 self._mock_host)
60 self._mock_host.is_up.expect_call().and_return(True)
61 drone = drones._RemoteDrone('fakehost')
62 mock_return={}
63 mock_return['results'] = ['mock return']
64 mock_return['warnings'] = []
65 drone.queue_call('foo')
66 mock_result = utils.CmdResult(stdout=cPickle.dumps(mock_return))
67 self._mock_host.run.expect_call(
68 'python %s' % self.drone_utility_path,
69 stdin=cPickle.dumps(drone.get_calls()), stdout_tee=None,
70 connect_timeout=mock.is_instance_comparator(int)).and_return(
71 mock_result)
72 self.assertEqual(mock_return['results'], drone.execute_queued_calls())
73 self.god.check_playback()
74
75
76
Eric Lid656d562011-04-20 11:48:29 -070077if __name__ == '__main__':
78 unittest.main()