Need to get the drone temporary directory under the results dir as well. Added unit tests to check this and to check the behavior of attach_file_to_execution, which was being affected by this bug (but wasn't actually buggy itself).
Signed-off-by: Steve Howard <showard@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@3855 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/scheduler/drone_manager.py b/scheduler/drone_manager.py
index 93753fd..6834d92 100644
--- a/scheduler/drone_manager.py
+++ b/scheduler/drone_manager.py
@@ -113,12 +113,12 @@
def initialize(self, base_results_dir, drone_hostnames,
results_repository_hostname):
self._results_dir = base_results_dir
- drones.set_temporary_directory(os.path.join(
- drones.AUTOTEST_INSTALL_DIR, drone_utility._TEMPORARY_DIRECTORY))
+ drones.set_temporary_directory(
+ self.absolute_path(drone_utility._TEMPORARY_DIRECTORY))
for hostname in drone_hostnames:
drone = self._add_drone(hostname)
- drone.call('initialize', base_results_dir)
+ drone.call('initialize', self.absolute_path(''))
if not self._drones:
# all drones failed to initialize
diff --git a/scheduler/drone_manager_unittest.py b/scheduler/drone_manager_unittest.py
index 6ad9601..d388a82 100755
--- a/scheduler/drone_manager_unittest.py
+++ b/scheduler/drone_manager_unittest.py
@@ -3,7 +3,7 @@
import os, unittest
import common
from autotest_lib.client.common_lib.test_utils import mock
-from autotest_lib.scheduler import drone_manager, drones
+from autotest_lib.scheduler import drone_manager, drone_utility, drones
class MockDrone(drones._AbstractDrone):
def __init__(self, name, active_processes, max_processes):
@@ -20,6 +20,11 @@
self._recorded_calls['queue_call'].append((method, args, kwargs))
+ def call(self, method, *args, **kwargs):
+ # don't bother differentiating between call() and queue_call()
+ return self.queue_call(method, *args, **kwargs)
+
+
def send_file_to(self, drone, source_path, destination_path,
can_fail=False):
self._recorded_calls['send_file_to'].append(
@@ -53,6 +58,7 @@
_RESULTS_DIR = '/results/dir'
_SOURCE_PATH = 'source/path'
_DESTINATION_PATH = 'destination/path'
+ _WORKING_DIRECTORY = 'working/directory'
def setUp(self):
self.god = mock.mock_god()
@@ -61,6 +67,9 @@
self.manager = drone_manager.DroneManager()
self.god.stub_with(self.manager, '_results_dir', self._RESULTS_DIR)
+ # we don't want this to ever actually get called
+ self.god.stub_function(drones, 'get_drone')
+
# set up some dummy drones
self.mock_drone = MockDrone('mock_drone', 0, 10)
self.manager._drones[self.mock_drone.name] = self.mock_drone
@@ -102,21 +111,39 @@
self.assertEquals(drone.name, 1)
+ def test_initialize(self):
+ self.god.stub_function(drones, 'set_temporary_directory')
+ results_hostname = 'results_repo'
+
+ drones.set_temporary_directory.expect_call(
+ os.path.join(self._DRONE_RESULTS_DIR,
+ drone_utility._TEMPORARY_DIRECTORY))
+ (drones.get_drone.expect_call(self.mock_drone.name)
+ .and_return(self.mock_drone))
+ drones.get_drone.expect_call(results_hostname).and_return(object())
+
+ self.manager.initialize(base_results_dir=self._RESULTS_DIR,
+ drone_hostnames=[self.mock_drone.name],
+ results_repository_hostname=results_hostname)
+
+ self.assert_(self.mock_drone.was_call_queued(
+ 'initialize', self._DRONE_RESULTS_DIR + '/'))
+
+
def test_execute_command(self):
self.manager._enqueue_drone(self.mock_drone)
- working_directory = 'working/directory'
pidfile_name = 'my_pidfile'
log_file = 'log_file'
pidfile_id = self.manager.execute_command(
command=['test', drone_manager.WORKING_DIRECTORY],
- working_directory=working_directory,
+ working_directory=self._WORKING_DIRECTORY,
pidfile_name=pidfile_name,
log_file=log_file)
full_working_directory = os.path.join(self._DRONE_RESULTS_DIR,
- working_directory)
+ self._WORKING_DIRECTORY)
self.assertEquals(pidfile_id.path,
os.path.join(full_working_directory, pidfile_name))
self.assert_(self.mock_drone.was_call_queued(
@@ -125,6 +152,22 @@
os.path.join(self._DRONE_RESULTS_DIR, log_file), pidfile_name))
+ def test_attach_file_to_execution(self):
+ self.manager._enqueue_drone(self.mock_drone)
+
+ contents = 'my\ncontents'
+ attached_path = self.manager.attach_file_to_execution(
+ self._WORKING_DIRECTORY, contents)
+ self.manager.execute_command(command=['test'],
+ working_directory=self._WORKING_DIRECTORY,
+ pidfile_name='mypidfile')
+
+ self.assert_(self.mock_drone.was_call_queued(
+ 'write_to_file',
+ os.path.join(self._DRONE_RESULTS_DIR, attached_path),
+ contents))
+
+
def test_copy_results_on_drone(self):
self.manager.copy_results_on_drone(self.mock_drone_process,
self._SOURCE_PATH,