File obs-server-2.10-0027-backend-Support-new-VM-types-without-modifying-worke.patch of Package obs-server

From 5fe4d6e2d9e77ac705997d5264643e3468eeb2d1 Mon Sep 17 00:00:00 2001
From: Oleg Girko <ol@infoserver.lv>
Date: Tue, 11 Feb 2020 22:45:47 +0000
Subject: [PATCH] [backend] Support new VM types without modifying worker code.

This change allows worker to pass unknown VM type down to build utlilty
without specific processing.
The unknown VM type is handled as it was some kind of container,
similar to lxc or docker.

This allows worker to take advantage of new VM types added to build
without need to modify worker to support each of them.
Adding full virtualisation methods still requires worker modification.

Signed-off-by: Oleg Girko <ol@infoserver.lv>
---
 dist/obsworker        | 25 +++++++++++++------------
 src/backend/bs_worker |  2 +-
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/dist/obsworker b/dist/obsworker
index 2719bc3cbe..c2503669d3 100755
--- a/dist/obsworker
+++ b/dist/obsworker
@@ -142,18 +142,18 @@ ARCH=""
 EMULATOR=""
 if [ -n "$OBS_VM_TYPE" -a "$OBS_VM_TYPE" != "auto" ] ; then
     if [ "${OBS_VM_TYPE#emulator:}" != "$OBS_VM_TYPE" ] ; then
-        vmopt="--emulator"
+        vmopt="--vm-type emulator"
         options=(${OBS_VM_TYPE//:/ })
         ARCH="--arch ${options[1]}"
         [ -n "${options[2]}" ] && EMULATOR="--emulator-script ${options[2]}"
     elif [ "$OBS_VM_TYPE" != "none" ] ; then
-        vmopt="--$OBS_VM_TYPE"
+        vmopt="--vm-type $OBS_VM_TYPE"
     fi
 elif [ -e /dev/kvm -a -x /usr/bin/qemu-kvm ] ; then
-    vmopt=--kvm
+    vmopt="--vm-type kvm"
     OBS_VM_TYPE="kvm"
 elif [ -e /sys/hypervisor/type ] && [ -x /usr/sbin/xl -o -x /usr/sbin/xm ] && grep -q xen /sys/hypervisor/type; then
-    vmopt=--xen
+    vmopt="--vm-type xen"
     OBS_VM_TYPE="xen"
 fi
 
@@ -352,7 +352,7 @@ case "$1" in
             # start one build backend per CPU
             NUM=`ls -d /sys/devices/system/cpu/cpu[0-9]* | wc -l`
         fi
-	if [ "--zvm" == "$vmopt" ]; then
+	if [ "zvm" == "$OBS_VM_TYPE" ]; then
 	    check_vmcp || rc_status -v
 	    create_initrd $OBS_VM_KERNEL $OBS_VM_INITRD || rc_status -v
             if [ -n "$OBS_WORKER_INSTANCE_NAMES" ]; then
@@ -368,14 +368,15 @@ case "$1" in
 	# print some config data
         echo "Run $NUM obsworker using $OBS_WORKER_DIRECTORY"
         echo -n "Type of obsworker is "
-	if [ "--kvm" == "$vmopt" ]; then echo "KVM virtual machine"
-	elif [ "--xen" == "$vmopt" ]; then echo "XEN virtual machine"
-	elif [ "--zvm" == "$vmopt" ]; then echo "z/VM virtual machine"
-	elif [ "--pvm" == "$vmopt" ]; then echo "PowerVM LPAR"
-	elif [ "--emulator" == "$vmopt" ]; then echo "System emulated virtual machine"
-	elif [ "--lxc" == "$vmopt" ]; then echo "LXC container"
+	if [ "kvm" == "$OBS_VM_TYPE" ]; then echo "KVM virtual machine"
+	elif [ "xen" == "$OBS_VM_TYPE" ]; then echo "XEN virtual machine"
+	elif [ "zvm" == "$OBS_VM_TYPE" ]; then echo "z/VM virtual machine"
+	elif [ "pvm" == "$OBS_VM_TYPE" ]; then echo "PowerVM LPAR"
+	elif [ "${OBS_VM_TYPE#emulator:}" != "$OBS_VM_TYPE" ]; then echo "System emulated virtual machine"
+	elif [ "lxc" == "$OBS_VM_TYPE" ]; then echo "LXC container"
 	elif [ "openstack" == "$OBS_VM_TYPE" ]; then echo "OpenStack virtual machine"
-	else  echo "chroot"
+	elif [ "auto" == "$OBS_VM_TYPE" -o "none" == "$OBS_VM_TYPE" -o -z "$OBS_VM_TY{E" ]; then echo "chroot"
+	else  echo "$OBS_VM_TYPE"
 	fi
 
         # find SLP announced OBS servers
diff --git a/src/backend/bs_worker b/src/backend/bs_worker
index fb47639c65..01604bde51 100755
--- a/src/backend/bs_worker
+++ b/src/backend/bs_worker
@@ -216,7 +216,7 @@ sub kill_job {
     push @args, '--vm-worker-nr', $vm_worker_instance if $vm_worker_instance;
   } else {
     push @args, '--root', $buildroot;
-    push @args, '--vm-type', $vm if $vm eq 'lxc' || $vm eq 'docker';
+    push @args, '--vm-type', $vm if $vm ne '' && $vm ne 'chroot';
   }
   if (system("$statedir/build/build", @args, "--kill")) {
     return 0;
-- 
2.31.1