Add some missing functions from the host class and utils
check_uptime, get_arch, get_kernel_ver, get_cmdline
Signed-off-by: Martin J. Bligh <mbligh@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@797 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/hosts/ssh_host.py b/server/hosts/ssh_host.py
index a68ba13..463546f 100644
--- a/server/hosts/ssh_host.py
+++ b/server/hosts/ssh_host.py
@@ -18,14 +18,8 @@
"""
-import types
-import os
-import time
-
-import base_classes
-import utils
-import errors
-import bootloader
+import types, os, time, re
+import base_classes, utils, errors, bootloader
class SSHHost(base_classes.RemoteHost):
@@ -336,9 +330,52 @@
The number of CPUs
"""
- proc_cpuinfo= self.run("cat /proc/cpuinfo").stdout
+ proc_cpuinfo = self.run("cat /proc/cpuinfo").stdout
cpus = 0
for line in proc_cpuinfo.splitlines():
if line.startswith('processor'):
cpus += 1
return cpus
+
+
+ def check_uptime(self):
+ """
+ Check that uptime is available and monotonically increasing.
+ """
+ if not self.ping():
+ raise "Client is not pingable"
+ result = self.run("/bin/cat /proc/uptime", 30)
+ return result.stdout.strip().split()[0]
+
+
+ def get_arch(self):
+ """
+ Get the hardware architecture of the remote machine
+ """
+ arch = self.run('/bin/uname -m').stdout.rstrip()
+ if re.match(r'i\d86$', arch):
+ arch = 'i386'
+ return arch
+
+
+ def get_kernel_ver(self):
+ """
+ Get the kernel version of the remote machine
+ """
+ return self.run('/bin/uname -r').stdout.rstrip()
+
+
+ def get_cmdline(self):
+ """
+ Get the kernel command line of the remote machine
+ """
+ return self.run('cat /proc/cmdline').stdout.rstrip()
+
+
+ def ping(self):
+ """
+ Ping the remote system, and return whether it's available
+ """
+ fpingcmd = "%s -q %s" % ('/usr/bin/fping', self.hostname)
+ rc = utils.system(fpingcmd, ignore_status = 1)
+ return (rc == 0)
diff --git a/server/samples/info.srv b/server/samples/info.srv
new file mode 100644
index 0000000..731b2ef
--- /dev/null
+++ b/server/samples/info.srv
@@ -0,0 +1,6 @@
+host = hosts.SSHHost(machines[0], initialize = False)
+print 'Uptime: ' + host.check_uptime()
+print 'Arch: ' + host.get_arch()
+print 'Kernel ver: ' + host.get_kernel_ver()
+print 'Kernel cmdline: ' + host.get_cmdline()
+
diff --git a/server/utils.py b/server/utils.py
index acc57d2..cab27fa 100644
--- a/server/utils.py
+++ b/server/utils.py
@@ -239,6 +239,14 @@
return result
+def system(command, timeout=None, ignore_status=False):
+ return run(command, timeout, ignore_status).exit_status
+
+
+def system_output(command, timeout=None, ignore_status=False):
+ return run(command, timeout, ignore_status).stdout
+
+
def get_tmp_dir():
"""Return the pathname of a directory on the host suitable
for temporary file storage.