Pull the server-side errors.py into the common error library.
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1007 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/error.py b/client/common_lib/error.py
index c0925c1..a26383d 100644
--- a/client/common_lib/error.py
+++ b/client/common_lib/error.py
@@ -47,3 +47,32 @@
def __init__(self, prefix):
msg = prefix + format_error()
TestError.__init__(self, msg)
+
+
+# server-specific errors
+
+class AutoservError(Exception):
+ pass
+
+
+class AutoservRunError(AutoservError):
+ """Errors raised by one of the run functions"""
+ pass
+
+
+class AutoservVirtError(AutoservError):
+ """Vitualization related error"""
+ pass
+
+
+class AutoservUnsupportedError(AutoservError):
+ """Error raised when you try to use an unsupported optional feature"""
+ pass
+
+class AutoservHostError(AutoservError):
+ """Error reaching a host"""
+ pass
+
+class AutoservRebootError(AutoservError):
+ """Error occured while rebooting a machine"""
+ pass
diff --git a/server/autotest.py b/server/autotest.py
index 7279476..8973a00 100644
--- a/server/autotest.py
+++ b/server/autotest.py
@@ -24,9 +24,9 @@
import time
import installable_object
-import errors
import utils
from common import logging
+from common.error import *
AUTOTEST_SVN = 'svn://test.kernel.org/autotest/trunk/client'
@@ -37,10 +37,10 @@
BOOT_TIME = 1800
-class AutotestRunError(errors.AutoservRunError):
+class AutotestRunError(AutoservRunError):
pass
-class AutotestTimeoutError(errors.AutoservRunError):
+class AutotestTimeoutError(AutoservRunError):
"""This exception is raised when an autotest test exceeds the timeout
parameter passed to run_timed_test and is killed.
"""
@@ -126,7 +126,7 @@
try:
host.run('svn checkout %s %s' %
(AUTOTEST_SVN, autodir))
- except errors.AutoservRunError, e:
+ except AutoservRunError, e:
host.run('svn checkout %s %s' %
(AUTOTEST_HTTP, autodir))
print "Installation of autotest completed"
@@ -380,7 +380,7 @@
self.host.hostname,)
try:
self.host.hardreset(wait=False)
- except errors.AutoservUnsupportedError:
+ except AutoservUnsupportedError:
print "Hardreset unsupported on %s" % (
self.host.hostname,)
raise AutotestRunError("%s failed to "
@@ -403,12 +403,12 @@
dir = os.path.dirname(host.run(cmd).stdout)
if dir:
return dir
- except errors.AutoservRunError:
+ except AutoservRunError:
pass
for path in ['/usr/local/autotest', '/home/autotest']:
try:
host.run('ls ' + os.path.join(path, 'bin/autotest'))
return path
- except errors.AutoservRunError:
+ except AutoservRunError:
pass
raise AutotestRunError("Cannot figure out autotest directory")
diff --git a/server/control_segments/verify b/server/control_segments/verify
index 1cc35e2..cb6aba8 100644
--- a/server/control_segments/verify
+++ b/server/control_segments/verify
@@ -2,7 +2,7 @@
df = host.run('df -m %s | tail -1' % path).stdout.split()
free_space_gb = int(df[3])/1000
if free_space_gb < gb:
- raise errors.AutoservHostError('Not enough free space on %s - %dGB free, want %dGB' % (path, free_space_gb, gb))
+ raise AutoservHostError('Not enough free space on %s - %dGB free, want %dGB' % (path, free_space_gb, gb))
# This needs more stuff in it. Check for diskspace, etc. But it's a start.
diff --git a/server/deb_kernel.py b/server/deb_kernel.py
index c12eacc..ab10aee 100644
--- a/server/deb_kernel.py
+++ b/server/deb_kernel.py
@@ -21,9 +21,10 @@
import urllib
import kernel
-import errors
import utils
+from common.error import *
+
class DEBKernel(kernel.Kernel):
"""
diff --git a/server/errors.py b/server/errors.py
deleted file mode 100644
index c1f8d18..0000000
--- a/server/errors.py
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/python
-#
-# Copyright 2007 Google Inc. Released under the GPL v2
-
-"""
-Exceptions deliberatly thrown by autoserv
-"""
-
-__author__ = """
-mbligh@google.com (Martin J. Bligh),
-poirier@google.com (Benjamin Poirier),
-stutsman@google.com (Ryan Stutsman)
-"""
-
-
-class AutoservError(Exception):
- pass
-
-
-class AutoservRunError(AutoservError):
- """Errors raised by one of the run functions"""
- pass
-
-
-class AutoservVirtError(AutoservError):
- """Vitualization related error"""
- pass
-
-
-class AutoservUnsupportedError(AutoservError):
- """Error raised when you try to use an unsupported optional feature"""
- pass
-
-class AutoservHostError(AutoservError):
- """Error reaching a host"""
- pass
-
-class AutoservRebootError(AutoservError):
- """Error occured while rebooting a machine"""
- pass
diff --git a/server/hosts/bootloader.py b/server/hosts/bootloader.py
index 7c67cf8..f495653 100644
--- a/server/hosts/bootloader.py
+++ b/server/hosts/bootloader.py
@@ -18,9 +18,10 @@
import sys
import weakref
-import errors
import utils
+from common.error import *
+
BOOTTOOL_SRC = '../client/tools/boottool' # Get it from autotest client
@@ -152,7 +153,7 @@
def install_boottool(self):
if self.__host() is None:
- raise errors.AutoservError("Host does not exist anymore")
+ raise AutoservError("Host does not exist anymore")
tmpdir = self.__host().get_tmp_dir()
self.__host().send_file(os.path.abspath(os.path.join(
utils.get_server_dir(), BOOTTOOL_SRC)), tmpdir)
diff --git a/server/hosts/ssh_host.py b/server/hosts/ssh_host.py
index b62cfb3..471e5a5 100644
--- a/server/hosts/ssh_host.py
+++ b/server/hosts/ssh_host.py
@@ -19,7 +19,9 @@
import types, os, sys, signal, subprocess, time, re, socket
-import base_classes, utils, errors, bootloader
+import base_classes, utils, bootloader
+
+from common.error import *
class SSHHost(base_classes.RemoteHost):
@@ -94,7 +96,7 @@
for dir in self.tmp_dirs:
try:
self.run('rm -rf "%s"' % (utils.sh_escape(dir)))
- except errors.AutoservRunError:
+ except AutoservRunError:
pass
# kill the console logger
if getattr(self, 'logger_pid', None):
@@ -131,7 +133,7 @@
# Get the gateway of the remote machine
try:
traceroute = self.run('traceroute -n %s' % local_ip)
- except errors.AutoservRunError:
+ except AutoservRunError:
return
first_node = traceroute.stdout.split("\n")[0]
match = re.search(r'\s+((\d+\.){3}\d+)\s+', first_node)
@@ -143,7 +145,7 @@
try:
self.run('ping -c 1 %s' % router_ip)
arp = self.run('arp -n -a %s' % router_ip)
- except errors.AutoservRunError:
+ except AutoservRunError:
return
match = re.search(r'\s+(([0-9A-F]{2}:){5}[0-9A-F]{2})\s+', arp.stdout)
if match:
@@ -179,7 +181,7 @@
return
try:
self.run('modprobe netconsole %s' % self.__netconsole_param)
- except errors.AutoservRunError:
+ except AutoservRunError:
# if it fails there isn't much we can do, just keep going
pass
@@ -187,21 +189,21 @@
def __unload_netconsole_module(self):
try:
self.run('modprobe -r netconsole')
- except errors.AutoservRunError:
+ except AutoservRunError:
pass
def _wait_for_restart(self, timeout):
if not self.wait_down(300): # Make sure he's dead, Jim
self.__record("ABORT", None, "reboot.verify", "shutdown failed")
- raise errors.AutoservRebootError("Host did not shut down")
+ raise AutoservRebootError("Host did not shut down")
self.wait_up(timeout)
time.sleep(2) # this is needed for complete reliability
if self.wait_up(timeout):
self.__record("GOOD", None, "reboot.verify")
else:
self.__record("ABORT", None, "reboot.verify", "bringup failed")
- raise errors.AutoservRebootError("Host did not return from reboot")
+ raise AutoservRebootError("Host did not return from reboot")
print "Reboot complete"
@@ -212,7 +214,7 @@
self.__record("GOOD", None, "reboot.start", "hard reset")
if not self.__console_run(r"'~$hardreset'"):
self.__record("ABORT", None, "reboot.start", "hard reset unavailable")
- raise errors.AutoservUnsupportedError
+ raise AutoservUnsupportedError
if wait:
self._wait_for_restart(timeout)
@@ -265,7 +267,7 @@
res = utils.run('which conmux-attach')
if res.exit_status == 0:
return res.stdout.strip()
- except errors.AutoservRunError, e:
+ except AutoservRunError, e:
pass
autotest_conmux = os.path.join(self.serverdir, '..',
'conmux', 'conmux-attach')
@@ -378,7 +380,7 @@
self.__record("GOOD", None, "reboot.start")
try:
self.run('(sleep 5; reboot) </dev/null >/dev/null 2>&1 &')
- except errors.AutoservRunError:
+ except AutoservRunError:
self.__record("ABORT", None, "reboot.start",
"reboot command failed")
raise
@@ -578,11 +580,11 @@
print "Performing a hardreset on %s" % self.hostname
try:
self.hardreset()
- except errors.AutoservUnsupportedError:
+ except AutoservUnsupportedError:
print "Hardreset is unsupported on %s" % self.hostname
if not self.wait_up(60 * 30):
# 30 minutes should be more than enough
- raise errors.AutoservHostError
+ raise AutoservHostError
print 'Host up, continuing'
diff --git a/server/kvm.py b/server/kvm.py
index d8df7e2..f997d16 100644
--- a/server/kvm.py
+++ b/server/kvm.py
@@ -17,10 +17,11 @@
import os
import hypervisor
-import errors
import utils
import hosts
+from common.error import *
+
_qemu_ifup_script= """\
#!/bin/sh
@@ -117,7 +118,7 @@
elif cpu_flags.find('svm') != -1:
module_type= "amd"
else:
- raise errors.AutoservVirtError("No harware "
+ raise AutoservVirtError("No harware "
"virtualization extensions found, "
"KVM cannot run")
@@ -223,7 +224,7 @@
try:
self.host.run('make -C "%s" clean' % (
utils.sh_escape(self.build_dir),))
- except errors.AutoservRunError:
+ except AutoservRunError:
# directory was already clean and contained
# no makefile
pass
@@ -290,7 +291,7 @@
if not address["is_used"]:
break
else:
- raise errors.AutoservVirtError(
+ raise AutoservVirtError(
"No more addresses available")
# TODO(poirier): uses start-stop-daemon until qemu -pidfile
@@ -418,7 +419,7 @@
# have references to the guests.
return
else:
- raise errors.AutoservVirtError("Unknown guest hostname")
+ raise AutoservVirtError("Unknown guest hostname")
pid_file_name= utils.sh_escape(os.path.join(self.pid_dir,
"vhost%s_pid" % (address["ip"],)))
@@ -460,10 +461,10 @@
if address["is_used"]:
break
else:
- raise errors.AutoservVirtError("guest "
+ raise AutoservVirtError("guest "
"hostname not in use")
else:
- raise errors.AutoservVirtError("Unknown guest hostname")
+ raise AutoservVirtError("Unknown guest hostname")
monitor_file_name= utils.sh_escape(os.path.join(self.pid_dir,
"vhost%s_monitor" % (address["ip"],)))
diff --git a/server/rpm_kernel.py b/server/rpm_kernel.py
index e6b0929..9c690b5 100644
--- a/server/rpm_kernel.py
+++ b/server/rpm_kernel.py
@@ -22,9 +22,10 @@
import urllib
import kernel
-import errors
import utils
+from common.error import *
+
class RPMKernel(kernel.Kernel):
"""
diff --git a/server/self-test/autotest_test.py b/server/self-test/autotest_test.py
index 39dfe2a..033b091 100644
--- a/server/self-test/autotest_test.py
+++ b/server/self-test/autotest_test.py
@@ -121,7 +121,7 @@
autotest.AUTOTEST_SVN + ' ' +
"/usr/local/autotest")
if (command == first):
- raise autotest.errors.AutoservRunError(
+ raise autotest.AutoservRunError(
"svn not found")
host = MockFirstInstallFailsHost()
diff --git a/server/server_job.py b/server/server_job.py
index fb73412..aea544c 100755
--- a/server/server_job.py
+++ b/server/server_job.py
@@ -12,7 +12,7 @@
"""
import os, sys, re, time
-import test, errors
+import test
from utils import *
from common.error import *
@@ -37,8 +37,9 @@
preamble = """\
import os, sys
-import errors, hosts, autotest, kvm
+import hosts, autotest, kvm
import source_kernel, rpm_kernel, deb_kernel
+from common.error import *
from subcommand import *
from utils import run, get_tmp_dir, sh_escape
@@ -102,14 +103,14 @@
def verify_machines(machines):
if not machines:
- raise errors.AutoservError('No machines specified to verify')
+ raise AutoservError('No machines specified to verify')
namespace = {'machines' : machines, 'job' : None}
exec(preamble + verify, namespace, namespace)
def repair_machines(machines):
if not machines:
- raise errors.AutoservError('No machines specified to repair')
+ raise AutoservError('No machines specified to repair')
namespace = {'machines' : machines, 'job' : None}
exec(preamble + repair, namespace, namespace)
diff --git a/server/utils.py b/server/utils.py
index 033db5d..0e007da 100644
--- a/server/utils.py
+++ b/server/utils.py
@@ -14,7 +14,7 @@
import atexit, os, select, shutil, signal, StringIO, subprocess, tempfile
import time, types, urllib, re, sys, textwrap
-import hosts, errors
+import hosts
from common.error import *
# A dictionary of pid and a list of tmpdirs for that pid
@@ -245,7 +245,7 @@
result.stderr = stderr_file.getvalue()
if not ignore_status and result.exit_status > 0:
- raise errors.AutoservRunError("command execution error", result)
+ raise AutoservRunError("command execution error", result)
return result