| OLD | NEW | 
|---|
| 1 """This class defines the Remote host class, mixing in the SiteHost class | 1 """This class defines the Remote host class, mixing in the SiteHost class | 
| 2 if it is available.""" | 2 if it is available.""" | 
| 3 | 3 | 
| 4 import os, logging | 4 import os, logging, urllib | 
| 5 from autotest_lib.client.common_lib import error | 5 from autotest_lib.client.common_lib import error | 
| 6 from autotest_lib.server import utils | 6 from autotest_lib.server import utils | 
| 7 from autotest_lib.server.hosts import base_classes, bootloader | 7 from autotest_lib.server.hosts import base_classes, bootloader | 
| 8 | 8 | 
| 9 | 9 | 
| 10 class RemoteHost(base_classes.Host): | 10 class RemoteHost(base_classes.Host): | 
| 11     """ | 11     """ | 
| 12     This class represents a remote machine on which you can run | 12     This class represents a remote machine on which you can run | 
| 13     programs. | 13     programs. | 
| 14 | 14 | 
| 15     It may be accessed through a network, a serial line, ... | 15     It may be accessed through a network, a serial line, ... | 
| 16     It is not the machine autoserv is running on. | 16     It is not the machine autoserv is running on. | 
| 17 | 17 | 
| 18     Implementation details: | 18     Implementation details: | 
| 19     This is an abstract class, leaf subclasses must implement the methods | 19     This is an abstract class, leaf subclasses must implement the methods | 
| 20     listed here and in parent classes which have no implementation. They | 20     listed here and in parent classes which have no implementation. They | 
| 21     may reimplement methods which already have an implementation. You | 21     may reimplement methods which already have an implementation. You | 
| 22     must not instantiate this class but should instantiate one of those | 22     must not instantiate this class but should instantiate one of those | 
| 23     leaf subclasses. | 23     leaf subclasses. | 
| 24     """ | 24     """ | 
| 25 | 25 | 
| 26     DEFAULT_REBOOT_TIMEOUT = base_classes.Host.DEFAULT_REBOOT_TIMEOUT | 26     DEFAULT_REBOOT_TIMEOUT = base_classes.Host.DEFAULT_REBOOT_TIMEOUT | 
| 27     LAST_BOOT_TAG = object() | 27     LAST_BOOT_TAG = object() | 
|  | 28     DEFAULT_HALT_TIMEOUT = 2 * 60 | 
| 28 | 29 | 
| 29     VAR_LOG_MESSAGES_COPY_PATH = "/var/log/messages.autotest_start" | 30     VAR_LOG_MESSAGES_COPY_PATH = "/var/log/messages.autotest_start" | 
| 30 | 31 | 
| 31     def _initialize(self, hostname, autodir=None, *args, **dargs): | 32     def _initialize(self, hostname, autodir=None, *args, **dargs): | 
| 32         super(RemoteHost, self)._initialize(*args, **dargs) | 33         super(RemoteHost, self)._initialize(*args, **dargs) | 
| 33 | 34 | 
| 34         self.hostname = hostname | 35         self.hostname = hostname | 
| 35         self.autodir = autodir | 36         self.autodir = autodir | 
| 36         self.tmp_dirs = [] | 37         self.tmp_dirs = [] | 
| 37 | 38 | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 81         where autotest is installed. Called in server/autotest.py | 82         where autotest is installed. Called in server/autotest.py | 
| 82         after a successful install | 83         after a successful install | 
| 83         """ | 84         """ | 
| 84         self.autodir = autodir | 85         self.autodir = autodir | 
| 85 | 86 | 
| 86 | 87 | 
| 87     def sysrq_reboot(self): | 88     def sysrq_reboot(self): | 
| 88         self.run('echo b > /proc/sysrq-trigger &') | 89         self.run('echo b > /proc/sysrq-trigger &') | 
| 89 | 90 | 
| 90 | 91 | 
|  | 92     def halt(self, timeout=DEFAULT_HALT_TIMEOUT, wait=True): | 
|  | 93         self.run('/sbin/halt') | 
|  | 94         if wait: | 
|  | 95             self.wait_down(timeout=timeout) | 
|  | 96 | 
|  | 97 | 
| 91     def reboot(self, timeout=DEFAULT_REBOOT_TIMEOUT, label=LAST_BOOT_TAG, | 98     def reboot(self, timeout=DEFAULT_REBOOT_TIMEOUT, label=LAST_BOOT_TAG, | 
| 92                kernel_args=None, wait=True, fastsync=False, | 99                kernel_args=None, wait=True, fastsync=False, | 
| 93                reboot_cmd=None, **dargs): | 100                reboot_cmd=None, **dargs): | 
| 94         """ | 101         """ | 
| 95         Reboot the remote host. | 102         Reboot the remote host. | 
| 96 | 103 | 
| 97         Args: | 104         Args: | 
| 98                 timeout - How long to wait for the reboot. | 105                 timeout - How long to wait for the reboot. | 
| 99                 label - The label we should boot into.  If None, we will | 106                 label - The label we should boot into.  If None, we will | 
| 100                         boot into the default kernel.  If it's LAST_BOOT_TAG, | 107                         boot into the default kernel.  If it's LAST_BOOT_TAG, | 
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 206 | 213 | 
| 207         if self.job: | 214         if self.job: | 
| 208             keyval_path = os.path.join(self.job.resultdir, 'host_keyvals', | 215             keyval_path = os.path.join(self.job.resultdir, 'host_keyvals', | 
| 209                                        self.hostname) | 216                                        self.hostname) | 
| 210             keyvals = utils.read_keyval(keyval_path) | 217             keyvals = utils.read_keyval(keyval_path) | 
| 211             return keyvals.get('platform', None) | 218             return keyvals.get('platform', None) | 
| 212         else: | 219         else: | 
| 213             return None | 220             return None | 
| 214 | 221 | 
| 215 | 222 | 
|  | 223     def get_all_labels(self): | 
|  | 224         """ | 
|  | 225         Return all labels, or empty list if label is not set. | 
|  | 226         """ | 
|  | 227         if self.job: | 
|  | 228             keyval_path = os.path.join(self.job.resultdir, 'host_keyvals', | 
|  | 229                                        self.hostname) | 
|  | 230             keyvals = utils.read_keyval(keyval_path) | 
|  | 231             all_labels = keyvals.get('labels', '') | 
|  | 232             if all_labels: | 
|  | 233               all_labels = all_labels.split(',') | 
|  | 234               return [urllib.unquote(label) for label in all_labels] | 
|  | 235         return [] | 
|  | 236 | 
|  | 237 | 
| 216     def delete_tmp_dir(self, tmpdir): | 238     def delete_tmp_dir(self, tmpdir): | 
| 217         """ | 239         """ | 
| 218         Delete the given temporary directory on the remote machine. | 240         Delete the given temporary directory on the remote machine. | 
| 219         """ | 241         """ | 
| 220         self.run('rm -rf "%s"' % utils.sh_escape(tmpdir), ignore_status=True) | 242         self.run('rm -rf "%s"' % utils.sh_escape(tmpdir), ignore_status=True) | 
| 221         self.tmp_dirs.remove(tmpdir) | 243         self.tmp_dirs.remove(tmpdir) | 
| 222 | 244 | 
| 223 | 245 | 
| 224     def check_uptime(self): | 246     def check_uptime(self): | 
| 225         """ | 247         """ | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 241         """ | 263         """ | 
| 242         processes = self.get_wait_up_processes() | 264         processes = self.get_wait_up_processes() | 
| 243         if len(processes) == 0: | 265         if len(processes) == 0: | 
| 244             return True # wait up processes aren't being used | 266             return True # wait up processes aren't being used | 
| 245         for procname in processes: | 267         for procname in processes: | 
| 246             exit_status = self.run("{ ps -e || ps; } | grep '%s'" % procname, | 268             exit_status = self.run("{ ps -e || ps; } | grep '%s'" % procname, | 
| 247                                    ignore_status=True).exit_status | 269                                    ignore_status=True).exit_status | 
| 248             if exit_status == 0: | 270             if exit_status == 0: | 
| 249                 return True | 271                 return True | 
| 250         return False | 272         return False | 
| OLD | NEW | 
|---|