Skip to content

Commit

Permalink
fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed May 19, 2012
1 parent efcea69 commit 508b3b6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 4 additions & 3 deletions master/buildbot/libvirtbuildslave.py
Expand Up @@ -253,9 +253,10 @@ def start_instance(self, build):
else:
self.domain = yield self.connection.lookupByName(self.name)
yield self.domain.create()
except Exception:
log.msg("Cannot start a VM (%s), failing gracefully and triggering a new build check" % self.name)
log.err(failure.Failure())
except:
log.err(failure.Failure(),
"Cannot start a VM (%s), failing gracefully and triggering"
"a new build check" % self.name)
self.domain = None
defer.returnValue(False)

Expand Down
23 changes: 23 additions & 0 deletions master/buildbot/test/unit/test_libvirtslave.py
Expand Up @@ -19,6 +19,7 @@
from twisted.python import failure
from buildbot import libvirtbuildslave, config
from buildbot.test.fake import libvirt
from buildbot.test.util import compat


class TestLibVirtSlave(unittest.TestCase):
Expand Down Expand Up @@ -107,6 +108,28 @@ def test_start_instance(self):

self.assertEqual(started, True)

@compat.usesFlushLoggedErrors
@defer.inlineCallbacks
def test_start_instance_create_fails(self):
bs = self.ConcreteBuildSlave('b', 'p', self.conn, 'p', 'o',
xml='<xml/>')

prep = mock.Mock()
prep.side_effect = lambda: defer.succeed(0)
self.patch(bs, "_prepare_base_image", prep)

create = mock.Mock()
create.side_effect = lambda self : defer.fail(
failure.Failure(RuntimeError('oh noes')))
self.patch(libvirtbuildslave.Connection, 'create', create)

yield bs._find_existing_deferred
started = yield bs.start_instance(mock.Mock())

self.assertEqual(bs.domain, None)
self.assertEqual(started, False)
self.assertEqual(len(self.flushLoggedErrors(RuntimeError)), 1)

@defer.inlineCallbacks
def setup_canStartBuild(self):
bs = self.ConcreteBuildSlave('b', 'p', self.conn, 'p', 'o')
Expand Down

0 comments on commit 508b3b6

Please sign in to comment.