#1 Add CI tests using the standard test interface
Merged 6 years ago by agk. Opened 6 years ago by bgoncalv.
rpms/ bgoncalv/device-mapper-persistent-data device-mapper-persistent-data-tests  into  master

@@ -0,0 +1,76 @@ 

+ # Copyright (c) 2006 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 v.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.

+ #

+ # Author: Jakub Krysl <jkrysl@redhat.com>

+ 

+ # The toplevel namespace within which the test lives.

+ TOPLEVEL_NAMESPACE=kernel

+ 

+ # The name of the package under test:

+ PACKAGE_NAME=storage

+ 

+ # The path of the test below the package:

+ RELATIVE_PATH=lvm/device-mapper-persistent-data/thin

+ 

+ # Version of the Test. Used with make tag.

+ export TESTVERSION=1.0

+ 

+ # The combined namespace of the test.

+ export TEST=/$(TOPLEVEL_NAMESPACE)/$(PACKAGE_NAME)/$(RELATIVE_PATH)

+ 

+ 

+ # A phony target is one that is not really the name of a file.

+ # It is just a name for some commands to be executed when you

+ # make an explicit request. There are two reasons to use a

+ # phony target: to avoid a conflict with a file of the same

+ # name, and to improve performance.

+ .PHONY: all install download clean

+ 

+ # executables to be built should be added here, they will be generated on the system under test.

+ BUILT_FILES=

+ 

+ # data files, .c files, scripts anything needed to either compile the test and/or run it.

+ FILES=$(METADATA) runtest.sh PURPOSE

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	chmod a+x ./runtest.sh

+ 

+ clean:

+ 	rm -f *~ *.rpm $(BUILT_FILES)

+ 

+ # You may need to add other targets e.g. to build executables from source code

+ # Add them here:

+ 

+ 

+ # Include Common Makefile

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ # Generate the testinfo.desc here:

+ $(METADATA): Makefile

+ 	@touch $(METADATA)

+ # Change to the test owner's name

+ 	@echo "Owner:        Jakub Krysl <jkrysl@redhat.com>" > $(METADATA)

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

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

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

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

+ 	@echo "Description:  Testing thin tools provided by device-mapper-persistent-data">> $(METADATA)

+ 	@echo "TestTime:     1h" >> $(METADATA)

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

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

+ 	@echo "RhtsRequires:        kernel-kernel-storage-misc-env_setup" >> $(METADATA)

+ 

+ 	rhts-lint $(METADATA)

@@ -0,0 +1,30 @@ 

+ #===========================================================================

+ #

+ # PURPOSE file for:

+ #   /kernel/storage/lvm/device-mapper-persistent-data/thin

+ #

+ # Description:

+ #   Testing thin tools provided by device-mapper-persistent-data

+ #

+ # Bugs related:

+ #

+ #

+ # Author(s):

+ #   Jakub Krysl

+ #   <jkrysl@redhat.com>

+ # 

+ #===========================================================================

+ # Note:

+ # As with some of Storage tests, at the end of the test it will check

+ # for errors on the logs.

+ # This check if implemented on /kernel/storage/include/python_modules

+ # LogChecker.py module

+ #

+ # To avoid Storage tests reporting error that were caused before the test

+ # started to run is recommended to run /kernel/storage/misc/log_checker

+ # just before running this test

+ #===========================================================================

+ # This task takes optional parameters:

+ #  

+ #===========================================================================

+ # EndFile

The added file is too large to be shown here, see it at: tests/functions_test/dmpd_functions.py
The added file is too large to be shown here, see it at: tests/functions_test/dmpd_library.py
@@ -0,0 +1,18 @@ 

+ #!/bin/sh

+ # Copyright (c) 2017 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 v.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.

+ #

+ # Author: Jakub Krysl   <jkrysl@redhat.com>

+ rhts-run-simple-test functions_test ./dmpd_functions.py

file added
+26
@@ -0,0 +1,26 @@ 

+ ---

+ # Tests suitable to run in classic environment

+ - hosts: localhost

+   roles:

+   - role: standard-test-beakerlib

+     tags:

+     - classic

+     tests:

+     - tools_not_linked_usr

+     - functions_test

+     required_packages:

+     - findutils         # beakerlib needs find command

+     - which             # tools_not_linked_usr needs which command

+ 

+ # Tests suitable to run in container and atomic environments

+ - hosts: localhost

+   roles:

