From 7416f4c3b623ad68505293da55056a02469f6b11 Mon Sep 17 00:00:00 2001 From: Andrei Stepanov Date: Feb 13 2018 11:28:12 +0000 Subject: Rewrite basic role with str-common. Basic role is based on str-common role. --- diff --git a/roles/standard-test-basic/README.md b/roles/standard-test-basic/README.md index 82e0c2c..ec1de4a 100644 --- a/roles/standard-test-basic/README.md +++ b/roles/standard-test-basic/README.md @@ -1,21 +1,19 @@ # Ansible role for tests using basic scripts -Put this role in your test_local.yml playbook. The playbook -will first install package dependencies listed on playbook on -your localhost, then it will proceed to run testing. -You can redefine the following variables in -roles/standard-test-basic/vars/main.yml: +Put this role in your `tests.yml` playbook. The playbook will first install +package dependencies listed on playbook on your localhost, then it will proceed +to run testing. You can redefine the following variables in +`roles/standard-test-basic/vars/main.yml`: - * tests: A list of test cases - * artifacts: An artifacts directory on localhost to store logs - * remote_artifacts: The directory on the system under test - where the logs are stored. Note: if this variable is left - undefined, it will default to /tmp/artifacts - * required_packages: A list of prerequisite packages required by - tests. Please note that for Atomic Host, additional - packages will be installed using the rpm-ostree command which - is affecting the test subject (it's similar as rebuilding an - rpm package to be tested) so this should be used with caution - and only when necessary. + * **tests**: A list of test cases + * **artifacts**: An artifacts directory on localhost to store logs + * **remote_artifacts**: The directory on the system under test where the logs + are stored. Note: if this variable is left undefined, it will default to + `/tmp/artifacts` + * **required_packages**: A list of prerequisite packages required by tests. + Please note that for Atomic Host, additional packages will be installed + using the `rpm-ostree` command which is affecting the test subject (it's + similar as rebuilding an rpm package to be tested) so this should be used + with caution and only when necessary. -Check glib2 package tests to find examples for using this role. +Check `glib2` package tests to find examples for using this role. diff --git a/roles/standard-test-basic/defaults/main.yml b/roles/standard-test-basic/defaults/main.yml deleted file mode 100644 index 1650168..0000000 --- a/roles/standard-test-basic/defaults/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}" diff --git a/roles/standard-test-basic/meta/main.yml b/roles/standard-test-basic/meta/main.yml new file mode 100644 index 0000000..a113e4e --- /dev/null +++ b/roles/standard-test-basic/meta/main.yml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: str-common diff --git a/roles/standard-test-basic/tasks/main.yml b/roles/standard-test-basic/tasks/main.yml index 08e9006..049b638 100644 --- a/roles/standard-test-basic/tasks/main.yml +++ b/roles/standard-test-basic/tasks/main.yml @@ -1,105 +1,5 @@ --- -- name: Packages to be present on the system. - set_fact: - # Separate debuginfo and ordinary packages. There is an issue on GitHub: - # https://github.com/ansible/ansible/issues/31579. The easiest way to - # install debuginfo for package is to use 'debuginfo-install'. This - # program is present on RHEL/CentOS/Fedora and it automatically enables - # debuginfo repos. - pkgs_ordinary_req: > - {{ - required_packages | - reject('match', '.*-debuginfo$') | - list - }} - pkgs_debuginfo_req: > - {{ - required_packages | - select('match', '.*-debuginfo$') | - list | - regex_replace('-debuginfo') - }} - -- name: Target OS identification - block: - - name: Test if system is Atomic Host - lineinfile: - name: /etc/os-release - regexp: .*Atomic Host.* - state: absent - check_mode: yes - changed_when: False - register: os_release_atomic - - name: Set Ansible fact 'is_atomic_host' - set_fact: - is_atomic_host: "{{ os_release_atomic.found > 0 }}" - -- block: - - name: Install the basic requirements on target - package: name={{item}} state=latest - with_items: - - rsync # needed to copy tests to target - - - name: Install any test-specific package requirements - # Note, this method cannot install -debuginfo packages. - package: name={{item}} state=latest - with_items: - - "{{ pkgs_ordinary_req }}" - - - block: - - name: Install yum-utils - package: name=yum-utils state=latest - when: ansible_pkg_mgr == 'yum' - - - name: Install dnf-utils - # System can have installed yum-utils. Which conflicts wih dnf-utils. - # Therefore, remove yum-utils and install dnf-utils. - shell: dnf --assumeyes --allowerasing install dnf-utils - when: ansible_pkg_mgr == 'dnf' - - - name: Care about debuginfo packages for DNF/YUM systems - shell: | - debuginfo-install --assumeyes {{item}} - with_items: - - "{{ pkgs_debuginfo_req }}" - when: - - "[ansible_pkg_mgr] | intersect(['dnf', 'yum'])" - - pkgs_debuginfo_req - - # Only manually install packages on non atomic hosts - when: ansible_pkg_mgr != 'unknown' - -- block: - - name: Check presence of required packages for Atomic Host - shell: rpm -q {{ pkgs_ordinary_req|join(" ") }} - register: package_check - changed_when: False - failed_when: False - args: { warn: no } - - name: Install required packages at Atomic Host - shell: - rpm-ostree install {{ pkgs_ordinary_req|join(" ") }} - && rpm-ostree ex livefs - when: package_check.rc != 0 - when: - - is_atomic_host - - pkgs_ordinary_req - -- name: Define remote_artifacts if it is not already defined - set_fact: - remote_artifacts: /tmp/artifacts - when: remote_artifacts is not defined - -- name: Copy tests to target - synchronize: - src: "{{ playbook_dir }}/" - dest: /usr/local/bin/ - ssh_args: "-o UserKnownHostsFile=/dev/null" - -- name: Make artifacts directory - file: path={{ remote_artifacts }} state=directory owner=root mode=755 recurse=yes - - block: - name: Execute tests shell: | @@ -123,23 +23,19 @@ TEST: "{{item if item.keys is not defined else item.keys()[0]}}" TEST_DIR: - "/usr/local/bin/{{item if item.keys is not defined else item[item.keys()[0]]['dir']|default(item.keys()[0])}}" + "{{ tenv_workdir }}/{{ item if item.keys is not defined else item[item.keys()[0]]['dir']|default(item.keys()[0]) }}" TEST_CMD: "{{'./runtest.sh' if item.keys is not defined else item[item.keys()[0]]['run']|default('./runtest.sh')}}" with_items: - "{{ tests }}" - - name: Pull out the logs - synchronize: - dest: "{{ artifacts }}/" - src: "{{ remote_artifacts }}/" - mode: pull - ssh_args: "-o UserKnownHostsFile=/dev/null" - when: artifacts|default("") != "" - # Can't go in block. See # https://github.com/ansible/ansible/issues/20736 - name: Check the results shell: grep "^FAIL" {{ remote_artifacts }}/test.log register: test_fails failed_when: test_fails.stdout or test_fails.stderr + + - include_role: + name: str-common + tasks_from: end.yml diff --git a/roles/standard-test-basic/vars/main.yml b/roles/standard-test-basic/vars/main.yml deleted file mode 100644 index b9860b2..0000000 --- a/roles/standard-test-basic/vars/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -remote_artifacts: /tmp/artifacts -tests: [] -required_packages: [] diff --git a/roles/standard-test-beakerlib/README.md b/roles/standard-test-beakerlib/README.md index f6ff920..9b69440 100644 --- a/roles/standard-test-beakerlib/README.md +++ b/roles/standard-test-beakerlib/README.md @@ -1,43 +1,41 @@ # Ansible role for Beakerlib tests -Put this role in your test_local.yml playbook. The playbook -will first install beakerlib and restraint binaries on -your localhost, then it will proceed to run testing. -You can redefine the following variables in -roles/standard-test-beakerlib/vars/main.yml: +Put this role in your `tests.yml` playbook. The playbook will first install +beakerlib and restraint binaries on your localhost, then it will proceed to run +testing. You can redefine the following variables in +`roles/standard-test-beakerlib/vars/main.yml`: - * tests: A list of beakerlib test files - * artifacts: An artifacts directory on localhost to store logs - * remote_artifacts: The directory on the system under test - where the logs are stored. Note: if this variable is left - undefined, it will default to /tmp/artifacts - * required_packages: A list of prerequisite packages required by - beakerlib tests. Please note that for Atomic Host, additional - packages will be installed using the rpm-ostree command which - is affecting the test subject (it's similar as rebuilding an - rpm package to be tested) so this should be used with caution - and only when necessary. - * repositories: A list of dictionaries defining git repos with - tests to be fetched. Available options are consistent with the - ansible git module syntax: + * **tests**: A list of beakerlib test files + * **artifacts**: An artifacts directory on localhost to store logs + * **remote_artifacts**: The directory on the system under test where the logs + are stored. Note: if this variable is left undefined, it will default to + `/tmp/artifacts` + * **required_packages**: A list of prerequisite packages required by beakerlib + tests. Please note that for Atomic Host, additional packages will be installed + using the rpm-ostree command which is affecting the test subject (it's similar + as rebuilding an rpm package to be tested) so this should be used with caution + and only when necessary. + * **repositories**: A list of dictionaries defining git repos with tests to be + fetched. Available options are consistent with the ansible git module + syntax: url ... repository url (required) dest ... destination directory (required) version ... desired branch (optional, defaults to master) Example usage: -- hosts: localhost - roles: - - role: standard-test-beakerlib - tags: - - classic - repositories: - - repo: "https://src.fedoraproject.org/tests/shell.git" - dest: "shell" - tests: - - shell/func - - shell/login - - shell/smoke - required_packages: - - expect - - which + - hosts: localhost + roles: + - role: standard-test-beakerlib + tags: + - classic + repositories: + - repo: "https://src.fedoraproject.org/tests/shell.git" + dest: "shell" + tests: + - shell/func + - shell/login + - shell/smoke + required_packages: + - expect + - which diff --git a/roles/standard-test-beakerlib/defaults/main.yml b/roles/standard-test-beakerlib/defaults/main.yml deleted file mode 100644 index 1650168..0000000 --- a/roles/standard-test-beakerlib/defaults/main.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}" diff --git a/roles/standard-test-beakerlib/tasks/main.yml b/roles/standard-test-beakerlib/tasks/main.yml index 7863ed3..7c580e5 100644 --- a/roles/standard-test-beakerlib/tasks/main.yml +++ b/roles/standard-test-beakerlib/tasks/main.yml @@ -5,14 +5,14 @@ - name: Add restraint repo for restraint-rhts on Fedora hosts shell: dnf copr enable -y bpeck/restraint ignore_errors: True - when: hostvars[test_runner_inventory_name]['ansible_distribution'] == 'Fedora' + when: "hostvars[test_runner_inventory_name]['is_dnf_os']" - name: Add restraint repo for restraint-rhts on RHEL/CentOS hosts block: - package: name=yum-plugin-copr - shell: yum copr -y enable bpeck/restraint ignore_errors: True - when: "[hostvars[test_runner_inventory_name]['ansible_distribution'] ] | intersect(['RedHat', 'CentOS'])" + when: "hostvars[test_runner_inventory_name]['is_yum_os']" - name: Install the beakerlib requirements package: name={{item}} state=present @@ -109,17 +109,13 @@ with_items: - "{{ tests }}" - - name: Pull out the logs from test environment - synchronize: - dest: "{{ artifacts }}/" - src: "{{ remote_artifacts }}/" - mode: pull - ssh_args: "-o UserKnownHostsFile=/dev/null" - when: artifacts|default("") != "" - # Can't go in block. See # https://github.com/ansible/ansible/issues/20736 - name: Check the results shell: grep "^FAIL" {{ remote_artifacts }}/test.log register: test_fails failed_when: test_fails.stdout or test_fails.stderr + + - include_role: + name: str-common + tasks_from: end.yml diff --git a/roles/str-common/defaults/main.yml b/roles/str-common/defaults/main.yml index 7678f1e..4e49707 100644 --- a/roles/str-common/defaults/main.yml +++ b/roles/str-common/defaults/main.yml @@ -5,3 +5,4 @@ required_packages: [] tenv_workdir: /var/str/ remote_artifacts: /tmp/artifacts/ test_runner_inventory_name: test-runner +artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}" diff --git a/roles/str-common/tasks/end.yml b/roles/str-common/tasks/end.yml new file mode 100644 index 0000000..0ea910a --- /dev/null +++ b/roles/str-common/tasks/end.yml @@ -0,0 +1,9 @@ +--- + +- name: Pull out the logs from test environment to test runner + synchronize: + dest: "{{ artifacts }}/" + src: "{{ remote_artifacts }}/" + mode: pull + ssh_args: "-o UserKnownHostsFile=/dev/null" + when: artifacts|default("") != "" diff --git a/roles/str-common/tasks/inspect.yml b/roles/str-common/tasks/inspect.yml index 316d48f..faf81bb 100644 --- a/roles/str-common/tasks/inspect.yml +++ b/roles/str-common/tasks/inspect.yml @@ -8,8 +8,15 @@ changed_when: False register: os_release_atomic - name: Set fact 'is_atomic' + delegate_facts: True set_fact: is_atomic : "{{ os_release_atomic.found > 0 }}" - - debug: - msg: "System is Atomic Host: {{ is_atomic }}" - verbosity: 1 + +- name: Set facts about system + delegate_facts: True + set_fact: + is_yum_os: > + {{ ansible_pkg_mgr == 'yum' }} + is_dnf_os: > + {{ ansible_pkg_mgr == 'dnf' }} + diff --git a/roles/str-common/tasks/main.yml b/roles/str-common/tasks/main.yml index 04e7c01..f259710 100644 --- a/roles/str-common/tasks/main.yml +++ b/roles/str-common/tasks/main.yml @@ -1,7 +1,26 @@ - import_tasks: inspect.yml + +- debug: + msg: "System uses yum: {{ is_yum_os }}" + verbosity: 1 + +- debug: + msg: "System uses dnf: {{ is_dnf_os }}" + verbosity: 1 + +- debug: + msg: "System is Atomic Host: {{ is_atomic }}" + verbosity: 1 + - import_tasks: trunner.yml - import_tasks: pkgs.yml - - name: Make artifacts directory file: path={{ remote_artifacts }} state=directory owner=root mode=755 recurse=yes + +# Next task requires rsync on test environment +- name: Copy tests to test environment + synchronize: + src: "{{ playbook_dir }}/" + dest: "{{ tenv_workdir }}" + ssh_args: "-o UserKnownHostsFile=/dev/null" diff --git a/roles/str-common/tasks/pkgs-dnf.yml b/roles/str-common/tasks/pkgs-dnf.yml index ca45a8e..554a817 100644 --- a/roles/str-common/tasks/pkgs-dnf.yml +++ b/roles/str-common/tasks/pkgs-dnf.yml @@ -4,6 +4,11 @@ with_items: - "{{ pkgs_ordinary_req }}" +- name: Install the common requirements on target + package: name={{item}} state=present + with_items: + - rsync # needed to copy tests to target + - block: - name: Install dnf-utils # System can have installed yum-utils. Which conflicts wih dnf-utils. diff --git a/roles/str-common/tasks/pkgs-rpm-ostree.yml b/roles/str-common/tasks/pkgs-rpm-ostree.yml index 31b25e7..48ff116 100644 --- a/roles/str-common/tasks/pkgs-rpm-ostree.yml +++ b/roles/str-common/tasks/pkgs-rpm-ostree.yml @@ -1,11 +1,11 @@ - block: - - name: Check presence of required packages for Atomic Host + - name: Check presence of test-specific package requirements shell: rpm -q {{ pkgs_ordinary_req|join(" ") }} register: package_check changed_when: False failed_when: False args: { warn: no } - - name: Install required packages at Atomic Host + - name: Install test-specific package requirements shell: rpm-ostree install {{ pkgs_ordinary_req|join(" ") }} && rpm-ostree ex livefs diff --git a/roles/str-common/tasks/pkgs-yum.yml b/roles/str-common/tasks/pkgs-yum.yml index 9ed4bc1..a23042e 100644 --- a/roles/str-common/tasks/pkgs-yum.yml +++ b/roles/str-common/tasks/pkgs-yum.yml @@ -4,6 +4,11 @@ with_items: - "{{ pkgs_ordinary_req }}" +- name: Install the common requirements on target + package: name={{item}} state=present + with_items: + - rsync # needed to copy tests to target + - block: - name: Install yum-utils package: name=yum-utils state=latest diff --git a/roles/str-common/tasks/trunner.yml b/roles/str-common/tasks/trunner.yml index 6a21fdb..01e6d80 100644 --- a/roles/str-common/tasks/trunner.yml +++ b/roles/str-common/tasks/trunner.yml @@ -9,11 +9,7 @@ setup: delegate_facts: True - - debug: - msg: - "{{ test_runner_inventory_name }} is - {{ hostvars[test_runner_inventory_name]['ansible_distribution'] }}" - verbosity: 1 + - import_tasks: inspect.yml - name: Fetch tests from remote repositories git: @@ -23,3 +19,21 @@ with_items: "{{ repositories }}" when: repositories is defined + +- debug: + msg: > + {{ test_runner_inventory_name }} is: + {{ hostvars[test_runner_inventory_name]['ansible_distribution'] }} + verbosity: 1 + +- debug: + msg: > + {{ test_runner_inventory_name }} uses yum: + {{ hostvars[test_runner_inventory_name]['is_yum_os'] }} + verbosity: 1 + +- debug: + msg: > + {{ test_runner_inventory_name }} uses dnf: + {{ hostvars[test_runner_inventory_name]['is_dnf_os'] }} + verbosity: 1