Next: , Previous: Amazon Web Services Elastic Compute Cloud ("AWS EC2"), Up: Latent Buildslaves


4.9.3.2 Libvirt

libvirt is a virtualization API for interacting with the virtualization capabilities of recent versions of Linux and other OSes. It is LGPL and comes with a stable C API, and python bindings.

This means we now have an API which when tied to buildbot allows us to have slaves that run under Xen, QEMU, KVM, LXC, OpenVZ, User Mode Linux, VirtualBox and VMWare.

The libvirt code in Buildbot was developed against libvirt 0.7.5 on Ubuntu Lucid. It is used with KVM to test python code on Karmic VM's, but obviously isn't limited to that. Each build is run on a new VM, images are temporary and thrown away after each build.

Setting up libvirt

We won't show you how to set up libvirt as it is quite different on each platform, but there are a few things you should keep in mind.

Configuring your base image

You need to create a base image for your builds that has everything needed to build your software. You need to configure the base image with a buildbot slave that is configured to connect to the master on boot.

Because this image may need updating a lot, we strongly suggest scripting its creation.

If you want to have multiple slaves using the same base image it can be annoying to duplicate the image just to change the buildbot credentials. One option is to use libvirt's DHCP server to allocate an identity to the slave: DHCP sets a hostname, and the slave takes its identity from that.

Doing all this is really beyond the scope of the manual, but there is a vmbuilder script and a network.xml file to create such a DHCP server in contrib/ (see Contrib Scripts) that should get you started:

     sudo apt-get install ubuntu-vm-builder
     sudo contrib/libvirt/vmbuilder

Should create an ubuntu/ folder with a suitable image in it.

     virsh net-define contrib/libvirt/network.xml
     virsh net-start buildbot-network

Should set up a KVM compatible libvirt network for your buildbot VM's to run on.

Configuring your Master

If you want to add a simple on demand VM to your setup, you only need the following. We set the username to minion1, the password to sekrit. The base image is called base_image and a copy of it will be made for the duration of the VM's life. That copy will be thrown away every time a build is complete.

     from buildbot.libvirtbuildslave import LibVirtBuildSlave
     c['slaves'] = [LibVirtBuildSlave('minion1', 'sekrit',
                                        '/home/buildbot/images/minion1', '/home/buildbot/images/base_image')]

You can use virt-manager to define 'minion1' with the correct hardware. If you don't, buildbot won't be able to find a VM to start.

LibVirtBuildSlave accepts the following arguments:

name
Both a buildbot username and the name of the virtual machine
password
A password for the buildbot to login to the master with
hd_image
The path to a libvirt disk image, normally in qcow2 format when using KVM.
base_image
If given a base image, buildbot will clone it every time it starts a VM. This means you always have a clean environment to do your build in.
xml
If a VM isn't predefined in virt-manager, then you can instead provide XML like that used with virsh define. The VM will be created automatically when needed, and destroyed when not needed any longer.