Skip to content

Commit

Permalink
start_instance much more readable with inlineCallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jc2k authored and John Carr committed Apr 29, 2012
1 parent 895ef26 commit 91c96e6
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions master/buildbot/libvirtbuildslave.py
Expand Up @@ -221,6 +221,7 @@ def _log_result(res):
d.addBoth(_log_result)
return d

@defer.inlineCallbacks
def start_instance(self, build):
"""
I start a new instance of a VM.
Expand All @@ -234,36 +235,21 @@ def start_instance(self, build):
if self.domain is not None:
raise ValueError('domain active')

d = self._prepare_base_image()
yield self._prepare_base_image()

def _start(res):
try:
if self.xml:
d = self.connection.create(self.xml)
def _xml_start(res):
self.domain = res
return
d.addCallback(_xml_start)
return d
d = self.connection.lookupByName(self.name)
def _really_start(res):
self.domain = res
return self.domain.create()
d.addCallback(_really_start)
return d
d.addCallback(_start)

def _started(res):
return True
d.addCallback(_started)

def _start_failed(failure):
self.domain = yield self.connection.create(self.xml)
else:
self.domain = yield self.connection.lookupByName(self.name)
yield self.domain.create()
except Exception, f:
log.msg("Cannot start a VM (%s), failing gracefully and triggering a new build check" % self.name)
log.err(failure)
self.domain = None
return False
d.addErrback(_start_failed)

return d

return True

def stop_instance(self, fast=False):
"""
Expand Down

0 comments on commit 91c96e6

Please sign in to comment.