This patch adds basic preliminary support to cobbler
(https://fedorahosted.org/cobbler) to add as an install
server for autotest. Of course, deeper integration with
autotest is needed, but with this patch, it is already
possible to tell in the autotest web interface as well as
on the cli to reinstall the machine. There's still
a lot of work to do.

Signed-off-by: Cleber Rosa <[email protected]>
Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
 global_config.ini      |    6 ++++
 server/hosts/remote.py |   77 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/global_config.ini b/global_config.ini
index 1f0a76a..57ebb70 100644
--- a/global_config.ini
+++ b/global_config.ini
@@ -124,6 +124,12 @@ require_atfork_module: False
 # Set to False to disable ssh-agent usage with paramiko
 use_sshagent_with_paramiko: True
 
+[INSTALL_SERVER]
+type: cobbler
+#xmlrpc_server: http://foo.com/cobbler_api
+#user: bar
+#password: baz
+
 [PACKAGES]
 # Max age of packages in days. All packages older than this will be removed 
from
 # upload_location when the packager is run.
diff --git a/server/hosts/remote.py b/server/hosts/remote.py
index d1b4b46..1f8029d 100644
--- a/server/hosts/remote.py
+++ b/server/hosts/remote.py
@@ -1,8 +1,8 @@
 """This class defines the Remote host class, mixing in the SiteHost class
 if it is available."""
 
-import os, logging, urllib
-from autotest_lib.client.common_lib import error
+import os, logging, urllib, xmlrpclib, time
+from autotest_lib.client.common_lib import error, global_config
 from autotest_lib.server import utils
 from autotest_lib.server.hosts import base_classes, bootloader
 
@@ -35,6 +35,7 @@ class RemoteHost(base_classes.Host):
         self.hostname = hostname
         self.autodir = autodir
         self.tmp_dirs = []
+        self.global_config = global_config.global_config
 
 
     def __repr__(self):
@@ -45,6 +46,7 @@ class RemoteHost(base_classes.Host):
         super(RemoteHost, self).close()
         self.stop_loggers()
 
+
         if hasattr(self, 'tmp_dirs'):
             for dir in self.tmp_dirs:
                 try:
@@ -53,6 +55,77 @@ class RemoteHost(base_classes.Host):
                     pass
 
 
+    def install(self, distro=None, timeout=None):
+        """
+        Install a distro using the install server.
+
+        @param distro: Distro name inside the install server database.
+        """
+        server_url = self.global_config.get_config_value('INSTALL_SERVER',
+                                                         'xmlrpc_server',
+                                                         type=str,
+                                                         default='')
+        server_user = self.global_config.get_config_value('INSTALL_SERVER',
+                                                          'user',
+                                                          type=str,
+                                                          default='')
+        server_password = self.global_config.get_config_value('INSTALL_SERVER',
+                                                              'password',
+                                                              type=str,
+                                                              default='')
+
+        if server_url:
+            step_time = 60
+            if timeout is None:
+                # 1 hour of timeout by default
+                timeout = 1 * 3600
+            logging.info("Setting up machine %s install", self.hostname)
+            known_hosts_file = "%s/.ssh/known_hosts" % os.getenv("HOME")
+            if os.path.isfile(known_hosts_file):
+                logging.debug("Deleting known hosts file %s", known_hosts_file)
+                os.remove(known_hosts_file)
+            server = xmlrpclib.Server(server_url)
+            token = server.login(server_user, server_password)
+            try:
+                host = server.find_system({"name" : self.hostname})[0]
+            except IndexError, e:
+                ### TODO: Method to register this system as brand new
+                logging.error("Error finding %s: %s", self.hostname, e)
+                raise ValueError("No system %s registered on install server" %
+                                 self.hostname)
+
+            host_handle = server.get_system_handle(host, token)
+            if distro:
+                server.modify_system(host_handle, 'profile', distro, token)
+            # Enable netboot for that machine (next time it'll reboot and be
+            # reinstalled)
+            server.modify_system(host_handle, 'netboot_enabled', 'True', token)
+            # Now, let's just restart the machine (machine has to have
+            # power management data properly set up).
+            server.save_system(host_handle, token)
+            server.power_system(host_handle, 'reboot', token)
+            logging.info("Installing machine %s with profile %s (timeout %s 
s)",
+                         self.hostname, distro, timeout)
+            install_start = time.time()
+            time_elapsed = 0
+            install_successful = False
+            while time_elapsed < timeout:
+                sleep(step_time)
+                server_info = server.get_system(host)
+                install_successful = server_info.get('netboot_enabled', False)
+                if install_successful:
+                    break
+                time_elapsed = time.time() - install_start
+
+            if not install_successful:
+                raise error.HostInstallTimeoutError('Machine %s install '
+                                                    'timed out' % 
self.hostname)
+
+            self.wait_for_restart()
+            ### TODO: Method to verify correctness of install?
+            logging.info("Machine %s installed successfuly", self.hostname)
+
+
     def job_start(self):
         """
         Abstract method, called the first time a remote host object
-- 
1.7.6

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to