#4 Add CI tests using the standard test interface
Merged 6 years ago by jorton. Opened 6 years ago by yshapovalov.
git://fedorapeople.org/~yshapovalov/httpd add_tests  into  master

add tests with standart test interface
Yevhenii Shapovalov • 6 years ago  
tests/httpd-php-mysql-sanity-test/Makefile
file added
+67
@@ -0,0 +1,67 @@

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

+ #

+ #   Makefile of /CoreOS/httpd/Sanity/httpd-php-mysql-sanity-test

+ #   Description: test fetching data from mysqldb/mariadb through php

+ #   Author: Karel Srot <ksrot@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/httpd/Sanity/httpd-php-mysql-sanity-test

+ export TESTVERSION=1.0

+ 

+ BUILT_FILES=

+ 

+ FILES=$(METADATA) runtest.sh Makefile PURPOSE mysql.php php_mysql_test.sql php_mysql_test.conf

+ 

+ .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:           Karel Srot <ksrot@redhat.com>" > $(METADATA)

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

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

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

+ 	@echo "Description:     test fetching data from mysqldb/mariadb through php" >> $(METADATA)

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

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

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

+ 	@echo "Requires:        httpd php php-zts php-mysqlnd mysql-server mariadb-server" >> $(METADATA)

+ 	@echo "RhtsRequires:    library(httpd/http)" >> $(METADATA)

+ 	@echo "RhtsRequires:    library(mysql/basic)" >> $(METADATA)

+ 	@echo "RhtsRequires:    library(mariadb55/basic)" >> $(METADATA)

+ 	@echo "RhtsRequires:    library(php/utils)" >> $(METADATA)

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

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

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

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

+ 

+ 	rhts-lint $(METADATA)

tests/httpd-php-mysql-sanity-test/PURPOSE
file added
+3
@@ -0,0 +1,3 @@

+ PURPOSE of /CoreOS/httpd/Sanity/httpd-php-mysql-sanity-test

+ Description: test fetching data from mysqldb/mariadb through php

+ Author: Karel Srot <ksrot@redhat.com>

tests/httpd-php-mysql-sanity-test/new_mysql.php
file added
+12
@@ -0,0 +1,12 @@

+ <?php

+ $db = mysqli_connect("localhost", "root");

+ if (!$db) {

+     die("Could not connect");

+ }

+ if (!mysqli_select_db($db, "php_mysql_test")) {

+     die("Could not select database");

+ }

+ $res = mysqli_query($db, "SELECT * from foobar");

+ $row = mysqli_fetch_assoc($res);

+ printf("%s is %d\n", $row['name'], $row['value']);

+ ?>

tests/httpd-php-mysql-sanity-test/old_mysql.php
file added
+12
@@ -0,0 +1,12 @@

+ <?php

+ $db = mysql_connect("localhost", "root");

+ if (!$db) {

+     die("Could not connect");

+ }

+ if (!mysql_select_db("php_mysql_test")) {

+     die("Could not select database");

+ }

+ $res = mysql_query("SELECT * from foobar");

+ $row = mysql_fetch_assoc($res);

+ printf("%s is %d\n", $row['name'], $row['value']);

+ ?>

tests/httpd-php-mysql-sanity-test/php_mysql_test.conf
file added
+5
@@ -0,0 +1,5 @@

+ 

+ Alias /php_mysql_test /var/www/php_mysql_test

+ 

+ <Directory /var/www/php_mysql_test>

+ </Directory>

tests/httpd-php-mysql-sanity-test/php_mysql_test.sql
file added
+6
@@ -0,0 +1,6 @@

+ 

+ CREATE DATABASE php_mysql_test;

+ USE php_mysql_test;

+ 

+ CREATE TABLE foobar (name VARCHAR(10), value INTEGER);

+ INSERT INTO foobar VALUES("fish", 42);

tests/httpd-php-mysql-sanity-test/runtest.sh
file added
+102
@@ -0,0 +1,102 @@

+ #!/bin/bash

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

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

+ #

+ #   runtest.sh of /CoreOS/httpd/Sanity/httpd-php-mysql-sanity-test

+ #   Description: test fetching data from mysqldb/mariadb through php

+ #   Author: Karel Srot <ksrot@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

+ [ -e /usr/bin/rhts-environment.sh ] && . /usr/bin/rhts-environment.sh

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

+ 

+ PACKAGES="${PACKAGES:-httpd}"

+ REQUIRES="${REQUIRES:-php $DB}"

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlRun "rlImport httpd/http" 0 "Import httpd library"

