From 2372ac544c450733fc72a9c656b3bc88a75f96a4 Mon Sep 17 00:00:00 2001
From: Christopher Obbard <chris.obbard@collabora.com>
Date: Fri, 27 Nov 2020 19:04:46 +0000
Subject: [PATCH] image-builder: test-recipe: Check fakemachine backend

The smoke test should retrieve the backend it's running and compare it
against the requested backend.

Signed-off-by: Christopher Obbard <chris.obbard@collabora.com>
---
 image-builder/test-recipe.yaml | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/image-builder/test-recipe.yaml b/image-builder/test-recipe.yaml
index d0c9ba0..dd84e02 100644
--- a/image-builder/test-recipe.yaml
+++ b/image-builder/test-recipe.yaml
@@ -2,10 +2,26 @@
 {{- $mirror := or .mirror "https://repositories.apertis.org/apertis/" -}}
 {{- $suite := or .suite "v2021dev1" -}}
 {{- $osname := or .osname "apertis" -}}
+{{- $required_backend := or .required_backend "uml" -}}
 
 architecture: {{ $architecture }}
 
 actions:
+  - action: run
+    description: Check fakemachine backend
+    label: check-fakemachine-backend
+    command: |
+      BACKEND=$(systemd-detect-virt)
+
+      # workaround for https://github.com/systemd/systemd/issues/17754
+      # running fakemachine in uml mode inside gitlab runner we essentially run
+      # uml nested under kvm; systemd-detect-virt thinks we are running on kvm
+      grep -qP "^vendor_id\t: User Mode Linux" /proc/cpuinfo && BACKEND="uml"
+
+      echo "detected machine backend: ${BACKEND}"
+      echo "required machine backend: {{ $required_backend }}"
+      [ "${BACKEND}" = "{{ $required_backend }}" ]
+
   - action: debootstrap
     suite: {{ $suite }}
     components:
-- 
GitLab