From 6889e00e64adaf408260a2d0bf658ed09da234f9 Mon Sep 17 00:00:00 2001 From: Ahmed Karic Date: Fri, 20 Sep 2024 11:32:17 +0200 Subject: [PATCH] test: introduce image test-mode within the test environment - The test mode, introduced at the config/build phase (commit 241f3f2), causes the device to start in test-mode when used in GNS3 (or other environments). This has unintentionally become the default configuration for the image, which is not desirable and is only acceptable for the Infix test system. With this update, the original configuration is preserved, and the test mode is applied only within the test environment. - Align the 'dual' topology to use the same template as 'quad' Fixes #603 --- doc/ChangeLog.md | 6 ++-- test/.env | 2 +- test/env | 11 +++++++ test/inject-test-mode | 54 ++++++++++++++++++++++++++++++++++ test/virt/dual/topology.dot.in | 3 +- test/virt/quad/topology.dot.in | 1 + 6 files changed, 73 insertions(+), 4 deletions(-) create mode 100755 test/inject-test-mode diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 1f4fce13f..1fe27971c 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -24,8 +24,12 @@ All notable changes to the project are documented in this file. authorized users, like `admin`, to not being able to query status of OSPF or BFD. Workaround by using the UNIX shell `sudo vtysh`. Regression introduced in v24.08.0 +- Fix #603: regression in GNS3 image, starts in test mode by default. + Introduced in v24.08. - Fix #613: CLI regression in tab completion of container commands, e.g., `container shell `. Regression introduced in v24.08.0 +- Fix #616: Silent failure when selecting bash as login shell for + non-admin user, this silent lock has been removed. - Fix #618: CLI command `show interfaces` does not show bridges and bridge ports, regression introduced in v24.08.0 -- only affects bridges without multicast snooping @@ -33,8 +37,6 @@ All notable changes to the project are documented in this file. regression introduced in v24.06.0 - Spellcheck path to `/var/lib/containers` when unpacking OCI archives on container upgrade -- Fix #616: Silent failure when selecting bash as login shell for - non-admin user, this silent lock has been removed. - The timeout before giving up on loading the `startup-config` at boot is now 1 minute, just like operations via other front-ends (NETCONF and RESTCONF). This was previously (incorrectly) set to 10 seconds. diff --git a/test/.env b/test/.env index e61b722cc..99dfa08ce 100644 --- a/test/.env +++ b/test/.env @@ -2,7 +2,7 @@ # shellcheck disable=SC2034,SC2154 # Current container image -INFIX_TEST=ghcr.io/kernelkit/infix-test:1.8 +INFIX_TEST=ghcr.io/kernelkit/infix-test:1.9 ixdir=$(readlink -f "$testdir/..") logdir=$(readlink -f "$testdir/.log") diff --git a/test/env b/test/env index d47205edc..f10a1ca6b 100755 --- a/test/env +++ b/test/env @@ -70,6 +70,14 @@ usage: test/env [-cDhiKr] -f -q [...] EOF } +get_base_img() +{ + local files="$1" + local base_img_file + base_img_file=$(echo "$files" | tr ' ' '\n' | grep -- '-disk.img$') + echo "$envdir/qeneth/$(basename "$base_img_file")" +} + start_topology() { qenethdir="$1" @@ -87,6 +95,9 @@ start_topology() ln -sf "$file" "$envdir/qeneth/$filename" done + base_img=$(get_base_img "$files") + $testdir/inject-test-mode -b "$base_img" -o "${base_img%-disk.img}-disk-test.img" + (cd "$envdir/qeneth/" && $qeneth generate && $qeneth start) INFAMY_ARGS="$INFAMY_ARGS $envdir/qeneth/topology.dot" diff --git a/test/inject-test-mode b/test/inject-test-mode new file mode 100755 index 000000000..2f499b5b5 --- /dev/null +++ b/test/inject-test-mode @@ -0,0 +1,54 @@ +#!/bin/sh + +# This script injects a "test-mode" file into a copy of the main disk image. +# It begins by parsing the partition table of the disk image to identify the +# 'aux' partition, which is then extracted. An empty 'test-mode' file is +# injected into the extracted partition, and the modified partition is written +# back to the output image. The output image can subsequently be used as a +# backing image for Copy-on-Write (QCOW) images utilized by Qeneth. + +set -e + +while getopts "b:o:" opt; do + case $opt in + b) base_img="$OPTARG" ;; # Base image (Original image) + o) output_img="$OPTARG" ;; # Output image (Backing image for QCoW images) + *) echo "Usage: $0 -b -o " ; exit 1 ;; + esac +done + +if [ -z "$base_img" ] || [ -z "$output_img" ]; then + echo "Both -b (base image) and -o (output image) parameters are required." + exit 1 +fi + +rm -f "$output_img" +if ! cp "$base_img" "$output_img"; then + echo "Error: Failed to copy $base_img to $output_img" + exit 1 +fi + +if ! part_table=$(fdisk -l "$output_img" 2>/dev/null); then + echo "Error: Failed to read partition table from $output_img" + exit 1 +fi + +aux_line=$(echo "$part_table" | grep 'aux') +if [ -z "$aux_line" ]; then + echo "Error: 'aux' partition not found in $output_img" + exit 1 +fi + +start=$(echo "$aux_line" | awk '{print $2}') +end=$(echo "$aux_line" | awk '{print $3}') +count=$(($end - $start + 1)) +block_size=$(echo "$part_table" | grep "Logical sector size" | awk '{print $4}') + +dd if="$output_img" of="tmpaux" skip="$start" count="$count" bs="$block_size" status=none + +touch tmp-empty-file +e2cp tmp-empty-file tmpaux:/test-mode +rm tmp-empty-file + +dd of="$output_img" if="tmpaux" seek="$start" count="$count" bs="$block_size" status=none conv=notrunc +rm tmpaux diff --git a/test/virt/dual/topology.dot.in b/test/virt/dual/topology.dot.in index f28bf6968..588a2ee22 100644 --- a/test/virt/dual/topology.dot.in +++ b/test/virt/dual/topology.dot.in @@ -7,7 +7,8 @@ graph "dual" { node [shape=record, fontname="monospace"]; edge [color="cornflowerblue", penwidth="2"]; - qn_template="infix-x86_64"; + qn_template="infix-bios-x86_64"; + qn_image="infix-x86_64-disk-test.img" qn_oui="00:a0:85"; qn_append="quiet"; diff --git a/test/virt/quad/topology.dot.in b/test/virt/quad/topology.dot.in index dde7dc4c7..de3d55345 100644 --- a/test/virt/quad/topology.dot.in +++ b/test/virt/quad/topology.dot.in @@ -8,6 +8,7 @@ graph "quad" { edge [color="cornflowerblue", penwidth="2"]; qn_template="infix-bios-x86_64"; + qn_image="infix-x86_64-disk-test.img" qn_oui="00:a0:85"; qn_append="quiet";