tests: Remove nested vm from tar liveimg kickstart test
Use anaconda to install the root.tar.xz into a disk image. Copy the
disk image to the host, and use the cockpit vm support to boot it and
test it.
Cherry-picked from 4705ff3b1e
Related: rhbz#1769525
This commit is contained in:
parent
020fd300a4
commit
493055c03c
@ -80,6 +80,19 @@ class TestTar(composertest.ComposerTestCase):
|
|||||||
def test_tar_kickstart(self):
|
def test_tar_kickstart(self):
|
||||||
self.runCliTest("/tests/cli/test_compose_tar_kickstart.sh")
|
self.runCliTest("/tests/cli/test_compose_tar_kickstart.sh")
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory(prefix="/var/tmp/lorax-test.") as tmpdir:
|
||||||
|
# Copy the resulting disk image and shut down the VM
|
||||||
|
self.tearDownVirt(virt_dir="/var/tmp/test-results/*", local_dir=tmpdir)
|
||||||
|
|
||||||
|
# Boot the image, login using the ssh key
|
||||||
|
self.setUpTestMachine(tmpdir + "/disk.img", tmpdir + "/id_rsa")
|
||||||
|
|
||||||
|
# Upload the contents of the ./tests/ directory to the machine
|
||||||
|
self.machine.upload(["../tests"], "/")
|
||||||
|
|
||||||
|
# Run the test, on the booted image
|
||||||
|
self.runImageTest("/tests/cli/test_boot_tar_kickstart.sh")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
composertest.main()
|
composertest.main()
|
||||||
|
21
tests/cli/test_boot_tar_kickstart.sh
Executable file
21
tests/cli/test_boot_tar_kickstart.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Note: execute this file from the project root directory
|
||||||
|
|
||||||
|
#####
|
||||||
|
#
|
||||||
|
# Test the liveimg installed tar disk image
|
||||||
|
#
|
||||||
|
#####
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
. /usr/share/beakerlib/beakerlib.sh
|
||||||
|
. $(dirname $0)/lib/lib.sh
|
||||||
|
|
||||||
|
rlJournalStart
|
||||||
|
rlPhaseStartTest "Verify VM instance"
|
||||||
|
# Just the fact that this is running means the image can boot and ssh is working
|
||||||
|
rlAssertExists "/root/.ssh/authorized_keys"
|
||||||
|
rlPhaseEnd
|
||||||
|
rlJournalEnd
|
||||||
|
rlJournalPrintText
|
@ -16,27 +16,29 @@ CLI="${CLI:-./src/bin/composer-cli}"
|
|||||||
|
|
||||||
rlJournalStart
|
rlJournalStart
|
||||||
rlPhaseStartSetup
|
rlPhaseStartSetup
|
||||||
rlAssertExists $QEMU_BIN
|
TMP_DIR=$(mktemp -d /tmp/composer.XXXXX)
|
||||||
if ! rlCheckRpm httpd; then
|
SSH_KEY_DIR=$(mktemp -d /tmp/composer-ssh-keys.XXXXXX)
|
||||||
yum -y install httpd
|
|
||||||
fi
|
|
||||||
systemctl start httpd
|
|
||||||
|
|
||||||
ks_path="/var/www/html/ks-tar.cfg"
|
rlRun -t -c "ssh-keygen -t rsa -N '' -f $SSH_KEY_DIR/id_rsa"
|
||||||
tmp_dir=$(mktemp -d /tmp/composer.XXXXX)
|
PUB_KEY=$(cat "$SSH_KEY_DIR/id_rsa.pub")
|
||||||
ssh_key_dir=$(mktemp -d /tmp/composer-ssh-keys.XXXXXX)
|
|
||||||
|
|
||||||
rlRun -t -c "ssh-keygen -t rsa -N '' -f $ssh_key_dir/id_rsa"
|
cat > "$TMP_DIR/test-tar.toml" << __EOF__
|
||||||
pub_key=$(cat $ssh_key_dir/id_rsa.pub)
|
name = "test-tar"
|
||||||
|
|
||||||
bp_name="test-tar"
|
|
||||||
blueprint="$bp_name.toml"
|
|
||||||
cat > $blueprint << __EOF__
|
|
||||||
name = "$bp_name"
|
|
||||||
description = "tar image test"
|
description = "tar image test"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
modules = []
|
modules = []
|
||||||
|
|
||||||
|
[[groups]]
|
||||||
|
name = "anaconda-tools"
|
||||||
|
|
||||||
|
[[packages]]
|
||||||
|
name = "kernel"
|
||||||
|
version = "*"
|
||||||
|
|
||||||
|
[[packages]]
|
||||||
|
name = "beakerlib"
|
||||||
|
version = "*"
|
||||||
|
|
||||||
[[packages]]
|
[[packages]]
|
||||||
name = "openssh-server"
|
name = "openssh-server"
|
||||||
version = "*"
|
version = "*"
|
||||||
@ -56,50 +58,32 @@ version = "*"
|
|||||||
|
|
||||||
[[customizations.user]]
|
[[customizations.user]]
|
||||||
name = "root"
|
name = "root"
|
||||||
key = "$pub_key"
|
key = "$PUB_KEY"
|
||||||
|
|
||||||
__EOF__
|
__EOF__
|
||||||
rlRun -t -c "$CLI blueprints push $blueprint"
|
rlRun -t -c "$CLI blueprints push $TMP_DIR/test-tar.toml"
|
||||||
image_path="/var/www/html/root.tar.xz"
|
|
||||||
|
|
||||||
version=$(awk -F = '$1 == "VERSION_ID" { print $2 }' /etc/os-release | tr -d \")
|
|
||||||
arch=$(uname -m)
|
|
||||||
baseurl="http://download.eng.bos.redhat.com/rel-eng/latest-RHEL-${version}/compose/BaseOS/x86_64/os/"
|
|
||||||
rlRun -t -c "curl --remote-name-all $baseurl/images/pxeboot/{vmlinuz,initrd.img}"
|
|
||||||
|
|
||||||
rlRun -t -c "fallocate -l 5G disk.img"
|
|
||||||
rlPhaseEnd
|
rlPhaseEnd
|
||||||
|
|
||||||
rlPhaseStartTest "compose start"
|
rlPhaseStartTest "compose start"
|
||||||
rlAssertEquals "SELinux operates in enforcing mode" "$(getenforce)" "Enforcing"
|
rlAssertEquals "SELinux operates in enforcing mode" "$(getenforce)" "Enforcing"
|
||||||
uuid=$($CLI compose start $bp_name tar)
|
UUID=$($CLI compose start test-tar tar)
|
||||||
rlAssertEquals "exit code should be zero" $? 0
|
rlAssertEquals "exit code should be zero" $? 0
|
||||||
|
|
||||||
uuid=$(echo $uuid | cut -f 2 -d' ')
|
UUID=$(echo "$UUID" | cut -f 2 -d' ')
|
||||||
rlPhaseEnd
|
rlPhaseEnd
|
||||||
|
|
||||||
rlPhaseStartTest "compose finished"
|
rlPhaseStartTest "compose finished"
|
||||||
if [ -n "$uuid" ]; then
|
wait_for_compose "$UUID"
|
||||||
until $CLI compose status | grep -E "$uuid (FINISHED|FAILED)"; do
|
|
||||||
sleep 60
|
|
||||||
rlLogInfo "Waiting for compose to finish ..."
|
|
||||||
done;
|
|
||||||
else
|
|
||||||
rlFail "Compose uuid is empty!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
rlRun -t -c "$CLI compose image $uuid"
|
|
||||||
image="$uuid-root.tar.xz"
|
|
||||||
rlPhaseEnd
|
rlPhaseEnd
|
||||||
|
|
||||||
rlPhaseStartTest "Install tar image using kickstart liveimg command"
|
rlPhaseStartTest "Install tar image using kickstart liveimg command"
|
||||||
cat > $ks_path << __EOF__
|
cat > "$TMP_DIR/test-liveimg.ks" << __EOF__
|
||||||
cmdline
|
cmdline
|
||||||
lang en_US.UTF-8
|
lang en_US.UTF-8
|
||||||
timezone America/New_York
|
timezone America/New_York
|
||||||
keyboard us
|
keyboard us
|
||||||
rootpw --lock
|
rootpw --lock
|
||||||
sshkey --username root "$pub_key"
|
sshkey --username root "$PUB_KEY"
|
||||||
bootloader --location=mbr
|
bootloader --location=mbr
|
||||||
zerombr
|
zerombr
|
||||||
clearpart --initlabel --all
|
clearpart --initlabel --all
|
||||||
@ -109,31 +93,24 @@ autopart
|
|||||||
# (using 'poweroff' ks command just halted the machine without powering it off)
|
# (using 'poweroff' ks command just halted the machine without powering it off)
|
||||||
reboot
|
reboot
|
||||||
|
|
||||||
liveimg --url http://10.0.2.2/root.tar.xz
|
liveimg --url file:///var/lib/lorax/composer/results/$UUID/root.tar.xz
|
||||||
|
|
||||||
__EOF__
|
__EOF__
|
||||||
mv $image $image_path
|
# Build the disk image directly in the results directory
|
||||||
restorecon $image_path
|
rlRun -t -c "mkdir -p /var/tmp/test-results/"
|
||||||
rlLogInfo "Starting installation from tar image in a VM"
|
rlRun -t -c "fallocate -l 5G /var/tmp/test-results/disk.img"
|
||||||
$QEMU -m 2048 -drive file=disk.img,format=raw -nographic -kernel vmlinuz -initrd initrd.img \
|
|
||||||
-append "inst.ks=http://10.0.2.2/ks-tar.cfg inst.stage2=$baseurl console=ttyS0" --no-reboot
|
|
||||||
|
|
||||||
|
rlLogInfo "Starting installation from tar image using anaconda"
|
||||||
|
rlRun -t -c "anaconda --image=/var/tmp/test-results/disk.img --kickstart=$TMP_DIR/test-liveimg.ks"
|
||||||
rlLogInfo "Installation of the image finished."
|
rlLogInfo "Installation of the image finished."
|
||||||
rlPhaseEnd
|
|
||||||
|
|
||||||
rlPhaseStartTest "Boot and check the installed system"
|
# Include the ssh key needed to log into the image
|
||||||
boot_image "-drive file=disk.img,format=raw" 600
|
rlRun -t -c "cp $SSH_KEY_DIR/* /var/tmp/test-results"
|
||||||
# run generic tests to verify the instance
|
|
||||||
CHECK_CMDLINE=0 verify_image root localhost "-i $ssh_key_dir/id_rsa -p 2222"
|
|
||||||
rlPhaseEnd
|
rlPhaseEnd
|
||||||
|
|
||||||
rlPhaseStartCleanup
|
rlPhaseStartCleanup
|
||||||
rlRun -t -c "killall -9 $QEMU_BIN"
|
rlRun -t -c "$CLI compose delete $UUID"
|
||||||
rlRun -t -c "rm -rf $image $blueprint $image_path vmlinuz initrd.img disk.img $ks_path"
|
rlRun -t -c "rm -rf $TMP_DIR $SSH_KEY_DIR"
|
||||||
rlRun -t -c "$CLI blueprints delete $bp_name"
|
|
||||||
rlRun -t -c "$CLI compose delete $uuid"
|
|
||||||
rlRun -t -c "systemctl stop httpd"
|
|
||||||
rlPhaseEnd
|
rlPhaseEnd
|
||||||
|
|
||||||
rlJournalEnd
|
rlJournalEnd
|
||||||
rlJournalPrintText
|
rlJournalPrintText
|
||||||
|
Loading…
Reference in New Issue
Block a user