]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
Move more exceptions
authorZack Cerza <zack.cerza@inktank.com>
Tue, 9 Sep 2014 22:30:37 +0000 (16:30 -0600)
committerZack Cerza <zack.cerza@inktank.com>
Tue, 9 Sep 2014 23:56:44 +0000 (17:56 -0600)
Signed-off-by: Zack Cerza <zack.cerza@inktank.com>
teuthology/exceptions.py
teuthology/misc.py
teuthology/orchestra/daemon.py
teuthology/orchestra/run.py
teuthology/orchestra/test/test_integration.py
teuthology/orchestra/test/test_run.py

index 66131fa27f5d062c5bc495c93ab9b76d8ef43b6a..1a3056e5276013402d43c8be3b5c19c9c962c356 100644 (file)
@@ -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,
+            )
index 5f1ac07c517fa3a1b121d81d19871a344c03e02a..080e47e381200d82dd08dae4143f71acbfc2596d 100644 (file)
@@ -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):
index c35882ca119b216be9790bb60cf1c4e63fac92d9..21de682232c83dab8aef5e42f94447c4792477dd 100644 (file)
@@ -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()
         """
index b70244759f719ca00a665e4683d50fb005f58c9f..bfcb8785b15f4859acdb0b615177483b6b2eac75 100644 (file)
@@ -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.
index 7009b8994a8394e72d93ed8027a0a3e018f23a0f..4b761bb8684ae3a66f0416fb96de91b8d55f992e 100644 (file)
@@ -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'],
index 49f52ee960a3986f64c89fcd0468691bc2a086e5..65c08600c4928d526001de785e11049645f14204 100644 (file)
@@ -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