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,
+ )
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
]
)
retval.append(dev)
- except run.CommandFailedError:
+ except CommandFailedError:
log.debug("get_scratch_devices: %s is in use" % dev)
return retval
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):
"""
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()
"""
import shutil
from ..contextutil import safe_while
+from ..exceptions import (CommandCrashedError, CommandFailedError,
+ ConnectionLostError)
log = logging.getLogger(__name__)
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.
import os
from .. import connection, run
from .util import assert_raises
+from teuthology.exceptions import CommandCrashedError, ConnectionLostError
from pytest import skip
def test_crash(self):
ssh = connection.connect(HOST)
e = assert_raises(
- run.CommandCrashedError,
+ CommandCrashedError,
run.run,
client=ssh,
args=['sh', '-c', 'kill -ABRT $$'],
def test_lost(self):
ssh = connection.connect(HOST)
e = assert_raises(
- run.ConnectionLostError,
+ ConnectionLostError,
run.run,
client=ssh,
args=['sh', '-c', 'kill -ABRT $PPID'],
import logging
from .. import run
+from teuthology.exceptions import (CommandCrashedError, CommandFailedError,
+ ConnectionLostError)
from .util import assert_raises
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,
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,
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,
)
assert r.command == 'foo'
e = assert_raises(
- run.CommandFailedError,
+ CommandFailedError,
r.wait,
)
assert r.returncode == 42