Skip to content

Commit

Permalink
WIP install: new test to check against reference files
Browse files Browse the repository at this point in the history
Tests for generation of the reference files, and for checking against them.

FIXME: needs reference files for releases
  • Loading branch information
ydirson committed Sep 13, 2024
1 parent a2ef674 commit 0ec8cab
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,8 @@ def enable_hsts_header(self):
def disable_hsts_header(self):
self.ssh(['rm', '-f', f'{XAPI_CONF_DIR}/00-XCP-ng-tests-enable-hsts-header.conf'])
self.restart_toolstack(verify=True)

def firmware_type(self):
retcode = self.ssh(['test', '-d', '/sys/firmware/efi/'],
check=False, simple_output=False).returncode
return "uefi" if retcode == 0 else "bios"
31 changes: 31 additions & 0 deletions scripts/runtests-get-fsdiff-ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
set -e

# extract reference dumps from install

# needs at least --hosts=$NEST
# needs runtest-install output cache

VERSION="83nightly"

. $(dirname $0)/lib.sh

GITREV=$(git rev-parse HEAD)

declare -A FSDIFFCONFS=()
for conf in "${TESTCONFS[@]}"; do
IFS=- read fw sr < <(echo "$conf")
[ "$media" = "iso" -a "$sr" = "ext" ] || continue
FSDIFFCONFS[$fw-$VERSION]=$conf
done

for fsdiffconf in "${!FSDIFFCONFS[@]}"; do # "in FSDIFFCONFS.keys"
IFS=- read fw version < <(echo "$conf")
# get ref data for install
run_pytest \
--hosts="cache://install.test::Nested::boot_inst[$fw-$version-host1-iso-ext]-vm1-$GITREV" \
--log-file=test-fsdiffref-$conf.log \
tests/fs-diff/test_fsdiff_ref.py::test_fsdiff_mkref
done

report_failures
6 changes: 6 additions & 0 deletions scripts/runtests-postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ for conf in "${TESTCONFS[@]}"; do
--runner "./jobs.py run postinstall cache://${host1},cache://${host2}" \
--log-file=test-postinstall-$conf.log \
"$@"

run_pytest \
--hosts="cache://install.test::Nested::boot_inst[$fw-83nightly-host1-iso-ext]-vm1-$GITREV" \
--log-file=test-fsdiff-$conf.log \
"$@" \
tests/fs-diff/test_fsdiff_ref.py::test_fsdiff_against_ref
done

report_failures
7 changes: 7 additions & 0 deletions scripts/runtests-postupgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ for conf in "${REFCONFS[@]}"; do
# FIXME postinstall-intrapool-migrate (with TLS) needs a 2-host pool
;;
esac

# FIXME: check fsdiff with TLS activated, since that's what the 8.3+ ref have

run_pytest \
--hosts="cache://${host1}" \
--log-file=test-fsdiff-$conf.log \
tests/fs-diff/test_fsdiff_ref.py::test_fsdiff_against_ref
done

report_failures
36 changes: 36 additions & 0 deletions tests/fs-diff/test_fsdiff_ref.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import logging
import os
import pytest
import subprocess

from lib.commands import local_cmd

# Requirements:
# - 1 XCP-ng host

MYDIR = os.path.dirname(__file__)
REF_DIR = os.path.join(MYDIR, "data")
FSDIFF = os.path.realpath(f"{MYDIR}/../../scripts/xcpng-fs-diff.py")

def _ref_name(host):
return f"{host.inventory['PRODUCT_VERSION']}-{host.firmware_type()}"

# FIXME: not a test, rather a task done on a given (cached) host
def test_fsdiff_mkref(hosts):
host, = hosts

logging.info("Extracting reference data from %s", host.hostname_or_ip)
process = local_cmd([FSDIFF,
"--reference-host", host.hostname_or_ip,
"--save-reference", os.path.join(REF_DIR, _ref_name(host)),
])

def test_fsdiff_against_ref(hosts):
host, = hosts

ref_file = os.path.join(REF_DIR, _ref_name(host))
logging.info("Comparing %s with reference data", host.hostname_or_ip)
process = local_cmd([FSDIFF,
"--load-reference", ref_file,
"--test-host", host.hostname_or_ip,
])

0 comments on commit 0ec8cab

Please sign in to comment.