#1 Add CI tests using the standard test interface
Closed 2 years ago by praiskup. Opened 2 years ago by sturivny.
git://fedorapeople.org/~sturivny/tar new_tests  into  master

Add CI tests using the standard test interface
Serhii Turivny • 2 years ago  
tests/tar-testsuite/Makefile
file added
+63

@@ -0,0 +1,63 @@

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Makefile of /CoreOS/tar/Regression/tar-testsuite

+ #   Description: TAR testsuite

+ #   Author: Branislav Blaskovic <bblaskov@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2012 Red Hat, Inc. All rights reserved.

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   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, write to the Free

+ #   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

+ #   Boston, MA 02110-1301, USA.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ export TEST=/CoreOS/tar/Regression/tar-testsuite

+ 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:           Branislav Blaskovic <bblaskov@redhat.com>" > $(METADATA)

+ 	@echo "Name:            $(TEST)" >> $(METADATA)

+ 	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)

+ 	@echo "Path:            $(TEST_DIR)" >> $(METADATA)

+ 	@echo "Description:     TAR testsuite" >> $(METADATA)

+ 	@echo "Type:            Regression" >> $(METADATA)

+ 	@echo "TestTime:        60m" >> $(METADATA)

+ 	@echo "RunFor:          tar" >> $(METADATA)

+ 	@echo "Requires:        tar texinfo libacl-devel rsh libselinux-devel rpm-build gcc" >> $(METADATA)

+ 	@echo "Priority:        Normal" >> $(METADATA)

+ 	@echo "License:         GPLv2" >> $(METADATA)

+ 	@echo "Confidential:    no" >> $(METADATA)

+ 	@echo "Destructive:     no" >> $(METADATA)

+ 

+ 	rhts-lint $(METADATA)

tests/tar-testsuite/PURPOSE
file added
+3

@@ -0,0 +1,3 @@

+ PURPOSE of /CoreOS/tar/Regression/tar-testsuite

+ Description: TAR testsuite

+ Author: Branislav Blaskovic <bblaskov@redhat.com>

tests/tar-testsuite/runtest.sh
file added
+123

@@ -0,0 +1,123 @@

+ #!/bin/bash

+ # vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/tar/Regression/tar-testsuite

+ #   Description: TAR testsuite

+ #   Author: Branislav Blaskovic <bblaskov@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2012 Red Hat, Inc. All rights reserved.

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   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, write to the Free

+ #   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

+ #   Boston, MA 02110-1301, USA.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/bin/rhts-environment.sh

+ . /usr/lib/beakerlib/beakerlib.sh

+ 

+ PACKAGE="tar"

+ TESTUSER="tar-testsuite"

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm $PACKAGE

+         rlRun "useradd $TESTUSER"

+         rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"

+         rlRun "chmod -R 777 $TmpDir"

+         rlRun "pushd $TmpDir"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+ 

+         # Getting archive

+         rlFetchSrcForInstalled $PACKAGE

+         VERSION=`ls -1 *.src.rpm | head -1 | sed 's/tar-\([0-9.]*\).*src.rpm/\1/'`

+         RPM_NAME=`ls -1 *.src.rpm | head -1`

+ 

+         rlRun "chmod -R 777 $TmpDir"

+ 

+         if [ -f "$RPM_NAME" ];then

+             # Get folders

+             HOME_DIR=$(awk -F: -v v="$TESTUSER" '{if ($1==v) print $6}' /etc/passwd)

+             rlRun "su $TESTUSER -c \"mkdir -p $HOME_DIR/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}\""

+             SPECDIR=$(su $TESTUSER -c "rpm --define '_topdir $HOME_DIR/rpmbuild' --eval %{_specdir}")

+             BUILDDIR=$(su $TESTUSER -c "rpm --define '_topdir $HOME_DIR/rpmbuild' --eval %{_builddir}")

+ 

+             # Print some info

+             rlLog "RPM name: $RPM_NAME"

+             rlLog "Version: $VERSION"

+             rlLog "Spec Dir: $SPECDIR"

