lava-dispatcher docker images - part 2

18 Jun 2018
Posted by stylesen

This is part 2 of the three part blog post series on lava-dispatcher only docker images. If you haven't read part 1 already, then read it on - https://www.stylesen.org/lavadispatcher_docker_images_part_1

Docker based LAVA Worker running pure LXC job

This is the first use case in which we will look at starting a docker based LAVA worker and running a job that requests a LXC device type. The following command is used to start a docker based LAVA worker,

stylesen@hanshu:~$ sudo docker run \
-v /home/stylesen/docker-slave-files:/fileshare \
-v /var/run/docker.sock:/var/run/docker.sock -itd \
-e HOSTNAME='docker-slave-1' -e MASTER='tcp://lava.codehelp.co.uk:5556' \
-e SOCKET_ADDR='tcp://lava.codehelp.co.uk:5555' -e LOG_LEVEL='DEBUG' \
-e ENCRYPT=1 -e MASTER_CERT='/fileshare/master.key' \
-e SLAVE_CERT='/fileshare/docker-slave-1.key_secret' -p 2222:22 \
--name ld-latest linaro/lava-dispatcher-staging-stretch-amd64:latest

Unable to find image 'linaro/lava-dispatcher-staging-stretch-amd64:latest' locally
latest: Pulling from linaro/lava-dispatcher-staging-stretch-amd64
cc1a78bfd46b: Pull complete
5ddb65a5b8b4: Pull complete
41d8dcd3278b: Pull complete
071cc3e7e971: Pull complete
39bedb7bda2f: Pull complete
Digest: sha256:1bc7c7b2bee09beda4a6bd31a2953ae80847c706e8500495f6d0667f38fe0c9c
Status: Downloaded newer image for linaro/lava-dispatcher-staging-stretch-amd64:latest
522f079649816a931247c5917efea281846e394dba7ec19f522bba5f1e433fd5
stylesen@hanshu:~$

Lets have a closer look at the 'docker run' command above and see what are the options used:

'-v /home/stylesen/docker-slave-files:/fileshare' - mounts the directory /home/stylesen/docker-slave-files from the host machine, inside the docker container at the location /fileshare This location is used to exchange files from the host to the container and vice versa.

'-v /var/run/docker.sock:/var/run/docker.sock' - similarly the docker socket file is exposed within the container. This is optional and may be required for advanced job runs and use cases.

For options such as '-itd', '-p' and '--name' refer https://docs.docker.com/engine/reference/commandline/run/ to know what these option do for running docker images.

'-e' - This option is used to set environment variables inside the docker container being run. The following environment variables are set in the above command line which is consumed by the entrypoint.sh script inside the container and starts the lava-slave daemon based on these variable's values.

  1. HOSTNAME - Name of the slave
  2. MASTER - Main master socket
  3. SOCKET_ADDR - Log socket
  4. LOG_LEVEL - Log level, default to INFO
  5. ENCRYPT - Encrypt messages
  6. MASTER_CERT - Master certificate file
  7. SLAVE_CERT - Slave certificate file

We can see the docker based LAVA worker is started and running,

stylesen@hanshu:~$ sudo docker ps -a
CONTAINER ID        IMAGE                                               \
  COMMAND             CREATED              STATUS              PORTS    \
              NAMES

522f07964981        linaro/lava-dispatcher-staging-stretch-amd64:latest \
  "/entrypoint.sh"    About a minute ago   Up 58 seconds       \
0.0.0.0:2222->22/tcp   ld-latest

stylesen@hanshu:~$

If everything goes fine, we can see the LAVA master receiving ping messages from the above LAVA worker as seen below on the LAVA master logs:

stylesen@codehelp:~$ sudo tail -f /var/log/lava-server/lava-master.log
2018-06-18 00:24:30,878    INFO docker-slave-1 => HELLO
2018-06-18 00:24:30,878 WARNING New dispatcher <docker-slave-1>
2018-06-18 00:24:34,069   DEBUG lava-logs => PING(20)
2018-06-18 00:24:36,138   DEBUG docker-slave-1 => PING(20)
... <TRUNCATED OUTPUT> ...
^C
stylesen@codehelp:~$

The worker will also get listed on https://lava.codehelp.co.uk/scheduler/allworkers in the web UI. The docker based LAVA worker host docker-slave-1 is up and running. Let us add a LXC device to this worker on which we will run our LXC protocol based job. The name of the LXC device we will add to docker-slave-1 is 'lxc-docker-slave-01'. Create a jinja2 template file for lxc-docker-slave-01 and copy it to /etc/lava-server/dispatcher-config/devices/ on the LAVA master instance,

stylesen@codehelp:~$ cat \
/etc/lava-server/dispatcher-config/devices/lxc-docker-slave-01.jinja2

{% extends 'lxc.jinja2' %}
{% set exclusive = 'True' %}
stylesen@codehelp:~$ ls -alh \
/etc/lava-server/dispatcher-config/devices/lxc-docker-slave-01.jinja2

-rw-r--r-- 1 lavaserver lavaserver 56 Jun 18 00:36 \
/etc/lava-server/dispatcher-config/devices/lxc-docker-slave-01.jinja2

stylesen@codehelp:~$

In order to add the above device lxc-docker-slave-01 to the LAVA master database and associate it with our docker based LAVA worker docker-slave-1, login to the LAVA master instance and issue the following command:

stylesen@codehelp:~$ sudo lava-server manage devices add \
--device-type lxc --worker docker-slave-1 lxc-docker-slave-01

stylesen@codehelp:~$

The device will now be listed as part of the worker docker-slave-1 and could be seen in the link - https://lava.codehelp.co.uk/scheduler/worker/docker-slave-1

The LXC job we will submit to the above device will be https://git.linaro.org/lava-team/refactoring.git/tree/health-checks/lxc.yaml which is a normal LXC job requesting a LXC device type and runs a basic smoke test on a Debian based LXC device.

stylesen@harshu:/tmp$ lavacli -i lava.codehelp jobs submit lxc.yaml 
2486
stylesen@harshu:/tmp$

NOTE: lavacli is the official command line tool for interacting with LAVA instances. Read more about lavacli in https://staging.validation.linaro.org/static/docs/v2/lavacli.html

Thus job 2486 has been submitted successfully to LAVA instance lava.codehelp.co.uk and it ran successfully as seen in https://lava.codehelp.co.uk/scheduler/job/2486 This job used lava-lxc-mocker instead of lxc as seen from https://lava.codehelp.co.uk/scheduler/job/2486#L3

Read part 1...                                                                                                                     ... Continue Reading part 3

Read all parts of this blog post series from below links:

  1. lava-dispatcher docker images - part 1 - Introduction, Details and Preparation
  2. lava-dispatcher docker images - part 2 - Docker based LAVA Worker running pure LXC job
  3. lava-dispatcher docker images - part 3 - Docker based LAVA Worker running Nexus 4 job with and without LXC Protocol