deb, click, schroot, LXC, QEMU, phone, cloud: One autopkgtest to Rule Them All!

We currently use completely different methods and tools of building test beds and running tests for Debian vs. Click packages, for normal uploads vs. CI airline landings vs. upstream project merge proposal testing, and keep lots of knowledge about Click package test metadata external and not easily accessible/discoverable.

Today I released autopkgtest 3.0 (and 3.0.1 with a few minor updates) which is a major milestone in unifying how we run package tests both locally and in production CI. The goals of this are:

  • Keep all test metadata, such as test dependencies, commands to run the test etc., in the project/package source itself instead of external. We have had that for a long time for Debian packages with DEP-8 and debian/tests/control, but not yet for Ubuntu’s Click packages.
  • Use the same tools for Debian and Click packages to simplify what developers have to know about and to reduce the amount of test infrastructure code to maintain.
  • Use the exact same testbeds and test runners in production CI than what developers use locally, so that you can reproduce and investigate failures.
  • Re-use the existing autopkgtest capabilities for using various kinds of testbeds, and conversely, making all new testbed types immediately available to all package formats.
  • Stop putting tests into the Ubuntu archive as packages (such as mediaplayer-app-autopilot). This just adds packaging and archive space overhead and also makes updating tests a lot harder and taking longer than it should.

So, let’s dive into the new features!

New runner: adt-virt-ssh

We want to run tests on real hardware such as a laptop of a particular brand with a particular graphics card, or an Ubuntu phone. We also want to restructure our current CI machinery to run tests on a real OpenStack cloud and gradually get rid of our hand-maintained QA lab with its test machines. While these use cases seem rather different, they both have in common that there is an already existing machine which is pretty much only accessible with ssh. Once you have an ssh connection, they look pretty much the same, you just need different initial setup (like fiddling with adb, calling nova boot, etc.) to prepare them.

So the new adt-virt-ssh runner factorizes all the common bits such as communicating with adt-run, auto-detecting sudo availability, doing SSH connection sharing etc., and delegates the target specific bits to a “setup script”. E. g. we could specify --setup-script ssh-setup-nova or --setup-script ssh-setup-adb which would then get called with open at the appropriate time by adt-run; it calls the nova commands to create a VM, or run a few adb commands to install/start ssh and install the public key. Then autopkgtest does its thing, and eventually calls the script with cleanup again. The actual protocol is a bit more involved (see manpage), but that’s the general idea.

autopkgtest now ships readymade scripts for these two use cases. So you could e. g. run the libpng tests in a temporary cloud VM:

# if you don’t have one, create it with “nova keypair-create”
$ nova keypair-list
[…]
| pitti | 9f:31:cf:78:50:4f:42:04:7a:87:d7:2a:75:5e:46:56 |

find a suitable image

$ nova image-list […] | ca2e362c-62c9-4c0d-82a6-5d6a37fcb251 | Ubuntu Server 14.04 LTS (amd64 20140607.1) - Partner Image | ACTIVE |

$ nova flavor-list […] | 100 | standard.xsmall | 1024 | 10 | 10 | | 1 | 1.0 | N/A |

now run the tests: please be patient, this takes a few mins!

$ adt-run libpng –setup-commands=“apt-get update” — ssh -s /usr/share/autopkgtest/ssh-setup/nova –
-f standard.xsmall -i ca2e362c-62c9-4c0d-82a6-5d6a37fcb251 -k pitti […] adt-run [16:23:16]: test build: - - - - - - - - - - results - - - - - - - - - - build PASS adt-run: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ tests done.

Please see `man adt-virt-ssh` for details how to use it and how to write setup scripts. There is also a commented [/usr/share/autopkgtest/ssh-setup/SKELETON][4] template for writing your own for your use cases. You can also not use any setup script and just specify user and host name as options, but please remember that the ssh runner _cannot clean up_ after itself, so **never** use this on important machines which you can’t reset/reinstall!

## Test dependency installation without apt/root

Ubuntu phones with system images have a read-only file system where you can’t install test dependencies with apt. A similar case is using the “null” runner without root. When `apt-get install` is not available, autopkgtest now has a reduced fallback mode: it downloads the required test dependencies, unpacks them into a temporary directory, and runs the tests with `$PATH`, `$PYTHONPATH`, `$GI_TYPELIB_PATH`, etc. pointing to the unpacked temp dir. Of course this only works for packages which are relocatable in that way, i. e. libraries, Python modules, or command line tools; it will totally fail for things which look for config files, plugins etc. in hardcoded directory paths. But it’s good enough for the purposes of Click package testing such as installing autopilot, libautopilot-qt etc.

## Click package support