+   - role: standard-test-beakerlib

+     tags:

+     - container

+     - atomic

+     tests:

+     - tools_not_linked_usr

+     required_packages:

+     - findutils         # beakerlib needs find command

+     - which             # tools_not_linked_usr needs which command

@@ -0,0 +1,75 @@ 

+ # Copyright (c) 2006 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 v.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, see http://www.gnu.org/licenses/.

+ #

+ # Author: Bruno Goncalves <bgoncalv@redhat.com>

+ 

+ # The toplevel namespace within which the test lives.

+ TOPLEVEL_NAMESPACE=kernel

+ 

+ # The name of the package under test:

+ PACKAGE_NAME=storage

+ 

+ # The path of the test below the package:

+ RELATIVE_PATH=lvm/device-mapper-persistent-data/tools_not_linked_usr

+ 

+ # Version of the Test. Used with make tag.

+ export TESTVERSION=1.0

+ 

+ # The combined namespace of the test.

+ export TEST=/$(TOPLEVEL_NAMESPACE)/$(PACKAGE_NAME)/$(RELATIVE_PATH)

+ 

+ 

+ # A phony target is one that is not really the name of a file.

+ # It is just a name for some commands to be executed when you

+ # make an explicit request. There are two reasons to use a

+ # phony target: to avoid a conflict with a file of the same

+ # name, and to improve performance.

+ .PHONY: all install download clean

+ 

+ # executables to be built should be added here, they will be generated on the system under test.

+ BUILT_FILES=

+ 

+ # data files, .c files, scripts anything needed to either compile the test and/or run it.

+ FILES=$(METADATA) runtest.sh PURPOSE tools_not_linked_usr.py

+ 

+ run: $(FILES) build

+ 	./runtest.sh

+ 

+ build: $(BUILT_FILES)

+ 	chmod a+x ./runtest.sh

+ 	chmod a+x ./tools_not_linked_usr.py

+ 

+ clean:

+ 	rm -f *~ *.rpm $(BUILT_FILES)

+ 

+ # You may need to add other targets e.g. to build executables from source code

+ # Add them here:

+ 

+ 

+ # Include Common Makefile

+ include /usr/share/rhts/lib/rhts-make.include

+ 

+ # Generate the testinfo.desc here:

+ $(METADATA): Makefile

+ 	@touch $(METADATA)

+ # Change to the test owner's name

+ 	@echo "Owner:        Bruno Goncalves <bgoncalv@redhat.com>" > $(METADATA)

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

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

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

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

+ 	@echo "Description:  Make sure tools are not linked to lib under /usr.">> $(METADATA)

+ 	@echo "TestTime:     1h" >> $(METADATA)

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

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

+ 

+ 	rhts-lint $(METADATA)

@@ -0,0 +1,13 @@ 

+ #===========================================================================

+ #

+ # Description:

+ #   Make sure tools are not using any library that is linked to /usr

+ #

+ # Bugs related:

+ #

+ # Author(s):

+ #   Bruno Goncalves

+ #   <bgoncalv@redhat.com>

+ #

+ #===========================================================================

+ # EndFile

@@ -0,0 +1,18 @@ 

+ #!/bin/sh

+ # Copyright (c) 2006 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 v.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.

+ #

+ # Author: Bruno Goncalves   <bgoncalv@redhat.com>

+ rhts-run-simple-test tools_not_linked_usr ./tools_not_linked_usr.py

@@ -0,0 +1,93 @@ 

+ #!/usr/bin/python

+ 

+ # Copyright (c) 2006 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 v.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, see http://www.gnu.org/licenses/.

+ #

+ # Author: Bruno Goncalves <bgoncalv@redhat.com>

+ 

+ from os import walk

+ import subprocess

+ import sys

+ import re

+ 

+ def run(cmd):

+     print "INFO: Running '%s'..." % cmd

+     p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)

+     stdout, stderr = p.communicate()

+ 

+     retcode = p.returncode

+     output = stdout + stderr

+     print output

+     return retcode, output

+ 

+ def start_test():

+ 

+     #if uses any library linked to /usr this my affect the tools during boot

+     print ("INFO: Making sure tools provided by device-mapper-persistent-data "

+            "are not linked to /usr")

+ 

+     #Paths where we should have no libraries linked from

+     lib_paths = ["/usr/"]

+ 

+     package = "device-mapper-persistent-data"

+     run("yum install -y %s" % package)

