snabbco / snabb

Snabb: Simple and fast packet networking
Apache License 2.0
2.96k stars 298 forks source link

Functional testing with Nix? #839

Open lukego opened 8 years ago

lukego commented 8 years ago

NixOS has an impressive functional testing framework. I would like to understand how directly we can apply this to Snabb Switch.

Background on the NixOS approach:

The basic idea is to boot a network of NixOS virtual machines and to script their interactions.

So can we use this framework for Snabb functional tests? Examples of test cases:

The reasons I think we should consider building such tests on NixOS is that it would free us from managing processes directly in bash scripts, it would give us access to nice features like easy-to-browse logs, and it would save us the hassle of bootstrapping software test environments ourselves.

Question is: will it work? Could we port a simple test like the packetblaster one to NixOS as a proof of concept?

The main challenge I see is that the NixOS tests are based on booting virtual machines and running the code under test inside those VMs. This will not necessarily work for Snabb and our existing tests are all based on running processes as root directly on the host. Snabb does need to run as root for a variety of reasons and running the Snabb processes inside VMs seems like a potential performance liability, particularly when the tests themselves need to start VMs and would lead to nested virtualization.

So: Can we use this framework for running non-QEMU processes directly on the host machine as root?

cc @domenkozar

domenkozar commented 8 years ago

TL;DR: not without refactoring driver code to support non-QEMU "backend".

Looking at https://github.com/NixOS/nixpkgs/blob/master/nixos/lib/test-driver/Machine.pm, all of the commands are executed via qemu monitor to the guest machine. Some are very qemu specific such as start, which would start a VM. We could refactor that to introduce "local" backend and have a subset of commands available there.

For all the tests not doing performance testing, we could just port them to existing functional testing framework.

ghost commented 8 years ago

Just out of curiosity, this is perl right? Is it somehow NiX specific way of automation? Could this be better implemented with libvirt and its python interface?

domenkozar commented 8 years ago

@nnikolaev-virtualopensystems Yes. See https://github.com/NixOS/nixpkgs/issues/5241