+             rlLog "Build Dir: $BUILDDIR"

+ 

+             # Installing RPM

+             rlRun -s "su $TESTUSER -c \"rpm --define '_topdir $HOME_DIR/rpmbuild' -Uvh $TmpDir/$RPM_NAME\""

+             rlRun "mv $rlRun_LOG $TmpDir/rpm-install.log"

+ 

+             # Dependencies

+             REQ=""

+             for i in `yum deplist $RPM_NAME 2>/dev/null | grep "dependency:" | awk '/dependency:/ {print $2}'`; do REQ="$REQ $i"; done

+             if [ ! -z "$REQ" ]; then

+                 yum -y install $REQ 2>&1 >> $TmpDir/yum-install.log

+                 rlRun "rpm -q $REQ"

+             else

+                 rlLog "Build dependencies satisfied."

+             fi

+ 

+             # Building

+             rlRun -s "su $TESTUSER -c \"rpmbuild --define '_topdir $HOME_DIR/rpmbuild' -ba $SPECDIR/tar.spec\""

+             rlRun "mv $rlRun_LOG $TmpDir/rpmbuild.log"

+ 

+             # Using system /bin/tar for testsuite

+             rlRun "cd $BUILDDIR/tar-$VERSION"

+             rlRun "rm -f src/tar"

+ 

+             # Starting testsuite on /bin/tar

+             rlLog "Starting testsuite!"

+ 

+             rlRun "su $TESTUSER -c \"ln -s /bin/tar src/tar\""

+             rlRun -s "su $TESTUSER -c \"cd $BUILDDIR/tar-$VERSION/tests && ./testsuite\""

+             rlRun "mv $rlRun_LOG $TmpDir/testsuite.log"

+ 

+             # Grep fails from logs

+             while read line

+             do

+                 echo "$line" | grep "[0-9]\{0,\}:.*FAILED (" && rlFail "$line"

+             done < $TmpDir/testsuite.log

+ 

+             # Data from stderr

+             SKIPPED=`grep "[0-9]\{0,3\} tests were skipped" $TmpDir/testsuite.log`

+             if [ `echo $SKIPPED | wc -l` -eq 1 ];then

+                 rlLog "$SKIPPED"

+             fi

+         else

+ 

+             rlFail "No src RPM downloaded."

+ 

+         fi

+ 

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "cd $TmpDir"

+         rlBundleLogs "tar-testsuite-logs" "testsuite.log" "rpm-install.log" "rpmbuild.log" "yum-install.log"

+         rlRun "popd"

+         rlRun "userdel -r $TESTUSER"

+         rlRun "rm -rf $TmpDir" 0 "Removing tmp directory"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

tests/tar-using-remote-host-via-ssh/Makefile
file added
+63

@@ -0,0 +1,63 @@

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Makefile of /CoreOS/tar/Sanity/tar-using-remote-host-via-ssh

+ #   Description: It would be nice to have also tested the default behaviour over ssh.

+ #   Author: Petr Sklenar <psklenar@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2013 Red Hat, Inc. All rights reserved.

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   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, write to the Free

+ #   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

+ #   Boston, MA 02110-1301, USA.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ export TEST=/CoreOS/tar/Sanity/tar-using-remote-host-via-ssh

+ export TESTVERSION=1.1

+ 

+ BUILT_FILES=

+ 

+ FILES=$(METADATA) runtest.sh Makefile

+ 

+ .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:           Petr Sklenar <psklenar@redhat.com>" > $(METADATA)

+ 	@echo "Name:            $(TEST)" >> $(METADATA)

+ 	@echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)

+ 	@echo "Path:            $(TEST_DIR)" >> $(METADATA)

+ 	@echo "Description:     It would be nice to have also tested the default behaviour over ssh." >> $(METADATA)

+ 	@echo "Type:            Sanity" >> $(METADATA)

+ 	@echo "TestTime:        15m" >> $(METADATA)

+ 	@echo "RunFor:          tar ssh" >> $(METADATA)

