From 02c43871624f7cc74b81e808723c32de6cbd0ae9 Mon Sep 17 00:00:00 2001 From: Andrei Stepanov Date: Mar 14 2018 16:42:18 +0000 Subject: Rename files in /tests. Change pkg name. Chk artifacts dir. Signed-off-by: Andrei Stepanov --- diff --git a/tests/basic-fail-test/runtest.sh b/tests/basic-fail-test/runtest.sh deleted file mode 100644 index a7f2a1c..0000000 --- a/tests/basic-fail-test/runtest.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -echo "Running a command that should fail" - -false - diff --git a/tests/basic-simple-test/runtest.sh b/tests/basic-simple-test/runtest.sh deleted file mode 100644 index 87c587b..0000000 --- a/tests/basic-simple-test/runtest.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -PACKAGE="bash" - -echo "Using $PACKAGE version:" -rpm -q $PACKAGE diff --git a/tests/basic.yml b/tests/basic.yml new file mode 100644 index 0000000..6d79eb8 --- /dev/null +++ b/tests/basic.yml @@ -0,0 +1,38 @@ +- import_playbook: prepare.yml + +# Tests for basic role +- hosts: localhost + tags: + - atomic + - classic + - container + roles: + - role: standard-test-basic + tests: + - test-basic-simple + - test-basic-parameters: + dir: ./ + run: echo "check parameters on basic role" | grep "check parameters on basic role" + required_packages: + # Test if we can install required packages + - "{{req_pkg}}" + tasks: + - include_tasks: shared-tasks/artifacts_test_env.yml + - include_tasks: shared-tasks/artifacts_test_runner.yml + +# Make sure the role behaves correctly if test fails +- hosts: localhost + tags: + - atomic + - classic + - container + roles: + - role: standard-test-basic + tests: + - test-basic-fail + ignore_errors: yes + tasks: + # 'verify_failed_test' tasks should run after 'test-basic-fail' + - include_tasks: shared-tasks/verify_failed_test.yml + - include_tasks: shared-tasks/artifacts_test_env.yml + - include_tasks: shared-tasks/artifacts_test_runner.yml diff --git a/tests/beakerlib-fail-test/runtest.sh b/tests/beakerlib-fail-test/runtest.sh deleted file mode 100644 index f1e63f7..0000000 --- a/tests/beakerlib-fail-test/runtest.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Include Beaker environment -. /usr/share/beakerlib/beakerlib.sh || exit 1 - -PACKAGE="bash" - -rlJournalStart - rlPhaseStartTest "Simple beakerlib test" - # Running a command that should fail - rlRun "false" - rlPhaseEnd -rlJournalPrintText -rlJournalEnd diff --git a/tests/beakerlib-simple-test/runtest.sh b/tests/beakerlib-simple-test/runtest.sh deleted file mode 100644 index fb77e47..0000000 --- a/tests/beakerlib-simple-test/runtest.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# Include Beaker environment -. /usr/share/beakerlib/beakerlib.sh || exit 1 - -PACKAGE="bash" - -rlJournalStart - rlPhaseStartTest "Simple beakerlib test" - rlRun "ls /" - rlPhaseEnd -rlJournalPrintText -rlJournalEnd diff --git a/tests/beakerlib.yml b/tests/beakerlib.yml new file mode 100644 index 0000000..a0a24f4 --- /dev/null +++ b/tests/beakerlib.yml @@ -0,0 +1,35 @@ +- import_playbook: prepare.yml + +# Tests for beakerlib role +- hosts: localhost + tags: + - atomic + - classic + - container + roles: + - role: standard-test-beakerlib + tests: + - test-beakerlib-simple + required_packages: + - "{{req_pkg}}" + tasks: + - include_tasks: shared-tasks/artifacts_test_env.yml + - include_tasks: shared-tasks/artifacts_test_runner.yml + + +# Make sure the role behaves correctly if test fails +- hosts: localhost + tags: + - atomic + - classic + - container + roles: + - role: standard-test-beakerlib + tests: + - test-beakerlib-fail + ignore_errors: yes + tasks: + # 'tests_verify_failed_test' tasks should run after 'test-beakerlib-fail' + - include_tasks: shared-tasks/verify_failed_test.yml + - include_tasks: shared-tasks/artifacts_test_env.yml + - include_tasks: shared-tasks/artifacts_test_runner.yml diff --git a/tests/prepare.yml b/tests/prepare.yml new file mode 100644 index 0000000..e375046 --- /dev/null +++ b/tests/prepare.yml @@ -0,0 +1,9 @@ +# Preparation steps +- hosts: localhost + vars: + # Must be the same as in str-common/defaults/main.yml + artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}" + remote_artifacts: /tmp/artifacts/ + tasks: + - include_tasks: shared-tasks/artifacts.yml + - include_tasks: shared-tasks/req-pkg.yml diff --git a/tests/rhts-fail-test/Makefile b/tests/rhts-fail-test/Makefile deleted file mode 100644 index 9ae494f..0000000 --- a/tests/rhts-fail-test/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -export TESTVERSION=1.0 - -BUILT_FILES= - -FILES=$(METADATA) runtest.sh Makefile - -.PHONY: all install 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: Bruno Goncalves " > $(METADATA) - @echo "Name: $(TEST)" >> $(METADATA) - @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) - @echo "Path: $(TEST_DIR)" >> $(METADATA) - @echo "Description: fail rhts test role" >> $(METADATA) - @echo "Type: Sanity" >> $(METADATA) - @echo "TestTime: 10m" >> $(METADATA) - @echo "Priority: Normal" >> $(METADATA) - @echo "License: GPLv2" >> $(METADATA) - @echo "Confidential: no" >> $(METADATA) - @echo "Destructive: no" >> $(METADATA) - - rhts-lint $(METADATA) diff --git a/tests/rhts-fail-test/runtest.sh b/tests/rhts-fail-test/runtest.sh deleted file mode 100644 index f1e63f7..0000000 --- a/tests/rhts-fail-test/runtest.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Include Beaker environment -. /usr/share/beakerlib/beakerlib.sh || exit 1 - -PACKAGE="bash" - -rlJournalStart - rlPhaseStartTest "Simple beakerlib test" - # Running a command that should fail - rlRun "false" - rlPhaseEnd -rlJournalPrintText -rlJournalEnd diff --git a/tests/rhts-simple-test/Makefile b/tests/rhts-simple-test/Makefile deleted file mode 100644 index eb0d996..0000000 --- a/tests/rhts-simple-test/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -export TESTVERSION=1.0 - -BUILT_FILES= - -FILES=$(METADATA) runtest.sh Makefile - -.PHONY: all install 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: Bruno Goncalves " > $(METADATA) - @echo "Name: $(TEST)" >> $(METADATA) - @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) - @echo "Path: $(TEST_DIR)" >> $(METADATA) - @echo "Description: simple rhts test role" >> $(METADATA) - @echo "Type: Sanity" >> $(METADATA) - @echo "TestTime: 10m" >> $(METADATA) - @echo "Priority: Normal" >> $(METADATA) - @echo "License: GPLv2" >> $(METADATA) - @echo "Confidential: no" >> $(METADATA) - @echo "Destructive: no" >> $(METADATA) - - rhts-lint $(METADATA) diff --git a/tests/rhts-simple-test/runtest.sh b/tests/rhts-simple-test/runtest.sh deleted file mode 100644 index fb77e47..0000000 --- a/tests/rhts-simple-test/runtest.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# Include Beaker environment -. /usr/share/beakerlib/beakerlib.sh || exit 1 - -PACKAGE="bash" - -rlJournalStart - rlPhaseStartTest "Simple beakerlib test" - rlRun "ls /" - rlPhaseEnd -rlJournalPrintText -rlJournalEnd diff --git a/tests/rhts.yml b/tests/rhts.yml new file mode 100644 index 0000000..703ae01 --- /dev/null +++ b/tests/rhts.yml @@ -0,0 +1,33 @@ +- import_playbook: prepare.yml + +# Tests for rhts role only runs on classic tag +- hosts: localhost + tags: + - classic + roles: + - role: standard-test-rhts + tests: + - test-rhts-simple + required_packages: + # Test if we can install required packages + - "{{req_pkg}}" + tasks: + - include_tasks: shared-tasks/artifacts_test_env.yml + - include_tasks: shared-tasks/artifacts_test_runner.yml + +# Make sure the role behaves correctly if test fails +- hosts: localhost + tags: + - classic + roles: + - role: standard-test-rhts + tags: + - classic + tests: + - test-rhts-fail + ignore_errors: yes + tasks: + # 'verify_failed_test' tasks should run after 'testi-rhts-fail' + - include_tasks: shared-tasks/verify_failed_test.yml + - include_tasks: shared-tasks/artifacts_test_env.yml + - include_tasks: shared-tasks/artifacts_test_runner.yml diff --git a/tests/shared-tasks/artifacts.yml b/tests/shared-tasks/artifacts.yml new file mode 100644 index 0000000..0bcf897 --- /dev/null +++ b/tests/shared-tasks/artifacts.yml @@ -0,0 +1,19 @@ +# STR requires that artifacts dir must be absent +- name: "Check if {{artifacts}} is absent at test-runner" + stat: + path: "{{artifacts}}" + register: st_tr + delegate_to: localhost + +- fail: + msg: "Remove {{artifacts}} before test run at test-runner." + when: st_tr.stat.exists + +- name: "Check if {{artifacts}} is absent at test-environment." + stat: + path: "{{remote_artifacts}}" + register: st_te + +- fail: + msg: "Remove {{remote_artifacts}} before test run at test-environment." + when: st_te.stat.exists diff --git a/tests/shared-tasks/artifacts_test_env.yml b/tests/shared-tasks/artifacts_test_env.yml new file mode 100644 index 0000000..4d8ae88 --- /dev/null +++ b/tests/shared-tasks/artifacts_test_env.yml @@ -0,0 +1,9 @@ +# These tasks should run after as test that fails +- name: "Check if {{remote_artifacts}} was created properly on test environment" + shell: "ls {{remote_artifacts}}/test.log" + +- name: "Clean up {{remote_artifacts}} to not affect other tests on test environment" + file: + state: absent + path: "{{remote_artifacts}}/" + diff --git a/tests/shared-tasks/artifacts_test_runner.yml b/tests/shared-tasks/artifacts_test_runner.yml new file mode 100644 index 0000000..85b59d8 --- /dev/null +++ b/tests/shared-tasks/artifacts_test_runner.yml @@ -0,0 +1,10 @@ +# These tasks should run after as test that fails +- name: "Check if {{artifacts}} was created properly on test runner" + shell: "ls {{artifacts}}/test.log" + delegate_to: localhost + +- name: "Clean up {{artifacts}} to not affect other tests on test runner" + file: + state: absent + path: "{{artifacts}}/" + delegate_to: localhost diff --git a/tests/shared-tasks/req-pkg.yml b/tests/shared-tasks/req-pkg.yml new file mode 100644 index 0000000..59aef1d --- /dev/null +++ b/tests/shared-tasks/req-pkg.yml @@ -0,0 +1,8 @@ +- set_fact: + req_pkg: zsh + +- name: Remove a test package from test-environment + package: + name: "{{req_pkg}}" + #state: absent + state: present diff --git a/tests/shared-tasks/verify_failed_test.yml b/tests/shared-tasks/verify_failed_test.yml new file mode 100644 index 0000000..a51af94 --- /dev/null +++ b/tests/shared-tasks/verify_failed_test.yml @@ -0,0 +1,11 @@ +# These tasks should run after as test that fails +- name: Read test.log on test environment + shell: "cat {{remote_artifacts}}/test.log" + register: test_log + +- name: Check for FAIL on test.log on test environment + fail: msg="Could not find FAIL on test log" + when: test_log.stdout.find("FAIL") == -1 + # We should fail when we can not find FAIL string on log + # -1 means string not found + diff --git a/tests/test-basic-fail/runtest.sh b/tests/test-basic-fail/runtest.sh new file mode 100644 index 0000000..a7f2a1c --- /dev/null +++ b/tests/test-basic-fail/runtest.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "Running a command that should fail" + +false + diff --git a/tests/test-basic-simple/runtest.sh b/tests/test-basic-simple/runtest.sh new file mode 100644 index 0000000..87c587b --- /dev/null +++ b/tests/test-basic-simple/runtest.sh @@ -0,0 +1,5 @@ +#!/bin/bash +PACKAGE="bash" + +echo "Using $PACKAGE version:" +rpm -q $PACKAGE diff --git a/tests/test-beakerlib-fail/runtest.sh b/tests/test-beakerlib-fail/runtest.sh new file mode 100644 index 0000000..f1e63f7 --- /dev/null +++ b/tests/test-beakerlib-fail/runtest.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Simple beakerlib test" + # Running a command that should fail + rlRun "false" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/test-beakerlib-simple/runtest.sh b/tests/test-beakerlib-simple/runtest.sh new file mode 100644 index 0000000..fb77e47 --- /dev/null +++ b/tests/test-beakerlib-simple/runtest.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Simple beakerlib test" + rlRun "ls /" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/test-rhts-fail/Makefile b/tests/test-rhts-fail/Makefile new file mode 100644 index 0000000..9ae494f --- /dev/null +++ b/tests/test-rhts-fail/Makefile @@ -0,0 +1,34 @@ +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile + +.PHONY: all install 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: Bruno Goncalves " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: fail rhts test role" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/test-rhts-fail/runtest.sh b/tests/test-rhts-fail/runtest.sh new file mode 100644 index 0000000..f1e63f7 --- /dev/null +++ b/tests/test-rhts-fail/runtest.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Simple beakerlib test" + # Running a command that should fail + rlRun "false" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/test-rhts-simple/Makefile b/tests/test-rhts-simple/Makefile new file mode 100644 index 0000000..eb0d996 --- /dev/null +++ b/tests/test-rhts-simple/Makefile @@ -0,0 +1,34 @@ +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile + +.PHONY: all install 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: Bruno Goncalves " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: simple rhts test role" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 10m" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/test-rhts-simple/runtest.sh b/tests/test-rhts-simple/runtest.sh new file mode 100644 index 0000000..fb77e47 --- /dev/null +++ b/tests/test-rhts-simple/runtest.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="bash" + +rlJournalStart + rlPhaseStartTest "Simple beakerlib test" + rlRun "ls /" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd diff --git a/tests/tests.yml b/tests/tests.yml index 3d8526f..5bf5617 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -1,4 +1,4 @@ --- -- import_playbook: tests_basic.yml -- import_playbook: tests_beakerlib.yml -- import_playbook: tests_rhts.yml +- import_playbook: basic.yml +- import_playbook: beakerlib.yml +- import_playbook: rhts.yml diff --git a/tests/tests_artifacts_test_env.yml b/tests/tests_artifacts_test_env.yml deleted file mode 100644 index 4d8ae88..0000000 --- a/tests/tests_artifacts_test_env.yml +++ /dev/null @@ -1,9 +0,0 @@ -# These tasks should run after as test that fails -- name: "Check if {{remote_artifacts}} was created properly on test environment" - shell: "ls {{remote_artifacts}}/test.log" - -- name: "Clean up {{remote_artifacts}} to not affect other tests on test environment" - file: - state: absent - path: "{{remote_artifacts}}/" - diff --git a/tests/tests_artifacts_test_runner.yml b/tests/tests_artifacts_test_runner.yml deleted file mode 100644 index 85b59d8..0000000 --- a/tests/tests_artifacts_test_runner.yml +++ /dev/null @@ -1,10 +0,0 @@ -# These tasks should run after as test that fails -- name: "Check if {{artifacts}} was created properly on test runner" - shell: "ls {{artifacts}}/test.log" - delegate_to: localhost - -- name: "Clean up {{artifacts}} to not affect other tests on test runner" - file: - state: absent - path: "{{artifacts}}/" - delegate_to: localhost diff --git a/tests/tests_basic.yml b/tests/tests_basic.yml deleted file mode 100644 index 0962d25..0000000 --- a/tests/tests_basic.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Tests for basic role -- hosts: localhost - tags: - - atomic - - classic - - container - roles: - - role: standard-test-basic - tests: - - basic-simple-test - - basic-parameters-test: - dir: ./ - run: echo "check parameters on basic role" | grep "check parameters on basic role" - required_packages: - - iscsi-initiator-utils # test if we can install packages - - tasks: - - import_tasks: tests_artifacts_test_env.yml - - import_tasks: tests_artifacts_test_runner.yml - -#### Make sure the role behaves correctly if test fails -- hosts: localhost - tags: - - atomic - - classic - - container - - roles: - - role: standard-test-basic - tests: - - basic-fail-test - ignore_errors: yes - - tasks: - # 'tests_verify_failed_test' tasks should run after 'basic-fail-test' - - import_tasks: tests_verify_failed_test.yml - - import_tasks: tests_artifacts_test_env.yml - - import_tasks: tests_artifacts_test_runner.yml diff --git a/tests/tests_beakerlib.yml b/tests/tests_beakerlib.yml deleted file mode 100644 index db94326..0000000 --- a/tests/tests_beakerlib.yml +++ /dev/null @@ -1,35 +0,0 @@ -# Tests for beakerlib role -- hosts: localhost - tags: - - atomic - - classic - - container - roles: - - role: standard-test-beakerlib - tests: - - beakerlib-simple-test - required_packages: - - iscsi-initiator-utils # test if we can install packages - - tasks: - - import_tasks: tests_artifacts_test_env.yml - - import_tasks: tests_artifacts_test_runner.yml - - -#### Make sure the role behaves correctly if test fails -- hosts: localhost - tags: - - atomic - - classic - - container - roles: - - role: standard-test-beakerlib - tests: - - beakerlib-fail-test - ignore_errors: yes - - tasks: - # 'tests_verify_failed_test' tasks should run after 'beakerlib-fail-test' - - import_tasks: tests_verify_failed_test.yml - - import_tasks: tests_artifacts_test_env.yml - - import_tasks: tests_artifacts_test_runner.yml diff --git a/tests/tests_rhts.yml b/tests/tests_rhts.yml deleted file mode 100644 index eb47766..0000000 --- a/tests/tests_rhts.yml +++ /dev/null @@ -1,32 +0,0 @@ -# Tests for rhts role only runs on classic tag -- hosts: localhost - tags: - - classic - roles: - - role: standard-test-rhts - tests: - - rhts-simple-test - required_packages: - - iscsi-initiator-utils # test if we can install packages - - tasks: - - import_tasks: tests_artifacts_test_env.yml - - import_tasks: tests_artifacts_test_runner.yml - -#### Make sure the role behaves correctly if test fails -- hosts: localhost - tags: - - classic - roles: - - role: standard-test-rhts - tags: - - classic - tests: - - rhts-fail-test - ignore_errors: yes - - tasks: - # 'tests_verify_failed_test' tasks should run after 'rhts-fail-test' - - import_tasks: tests_verify_failed_test.yml - - import_tasks: tests_artifacts_test_env.yml - - import_tasks: tests_artifacts_test_runner.yml diff --git a/tests/tests_verify_failed_test.yml b/tests/tests_verify_failed_test.yml deleted file mode 100644 index a51af94..0000000 --- a/tests/tests_verify_failed_test.yml +++ /dev/null @@ -1,11 +0,0 @@ -# These tasks should run after as test that fails -- name: Read test.log on test environment - shell: "cat {{remote_artifacts}}/test.log" - register: test_log - -- name: Check for FAIL on test.log on test environment - fail: msg="Could not find FAIL on test log" - when: test_log.stdout.find("FAIL") == -1 - # We should fail when we can not find FAIL string on log - # -1 means string not found -