autopkgtest now recognizes click source directories and `*.click` package arguments, and introduces a [new test metadata specification][5] syntax in a [click package manifest][6]. This is similar in spirit and capabilities to DEP-8 `debian/tests/control`, except that it’s using JSON:

<pre>"x-test": {
    "unit": "tests/unittests",
    "smoke": {
        "path": "tests/smoketest",
        "depends": ["shunit2", "moreutils"],
        "restrictions": ["allow-stderr"]
    },
    "another": {
        "command": "echo hello > /tmp/world.txt"
    }
}

For convenience, there is also some magic to make running autopilot tests particularly simple. E. g. our existing click packages usually specify something like

<pre>"x-test": {
    "autopilot": "ubuntu_calculator_app"
}

which is enough to &#8220;do what I mean&#8221;, i. e. implicitly add the autopilot test depends and run autopilot with the specified test module name. You can specify your own dependencies and/or commands, and restrictions etc., of course.

So with this, and the previous support for non-apt test dependencies and the ssh runner, we can put all this together to run the tests for e. g. the Ubuntu calculator app on the phone:

<pre>$ bzr branch lp:ubuntu-calculator-app

built straight from that branch; TODO: where is the official” download URL?

$ wget http://people.canonical.com/~pitti/tmp/com.ubuntu.calculator_1.3.283_all.click $ adt-run ubuntu-calculator-app/ com.ubuntu.calculator_1.3.283_all.click —
ssh -s /usr/share/autopkgtest/ssh-setup/adb [..] Traceback (most recent call last): File “/tmp/adt-run.KfY5bG/tree/tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py”, line 93, in test_divide_with_infinity_length_result_number self._assert_result(“0.33333333”) File “/tmp/adt-run.KfY5bG/tree/tests/autopilot/ubuntu_calculator_app/tests/test_simple_page.py”, line 63, in _assert_result self.main_view.get_result, Eventually(Equals(expected_result))) File “/usr/lib/python3/dist-packages/testtools/testcase.py”, line 406, in assertThat raise mismatch_error testtools.matchers._impl.MismatchError: After 10.0 seconds test failed: ‘0.33333333’ != ‘0.3’

Ran 33 tests in 295.586s FAILED (failures=1)

Note that the current adb ssh setup script deals with some things like applying the autopilot click AppArmor hooks and disabling screen dimming, but it does not do the first-time setup (connecting to network, doing the gesture intro) and unlocking the screen. These are still on the TODO list, but I need to find out how to do these properly. Help appreciated!

## Click app tests in schroot/containers

But, that&#8217;s not the only thing you can do! autopkgtest has all these other runners, so why not try and run them in a schroot or container? To emulate the environment of an Ubuntu Touch session I wrote a `--setup-commands` script:

<pre>adt-run --setup-commands /usr/share/autopkgtest/setup-commands/ubuntu-touch-session \
ubuntu-calculator-app/ com.ubuntu.calculator_1.3.283_all.click --- schroot utopic

This will actually work in the sense of running (and succeeding) the autopilot tests, but it will fail due to a lot of `libust[11345/11358]: Error: Error opening shm /lttng-ust-wait...` warnings on stderr. I don&#8217;t know what these mean, just that I also see them on the phone itself occasionally.

I also wrote another setup-commands script which emulates &#8220;read-only apt&#8221;, so that you can test the &#8220;unpack only&#8221; fallback. So you could prepare a container with click and the App framework preinstalled (so that it doesn&#8217;t always take ages to install them), starting from a standard `adt-build-lxc` container:

<pre>$ sudo lxc-clone -o adt-utopic -n click

$ sudo lxc-start -n click # run “sudo apt-get install click ubuntu-sdk-libs ubuntu-app-launch-tools” there # then “sudo powerdown”

current apparmor profile doesn’t allow remounting something read-only

$ echo “lxc.aa_profile = unconfined” | sudo tee -a /var/lib/lxc/click/config

Now that container has enough stuff preinstalled to be reasonably fast to set up, and the remaining test dependencies (mostly autopilot) work fine with the unpack/`$*_PATH` fallback:

<pre>$ adt-run --setup-commands /usr/share/autopkgtest/setup-commands/ubuntu-touch-session \
      --setup-commands /usr/share/autopkgtest/setup-commands/ro-apt \
      ubuntu-calculator-app/ com.ubuntu.calculator_1.3.283_all.click \
      --- lxc -es click

This will successfully run all the tests, and provided you have apt-cacher-ng installed, it only takes a few seconds to set up. This might be a nice thing to do on merge proposals, if you don&#8217;t have an actual phone at hand, or don&#8217;t want to clutter it up.

autopkgtest 3.0.1 will be available in Utopic tomorrow (through autosyncs). If you can&#8217;t wait to try it out, [download it from my people.c.c page][7] ☺.

Feedback appreciated!