+ 	@echo "Requires:        tar rmt ssh rsh" >> $(METADATA)

+ 	@echo "Priority:        Normal" >> $(METADATA)

+ 	@echo "License:         GPLv2" >> $(METADATA)

+ 	@echo "Confidential:    no" >> $(METADATA)

+ 	@echo "Destructive:     no" >> $(METADATA)

+ 

+ 	rhts-lint $(METADATA)

tests/tar-using-remote-host-via-ssh/PURPOSE
file added
+3

@@ -0,0 +1,3 @@

+ PURPOSE of /CoreOS/tar/Sanity/tar-using-remote-host-via-ssh

+ Description: It would be nice to have also tested the default behaviour over ssh.

+ Author: Petr Sklenar <psklenar@redhat.com>

tests/tar-using-remote-host-via-ssh/runtest.sh
file added
+94

@@ -0,0 +1,94 @@

+ #!/bin/bash

+ # vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   runtest.sh of /CoreOS/tar/Sanity/tar-using-remote-host-via-ssh

+ #   Description: It would be nice to have also tested the default behaviour over ssh.

+ #   Author: Petr Sklenar <psklenar@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Copyright (c) 2013 Red Hat, Inc. All rights reserved.

+ #

+ #   This copyrighted material is made available to anyone wishing

+ #   to use, modify, copy, or redistribute it subject to the terms

+ #   and conditions of the GNU General Public License version 2.

+ #

+ #   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, write to the Free

+ #   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,

+ #   Boston, MA 02110-1301, USA.

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ 

+ # Include Beaker environment

+ . /usr/bin/rhts-environment.sh || exit 1

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGE="tar"

+ 

+ rlJournalStart

+ if rlIsRHEL 5 6 ;then

+ sshpath=`which ssh`

+ echo "DEBUG: ssh cmd $sshpath"

+ ls -la $sshpath

+ which ssh

+ sshcmd="--rsh-command=$sshpath"

+ else

+ sshcmd=""

+ fi

+ 

+     rlPhaseStartSetup

+         rlAssertRpm $PACKAGE

+         rlAssertRpm rmt

+         rlFileBackup /etc/ssh/ssh_config

+         rm -rf /tmp/mytarball.tar /tmp/tralalaa.petr

+         username=petr$RANDOM

+         conf=ssh_config

+ 

+         echo 'Host localhost' >> /etc/ssh/ssh_config

+         echo ' UserKnownHostsFile      /dev/null'  >> /etc/ssh/ssh_config

+         echo ' StrictHostKeyChecking   no'  >> /etc/ssh/ssh_config

+         echo ' HostbasedAuthentication no'  >> /etc/ssh/ssh_config

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+ # copy&paste from http://pkgs.devel.redhat.com/cgit/tests/openssh/tree/sshd/sanity/runtest.sh

+         rlRun "useradd $username"

+         rlRun "echo $username | passwd --stdin $username"

+         homedir=`getent passwd $username | awk -F: '{print $6}'`

+         ls /root/.ssh/id_rsa || ssh-keygen -t rsa -N  '' -f /root/.ssh/id_rsa

+         rlAssert0 "ssh-keygen passed" $?

+         mkdir /home/$username/.ssh

+         cat /root/.ssh/id_rsa.pub >> /home/$username/.ssh/authorized_keys

+         cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys

+         restorecon -R /home/$username/.ssh

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlAssertNotExists /tmp/mytarball.tar

+         echo 'hello world' > tralalaa.petr

+         rlRun "tar $sshcmd -c -f $username@localhost:/tmp/mytarball.tar tralalaa.petr"

+         rlAssertExists /tmp/mytarball.tar

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlLog "nothing"

+         rm -rf tralalaa.petr

+         rlRun "tar xvf /tmp/mytarball.tar"

+         rlRun "cat tralalaa.petr  | grep 'hello world'"

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rm -rf /tmp/mytarball.tar tralalaa.petr

+         userdel $username 

+         rlLog "clean up"

+         rlFileRestore

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

