From 1c6d83f0dff77cf247633259218b3e417d5e2d34 Mon Sep 17 00:00:00 2001 From: Andrei Stepanov Date: Feb 08 2018 11:00:40 +0000 Subject: Intoducing a common role. Common role holds basic tasks. This tasks can be used by different roles. --- diff --git a/roles/standard-test-beakerlib/meta/main.yml b/roles/standard-test-beakerlib/meta/main.yml new file mode 100644 index 0000000..a113e4e --- /dev/null +++ b/roles/standard-test-beakerlib/meta/main.yml @@ -0,0 +1,4 @@ +--- + +dependencies: + - role: str-common diff --git a/roles/standard-test-beakerlib/tasks/main.yml b/roles/standard-test-beakerlib/tasks/main.yml index ecee3a9..041c901 100644 --- a/roles/standard-test-beakerlib/tasks/main.yml +++ b/roles/standard-test-beakerlib/tasks/main.yml @@ -1,140 +1,36 @@ --- -- name: Add executor host - add_host: - name: executor - ansible_connection: local - ansible_ssh_host: 127.0.0.1 - ansible_ssh_connection: local -- 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 +- delegate_to: "{{ test_runner_inventory_name }}" 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: Gather facts - setup: - delegate_facts: True - - name: Add restraint repo for restraint-rhts on Fedora hosts shell: dnf copr enable -y bpeck/restraint - when: ansible_distribution == 'Fedora' + when: hostvars[test_runner_inventory_name]['ansible_distribution'] == 'Fedora' - name: Add restraint repo for restraint-rhts on RHEL/CentOS hosts block: - package: name=yum-plugin-copr - shell: yum copr -y enable bpeck/restraint - when: "[ansible_distribution] | intersect(['RedHat', 'CentOS'])" + when: "[hostvars[test_runner_inventory_name]['ansible_distribution'] ] | intersect(['RedHat', 'CentOS'])" - name: Install the beakerlib requirements - package: name={{item}} state=latest + package: name={{item}} state=present with_items: - beakerlib - restraint-rhts - rsync - - name: Fetch tests from remote repositories - git: - repo: "{{ item.repo }}" - dest: "{{ item.dest }}" - version: "{{ item.version | default('master') }}" - with_items: - "{{ repositories }}" - when: repositories is defined - - delegate_to: executor - -- block: - - name: Install the beakerlib requirements on target - package: name={{item}} state=latest - with_items: +- name: Install the beakerlib requirements to test environment + package: name={{item}} state=latest + with_items: - rsync - findutils + - make + when: not is_atomic - - name: Install any test-specific package requirements - # Note, this method cannot install -debuginfo packages. - package: name={{item}} state=present - 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: Put beakerlib binaries on the target +- name: Put beakerlib binaries to test environment copy: - src: "{{item}}" - dest: /usr/local/bin/ + src: "{{ item }}" + dest: "{{ tenv_workdir }}" mode: 755 with_fileglob: - "/usr/bin/beakerlib-*" @@ -146,36 +42,35 @@ - "/usr/share/restraint/*" - "rpm.py" -- name: Copy tests to target +- name: Copy tests to test environment synchronize: src: "{{ playbook_dir }}/" - dest: /usr/local/bin/ + dest: "{{ tenv_workdir }}" ssh_args: "-o UserKnownHostsFile=/dev/null" -- name: Fix up beakerlib +- name: Fix up beakerlib at tests environment shell: > - find /usr/local/bin -type f + find {{ tenv_workdir }} -type f | xargs sed -i - -e 's|/usr/share/beakerlib|/usr/local/bin|g' - -e 's|/usr/lib/beakerlib|/usr/local/bin|g' - -e 's|/usr/share/rhts/lib/rhts-|/usr/local/bin/rhts-|g' - -e 's|/usr/bin/rhts-|/usr/local/bin/rhts-|g' - -e 's|/usr/share/rhts/lib/rhts_|/usr/local/bin/rhts-|g' - -e 's|/usr/bin/rhts_|/usr/local/bin/rhts-|g' - -e 's|/usr/share/rhts-library/rhtslib.sh|/usr/local/bin/beakerlib.sh|g' - -e 's|/usr/bin/rstrnt-|/usr/local/bin/rstrnt-|g' + -e 's|/usr/share/beakerlib|{{ tenv_workdir }}|g' + -e 's|/usr/lib/beakerlib|{{ tenv_workdir }}|g' + -e 's|/usr/share/rhts/lib/rhts-|{{ tenv_workdir }}/rhts-|g' + -e 's|/usr/bin/rhts-|{{ tenv_workdir }}/rhts-|g' + -e 's|/usr/share/rhts/lib/rhts_|{{ tenv_workdir }}/rhts-|g' + -e 's|/usr/bin/rhts_|{{ tenv_workdir }}/rhts-|g' + -e 's|/usr/share/rhts-library/rhtslib.sh|{{ tenv_workdir }}/beakerlib.sh|g' + -e 's|/usr/bin/rstrnt-|{{ tenv_workdir }}/rstrnt-|g' -- name: Make artifacts directory - file: path={{ remote_artifacts }} state=directory owner=root mode=755 recurse=yes - block: - - name: Execute beakerlib tests + - name: Run beakerlib tests shell: | export OUTPUTFILE=/dev/stdout TEST={{ item }} + export PATH="$PATH:{{ tenv_workdir }}" logfile={{ remote_artifacts }}/test.$(echo {{ item }} | sed -e 's/\//-/g').log exec 2>>$logfile 1>>$logfile - cd /usr/local/bin + cd {{ tenv_workdir }} if [ -f {{ item }} ]; then cd $(dirname {{ item }}) /bin/sh -e ./$(basename {{ item }}) @@ -195,7 +90,7 @@ - "{{ tests }}" always: - - name: Make the master test summary log artifact + - name: Make the master tests summary log artifact shell: | logfile={{ remote_artifacts }}/test.$(echo {{ item }} | sed -e 's/\//-/g').log if grep -q '\[ *FAIL *\]' "$logfile"; then @@ -212,7 +107,7 @@ with_items: - "{{ tests }}" - - name: Pull out the logs + - name: Pull out the logs from test environment synchronize: dest: "{{ artifacts }}/" src: "{{ remote_artifacts }}/" diff --git a/roles/standard-test-beakerlib/vars/main.yml b/roles/standard-test-beakerlib/vars/main.yml deleted file mode 100644 index b9860b2..0000000 --- a/roles/standard-test-beakerlib/vars/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -remote_artifacts: /tmp/artifacts -tests: [] -required_packages: [] diff --git a/roles/str-common/defaults/main.yml b/roles/str-common/defaults/main.yml new file mode 100644 index 0000000..7678f1e --- /dev/null +++ b/roles/str-common/defaults/main.yml @@ -0,0 +1,7 @@ +--- + +tests: [] +required_packages: [] +tenv_workdir: /var/str/ +remote_artifacts: /tmp/artifacts/ +test_runner_inventory_name: test-runner diff --git a/roles/str-common/tasks/inspect.yml b/roles/str-common/tasks/inspect.yml new file mode 100644 index 0000000..316d48f --- /dev/null +++ b/roles/str-common/tasks/inspect.yml @@ -0,0 +1,15 @@ +- block: + - name: Check 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 fact 'is_atomic' + set_fact: + is_atomic : "{{ os_release_atomic.found > 0 }}" + - debug: + msg: "System is Atomic Host: {{ is_atomic }}" + verbosity: 1 diff --git a/roles/str-common/tasks/main.yml b/roles/str-common/tasks/main.yml new file mode 100644 index 0000000..04e7c01 --- /dev/null +++ b/roles/str-common/tasks/main.yml @@ -0,0 +1,7 @@ +- import_tasks: inspect.yml +- import_tasks: trunner.yml +- import_tasks: pkgs.yml + + +- name: Make artifacts directory + file: path={{ remote_artifacts }} state=directory owner=root mode=755 recurse=yes diff --git a/roles/str-common/tasks/pkgs-dnf.yml b/roles/str-common/tasks/pkgs-dnf.yml new file mode 100644 index 0000000..ca45a8e --- /dev/null +++ b/roles/str-common/tasks/pkgs-dnf.yml @@ -0,0 +1,20 @@ +- name: Install test-specific package requirements + # Note, this method cannot install -debuginfo packages. + package: name={{item}} state=present + with_items: + - "{{ pkgs_ordinary_req }}" + +- block: + - 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: Install debuginfo packages + shell: | + debuginfo-install --assumeyes {{item}} + with_items: + - "{{ pkgs_debuginfo_req }}" + when: + - pkgs_debuginfo_req diff --git a/roles/str-common/tasks/pkgs-rpm-ostree.yml b/roles/str-common/tasks/pkgs-rpm-ostree.yml new file mode 100644 index 0000000..31b25e7 --- /dev/null +++ b/roles/str-common/tasks/pkgs-rpm-ostree.yml @@ -0,0 +1,14 @@ +- 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: + - pkgs_ordinary_req diff --git a/roles/str-common/tasks/pkgs-yum.yml b/roles/str-common/tasks/pkgs-yum.yml new file mode 100644 index 0000000..9ed4bc1 --- /dev/null +++ b/roles/str-common/tasks/pkgs-yum.yml @@ -0,0 +1,18 @@ +- name: Install test-specific package requirements + # Note, this method cannot install -debuginfo packages. + package: name={{item}} state=present + with_items: + - "{{ pkgs_ordinary_req }}" + +- block: + - name: Install yum-utils + package: name=yum-utils state=latest + when: ansible_pkg_mgr == "yum" + + - name: Care about debuginfo packages for YUM systems + shell: | + debuginfo-install --assumeyes {{item}} + with_items: + - "{{ pkgs_debuginfo_req }}" + when: + - pkgs_debuginfo_req diff --git a/roles/str-common/tasks/pkgs.yml b/roles/str-common/tasks/pkgs.yml new file mode 100644 index 0000000..6e75ae9 --- /dev/null +++ b/roles/str-common/tasks/pkgs.yml @@ -0,0 +1,29 @@ +- name: Build packages lists to be present on test environment + # 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. + set_fact: + pkgs_ordinary_req: > + {{ + required_packages | + reject('match', '.*-debuginfo$') | + list + }} + pkgs_debuginfo_req: > + {{ + required_packages | + select('match', '.*-debuginfo$') | + list | + regex_replace('-debuginfo') + }} + pkg_mgr: > + {{ + 'rpm-ostree' if ansible_pkg_mgr == 'unknown' and is_atomic else ansible_pkg_mgr + }} + +- debug: + msg: "Package manager: {{ pkg_mgr }}" + verbosity: 1 + +- include_tasks: "pkgs-{{ pkg_mgr | trim}}.yml" diff --git a/roles/str-common/tasks/trunner.yml b/roles/str-common/tasks/trunner.yml new file mode 100644 index 0000000..6a21fdb --- /dev/null +++ b/roles/str-common/tasks/trunner.yml @@ -0,0 +1,25 @@ +- name: Add test-runner to ansible inventory + add_host: + name: "{{ test_runner_inventory_name }}" + ansible_connection: local + +- delegate_to: "{{ test_runner_inventory_name }}" + block: + - name: Gather facts + setup: + delegate_facts: True + + - debug: + msg: + "{{ test_runner_inventory_name }} is + {{ hostvars[test_runner_inventory_name]['ansible_distribution'] }}" + verbosity: 1 + + - name: Fetch tests from remote repositories + git: + repo: "{{ item.repo }}" + dest: "{{ item.dest }}" + version: "{{ item.version | default('master') }}" + with_items: + "{{ repositories }}" + when: repositories is defined