I've taken a tiny step towards getting together a prototype toolset for developing an initial development iteration of the NAS functionality of the FreedomBox.

Here's what I am trying to do:

  • create a disk image for a system that provides simplistic NAS functionality, with no configuration, including no authentication: just serve whatever disks are available over SMB
  • use a TDD approach to developing it

In essence, this means I want to specify the functionality of the system I am building using automated tests. As soon as those tests pass, I will write more tests, and make them pass. When I can't think of new relevant tests, I know I'm done.

I'm building a simple tool, systest, that will execute the tests. It is built on top of Python's unittest library, because that makes my implementation simple.

I've now developed systest far enough that I can almost automatically do this:

  • build a new image, using vmdebootstrap, plus a customization script
  • start the image with KVM controlled by libvirt
  • run the tests using systest

(The command line would be something like this: ./build-fbxnas && virsh start fbxnas && sleep 30 && ~/systest/systest --target=192.168.122.89 --user=tomjon ~/systest/tests-debian-base-install.py --user-ssh-private-key=tomjon.secret --log=foo.log --user-password=password1 where build-fbxnas is a wrapper script around vmdebootstrap. But I didn't actually run that command, and it's lacking the virt-install command to actually set up the virtual machine the first time.)

systest contains very little code, but to get that far, I had to shave some yaks, and that made writing it rather an unpleasant experience.

The tests so far really simple, and don't test NAS stuff at all, just that the basic Debian install works: only the ssh port is open, and basic networking and such things work. However, now that I've gotten this much to work, I can start writing NAS tests. (smbclient may be my next yak. This would be a lot easier if I had ever used Samba for anything real...)

systest and vmdebootstrap are on Gitorious. No .debs yet, this stuff is much too raw, but you can run them from the checkouts, no install necessary.

PS. If anyone knows how to query KVM or libvirt for the IP address assigned by their internal DHCP server to the virtual machine guest, automatically, without asking the actual virtual machine, please tell.

I don't know if you have already, but you could take a look at vagrant for ideas: http://vagrantup.com/
Comment by terceiro Wed Jun 29 19:00:05 2011
Thanks for your suggestion. Vagrant seems to be a tool for building virtual machines for web development, which don't seem to be useful to my purposes at all. I need to build disk images to run on real hardware (as well as in virtual machines), and that's different enough that I'd rather not fight with someone else's project to make it do my bidding, it's easier to write something from scratch.
Comment by Lars Wirzenius Wed Jun 29 20:09:11 2011
Rather than querying libvirt for an IP, you can configure the dnsmasq daemon it's running to do static DHCP for a given MAC address. All you have to do then is to assign the corresponding MAC to the VM ethernet device. You even get name resolution with this :) See http://libvirt.org/formatnetwork.html
Comment by bertagaz Wed Jun 29 23:28:24 2011
Thanks, bertagaz, that looks like it would work. It would require me to start manually maintaining MAC and IP addresses, to make sure they don't ever collide, and that's not work I should have to do, just to find out what the IP address is. But if that's what I have to do, then so be it.
Comment by Lars Wirzenius Thu Jun 30 08:23:42 2011

Do you actually need the guest's IP address, or would access to the samba TCP port be enough?

For testing web servers with qemu, I redirect the HTTP and SSH ports to local ports on the host like this:

qemu -hda ept.qcow -monitor stdio -redir tcp:8080::80 -redir tcp:8022::22

Given KVM's qemu roots, I suspect you could do something similar.

(And, if this wouldn't work directly, you could redirect port 22, then ssh to the guest to query for the IP address).

Comment by MarkV Fri Jul 1 21:26:32 2011
If the only thing I would want to test is Samba, then I could live with port redirection. However, there's a lot of things I want to test, and setting up redirections for them is too much work, and doesn't even work for some things, such as ping.
Comment by Lars Wirzenius Sat Jul 2 08:35:10 2011

You might not have to maintain a MAC and IP list. I guess you only need one VM to boot the newer disk image generated by vmdebootstrap.

In that case, just tell vmdebootstrap to always use the same name for the generated disk image. Then configure one VM to use this file as its disk image, assign it one MAC address, and configure dnsmasq to give it one IP. You're done then, each time you generate a new image, just fire the VM.

This might even be scriptable and included in vmdebootstrap :)

Comment by bertagaz Sat Jul 2 13:56:14 2011