tests/tests.yml
file added
+44

@@ -0,0 +1,44 @@

+ ---

+ # This first play always runs on the local staging system

+ - hosts: localhost

+   roles:

+   - role: standard-test-beakerlib

+     tags:

+     - classic

+     tests:

+     - tar-testsuite

+     - tar-using-remote-host-via-ssh

+     required_packages:

+     - tar              # required by both tests

+     - rmt              # required by tar-using-remote-host-via-ssh

+     - rsh              # required by both tests

+     - texinfo          # required by tar-testsuite

+     - libacl-devel     # required by tar-testsuite

+     - libselinux-devel # required by tar-testsuite

+     - rpm-build        # required by tar-testsuite

+     - gcc              # required by tar-testsuite

+     - attr             # required by tar-testsuite

+     - autoconf         # required by tar-testsuite

+     - automake         # required by tar-testsuite

+ 

+ - hosts: localhost

+   roles:

+   - role: standard-test-beakerlib

+     tags:

+     - container

+     tests:

+     - tar-testsuite

+     required_packages:

+     - tar              # required by tar-testsuite

+     - rsh              # required by tar-testsuite

+     - texinfo          # required by tar-testsuite

+     - libacl-devel     # required by tar-testsuite

+     - libselinux-devel # required by tar-testsuite

+     - rpm-build        # required by tar-testsuite

+     - gcc              # required by tar-testsuite

+     - attr             # required by tar-testsuite

+     - autoconf         # required by tar-testsuite

+     - automake         # required by tar-testsuite

+     - gettext          # required by tar-testsuite

+     - wget             # required by tar-testsuite

+     - policycoreutils  # required by tar-testsuite

no initial comment

Justification

Adds tests according to the CI wiki specifically the standard test interface in the spec.

The playbook includes Tier1 level test cases that have been tested in the following contexts and is passing reliably: Classic and Container. Test logs are stored in the artifacts directory.

The following steps are used to execute the tests using the standard test interface:

Test enveronment

Make sure you have installed packages from the spec

# rpm -q ansible python2-dnf libselinux-python standard-test-roles
ansible-2.3.2.0-1.fc26.noarch
python2-dnf-2.6.3-11.fc26.noarch
libselinux-python-2.6-7.fc26.x86_64
standard-test-roles-2.4-1.fc26.noarch

Run tests for Classic

# export TEST_SUBJECTS=
# sudo ansible-playbook --tags classic tests.yml

Snip of the example test run for Classic tests:

TASK [standard-test-beakerlib : Check the results] ******************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP **********************************************************************************************************************************************************************************************************
localhost                  : ok=30   changed=18   unreachable=0    failed=0   

PASS tar-testsuite
PASS tar-using-remote-host-via-ssh
PASS tar-testsuite

Run tests for Container

# export TEST_SUBJECTS=docker:docker.io/library/fedora:26
# sudo ansible-playbook --tags=container tests.yml

Snip of the example test run for Container tests:

TASK [standard-test-beakerlib : Check the results] ******************************************************************************************************************************************************************
changed: [a1fb2a54882aeb406b80b4cf5adc656259bb2c51b8c5f933c2f713a415aad105]

PLAY RECAP **********************************************************************************************************************************************************************************************************
a1fb2a54882aeb406b80b4cf5adc656259bb2c51b8c5f933c2f713a415aad105 : ok=16   changed=11   unreachable=0    failed=0   

PASS tar-testsuite

Notes

Tests will be enabled in CI, yet gating is currently disabled, so nothing will change. Tests will run on each dist-git commit, they are not triggered on koji builds and if you are using FMN, it should notify you of failures normally.

The RH QE maintainer contact in case you have questions: rhack @redhat.com
The idea is that these tests become yours just as you're maintaining the package, there will of course be people around if you have questions or troubles.

Closing in favor of https://pagure.io/fedora-infrastructure/issue/6695

Feel free to re-submit but to accept this we need to have someone who commits himself to take care of this form of testing.

Pull-Request has been closed by praiskup

2 years ago