+     #Get all tools that we need to check

+     ret, output = run("rpm -ql %s | grep \"sbin/\"" % package)

+     if ret != 0:

+         print("FAIL: Could not get the tools shipped from %s" % package)

+         return False

+     tools = output.split("\n")

+ 

+     error = False

+     for tool in tools:

+         if not tool:

+             #skip any blank line

+             continue

+         tool_error = 0

+         for lib_path in lib_paths:

+             print "INFO: Checking if %s is not linked to libraries at %s" % (tool, lib_path)

+             ret, linked_lib = run("ldd %s" % tool)

+             if ret != 0:

+                 print("FAIL: Could not list dynamically libraries for %s" % (tool))

+                 tool_error += 1

+             else:

+                 #The command executed sucessfuly

+                 #check if any library linked is from lib_path

+                 links = linked_lib.split("\n")

+                 for link in links:

+                     if re.match(".*%s.*" % lib_path, link):

+                         print("FAIL: %s is linked to %s" % (tool, link))

+                         tool_error += 1

+ 

+             if tool_error == 0:

+                 print("%s is not linked to %s" % (tool, lib_path))

+             else:

+                 #found some error in at least 1 tool

+                 error = True

+ 

+     if error:

+         return False

+ 

+     return True

+ 

+ 

+ def main():

+ 

+     if not start_test():

+         print "FAIL: test failed"

+         sys.exit(1)

+ 

+     print "PASS: Test pass"

+     sys.exit(0)

+ 

+ main()

+ 

Adds tests according to the CI wiki [0] specifically the standard test interface in the spec [1].

The playbook includes Tier1 level test cases that have been tested in the following contexts and is passing reliably: Atomic Host, Docker, and Classic.
Test logs are stored in the Artifacts directory.

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

  • Atomic
    sudo ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS=../atomic.qcow2 TEST_ARTIFACTS=$PWD/artifacts ansible-playbook --tags atomic tests.yml

  • Docker
    sudo ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS=docker:docker.io/library/fedora:rawhide TEST_ARTIFACTS=$PWD/artifacts ansible-playbook --tags container tests.yml

  • Classic
    sudo ANSIBLE_INVENTORY=$(test -e inventory && echo inventory || echo /usr/share/ansible/inventory) TEST_SUBJECTS="" TEST_ARTIFACTS=$PWD/artifacts ansible-playbook --tags classic tests.yml

[0] https://fedoraproject.org/wiki/CI
[1] https://fedoraproject.org/wiki/Changes/InvokingTests

Test Logs: (If you you would like a pointer to the complete log, I can include that as well)

All tests were executed on Fedora Rawhide

  • Atomic

    <snip>
    TASK [standard-test-beakerlib : Execute beakerlib tests] **********************
    changed: [../atomic.qcow2] => (item=tools_not_linked_usr)

    TASK [standard-test-beakerlib : Make the master test summary log artifact] **********************
    changed: [../atomic.qcow2] => (item=tools_not_linked_usr)

    TASK [standard-test-beakerlib : Pull out the logs] ************************
    changed: [../atomic.qcow2]

    TASK [standard-test-beakerlib : Check the results] ************************
    changed: [../atomic.qcow2]

    PLAY RECAP ********************************
    ../atomic.qcow2 : ok=14 changed=10 unreachable=0 failed=0

    Test results:

    PASS tools_not_linked_usr

  • Docker

    <snip>
    TASK [standard-test-beakerlib : Execute beakerlib tests] **********************
    changed: [0b2b558e75c3e249e24f1bc55bd3d8750056d9dc47e197684732b688af8acd05] => (item=tools_not_linked_usr)

    TASK [standard-test-beakerlib : Make the master test summary log artifact] **********************
    changed: [0b2b558e75c3e249e24f1bc55bd3d8750056d9dc47e197684732b688af8acd05] => (item=tools_not_linked_usr)

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

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

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

    Test results:

    PASS tools_not_linked_usr

  • Classic

    <snip>
    TASK [standard-test-beakerlib : Execute beakerlib tests] **********************
    changed: [localhost] => (item=tools_not_linked_usr)
    changed: [localhost] => (item=functions_test)

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

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

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

    PLAY [localhost] ****************************

    TASK [Gathering Facts] ****************************
    ok: [localhost]

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

    cat artifacts/test.log
    PASS tools_not_linked_usr
    PASS functions_test

Pull-Request has been merged by agk

6 years ago