From 49d59f4fa7b6f6dc99bbb56e30c94b5ae692f2f7 Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Wed, 25 Oct 2017 12:12:12 +0200 Subject: Move master files in lava-master --- Dockerfile | 70 ------------------------------------------- configs/tftpd-hpa | 6 ---- lava-master/Dockerfile | 70 +++++++++++++++++++++++++++++++++++++++++++ lava-master/configs/tftpd-hpa | 6 ++++ lava-master/scripts/start.sh | 37 +++++++++++++++++++++++ lava-master/scripts/stop.sh | 10 +++++++ scripts/start.sh | 37 ----------------------- scripts/stop.sh | 10 ------- 8 files changed, 123 insertions(+), 123 deletions(-) delete mode 100644 Dockerfile delete mode 100644 configs/tftpd-hpa create mode 100644 lava-master/Dockerfile create mode 100644 lava-master/configs/tftpd-hpa create mode 100755 lava-master/scripts/start.sh create mode 100755 lava-master/scripts/stop.sh delete mode 100755 scripts/start.sh delete mode 100755 scripts/stop.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 942f1f6..0000000 --- a/Dockerfile +++ /dev/null @@ -1,70 +0,0 @@ -FROM bitnami/minideb:stretch - -RUN apt-get update - -# Add services helper utilities to start and stop LAVA -COPY scripts/stop.sh . -COPY scripts/start.sh . - -# Install debian packages used by the container -# Configure apache to run the lava server -# Log the hostname used during install for the slave name -RUN echo 'lava-server lava-server/instance-name string lava-docker-instance' | debconf-set-selections \ - && echo 'locales locales/locales_to_be_generated multiselect C.UTF-8 UTF-8, en_US.UTF-8 UTF-8 ' | debconf-set-selections \ - && echo 'locales locales/default_environment_locale select en_US.UTF-8' | debconf-set-selections - -RUN DEBIAN_FRONTEND=noninteractive apt-get -y install \ - locales \ - postgresql \ - screen \ - sudo \ - wget \ - gnupg \ - vim - -RUN wget http://images.validation.linaro.org/production-repo/production-repo.key.asc \ - && apt-key add production-repo.key.asc \ - && echo 'deb http://images.validation.linaro.org/production-repo/ stretch-backports main' > /etc/apt/sources.list.d/lava.list \ - && apt-get clean && apt-get update - -RUN service postgresql start \ - && DEBIAN_FRONTEND=noninteractive apt-get -y install \ - lava \ - qemu-system \ - qemu-system-arm \ - qemu-system-i386 \ - qemu-kvm \ - ser2net \ - u-boot-tools \ - python-setproctitle \ - && a2enmod proxy \ - && a2enmod proxy_http \ - && a2dissite 000-default \ - && a2ensite lava-server \ - && /stop.sh - -# Create a admin user (Insecure note, this creates a default user, username: admin/admin) -RUN /start.sh \ - && lava-server manage users add --passwd admin --staff --superuser --email admin@example.com admin \ - && /stop.sh - -# Install latest -RUN /start.sh \ - && git clone https://github.com/kernelci/lava-dispatcher.git -b master /root/lava-dispatcher \ - && cd /root/lava-dispatcher \ - && git checkout release \ - && git clone -b master https://github.com/kernelci/lava-server.git /root/lava-server \ - && cd /root/lava-server \ - && git checkout release \ - && git config --global user.name "Docker Build" \ - && git config --global user.email "info@kernelci.org" \ - && echo "cd \${DIR} && dpkg -i *.deb" >> /root/lava-server/share/debian-dev-build.sh \ - && cd /root/lava-dispatcher && /root/lava-server/share/debian-dev-build.sh -p lava-dispatcher \ - && cd /root/lava-server && /root/lava-server/share/debian-dev-build.sh -p lava-server \ - && /stop.sh - -COPY configs/tftpd-hpa /etc/default/tftpd-hpa - -EXPOSE 69/udp 80 3079 5555 5556 - -CMD /start.sh && bash diff --git a/configs/tftpd-hpa b/configs/tftpd-hpa deleted file mode 100644 index bb6f079..0000000 --- a/configs/tftpd-hpa +++ /dev/null @@ -1,6 +0,0 @@ -# /etc/default/tftpd-hpa - -TFTP_USERNAME="tftp" -TFTP_DIRECTORY="/var/lib/lava/dispatcher/tmp/" -TFTP_ADDRESS="0.0.0.0:69" -TFTP_OPTIONS="--secure" diff --git a/lava-master/Dockerfile b/lava-master/Dockerfile new file mode 100644 index 0000000..942f1f6 --- /dev/null +++ b/lava-master/Dockerfile @@ -0,0 +1,70 @@ +FROM bitnami/minideb:stretch + +RUN apt-get update + +# Add services helper utilities to start and stop LAVA +COPY scripts/stop.sh . +COPY scripts/start.sh . + +# Install debian packages used by the container +# Configure apache to run the lava server +# Log the hostname used during install for the slave name +RUN echo 'lava-server lava-server/instance-name string lava-docker-instance' | debconf-set-selections \ + && echo 'locales locales/locales_to_be_generated multiselect C.UTF-8 UTF-8, en_US.UTF-8 UTF-8 ' | debconf-set-selections \ + && echo 'locales locales/default_environment_locale select en_US.UTF-8' | debconf-set-selections + +RUN DEBIAN_FRONTEND=noninteractive apt-get -y install \ + locales \ + postgresql \ + screen \ + sudo \ + wget \ + gnupg \ + vim + +RUN wget http://images.validation.linaro.org/production-repo/production-repo.key.asc \ + && apt-key add production-repo.key.asc \ + && echo 'deb http://images.validation.linaro.org/production-repo/ stretch-backports main' > /etc/apt/sources.list.d/lava.list \ + && apt-get clean && apt-get update + +RUN service postgresql start \ + && DEBIAN_FRONTEND=noninteractive apt-get -y install \ + lava \ + qemu-system \ + qemu-system-arm \ + qemu-system-i386 \ + qemu-kvm \ + ser2net \ + u-boot-tools \ + python-setproctitle \ + && a2enmod proxy \ + && a2enmod proxy_http \ + && a2dissite 000-default \ + && a2ensite lava-server \ + && /stop.sh + +# Create a admin user (Insecure note, this creates a default user, username: admin/admin) +RUN /start.sh \ + && lava-server manage users add --passwd admin --staff --superuser --email admin@example.com admin \ + && /stop.sh + +# Install latest +RUN /start.sh \ + && git clone https://github.com/kernelci/lava-dispatcher.git -b master /root/lava-dispatcher \ + && cd /root/lava-dispatcher \ + && git checkout release \ + && git clone -b master https://github.com/kernelci/lava-server.git /root/lava-server \ + && cd /root/lava-server \ + && git checkout release \ + && git config --global user.name "Docker Build" \ + && git config --global user.email "info@kernelci.org" \ + && echo "cd \${DIR} && dpkg -i *.deb" >> /root/lava-server/share/debian-dev-build.sh \ + && cd /root/lava-dispatcher && /root/lava-server/share/debian-dev-build.sh -p lava-dispatcher \ + && cd /root/lava-server && /root/lava-server/share/debian-dev-build.sh -p lava-server \ + && /stop.sh + +COPY configs/tftpd-hpa /etc/default/tftpd-hpa + +EXPOSE 69/udp 80 3079 5555 5556 + +CMD /start.sh && bash diff --git a/lava-master/configs/tftpd-hpa b/lava-master/configs/tftpd-hpa new file mode 100644 index 0000000..bb6f079 --- /dev/null +++ b/lava-master/configs/tftpd-hpa @@ -0,0 +1,6 @@ +# /etc/default/tftpd-hpa + +TFTP_USERNAME="tftp" +TFTP_DIRECTORY="/var/lib/lava/dispatcher/tmp/" +TFTP_ADDRESS="0.0.0.0:69" +TFTP_OPTIONS="--secure" diff --git a/lava-master/scripts/start.sh b/lava-master/scripts/start.sh new file mode 100755 index 0000000..f4cc4eb --- /dev/null +++ b/lava-master/scripts/start.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +postgres-ready () { + echo "Waiting for lavaserver database to be active" + while (( $(ps -ef | grep -v grep | grep postgres | grep lavaserver | wc -l) == 0 )) + do + echo -n "." + sleep 1 + done + echo + echo "[ ok ] LAVA server ready" +} + +start () { + echo "Starting $1" + if (( $(ps -ef | grep -v grep | grep -v add_device | grep -v dispatcher-config | grep "$1" | wc -l) > 0 )) + then + echo "$1 appears to be running" + else + service "$1" start + fi +} + +#remove lava-pid files incase the image is stored without first stopping the services +rm -f /var/run/lava-*.pid 2> /dev/null + +start postgresql +start apache2 +start lava-server +start lava-master +start lava-coordinator +start lava-slave +start lava-server-gunicorn +start tftpd-hpa + +postgres-ready +service apache2 reload #added after the website not running a few times on boot diff --git a/lava-master/scripts/stop.sh b/lava-master/scripts/stop.sh new file mode 100755 index 0000000..ccf30fb --- /dev/null +++ b/lava-master/scripts/stop.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +service lava-master stop +service lava-slave stop +service lava-server stop +service lava-coordinator stop +service lava-server-gunicorn stop +service apache2 stop +service postgresql stop +service tftpd-hpa stop diff --git a/scripts/start.sh b/scripts/start.sh deleted file mode 100755 index f4cc4eb..0000000 --- a/scripts/start.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -postgres-ready () { - echo "Waiting for lavaserver database to be active" - while (( $(ps -ef | grep -v grep | grep postgres | grep lavaserver | wc -l) == 0 )) - do - echo -n "." - sleep 1 - done - echo - echo "[ ok ] LAVA server ready" -} - -start () { - echo "Starting $1" - if (( $(ps -ef | grep -v grep | grep -v add_device | grep -v dispatcher-config | grep "$1" | wc -l) > 0 )) - then - echo "$1 appears to be running" - else - service "$1" start - fi -} - -#remove lava-pid files incase the image is stored without first stopping the services -rm -f /var/run/lava-*.pid 2> /dev/null - -start postgresql -start apache2 -start lava-server -start lava-master -start lava-coordinator -start lava-slave -start lava-server-gunicorn -start tftpd-hpa - -postgres-ready -service apache2 reload #added after the website not running a few times on boot diff --git a/scripts/stop.sh b/scripts/stop.sh deleted file mode 100755 index ccf30fb..0000000 --- a/scripts/stop.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -service lava-master stop -service lava-slave stop -service lava-server stop -service lava-coordinator stop -service lava-server-gunicorn stop -service apache2 stop -service postgresql stop -service tftpd-hpa stop -- cgit 1.2.3-korg From 88baa3f2459a5d32150048745003f4987b964be2 Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Wed, 25 Oct 2017 12:15:18 +0200 Subject: import lava-slave --- lava-slave/Dockerfile | 58 +++++++++++++++++++++++++++++++++++++++++++ lava-slave/configs/lava-slave | 15 +++++++++++ lava-slave/configs/tftpd-hpa | 6 +++++ lava-slave/scripts/start.sh | 14 +++++++++++ lava-slave/scripts/stop.sh | 3 +++ 5 files changed, 96 insertions(+) create mode 100644 lava-slave/Dockerfile create mode 100644 lava-slave/configs/lava-slave create mode 100644 lava-slave/configs/tftpd-hpa create mode 100755 lava-slave/scripts/start.sh create mode 100755 lava-slave/scripts/stop.sh diff --git a/lava-slave/Dockerfile b/lava-slave/Dockerfile new file mode 100644 index 0000000..6aece71 --- /dev/null +++ b/lava-slave/Dockerfile @@ -0,0 +1,58 @@ +FROM bitnami/minideb:stretch + +RUN apt-get update + +# Add services helper utilities to start and stop LAVA +COPY scripts/stop.sh . +COPY scripts/start.sh . + +RUN \ + echo 'lava-server lava-server/instance-name string lava-slave-instance' | debconf-set-selections && \ + echo 'locales locales/locales_to_be_generated multiselect C.UTF-8 UTF-8, en_US.UTF-8 UTF-8 ' | debconf-set-selections && \ + echo 'locales locales/default_environment_locale select en_US.UTF-8' | debconf-set-selections && \ + DEBIAN_FRONTEND=noninteractive apt-get -y install \ + locales \ + lava-dispatcher \ + lava-dev \ + git \ + vim \ + sudo \ + python-setproctitle \ + tftpd-hpa \ + u-boot-tools \ + device-tree-compiler \ + qemu-system \ + qemu-system-arm \ + qemu-system-i386 \ + qemu-kvm \ + xnbd-server \ + e2fsprogs + +RUN wget http://images.validation.linaro.org/production-repo/production-repo.key.asc \ + && apt-key add production-repo.key.asc \ + && echo 'deb http://images.validation.linaro.org/production-repo/ stretch-backports main' > /etc/apt/sources.list.d/lava.list \ + && apt-get clean && apt-get update + +RUN DEBIAN_FRONTEND=noninteractive apt-get -y install lava-dispatcher + +#RUN \ +# git clone https://github.com/kernelci/lava-server.git -b release /root/lava-server && \ +# git clone https://github.com/kernelci/lava-dispatcher.git -b master /root/lava-dispatcher && \ +# cd /root/lava-dispatcher && \ +# git checkout release && \ +# git config --global user.name "Docker Build" && \ +# git config --global user.email "info@kernelci.org" && \ +# echo "cd \${DIR} && dpkg -i *.deb" >> /root/lava-server/share/debian-dev-build.sh && \ +# sleep 2 && \ +# /root/lava-server/share/debian-dev-build.sh -p lava-dispatcher + +COPY configs/lava-slave /etc/lava-dispatcher/lava-slave + +COPY configs/tftpd-hpa /etc/default/tftpd-hpa + +#TODO made this customizable, 1000 ports by default is too much +RUN sed -i 's,XNBD_PORT_RANGE_MIN.*,XNBD_PORT_RANGE_MIN=55950,' /usr/lib/python2.7/dist-packages/lava_dispatcher/pipeline/utils/constants.py + +EXPOSE 69/udp 80 + +CMD /start.sh diff --git a/lava-slave/configs/lava-slave b/lava-slave/configs/lava-slave new file mode 100644 index 0000000..6b991ad --- /dev/null +++ b/lava-slave/configs/lava-slave @@ -0,0 +1,15 @@ +# Configuration for lava-slave daemon + +# URL to the master and the logger +MASTER_URL="tcp://{LAVA_MASTER}:5556" +LOGGER_URL="tcp://{LAVA_MASTER}:5555" + +# Logging level should be uppercase (DEBUG, INFO, WARNING, ERROR) +# LOGLEVEL="DEBUG" + +# Encryption +# If set, will activate encryption using the master public and the slave +# private keys +# ENCRYPT="--encrypt" +# MASTER_CERT="--master-cert /etc/lava-dispatcher/certificates.d/" +# SLAVE_CERT="--slave-cert /etc/lava-dispatcher/certificates.d/" diff --git a/lava-slave/configs/tftpd-hpa b/lava-slave/configs/tftpd-hpa new file mode 100644 index 0000000..bb6f079 --- /dev/null +++ b/lava-slave/configs/tftpd-hpa @@ -0,0 +1,6 @@ +# /etc/default/tftpd-hpa + +TFTP_USERNAME="tftp" +TFTP_DIRECTORY="/var/lib/lava/dispatcher/tmp/" +TFTP_ADDRESS="0.0.0.0:69" +TFTP_OPTIONS="--secure" diff --git a/lava-slave/scripts/start.sh b/lava-slave/scripts/start.sh new file mode 100755 index 0000000..f442e8d --- /dev/null +++ b/lava-slave/scripts/start.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Set LAVA Master IP +if [[ -n "$LAVA_MASTER" ]]; then + sed -i -e "s/{LAVA_MASTER}/$LAVA_MASTER/g" /etc/lava-dispatcher/lava-slave +fi + +service tftpd-hpa start || exit 4 + +# FIXME lava-slave does not run if old pid is present +rm -f /var/run/lava-slave.pid +service lava-slave start || exit 5 + +# start an http file server for boot/transfer_overlay support +(cd /var/lib/lava/dispatcher; python -m SimpleHTTPServer 80) diff --git a/lava-slave/scripts/stop.sh b/lava-slave/scripts/stop.sh new file mode 100755 index 0000000..0f18456 --- /dev/null +++ b/lava-slave/scripts/stop.sh @@ -0,0 +1,3 @@ +#!/bin/bash +service tftpd-hpa stop +service lava-slave stop -- cgit 1.2.3-korg From 5d1654506ae782d6b7d4467076555e70656f5c85 Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Wed, 25 Oct 2017 12:22:30 +0200 Subject: Introduce docker-compose This commit introduce two compoments: lavalab-en.py which generate: - device files - conmux config files - users files - tokens files - udev rules for host - final docker-compose.yml file Except of docker-compose.yml, all other files are ignored for the moment and will be handled by a following commit. docker-compose: The docker compose permits to building and running easily lava-docker images. It permit also to remove some contraints like knowing the LAVA_SERVER_IP/LAVA_MASTER. --- README.md | 91 +++++++++++++++++++++++++------ boards.yaml | 55 +++++++++++++++++++ docker-compose.template | 34 ++++++++++++ lavalab-gen.py | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ tokens.yaml | 10 ++++ 5 files changed, 315 insertions(+), 16 deletions(-) create mode 100644 boards.yaml create mode 100644 docker-compose.template create mode 100755 lavalab-gen.py create mode 100644 tokens.yaml diff --git a/README.md b/README.md index de4c1e8..9d9a92d 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,96 @@ # Linaro's Automated Validation Architecture (LAVA) Docker Container Preinstalls and preconfigures the latest LAVA server release. -## Building -To build an image locally, execute the following from the directory you cloned the repo: +## Prerequisite +The package docker-compose is necessary + +## Name Conventions +Each board must be named by their device-type as "device-type-XX" where XX is a number +Each tty will have a name /dev/boardname (via the udev rules) +Each conmux config file will be named boardname.cf +Each slave must be named lab-slave-XX +## Know limitation +The current lava-docker provide support for only one slave + +## Architecture +The host must have a dedicated LAN. (192.168.66.0/24) +The host must have IP set to 192.168.66.1 on this LAN. +A sample dhcpd config file is available in the dhcpd directory + +## Generating files +### boards.yaml +This file describe how are setuped your boards, and how they are connected and powered. ``` -sudo docker build -t lava . +lab-slave-name: + devicename: + type: the devicetype of this device + pdu: + daemon: The hostname running the PDU daemon (always localhost) + host: The host name of the PDU as named in lavapdu.conf + port: portnumber (The port number of the PDU where the device is connected) + uart: + type: + serial: The serial number in case of FTDI uart ``` +Notes: +uart FTDI only need serial -## Running -To run the image from a host terminal / command line execute the following: +Examples: see boards.yaml + +### tokens.yaml +The tokens format have two section, one for user generation, the other for callback tokens +``` +lava_server_users: + - name: LAVA username + token: The token of this use + password: Password the this user (generated if not provided) +callback_tokens: + - filename: The filename for storing the informations below, the name should be unique along other callback tokens + username: The LAVA user owning the token below. (This user should be created via lava_server_users:) + token: The token for this callback + description: The description of this token. This string could be used with LAVA-CI. +``` +Example: see tokens.yaml + +### Generate +``` +lavalab-gen.py +``` +this scripts will generate all necessary files in the following location: ``` -sudo docker run -it -v /dev:/dev -p 69:69/udp -p 80:80 -p 3079:3079 -p 5555:5555 -p 5556:5556 -h --privileged kernelci/lava-docker:latest +conmux/ All files needed by conmux +tokens/ This is where the callback tokens will be generated +users/ This is where the users will be generated +devices/ All LAVA devices files (note that an extran qemu device is also created for the master) +udev-rules for host +docker-compose.yml Generated from docker-compose.template ``` -Where HOSTNAME is the hostname used during the container build process (check the docker build log), as that is the name used for the worker configuration. You can use `lava-docker` as the pre-built container hostname. -## Additional Setup -In order for TFTP requests to find their way back to the running container, you will need to describe the host IP address to the LAVA master node. You can to create a yaml file on the LAVA master node as described below. +All thoses files (except for udev-rules) will be handled by docker. +The udev-rules is for generating the right /dev/xxx TTY names. +You can still hack after generated files. + +## Building +To build an image locally, execute the following from the directory you cloned the repo: + +``` +docker-compose build +``` + +## Running ``` -echo "dispatcher_ip: /etc/lava-server/dispatcher.d/.yaml +docker-compose up ``` +## Process wrapper +You can use the lavalab-gen.sh wrapper which will do all the above actions + ## Security Note that this container provides defaults which are unsecure. If you plan on deploying this in a production enviroment please consider the following items: * Changing the default admin password * Using HTTPS -Secure CSRF tokens are disabled as the container uses HTTP by default. To use SSL with this container you will need to remove the following lines from your ```/etc/lava-server/settings.conf``` - -``` - "CSRF_COOKIE_SECURE": false, - "SESSION_COOKIE_SECURE": false, -``` diff --git a/boards.yaml b/boards.yaml new file mode 100644 index 0000000..1f3788f --- /dev/null +++ b/boards.yaml @@ -0,0 +1,55 @@ +lab-slave-0: + bcm2837-rpi-3-b-01: + type: bcm2837-rpi-3-b + pdu: + daemon: localhost + host: acme-0 + port: 1 + uart: + type: FTDI + serial: FT9QQZTA + am335x-boneblack-01: + type: beaglebone-black + pdu: + daemon: localhost + host: acme-0 + port: 2 + uart: + type: FTDI + serial: FT9QR1A9 + meson-gxl-s905x-libretech-cc-01: + type: meson-gxl-s905x-libretech-cc + pdu: + daemon: localhost + host: acme-0 + port: 3 + uart: + type: FTDI + serial: FT9QQYCN + dragonboard-410c-01: + type: dragonboard-410c + pdu: + daemon: localhost + host: acme-0 + port: 4 + uart: + type: FTDI + serial: FT9R7VDB + r8a7796-m3ulcb-01: + type: r8a7796-m3ulcb + pdu: + daemon: localhost + host: acme-0 + port: 5 + uart: + type: FTDI + serial: AK04WW0Q + imx6q-sabrelite-01: + type: imx6q-sabrelite + pdu: + daemon: localhost + host: acme-0 + port: 6 + uart: + type: FTDI + serial: FTAJMM4V diff --git a/docker-compose.template b/docker-compose.template new file mode 100644 index 0000000..dfe82c9 --- /dev/null +++ b/docker-compose.template @@ -0,0 +1,34 @@ +version: '2.0' +services: + lava-master: + hostname: lava-master + restart: always + stdin_open: true + tty: true + build: + context: lava-master + devices: + - "/dev/kvm:/dev/kvm" + ports: + - "10080:80" + - "1022:22" + - "5555:5555" + - "5556:5556" + volumes: +# boot and /lib/modules are for libguestfs + - "/boot:/boot" + - "/lib/modules:/lib/modules" + lava-slave: + hostname: lab-slave-0 + restart: always + build: + context: lava-slave + devices: + environment: + LAVA_MASTER: "lava-master" + ports: + - "69:69/udp" + - "80:80" + - "55980-56000:55980-56000" + links: + - "lava-master" diff --git a/lavalab-gen.py b/lavalab-gen.py new file mode 100755 index 0000000..a584a1f --- /dev/null +++ b/lavalab-gen.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python +# +from __future__ import print_function +import os, sys, time +import subprocess +import argparse +import yaml +import string +import socket + +# Defaults +boards_yaml = "boards.yaml" +tokens_yaml = "tokens.yaml" +baud_default = 115200 + +template = string.Template("""# +# auto-generated by lavalab-gen.py for ${board} +# +listener ${board} +application console '${board} console' 'exec sg dialout "cu-loop /dev/${board} ${baud}"' +command 'hardreset' 'Reboot ${board}' 'pduclient --daemon ${daemon} --host ${host} --port ${port} --command reboot ${delay} ' +command 'b' 'Reboot ${board}' 'pduclient --daemon ${daemon} --host ${host} --port ${port} --command reboot ' +command 'off' 'Power off ${board}' 'pduclient --daemon ${daemon} --host ${host} --port ${port} --command off ' +command 'on' 'Power on ${board}' 'pduclient --daemon ${daemon} --host ${host} --port ${port} --command on ' +""") + +#no comment it is volontary +template_device = string.Template("""{% extends '${devicetype}.jinja2' %} +{% set connection_command = 'conmux-console ${board}' %} +{% set hard_reset_command = 'pduclient --daemon localhost --hostname acme-0 --port ${port} --command=reboot' %} +{% set power_off_command = 'pduclient --daemon localhost --hostname acme-0 --port ${port} --command=off' %} +{% set power_on_command = 'pduclient --daemon localhost --hostname acme-0 --port ${port} --command=on' %} +""") + +template_udev = string.Template("""# +SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="${serial}", MODE="0664", OWNER="uucp", SYMLINK+="${board}" +""") + +def main(args): + fp = open(boards_yaml, "r") + labs = yaml.load(fp) + fp.close() + udev_line ="" + tdc = open("docker-compose.template", "r") + dockcomp = yaml.load(tdc) + tdc.close() + dc_devices = dockcomp["services"]["lava-slave"]["devices"] + if dc_devices is None: + dockcomp["services"]["lava-slave"]["devices"] = [] + dc_devices = dockcomp["services"]["lava-slave"]["devices"] + + for lab_name in labs: + lab = labs[lab_name] + for board_name in lab: + b = lab[board_name] + if b.get("disabled", None): + continue + + if not b.has_key("uart"): + print("WARNING: %s missing uart property" % board_name) + continue + + baud = b["uart"].get("baud", baud_default) + if b.has_key("pdu"): + daemon = b["pdu"]["daemon"] + host = b["pdu"]["host"] + port = b["pdu"]["port"] + devicetype = b["type"] + delay_opt = "" + line = template.substitute(board=board_name, baud=baud, daemon=daemon, host=host, port=port, delay=delay_opt) + device_line = template_device.substitute(board=board_name, port=port, devicetype=devicetype) + serial = b["uart"]["serial"] + udev_line += template_udev.substitute(board=board_name, serial=serial) + dc_devices.append("/dev/%s:/dev/%s" % (board_name, board_name)) + if b.has_key("fastboot_serial_number"): + fserial = b["fastboot_serial_number"] + device_line += "{%% set fastboot_serial_number = '%s' %%}" % fserial + + if not os.path.isdir("lava-slave/conmux/"): + os.mkdir("lava-slave/conmux/") + if not os.path.isdir("lava-master/devices/"): + os.mkdir("lava-master/devices/") + device_path = "lava-master/devices/%s" % lab_name + if not os.path.isdir(device_path): + os.mkdir(device_path) + fp = open("lava-slave/conmux/%s.cf" % board_name, "w") + fp.write(line) + fp.close() + board_device_file = "%s/%s.jinja2" % (device_path, board_name) + fp = open(board_device_file, "w") + fp.write(device_line) + fp.close() + fp = open("lavalab-udev-%s.rules" % lab_name, "w") + fp.write(udev_line) + fp.close() + if not os.path.isdir("lava-master/slaves/"): + os.mkdir("lava-master/slaves/") + fp = open("lava-master/slaves/%s.yaml" % lab_name, "w") + fp.write("dispatcher_ip: 192.168.66.1") + fp.close() + + #now proceed with tokens + fp = open(tokens_yaml, "r") + tokens = yaml.load(fp) + fp.close() + if not os.path.isdir("lava-master/users/"): + os.mkdir("lava-master/users/") + if not os.path.isdir("lava-master/tokens/"): + os.mkdir("lava-master/tokens/") + for section_name in tokens: + section = tokens[section_name] + if section_name == "lava_server_users": + for user in section: + username = user["name"] + ftok = open("lava-master/users/%s" % username, "w") + token = user["token"] + ftok.write("TOKEN=" + token + "\n") + if user.has_key("password"): + password = user["password"] + ftok.write("PASSWORD=" + password) + ftok.close() + if section_name == "callback_tokens": + for token in section: + filename = token["filename"] + ftok = open("lava-master/tokens/%s" % filename, "w") + username = token["username"] + ftok.write("USER=" + username + "\n") + vtoken = token["token"] + ftok.write("TOKEN=" + vtoken + "\n") + description = token["description"] + ftok.write("DESCRIPTION=" + description) + ftok.close() + with file('docker-compose.yml', 'w') as f: + yaml.dump(dockcomp, f) + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--header", help="use this file as header for output file") + args = parser.parse_args() + main(args) + diff --git a/tokens.yaml b/tokens.yaml new file mode 100644 index 0000000..c6a430f --- /dev/null +++ b/tokens.yaml @@ -0,0 +1,10 @@ +lava_server_users: + - name: example + token: longrandomtoken + password: examplepassword + +callback_tokens: + - filename: example + username: example + token: longrandomtokencallback + description: example-callback -- cgit 1.2.3-korg From 626402f90d0f8435e9268268180d46fe3b58f040 Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Wed, 25 Oct 2017 13:37:34 +0200 Subject: Handle generated files This commit add suppot for generated files by lalalab-gen.py. --- lava-master/Dockerfile | 7 ++++ lava-master/device-types/.empty | 0 lava-master/scripts/setup.sh | 74 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 lava-master/device-types/.empty create mode 100755 lava-master/scripts/setup.sh diff --git a/lava-master/Dockerfile b/lava-master/Dockerfile index 942f1f6..4fd4148 100644 --- a/lava-master/Dockerfile +++ b/lava-master/Dockerfile @@ -65,6 +65,13 @@ RUN /start.sh \ COPY configs/tftpd-hpa /etc/default/tftpd-hpa +COPY devices/ /root/devices/ +COPY device-types/ /root/device-types/ +COPY users/ /root/lava-users/ +COPY tokens/ /root/lava-callback-tokens/ +COPY scripts/setup.sh / +RUN /start.sh && /setup.sh && /stop.sh + EXPOSE 69/udp 80 3079 5555 5556 CMD /start.sh && bash diff --git a/lava-master/device-types/.empty b/lava-master/device-types/.empty new file mode 100644 index 0000000..e69de29 diff --git a/lava-master/scripts/setup.sh b/lava-master/scripts/setup.sh new file mode 100755 index 0000000..011a9c7 --- /dev/null +++ b/lava-master/scripts/setup.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +if [ -e /root/lava-users ];then + for ut in $(ls /root/lava-users) + do + # User is the filename + USER=$ut + . /root/lava-users/$ut + if [ -z "$PASSWORD" -o "$PASSWORD" = "$TOKEN" ];then + echo "Generating password..." + #Could be very long, should be avoided + PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) + fi + echo "Adding username $USER DEBUG(with $TOKEN / $PASSWORD)" + lava-server manage users add --passwd $PASSWORD $USER || exit 1 + if [ ! -z "$TOKEN" ];then + lava-server manage tokens add --user $USER --secret $TOKEN || exit 1 + fi + done +fi + +if [ -e /root/lava-callback-tokens ];then + for ct in $(ls /root/lava-callback-tokens) + do + . /root/lava-callback-tokens/$ct + if [ -z "$USER" ];then + echo "Missing USER" + exit 1 + fi + if [ -z "$TOKEN" ];then + echo "Missing TOKEN for $USER" + exit 1 + fi + if [ -z "$DESCRIPTION" ];then + echo "Missing DESCRIPTION for $USER" + exit 1 + fi + echo "Adding $USER ($DESCRIPTION) DEBUG($TOKEN)" + lava-server manage tokens add --user $USER --secret $TOKEN --description $DESCRIPTION || exit 1 + done +fi + +# This directory is used for storing device-types already added +mkdir -p /root/.lavadocker/ +if [ -e /root/device-types ];then + for i in $(ls /root/device-types/*yaml) + do + cp /root/device-types/$i /etc/lava-server/dispatcher-config/device-types/ + devicetype=$(basename $i) + lava-server manage device-types add $devicetype || exit 1 + touch /root/.lavadocker/devicetype-$devicetype + done +fi + +for worker in $(ls /root/devices/) +do + echo "Adding worker $worker" + lava-server manage workers add $worker || exit $? + for device in $(ls /root/devices/$worker/) + do + devicename=$(echo $device | sed 's,.jinja2,,') + devicetype=$(grep -h extends /root/devices/$worker/$device| grep -o '[a-zA-Z0-9_-]*.jinja2' | sed 's,.jinja2,,') + if [ -e /root/.lavadocker/devicetype-$devicetype ];then + echo "Skip devicetype $devicetype" + else + echo "Add devicetype $devicetype" + lava-server manage device-types add $devicetype || exit $? + touch /root/.lavadocker/devicetype-$devicetype + fi + echo "Add device $devicename on $worker" + cp /root/devices/$worker/$device /etc/lava-server/dispatcher-config/devices/ || exit $? + lava-server manage devices add --device-type $devicetype --worker $worker $devicename || exit $? + done +done -- cgit 1.2.3-korg From 905a723528e499e9eae193b4d72388076d561f6c Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Wed, 25 Oct 2017 13:45:56 +0200 Subject: Add support for conmux --- lava-slave/Dockerfile | 5 +++++ lava-slave/scripts/cu-loop | 11 +++++++++++ lava-slave/scripts/start.sh | 9 +++++++++ 3 files changed, 25 insertions(+) create mode 100755 lava-slave/scripts/cu-loop diff --git a/lava-slave/Dockerfile b/lava-slave/Dockerfile index 6aece71..e87ac63 100644 --- a/lava-slave/Dockerfile +++ b/lava-slave/Dockerfile @@ -17,6 +17,8 @@ RUN \ git \ vim \ sudo \ + cu \ + conmux \ python-setproctitle \ tftpd-hpa \ u-boot-tools \ @@ -50,6 +52,9 @@ COPY configs/lava-slave /etc/lava-dispatcher/lava-slave COPY configs/tftpd-hpa /etc/default/tftpd-hpa +COPY scripts/cu-loop /usr/local/bin/ +COPY conmux/* /etc/conmux/ + #TODO made this customizable, 1000 ports by default is too much RUN sed -i 's,XNBD_PORT_RANGE_MIN.*,XNBD_PORT_RANGE_MIN=55950,' /usr/lib/python2.7/dist-packages/lava_dispatcher/pipeline/utils/constants.py diff --git a/lava-slave/scripts/cu-loop b/lava-slave/scripts/cu-loop new file mode 100755 index 0000000..fbe5777 --- /dev/null +++ b/lava-slave/scripts/cu-loop @@ -0,0 +1,11 @@ +#!/bin/sh +DEV=$1 +BAUD=${2:-115200} + +while true; do + # NOTE: needs cu >= 1.07-24 + # c.f. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=336996 + test -e $DEV && cu -l $DEV -s $BAUD --parity=none --nostop --nortscts dir + sleep 0.2 +done + diff --git a/lava-slave/scripts/start.sh b/lava-slave/scripts/start.sh index f442e8d..dcbbcd7 100755 --- a/lava-slave/scripts/start.sh +++ b/lava-slave/scripts/start.sh @@ -10,5 +10,14 @@ service tftpd-hpa start || exit 4 rm -f /var/run/lava-slave.pid service lava-slave start || exit 5 +touch /var/run/conmux-registry +/usr/sbin/conmux-registry 63000 /var/run/conmux-registry& +sleep 2 +for item in $(ls /etc/conmux/*cf) +do + echo "Add $item" + /usr/sbin/conmux $item & +done + # start an http file server for boot/transfer_overlay support (cd /var/lib/lava/dispatcher; python -m SimpleHTTPServer 80) -- cgit 1.2.3-korg From 26cc005179760bd25b8bdd724a936847c81d24eb Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Wed, 25 Oct 2017 14:07:15 +0200 Subject: Add support for lavapdu --- lava-slave/Dockerfile | 5 +++++ lava-slave/lavapdu.conf | 19 +++++++++++++++++++ lava-slave/scripts/start.sh | 11 +++++++++++ 3 files changed, 35 insertions(+) create mode 100644 lava-slave/lavapdu.conf diff --git a/lava-slave/Dockerfile b/lava-slave/Dockerfile index e87ac63..5e0f3cb 100644 --- a/lava-slave/Dockerfile +++ b/lava-slave/Dockerfile @@ -55,6 +55,11 @@ COPY configs/tftpd-hpa /etc/default/tftpd-hpa COPY scripts/cu-loop /usr/local/bin/ COPY conmux/* /etc/conmux/ +#install pdudaemon +RUN DEBIAN_FRONTEND=noninteractive apt-get -y install postgresql +RUN service postgresql start && DEBIAN_FRONTEND=noninteractive apt-get -y install lavapdu-daemon lavapdu-client && service postgresql stop +COPY lavapdu.conf /etc/lavapdu/ + #TODO made this customizable, 1000 ports by default is too much RUN sed -i 's,XNBD_PORT_RANGE_MIN.*,XNBD_PORT_RANGE_MIN=55950,' /usr/lib/python2.7/dist-packages/lava_dispatcher/pipeline/utils/constants.py diff --git a/lava-slave/lavapdu.conf b/lava-slave/lavapdu.conf new file mode 100644 index 0000000..720c22b --- /dev/null +++ b/lava-slave/lavapdu.conf @@ -0,0 +1,19 @@ +{ + "daemon": { + "hostname": "0.0.0.0", + "port": 16421, + "dbhost": "127.0.0.1", + "dbuser": "pdudaemon", + "dbpass": "pdudaemon", + "dbname": "lavapdu", + "retries": 5, + "logging_level": "INFO" + }, + "pdus": { + "acme-0": { + "driver": "localcmdline", + "cmd_on": "/usr/local/bin/acme-cli -s 192.168.66.2 switch_on %d", + "cmd_off": "/usr/local/bin/acme-cli -s 192.168.66.2 switch_off %d" + } + } +} diff --git a/lava-slave/scripts/start.sh b/lava-slave/scripts/start.sh index dcbbcd7..c9645b3 100755 --- a/lava-slave/scripts/start.sh +++ b/lava-slave/scripts/start.sh @@ -10,6 +10,17 @@ service tftpd-hpa start || exit 4 rm -f /var/run/lava-slave.pid service lava-slave start || exit 5 +if [ -e /etc/lavapdu ];then + /etc/init.d/postgresql start || exit 6 + + echo "== Start lavapdu listen ==" + /etc/init.d/lavapdu-listen start || exit 7 + # lava listen create the database, let it some time + sleep 5 + echo "== Start lavapdu runner ==" + /etc/init.d/lavapdu-runner start || exit 8 +fi + touch /var/run/conmux-registry /usr/sbin/conmux-registry 63000 /var/run/conmux-registry& sleep 2 -- cgit 1.2.3-korg