From: Zack Cerza Date: Tue, 9 Sep 2014 22:30:37 +0000 (-0600) Subject: Move more exceptions X-Git-Tag: 1.1.0~1180 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3df89f18b3fd08640588c3c823434eacbdec609d;p=teuthology.git Move more exceptions Signed-off-by: Zack Cerza --- diff --git a/teuthology/exceptions.py b/teuthology/exceptions.py index 66131fa27..1a3056e52 100644 --- a/teuthology/exceptions.py +++ b/teuthology/exceptions.py @@ -16,5 +16,52 @@ class BranchNotFoundError(ValueError): class GitError(RuntimeError): pass + class BootstrapError(RuntimeError): pass + + +class CommandFailedError(Exception): + + """ + Exception thrown on command failure + """ + def __init__(self, command, exitstatus, node=None): + self.command = command + self.exitstatus = exitstatus + self.node = node + + def __str__(self): + return "Command failed on {node} with status {status}: {cmd!r}".format( + node=self.node, + status=self.exitstatus, + cmd=self.command, + ) + + +class CommandCrashedError(Exception): + + """ + Exception thrown on crash + """ + def __init__(self, command): + self.command = command + + def __str__(self): + return "Command crashed: {command!r}".format( + command=self.command, + ) + + +class ConnectionLostError(Exception): + + """ + Exception thrown when the connection is lost + """ + def __init__(self, command): + self.command = command + + def __str__(self): + return "SSH connection was lost: {command!r}".format( + command=self.command, + ) diff --git a/teuthology/misc.py b/teuthology/misc.py index 5f1ac07c5..080e47e38 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -21,6 +21,8 @@ import re import tempfile from teuthology import safepath +from teuthology.exceptions import (CommandCrashedError, CommandFailedError, + ConnectionLostError) from .orchestra import run from .config import config from .contextutil import safe_while @@ -806,7 +808,7 @@ def get_scratch_devices(remote): ] ) retval.append(dev) - except run.CommandFailedError: + except CommandFailedError: log.debug("get_scratch_devices: %s is in use" % dev) return retval @@ -1074,9 +1076,9 @@ def stop_daemons_of_type(ctx, type_): for daemon in ctx.daemons.iter_daemons_of_role(type_): try: daemon.stop() - except (run.CommandFailedError, - run.CommandCrashedError, - run.ConnectionLostError): + except (CommandFailedError, + CommandCrashedError, + ConnectionLostError): exc_info = sys.exc_info() log.exception('Saw exception from %s.%s', daemon.role, daemon.id_) if exc_info != (None, None, None): diff --git a/teuthology/orchestra/daemon.py b/teuthology/orchestra/daemon.py index c35882ca1..21de68223 100644 --- a/teuthology/orchestra/daemon.py +++ b/teuthology/orchestra/daemon.py @@ -32,8 +32,8 @@ class DaemonState(object): """ Stop this daemon instance. - Note: this can raise a run.CommandFailedError, - run.CommandCrashedError, or run.ConnectionLostError. + Note: this can raise a CommandFailedError, + CommandCrashedError, or ConnectionLostError. :param timeout: timeout to pass to orchestra.run.wait() """ diff --git a/teuthology/orchestra/run.py b/teuthology/orchestra/run.py index b70244759..bfcb8785b 100644 --- a/teuthology/orchestra/run.py +++ b/teuthology/orchestra/run.py @@ -11,6 +11,8 @@ import logging import shutil from ..contextutil import safe_while +from ..exceptions import (CommandCrashedError, CommandFailedError, + ConnectionLostError) log = logging.getLogger(__name__) @@ -213,52 +215,6 @@ def copy_file_to(f, dst): return handler(f, dst) -class CommandFailedError(Exception): - - """ - Exception thrown on command failure - """ - def __init__(self, command, exitstatus, node=None): - self.command = command - self.exitstatus = exitstatus - self.node = node - - def __str__(self): - return "Command failed on {node} with status {status}: {cmd!r}".format( - node=self.node, - status=self.exitstatus, - cmd=self.command, - ) - - -class CommandCrashedError(Exception): - - """ - Exception thrown on crash - """ - def __init__(self, command): - self.command = command - - def __str__(self): - return "Command crashed: {command!r}".format( - command=self.command, - ) - - -class ConnectionLostError(Exception): - - """ - Exception thrown when the connection is lost - """ - def __init__(self, command): - self.command = command - - def __str__(self): - return "SSH connection was lost: {command!r}".format( - command=self.command, - ) - - def spawn_asyncresult(fn, *args, **kwargs): """ Spawn a Greenlet and pass it's results to an AsyncResult. diff --git a/teuthology/orchestra/test/test_integration.py b/teuthology/orchestra/test/test_integration.py index 7009b8994..4b761bb86 100644 --- a/teuthology/orchestra/test/test_integration.py +++ b/teuthology/orchestra/test/test_integration.py @@ -6,6 +6,7 @@ from cStringIO import StringIO import os from .. import connection, run from .util import assert_raises +from teuthology.exceptions import CommandCrashedError, ConnectionLostError from pytest import skip @@ -25,7 +26,7 @@ class TestIntegration(): def test_crash(self): ssh = connection.connect(HOST) e = assert_raises( - run.CommandCrashedError, + CommandCrashedError, run.run, client=ssh, args=['sh', '-c', 'kill -ABRT $$'], @@ -36,7 +37,7 @@ class TestIntegration(): def test_lost(self): ssh = connection.connect(HOST) e = assert_raises( - run.ConnectionLostError, + ConnectionLostError, run.run, client=ssh, args=['sh', '-c', 'kill -ABRT $PPID'], diff --git a/teuthology/orchestra/test/test_run.py b/teuthology/orchestra/test/test_run.py index 49f52ee96..65c08600c 100644 --- a/teuthology/orchestra/test/test_run.py +++ b/teuthology/orchestra/test/test_run.py @@ -4,6 +4,8 @@ import fudge import logging from .. import run +from teuthology.exceptions import (CommandCrashedError, CommandFailedError, + ConnectionLostError) from .util import assert_raises @@ -107,7 +109,7 @@ class TestRun(object): out.has_attr(channel=channel) channel.expects('recv_exit_status').with_args().returns(42) e = assert_raises( - run.CommandFailedError, + CommandFailedError, run.run, client=ssh, logger=logger, @@ -163,7 +165,7 @@ class TestRun(object): out.has_attr(channel=channel) channel.expects('recv_exit_status').with_args().returns(-1) e = assert_raises( - run.CommandCrashedError, + CommandCrashedError, run.run, client=ssh, logger=logger, @@ -218,7 +220,7 @@ class TestRun(object): transport.expects('getpeername').with_args().returns(('HOST', 22)) transport.expects('is_active').with_args().returns(False) e = assert_raises( - run.ConnectionLostError, + ConnectionLostError, run.run, client=ssh, logger=logger, @@ -280,7 +282,7 @@ class TestRun(object): ) assert r.command == 'foo' e = assert_raises( - run.CommandFailedError, + CommandFailedError, r.wait, ) assert r.returncode == 42