Running unit tests for LAVA server

14 Mar 2014
Posted by stylesen

Linaro Automated Validation Architecture popularly called LAVA is composed of different components. One of the core components in the LAVA framework is the lava-server component. LAVA developers in the recent past made sure that lava-server's unit tests are working properly and relevant to current code base. As a developer of LAVA I hit this issue everytime I want to run unit tests for lava-server (when I switch environments), mainly due to postgresql dependency. Following are stuff you need to setup in order to run unit tests in LAVA. (Do not do this production deployment, only recommended for dev mode deployments)

lava-master is the default postgresql user created for administering LAVA related databases. In order to run unit tests, the default postgresql user of LAVA should have permissions to create and drop databases. The test database created by LAVA unit test is called 'test_lava-master'. The 'lava-master' user creates and destroys this 'test_lava-master' database each time the unit tests are run. You must be 'root' user in order to perform the following operations:

Initialize the environment for LAVA instance.

root@suchi:~# . /srv/lava/instances/<instance_name>/bin/activate

Login as postgres user

(master)root@suchi:~# su postgres

Use the psql client to connect to postgresql.

postgres@suchi:~$ psql
psql (9.1.11)
Type "help" for help.

postgres=# alter user "lava-master" with superuser;
ALTER ROLE
postgres=# \q
postgres@suchi:~$ exit

We have successfully made 'lava-master' user as the superuser and ready to run unit tests. Use the following command to run unit tests for lava_scheduler_daemon

(master)root@suchi:~# lava-server manage test lava_scheduler_daemon
Creating test database for alias 'default'...
FATAL ERROR - The following SQL query failed: CREATE LANGUAGE plpgsql
The error was: language "plpgsql" already exists

...............
----------------------------------------------------------------------
Ran 15 tests in 3.853s

OK
Destroying test database for alias 'default'...

Following command runs the unit tests for lava_scheduler_app

(master)root@suchi:~# lava-server manage test lava_scheduler_app
Creating test database for alias 'default'...
FATAL ERROR - The following SQL query failed: CREATE LANGUAGE plpgsql
The error was: language "plpgsql" already exists

dataview-specific database connection not available, dataview query is NOT sandboxed
dataview-specific database connection not available, dataview query is NOT sandboxed
.......................................
----------------------------------------------------------------------
Ran 39 tests in 3.496s

OK
Destroying test database for alias 'default'...

For more verbose output pass '-v' option with values 2 or 3. Have a look at the following command for more options in running unit tests.

(master)root@suchi:~# lava-server manage test --help

Know more about:

Linaro - http://www.linaro.org

LAVA - http://www.linaro.org/engineering/engineering-groups/lava