How to test a pod driver in isolation

I recently wrote up these instructions for testing a pod driver in isolation; I thought it would be useful to post them here for future reference. (I actually think it would be nice to have command-line utilities for developing, debugging, and supporting modular potions of MAAS such as this. But we may not always have time to develop, test, and maintain CLI commands that aren’t part of the core product.)

First you’ll need to start up a reactor inside your ipython shell. The pod drivers use asynchronous calls, so you’ll need it to be ready to run them. A long time back, I developed a helper script to do this in ipython; it’s got some minor bugs (like not printing exceptions from deferreds until exit) but it works. If you follow the directions in the gist, you can do something like this in ipython:

reactor = %reactor

… and the reactor will start in a separate thread. Next, import the pod driver and its helper classes:

from provisioningserver.drivers.pod.virsh import VirshPodDriver
from provisioningserver.drivers.pod import RequestedMachine, RequestedMachineBlockDevice, RequestedMachineInterface

Then instantiate the pod driver and set up the context (connection information):

v = VirshPodDriver()
ctx = {'power_address': 'qemu+ssh://ubuntu@', 'power_pass': ''}

Then you can call discover() to test if it worked:

d =, context=ctx)

Wait a few seconds for the Deferred to complete, and then you can check the result:

>>> d.result

Composing a machine requires instantiating the helper classes to create a complete RequestedMachine object. You can do so as follows (though I’m not completely sure about the units for the block device, I’m fairly sure the 1 and 1024 used in the RequestedMachine are for the number of cores, and the memory in megabytes):

rbd = RequestedMachineBlockDevice(1024)
rmi = RequestedMachineInterface()
r = RequestedMachine("test-compose", "amd64/generic", 1, 1024, [rbd], [rmi])

The RequestedMachineInterface can be customized with optional parameters (see the branch Newell recently landed), so that you can request whatever network, bridge, or macvlan you would like to attach to.

Once you’re happy with the RequestedMachine object, you can compose it as follows:

d = v.compose(None, ctx, r)

… and check the result of the deferred, if you want, or look at the hypervisor UI to see what happened!

1 Like