+         if rlIsRHEL 5 6 && [ $httpCOLLECTION = 0 ]; then

+             DB="mysql-server"

+             rlRun "rlImport mysql/basic" 0 "Import mysqld library"

+             SERVICE=${mysqlServiceName}

+         else

+             DB="mariadb-server"

+             rlRun "rlImport mariadb55/basic" 0 "Import mariadb library"

+             SERVICE=${mariadbServiceName}

+         fi

+ 	# install also php-mysql on rhel-6 (instead of php-mysqlnd on rhel-7)

+         rlRun "rlImport php/utils"

+         phpPdoPhpMysqlSetup

+         rlAssertRpm --all

+         rlRun "rlServiceStart $SERVICE" 0

+         rlRun "echo DROP DATABASE php_mysql_test | mysql -u root" 0,1

+         rlRun "mysql --verbose -u root < php_mysql_test.sql"

+         rlRun "httpStop" 0 "Stop httpd if running"

+         rlRun "> $httpLOGDIR/error_log"

+         rlRun "rm -rvf $httpROOTDIR/php_mysql_test"

+         rlRun "mkdir -v $httpROOTDIR/php_mysql_test"

+         rlRun "cp -v php_mysql_test.conf $httpCONFDIR/conf.d/"

+         rlRun "php_version=`rlCheckRpm php`"

+         if [[ $php_version =~ php-7* ]] || [[ $php_version =~ php-5.[5-6]* ]]; then

+             rlRun "cp -v new_mysql.php $httpROOTDIR/php_mysql_test/mysql.php"

+         else

+             rlRun "cp -v old_mysql.php $httpROOTDIR/php_mysql_test/mysql.php"

+         fi

+         rlRun "sed -i 's|/var/www|$httpROOTDIR|' $httpCONFDIR/conf.d/php_mysql_test.conf"

+         rlRun "chown -R apache:  $httpROOTDIR/php_mysql_test"

+         #rlRun "restorecon  $httpROOTDIR/php_mysql_test"

+         selinuxenabled && rlRun "chcon -Rv -t httpd_sys_content_t $httpROOTDIR/php_mysql_test"

+         rlRun "httpStart" 0 "Start httpd"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         URL="http://localhost/php_mysql_test/"

+         RETVAL=0

+         tries=`seq 1 10`

+ 

+         for n in ${tries}; do

+             output=`curl -s $URL/mysql.php`

+             rv=$?

+             echo "PHP output ${n}: ${rv} x${output}y"

+             [ ${rv} -ne 0 -o "x${output}y" != "xfish is 42y" ] && RETVAL=66

+         done

+ 

+         if [ $RETVAL -ne 0 ]; then

+             rlFail

+         else

+             rlPass

+         fi

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "rm -f $httpCONFDIR/conf.d/php_mysql_test.conf"

+         rlRun "rm -rf $httpROOTDIR/php_mysql_test"

+         rlRun "echo DROP DATABASE php_mysql_test | mysql -u root"

+         rlRun "rlServiceRestore ${SERVICE}" 0

+         rlRun "httpStop" 0 "Stop httpd if running"

+ 	# uninstall php-mysql on rhel-6 if it was installed during setup

+         phpPdoPhpMysqlCleanup

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

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

+ ---

+ # Tests that run in all contexts

+ - hosts: localhost

+   vars:

+     use_beakerlib_libraries: true

+   roles:

+   - role: standard-test-rhts

+     tags:

+     - classic

+     - container

+     tests:

+     - httpd-php-mysql-sanity-test

+     required_packages:

+     - findutils         # beakerlib needs find command

+     - which             # smoke requires which 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 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.4.1.0-2.fc26.noarch \
python2-dnf-2.7.5-1.fc26.noarch \
libselinux-python-2.6-7.fc26.x86_64 \
standard-test-roles-2.5-0.2.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-rhts : Check the results for failures] **********************************************
changed: [localhost]

PLAY RECAP **********************************************************************************************
localhost                  : ok=39   changed=16   unreachable=0    failed=0   

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-rhts : Check the results for failures] **********************************************
changed: [05067643a57cfb50fc3cce0e149e7b2752674a2a0b4bad62fa9b0997b3e3de13]

PLAY RECAP **********************************************************************************************
05067643a57cfb50fc3cce0e149e7b2752674a2a0b4bad62fa9b0997b3e3de13 : ok=42   changed=34   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: yhsapova@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.

Pull-Request has been merged by jorton

6 years ago