From 94b563651d96ab3e8437cd8d884f4c893c073845 Mon Sep 17 00:00:00 2001 From: Chris Leech Date: Tue, 13 Jun 2023 14:08:13 +0200 Subject: [PATCH] Copy over gating tests from branch rhel-8.8.0 Signed-off-by: Chris Leech --- tests/.fmf/version | 1 + .../iscsi-target-initiator-restraint/Makefile | 62 ++++++++++ .../iscsi-target-initiator-restraint/PURPOSE | 3 + .../runtest.sh | 115 ++++++++++++++++++ tests/provision.fmf | 5 + tests/tests.yml | 37 ++++++ 6 files changed, 223 insertions(+) create mode 100644 tests/.fmf/version create mode 100644 tests/iscsi-target-initiator-restraint/Makefile create mode 100644 tests/iscsi-target-initiator-restraint/PURPOSE create mode 100755 tests/iscsi-target-initiator-restraint/runtest.sh create mode 100644 tests/provision.fmf create mode 100644 tests/tests.yml diff --git a/tests/.fmf/version b/tests/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/tests/iscsi-target-initiator-restraint/Makefile b/tests/iscsi-target-initiator-restraint/Makefile new file mode 100644 index 0000000..b28f6e3 --- /dev/null +++ b/tests/iscsi-target-initiator-restraint/Makefile @@ -0,0 +1,62 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /kernel/test_beakertask/Sanity/beaker_nvr_test +# Description: Install VDO +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2018 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/beaker_nvr_test +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Andy Walsh " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Creates iSCSI target/initiator, and logs it in locally" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: test_beakertask" >> $(METADATA) + @echo "Requires: test_beakertask" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Releases: -RHEL4 -RHELClient5 -RHELServer5" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/iscsi-target-initiator-restraint/PURPOSE b/tests/iscsi-target-initiator-restraint/PURPOSE new file mode 100644 index 0000000..0f298f5 --- /dev/null +++ b/tests/iscsi-target-initiator-restraint/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE Create an iSCSI target/initiator environment +Description: Set up and Log into an iSCSI target locally. +Author: Andy Walsh diff --git a/tests/iscsi-target-initiator-restraint/runtest.sh b/tests/iscsi-target-initiator-restraint/runtest.sh new file mode 100755 index 0000000..0a366be --- /dev/null +++ b/tests/iscsi-target-initiator-restraint/runtest.sh @@ -0,0 +1,115 @@ +#!/bin/bash +# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh for iSCSI target/initiator test +# Description: Set up and Log into an iSCSI target locally. +# Author: Andy Walsh +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2019 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +# Set up a target IQN to use through the test. +targetIQN=iqn.2019-03.com.redhat.test:testtargetname +targetIP=127.0.0.1 + +# Minimum size required for loopback device. Sometimes software (like VDO) +# needs more than ~10G. +minimumSize=15 + +rlJournalStart + +rlPhaseStartSetup + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "pushd $TmpDir" + + # Determine the size of the loopback device we're going to use + # (Free space on rootfs minus 1G) + loopbackSize=$(($(df --sync --output=avail / | tail -1) * 1024 - 1024*1024*1024)) + if [ ${loopbackSize} -lt $((1024*1024*1024*${minimumSize})) ]; then + rlDie "Not enough space to create the loopback device" + fi + + # Create the backing store and then set up the loopback device. + rlRun "truncate -s ${loopbackSize} $TmpDir/loop0.bin" 0 "Laying out loopfile backing" + rlRun "losetup /dev/loop0 $TmpDir/loop0.bin" 0 "Creating loopdevice" + + # Check whether we have the iscsi utilities installed, and if we don't, + # then install them. If this is being tested in OSCI, I believe that + # the package will be pre-installed when we get to this point. + if ! rlCheckRpm iscsi-initiator-utils; then + yum install -y iscsi-initiator-utils + fi + + if ! rlCheckRpm targetcli; then + yum install -y targetcli + fi + + if [ -f /etc/iscsi/initiatorname.iscsi ]; then + . /etc/iscsi/initiatorname.iscsi + fi + + # Make sure the target service is running. + rlRun "systemctl start target" +rlPhaseEnd + +rlPhaseStartTest + # Gather some system information for debug purposes + rlRun "uname -a" +rlPhaseEnd + +rlPhaseStartTest "Set up target" + rlRun "targetcli backstores/block create name=loopback_device dev=/dev/loop0" + rlRun "targetcli iscsi/ create ${targetIQN}" + rlRun "targetcli iscsi/${targetIQN}/tpg1/acls create ${InitiatorName}" + rlRun "targetcli iscsi/${targetIQN}/tpg1/luns create lun=100 /backstores/block/loopback_device" +rlPhaseEnd + +rlPhaseStartTest "Set up initiator (Log into target)" + rlRun "iscsiadm --mode discovery --type sendtargets --portal ${targetIP}" + rlRun "iscsiadm --mode node --target ${targetIQN} -l" + + # Occasionally logging into the iSCSI target and checking for the LUNs + # being presented and handled by udev seems to falsely cause the next check + # to fail. Adding a short sleep seems to fix that. + sleep 1 + + if [ ! -L /dev/disk/by-path/ip-${targetIP}\:3260-iscsi-${targetIQN}-lun-100 ]; then + rlFail "iSCSI LUN not found" + fi +rlPhaseEnd + +rlPhaseStartCleanup + # Log out of the target and tear down the iSCSI target configuration + rlRun "iscsiadm --mode node -u" + rlRun "targetcli iscsi/ delete ${targetIQN}" + rlRun "targetcli backstores/block delete loopback_device" + + rlRun "losetup -d /dev/loop0" 0 "Deleting loopdevice" + rlRun "rm -f $TmpDir/loop0.bin" 0 "Removing loopfile backing" + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" +rlPhaseEnd + +rlJournalPrintText +rlJournalEnd diff --git a/tests/provision.fmf b/tests/provision.fmf new file mode 100644 index 0000000..62a6eba --- /dev/null +++ b/tests/provision.fmf @@ -0,0 +1,5 @@ +--- + +standard-inventory-qcow2: + qemu: + m: 2G diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..9c6bdce --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,37 @@ +--- +# Tests suitable to run in classic environment +- hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - classic + tests: + - iscsi-target-initiator-restraint + required_packages: + - targetcli + +- hosts: localhost + roles: + - role: standard-test-basic + # python-stqe cannot be installed on 'atomic', no need to run on 'container' + tags: + - classic + repositories: + - repo: "https://gitlab.com/rh-kernel-stqe/python-stqe.git" + dest: "python-stqe" + version: 535ecebf5611e158079d806b6232e3d2c68f0d93 + tests: + # Install python-stqe first + # make sure we use same version of libsan + - install_stqe: + dir: python-stqe + run: pip3 install libsan==0.3.0 && python3 setup.py install --prefix= + - iscsi-initiator-utils: + dir: ./ + run: stqe-test run -t iscsi/iscsi_params.py + required_packages: + # required for python-stqe + - python3-pyyaml + - python3-netifaces + - python3-augeas + - python3-pip