> 4/9: hosts: add installable_host class

Each host in a job may have a profile associated with it. This does not
seem to be really a component of what a SSHHost is, so create a new
sub-class, InstallableHost, of SSHHost which just adds a profile to the
parent object.

If the global_config specifies an install server URL, then we use
InstallableHosts rather than SSHHosts.

Signed-off-by: Nishanth Aravamudan <n...@us.ibm.com>

---
 server/hosts/factory.py          |   10 +++++++---
 server/hosts/installable_host.py |   34 ++++++++++++++++++++++++++++++++++
 server/hosts/remote.py           |    2 ++
 3 files changed, 43 insertions(+), 3 deletions(-)
 create mode 100644 server/hosts/installable_host.py

diff --git a/server/hosts/factory.py b/server/hosts/factory.py
index 6bd3f20..0e0c3f1 100644
--- a/server/hosts/factory.py
+++ b/server/hosts/factory.py
@@ -1,6 +1,6 @@
 from autotest_lib.client.common_lib import utils, error, global_config
 from autotest_lib.server import autotest_remote, utils as server_utils
-from autotest_lib.server.hosts import site_factory, ssh_host, serial
+from autotest_lib.server.hosts import site_factory, installable_host, 
ssh_host, serial
 from autotest_lib.server.hosts import logfile_monitor
 
 DEFAULT_FOLLOW_PATH = '/var/log/kern.log'
@@ -20,7 +20,11 @@ def create_host(
         from autotest_lib.server.hosts import paramiko_host
         classes = [paramiko_host.ParamikoHost]
     elif SSH_ENGINE == 'raw_ssh':
-        classes = [ssh_host.SSHHost, ssh_host.AsyncSSHMixin]
+        if global_config.global_config.get_config_value('INSTALL_SERVER', 
'xmlrpc_url'):
+            classes = [installable_host.InstallableHost]
+        else:
+            classes = [ssh_host.SSHHost]
+        classes.append(ssh_host.AsyncSSHMixin)
     else:
         raise error.AutoServError("Unknown SSH engine %s. Please verify the "
                                   "value of the configuration key 'ssh_engine' 
"
@@ -68,7 +72,7 @@ def create_host(
     site_factory.postprocess_classes(classes, hostname,
                                      auto_monitor=auto_monitor, **args)
 
-    hostname, args['user'], args['password'], args['port'] = \
+    hostname, args['user'], args['password'], args['port'], args['profile'] = \
             server_utils.parse_machine(hostname, ssh_user, ssh_pass, ssh_port)
 
     # create a custom host class for this machine and return an instance of it
diff --git a/server/hosts/installable_host.py b/server/hosts/installable_host.py
new file mode 100644
index 0000000..5e55eea
--- /dev/null
+++ b/server/hosts/installable_host.py
@@ -0,0 +1,34 @@
+#
+# Copyright 2012 IBM Inc. Released under the GPL v2
+
+"""
+This module defines the InstallableHost class.
+
+Implementation details:
+You should import the "hosts" package instead of importing each type of host.
+
+        InstallableHost: a remote machine with a ssh access and a profile
+"""
+
+import sys, re, traceback, logging, subprocess, os
+from autotest_lib.client.common_lib import error, pxssh
+from autotest_lib.server import utils
+from autotest_lib.server.hosts import ssh_host
+
+
+class InstallableHost(ssh_host.SSHHost):
+    """
+    Implementation details:
+    This is a leaf class in an abstract class hierarchy, it must
+    implement the unimplemented methods in parent classes.
+    """
+
+    def _initialize(self, hostname, profile, *args, **dargs):
+        """
+        Construct a SSHHost object
+
+        Args:
+                hostname: network hostname or address of remote machine
+        """
+        super(InstallableHost, self)._initialize(hostname=hostname, *args, 
**dargs)
+        self.profile = profile
diff --git a/server/hosts/remote.py b/server/hosts/remote.py
index a4f1fa4..ba9ac0d 100644
--- a/server/hosts/remote.py
+++ b/server/hosts/remote.py
@@ -73,6 +73,8 @@ class RemoteHost(base_classes.Host):
 
         @param profile: Profile name inside the install server database.
         """
+        if profile is None:
+            profile = self.profile
         server_info = get_install_server_info()
         if server_info.get('xmlrpc_url', None) is not None:
             ServerInterface = self.INSTALL_SERVER_MAPPING[server_info['type']]
-- 
1.7.7.6

-- 
Nishanth Aravamudan <n...@us.ibm.com>
IBM Linux Technology Center

_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to