[Buildbot-devel] repo and gerrit support to buildbot

Neal Chant neal at ethermonkey.net
Tue Oct 5 20:14:27 UTC 2010


On Sun, 2010-10-03 at 17:00 -0500, Dustin J. Mitchell wrote:
> On Wed, Sep 29, 2010 at 3:59 AM, Neal Chant <neal at ethermonkey.net> wrote:
> > I'll dig it out, it works, but never made it to production - we ended up
> > using qemu-img creating sparse clones from templates and then virsh.
> 
> Sounds exciting - do you have time to clean it up and get it merged
> into buildbot?

Attached the original (part) master.cfg for virsh control of VMs, note
the comment on getting an instant VM stop.

For the particular project, we found the Windows VMs a big PITA and
didn't end up using this. The final virsh controller was bash (python is
on the 'to pickup' list). I'm happy to help where possible.

The project is happily building Linux-ant, Windows-C#, Windows-WP7 all
fed from SVN to on-demand fresh VMs.

Neal


-------------- next part --------------
# -*- python -*-
# ex: set syntax=python:

from twisted.internet import defer, threads
from buildbot.buildslave import AbstractLatentBuildSlave
import libvirt

# NOTES
# in this example, VM name was set the same as the builder.
# for *instant* stop of VM
	# edit /usr/lib/python2.6/site-packages/buildbot/buildslave.py
		#implements(ILatentBuildSlave)
			##build_wait_timeout=60*10,
      			#build_wait_timeout=1,

class VirshBuildSlave(AbstractLatentBuildSlave):
	#def __init__(self, name, password):
	#	self.virsh_name = name
	#	self.host_passwd = password

	#To use, subclass and implement start_instance and stop_instance.
	def start_instance(self):
	        return threads.deferToThread(self._start_instance)

    	def _start_instance(self):
        	# responsible for starting instance that will try to connect with this
        	# master. Should return deferred. Problems should use an errback. The
        	# callback value can be None, or can be an iterable of short strings to
        	# include in the "substantiate success" status message, such as
        	# identifying the instance that started.
		conn = libvirt.open(None)
		if conn == None:
			raise NotImplementedError # Should really raise a better error
		try:
	        	host = conn.lookupByName(self.slavename)
		except:
			raise NotImplementedError # Should really raise a better error

		run_state = host.info()[0]
		
		# Start VM
		#if libvirt.VIR_DOMAIN_SHUTOFF == run_state:
		#	print "In _start_instance()"
		#	host.create() # create _is_ start

		# Resume VM
		if libvirt.VIR_DOMAIN_PAUSED == run_state:
			print "In _start_instance()"		
			host.resume() # resume _is_ take from suspended state

	def stop_instance(self, fast=False):
		return threads.deferToThread(
	            self._stop_instance, fast)
     
	def _stop_instance(self, fast=False):
        	# responsible for shutting down instance. Return a deferred. If `fast`,
        	# we're trying to shut the master down, so callback as soon as is safe.
        	# Callback value is ignored.
        	conn = libvirt.open(None)
		if conn == None:
			raise NotImplementedError # Should really raise a better error
		try:
	        	host = conn.lookupByName(self.slavename)
		except:
			raise NotImplementedError # Should really raise a better error

		# Stop VM
		#run_state = host.info()[0]
		#if libvirt.VIR_DOMAIN_RUNNING == run_state:
		#	print "In _stop_instance()"
		#	host.destroy() # destroy _is_ halt

		# Pause VM
		run_state = host.info()[0]
		if libvirt.VIR_DOMAIN_RUNNING == run_state:
			print "In _stop_instance()"
			host.suspend() # suspend

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

####### BUILDSLAVES
c['slaves'] = [VirshBuildSlave("win7-x64", "winpass")]
c['slavePortnum'] = 9989




More information about the devel mailing list