Add a hosts attribute to server jobs for accessing all the hosts in
use as part of a server job, and replace the __del__ method on hosts
with an explicit close. When the job finishes it will take care to
close out any hosts left in job.hosts.
This will allow us to implement generic code that operates on all
hosts currently in use, and also fixes the general reliabilty issues
that we've seen with the __del__ method.
Risk: Medium
Visibility: Host.__del__ calls are pushed off until the end of the
job, and all hosts in use are available via job.hosts.
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@2427 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/autoserv b/server/autoserv
index 47b068d..936f1ff 100755
--- a/server/autoserv
+++ b/server/autoserv
@@ -148,6 +148,9 @@
job.run(cleanup, install_before, install_after)
finally:
job.cleanup_parser()
+ while job.hosts:
+ host = job.hosts.pop()
+ host.close()
except:
exit_code = 1
traceback.print_exc()
diff --git a/server/hosts/base_classes.py b/server/hosts/base_classes.py
index bd3b69a..0dd5922 100644
--- a/server/hosts/base_classes.py
+++ b/server/hosts/base_classes.py
@@ -20,7 +20,8 @@
import os, re, time
-from autotest_lib.client.common_lib import global_config, error, host_protections
+from autotest_lib.client.common_lib import global_config, error
+from autotest_lib.client.common_lib import host_protections
from autotest_lib.server import utils
from autotest_lib.server.hosts import bootloader
@@ -59,6 +60,8 @@
def __init__(self, *args, **dargs):
self._initialize(*args, **dargs)
self.start_loggers()
+ if self.job:
+ self.job.hosts.add(self)
def _initialize(self, initialize=True, target_file_owner=None,
@@ -71,6 +74,11 @@
self.target_file_owner = target_file_owner
+ def close(self):
+ if self.job:
+ self.job.hosts.discard(self)
+
+
def setup(self):
pass
diff --git a/server/hosts/remote.py b/server/hosts/remote.py
index 1cde00e..7659a3f 100644
--- a/server/hosts/remote.py
+++ b/server/hosts/remote.py
@@ -34,7 +34,8 @@
self.tmp_dirs = []
- def __del__(self):
+ def close(self):
+ super(RemoteHost, self).close()
self.stop_loggers()
if hasattr(self, 'tmp_dirs'):
diff --git a/server/server_job.py b/server/server_job.py
index fa1eb9b..f428914 100755
--- a/server/server_job.py
+++ b/server/server_job.py
@@ -118,6 +118,7 @@
self.ssh_pass = ssh_pass
self.run_test_cleanup = True
self.last_boot_tag = None
+ self.hosts = set()
self.stdout = fd_stack.fd_stack(1, sys.stdout)
self.stderr = fd_stack.fd_stack(2, sys.stderr)