#1 Add CI tests using the standard test interface
Merged 6 years ago by tmraz. Opened 6 years ago by astepano.
git://fedorapeople.org/~astepano/crontabs master  into  master

Add CI tests using the standard test interface
Andrei Stepanov • 6 years ago  
tests/test-of-functionality-of-crontabs/Makefile
file added
+63
@@ -0,0 +1,63 @@

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

+ #

+ #   Makefile of /CoreOS/crontabs/Sanity/test-of-functionality-of-crontabs

+ #   Description: test of functionality of crontabs

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

+ #

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

+ #

+ #   Copyright (c) 2011 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/crontabs/Sanity/test-of-functionality-of-crontabs

+ 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)

+ 	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:     test of functionality of crontabs" >> $(METADATA)

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

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

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

+ 	@echo "Requires:        crontabs" >> $(METADATA)

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

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

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

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

+ 

+ 	rhts-lint $(METADATA)

tests/test-of-functionality-of-crontabs/PURPOSE
file added
+3
@@ -0,0 +1,3 @@

+ PURPOSE of /CoreOS/crontabs/Sanity/test-of-functionality-of-crontabs

+ Description: test of functionality of crontabs

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

tests/test-of-functionality-of-crontabs/runtest.sh
file added
+83
@@ -0,0 +1,83 @@

+ #!/bin/bash

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

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

+ #

+ #   runtest.sh of /CoreOS/crontabs/Sanity/test-of-functionality-of-crontabs

+ #   Description: test of functionality of crontabs

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

+ #

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

+ #

+ #   Copyright (c) 2011 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 rhts environment

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

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

+ 

+ PACKAGE="crontabs"

+ #how long should we wait:

+ COUNT=5

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm $PACKAGE

+ 	user="petr$RANDOM"

+         rlRun "rm -rf /tmp/test.createdbypetr /tmp/test.createdbyroot" 0 "Removing tmp directory"

+ 	rlRun "useradd $user"

+ 	rlFileBackup /etc/crontab

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+ 	echo "*  *  *  *  * root echo root >> /tmp/test.createdbyroot" >> /etc/crontab

+ 	rlAssert0 "added first entry into crontab" $?

+ 	echo "*  *  *  *  * $user echo petr >> /tmp/test.createdbypetr" >> /etc/crontab

+ 	rlAssert0 "added second entry into crontab" $?

+ 	#sleep a while

+ 	rlRun "sleep ${COUNT}m" 0 "sleeping for 5m to wait for cron to create files"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest "check content"

+ 	byroot=`grep root /tmp/test.createdbyroot | wc -l`

+ 	bypetr=`grep petr /tmp/test.createdbypetr | wc -l`

+ 	if [ "$byroot" -ge "${COUNT}" ];then

+ 		rlPass "there is $byroot line"

+ 	else

+ 		rlFail "there is $byroot line"

+ 	fi

+ 

+         if [ "$bypetr" -ge "${COUNT}" ];then

+                 rlPass "there is $bypetr line"

+         else

+                 rlFail "there is $bypetr line"

+         fi

+     rlPhaseEnd

+ 

+    rlPhaseStartTest "check permissions of created files"

+ 	/bin/ls -la /tmp/test.createdbyroot | grep "root root"

+ 	rlAssert0 "permissions are root root" $?

+ 	/bin/ls -la /tmp/test.createdbypetr | grep "$user $user"

+ 	rlAssert0 "permissions are $user $user" $?

+    rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "rm -rf /tmp/test.createdbypetr /tmp/test.createdbyroot" 0 "Removing tmp directory"

+ 	rlRun "userdel -r $user"

+ 	rlFileRestore

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

tests/tests.yml
file added
+12
@@ -0,0 +1,12 @@

+ ---

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

+ - hosts: localhost

+   roles:

+   - role: standard-test-beakerlib

+     tags:

+     - classic

+     tests:

+     - test-of-functionality-of-crontabs

+     required_packages:

+     - crontabs          # test-of-functionality-of-crontabs needs crontabs

+     - findutils         # beakerlib needs find command

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. 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

$ sudo TEST_SUBJECTS='' ansible-playbook --inventory=/usr/share/ansible/inventory --tags=classic tests.yml

Snip of the example test run:

TASK [standard-test-beakerlib : Execute beakerlib tests] ****************************************************************
changed: [localhost] => (item=test-of-functionality-of-crontabs)

TASK [standard-test-beakerlib : Make the master test summary log artifact] **********************************************
changed: [localhost] => (item=test-of-functionality-of-crontabs)

TASK [standard-test-beakerlib : Pull out the logs] **********************************************************************
changed: [localhost]

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

PLAY RECAP **************************************************************************************************************
localhost                  : ok=15   changed=8    unreachable=0    failed=0

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: jmarko @redhat.com The idea is that these tests become yours just as you are maintaining the package, there will of course be people around if you have questions or troubles.

Pull-Request has been merged by tmraz

6 years ago