From 772db9524434cb2a73c1e86c1c2c2cf1fb009f50 Mon Sep 17 00:00:00 2001
From: Martin Weinelt <martin@darmstadt.freifunk.net>
Date: Sun, 22 Mar 2020 18:49:22 +0100
Subject: [PATCH] contrib/ci: add test stage

---
 contrib/ci/Jenkinsfile                        | 18 ++++++++++++++++++
 contrib/ci/jenkins-community-slave/Dockerfile |  4 ++--
 contrib/ci/jenkins-community-slave/README.md  | 14 ++++++++++----
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/contrib/ci/Jenkinsfile b/contrib/ci/Jenkinsfile
index 4a4cbc4c1..b4e2e2790 100644
--- a/contrib/ci/Jenkinsfile
+++ b/contrib/ci/Jenkinsfile
@@ -34,6 +34,23 @@ pipeline {
 				sh 'make update'
 				sh 'test -d /dl_cache && ln -s /dl_cache openwrt/dl || true'
 				sh 'make -j$(nproc) V=s'
+				stash includes: '**/output/images/factory/*-x86-64.img.gz', name: 'gluon-x86-64-factory'
+			}
+		}
+		stage('test') {
+			agent { label 'gluon-docker-v2' }
+			environment {
+				TMUX = "notmux"
+			}
+			steps {
+				unstash 'gluon-x86-64-factory'
+				sh label: 'Unpack image', script: 'gunzip -cd ./output/images/factory/*x86-64*.img.gz > ./image.img'
+				sh label: 'Print python environment', script: 'python3 -m pip freeze'
+				script {
+					for (f in findFiles(glob: '**/tests/*.py')) {
+						sh label: "Test ${f.name}", script: "python3 tests/${f.name} --use-tmp-workdir"
+					}
+				}
 			}
 		}
 	}
@@ -49,4 +66,5 @@ pipeline {
  can notify lemoer, that you have updated your node.
 
  - gluon-docker-v1: add shellcheck binary to the build environment
+ - gluon-docker-v2: add qemu-testlab testing, requires KVM virtualization support
 */
diff --git a/contrib/ci/jenkins-community-slave/Dockerfile b/contrib/ci/jenkins-community-slave/Dockerfile
index ef8642ab0..c1e6879bb 100644
--- a/contrib/ci/jenkins-community-slave/Dockerfile
+++ b/contrib/ci/jenkins-community-slave/Dockerfile
@@ -5,8 +5,8 @@ USER root
 # this is needed to install default-jre-headless in debian slim images
 RUN mkdir -p /usr/share/man/man1
  
-RUN apt-get update && apt-get install -y default-jre-headless curl python3 python3-pip python3-sphinx git
-RUN pip3 install jenkins-webapi sphinx_rtd_theme
+RUN apt-get update && apt-get install -y default-jre-headless curl git netcat-openbsd python3 python3-pip qemu-system-x86 iproute2 openssh-client
+RUN python3 -m pip install jenkins-webapi sphinx sphinx_rtd_theme gluon-qemu-testlab==0.0.5
  
 # Get docker-compose in the agent container
 RUN mkdir -p /home/jenkins
diff --git a/contrib/ci/jenkins-community-slave/README.md b/contrib/ci/jenkins-community-slave/README.md
index 74a32fb57..b80ebfc53 100644
--- a/contrib/ci/jenkins-community-slave/README.md
+++ b/contrib/ci/jenkins-community-slave/README.md
@@ -1,7 +1,11 @@
 # Gluon CI using Jenkins
 
 ## Requirements
-- Only a host with docker.
+- Linux system
+  - with docker installed
+  - with Hardware Virtualisation (KVM Support)
+    - Verify using: `lscpu | grep vmx`
+    - If machine is virtualized host needs to load `kvm_intel` with `nested=1` option and cpuflags need to include `vmx`
 
 ## Architecture
 
@@ -19,9 +23,11 @@ docker build -t gluon-jenkins .
 mkdir /var/cache/openwrt_dl_cache/
 chown 1000:1000 /var/cache/openwrt_dl_cache
 docker run --detach --restart always \
-    -e "SLAVE_NAME=whoareyou" \
-    -e "SLAVE_SECRET=changeme" \
-    -v /var/cache/openwrt_dl_cache/:/dl_cache
+    --env "SLAVE_NAME=whoareyou" \
+    --env "SLAVE_SECRET=changeme" \
+    --device /dev/kvm:/dev/kvm \
+    --volume /var/cache/openwrt_dl_cache/:/dl_cache \
+    gluon-jenkins
 ```
 4. Check whether the instance is running correctly:
    - Your node should appear [here](https://build.ffh.zone/label/gluon-docker/).
-- 
GitLab