From d320c1fbb067484f5d85b30e0e517d4c8c060e7e Mon Sep 17 00:00:00 2001 From: Andrei Stepanov Date: May 17 2018 11:25:31 +0000 Subject: Remove standard-test-rhts role. standard-test-rhts had next defects: * The role used only dnf. * It didn't work with Atomic Host. * It installed beakerlib-libraries, which was very confusing. * It used restrain framework as suit to run tests. All this were confusing. beakerlib-libraries now supported by standard-test-beakerlib role. Signed-off-by: Andrei Stepanov --- diff --git a/roles/standard-test-beakerlib/defaults/main.yml b/roles/standard-test-beakerlib/defaults/main.yml index d51fb71..a6d16f3 100644 --- a/roles/standard-test-beakerlib/defaults/main.yml +++ b/roles/standard-test-beakerlib/defaults/main.yml @@ -13,5 +13,12 @@ role_pkgs_req: - rsync - make - libselinux-python + - beakerlib-libraries - "{{ beakerlib_pkgs_req[distro_name_ver] | default([]) }}" - "{{ beakerlib_pkgs_req[distro_name] | default([]) }}" + +# Required enabled repos +role_copr_repos_req: + - mvadkert/beakerlib-libraries + +beakerlib_libraries_path: /usr/share/beakerlib-libraries diff --git a/roles/standard-test-beakerlib/files/resolve-test-dependencies b/roles/standard-test-beakerlib/files/resolve-test-dependencies new file mode 100755 index 0000000..79f130a --- /dev/null +++ b/roles/standard-test-beakerlib/files/resolve-test-dependencies @@ -0,0 +1,144 @@ +#!/bin/bash +# +# DESCRIPTION +# ----------- +# This script resolves dependencies of the given beakerlib libraries installed +# in BEAKER_LIBRARY_PATH. Dependencies are resolved from Makefiles which +# contains Requires and RhtsRequires fields specifying RPM dependencies. +# +# RhtsRequires are mandatory RPM requirements that need to be installed before +# running the test. +# +# Requires are optional RPM requirements that the harness should try to install +# on the system-under-test (SUT), but they are not mandatory. +# +# RETURNS +# ------- +# After the script finishes, it prints two lines, with space delimited list of +# components from RhtsRequires and Requires. +# +# BEAKERLIB_LIBRARY_PATH - path with the libraries +# +# AUTHORS +# ------- +# Jakub Heger +# Martin Kyral +# Miroslav Vadkerti +# + +[ -z "$BEAKERLIB_LIBRARY_PATH" ] && BEAKERLIB_LIBRARY_PATH="/mnt/libraries" + +# options +OPTS="h" + +# +# helpers +# + +function print_info() { + printf ":: %s\n" "$@" +} + +function print_error() { + printf "Error: %s\n" "$@" +} + +function exit_error() { + print_error "$@" + exit 1 +} + +function help() { +cat < + Martin Kyral + Miroslav Vadkerti + + Options: + -h Print this help. +EOF +} + +# +# Main +# + +while getopts $OPTS OPTION +do + case $OPTION in + h) + help + exit + ;; + esac +done + +TEST=$1 +[ -z "$TEST" ] && exit_error "No test specified" +[ -f "$TEST/Makefile" ] || exit_error "Makefile not found @ $TEST/Makefile" + +REQUIRES_DEPS= +RHTSREQUIRES_DEPS= +PROCESSED_LIBS= + +# +# Process a beakerlib library and recursively resolve it's dependencies. +# +# Params: +# $1 - library name - e.g. httpd/http +# +function process_library() { + # skip already processed beakerlib libraries + grep -wq "$1" <<< "$PROCESSED_LIBS" && return + PROCESSED_LIBS="$PROCESSED_LIBS $1" + + local COMPONENT=${1///*} + local LIBRARY=${1##*/} + + # check if library exists + if [ ! -d "${BEAKERLIB_LIBRARY_PATH}/$COMPONENT/Library/$LIBRARY" ]; then + print_error "Could not find library '$1' in '$BEAKERLIB_LIBRARY_PATH'" + return + fi + + resolve_deps "${BEAKERLIB_LIBRARY_PATH}/$COMPONENT/Library/$LIBRARY" +} + +# +# Recursively resolves test dependencies of beakerlib test specified with a path. +# +# Params: +# $1 - path to a beakerlib test +# +function resolve_deps() { + local REQUIRES=$(sed -n 's/.*\"Requires:[[:space:]]*\(.*\)".*/\1/p' "$1/Makefile") + local RHTSREQUIRES=$(sed -n 's/.*RhtsRequires:[[:space:]]*\(.*\)".*/\1/p' "$1/Makefile") + # sed -n 's/.*Requires:[[:space:]]*\(.*\)".*/\1/p' $1/Makefile + + for REQ in $REQUIRES; do + if egrep -qv '^\$\(' <<< "$REQ"; then + REQUIRES_DEPS="$REQUIRES_DEPS $REQ" + fi + done + + for RHTSREQ in $RHTSREQUIRES; do + if egrep -q "^library\(" <<< "$RHTSREQ"; then + process_library $(sed 's/library(\(.*\))/\1/' <<< "$RHTSREQ") + elif egrep -qv '^\$\(' <<< "$RHTSREQ"; then + RHTSREQUIRES_DEPS="$RHTSREQUIRES_DEPS $RHTSREQ" + fi + done +} + +resolve_deps "$TEST" + +echo "$RHTSREQUIRES_DEPS" | xargs -n1 | sort | uniq | tr '\n' ' ' +echo +echo "$REQUIRES_DEPS" | xargs -n1 | sort | uniq | tr '\n' ' ' +echo + +# vim: ts=2 sw=2 sts=2 ft=sh et ai: diff --git a/roles/standard-test-beakerlib/tasks/main.yml b/roles/standard-test-beakerlib/tasks/main.yml index 8c6f122..5a327bb 100644 --- a/roles/standard-test-beakerlib/tasks/main.yml +++ b/roles/standard-test-beakerlib/tasks/main.yml @@ -1,16 +1,54 @@ --- +- name: Get list of RPM packages listed at beakerlib tests' requirements + script: "{{ role_path }}/files/resolve-test-dependencies {{ tenv_workdir }}/{{ item }}" + with_flattened: + # tests - is defined at tests.yml playbook + - "{{ tests }}" + register: deps + environment: + BEAKERLIB_LIBRARY_PATH: "{{ beakerlib_libraries_path }}" + +- name: Set Ansible facts for required RPM packages for beakerlib tests + set_fact: + # RhtsRequires in Makefile + makefile_pkgs_req1: "{{ deps.results[0].stdout_lines[0].split()|d([], true) }}" + # Requires in Makefile + makefile_pkgs_req2: "{{ deps.results[0].stdout_lines[1].split()|d([], true) }}" + - debug: msg: > - 1 req pkgs for: {{ distro_name }}: {{ beakerlib_pkgs_req[distro_name] | default([]) }} - 2 req pkgs for: {{ distro_name_ver }}: {{ beakerlib_pkgs_req[distro_name_ver] | default([]) }} + Tests requre next RPM packages: {{ makefile_pkgs_req1 }} + Tests requre next RPM packages: {{ makefile_pkgs_req2 }} verbosity: 1 +- include_role: + name: str-common-pkgs + vars: + param_req_pkgs: "{{ makefile_pkgs_req1 | union(makefile_pkgs_req2) }}" + - name: Turn on usroverlay for Atomic Host when: is_atomic # This is dirty hack. It was made as temporary solution. command: rpm-ostree usroverlay +- name: Create legacy beakerlib directories + file: + dest: "{{ item }}" + state: directory + with_items: + - /usr/lib/beakerlib + - /usr/share/rhts-library + +- name: Create legacy beakerlib links + file: + src: /usr/share/beakerlib/beakerlib.sh + dest: "{{ item }}" + state: link + with_items: + - /usr/lib/beakerlib/beakerlib.sh + - /usr/share/rhts-library/rhtslib.sh + - name: Put beakerlib binaries to test environment Atomic Host when: is_atomic copy: @@ -38,11 +76,12 @@ with_fileglob: - "rhts-environment.sh" -- name: Copy tests to test environment - synchronize: - src: "{{ playbook_dir }}/" - dest: "{{ tenv_workdir }}" - ssh_args: "-o UserKnownHostsFile=/dev/null" +# Already in str-init +#- name: Copy tests to test environment +# synchronize: +# src: "{{ playbook_dir }}/" +# dest: "{{ tenv_workdir }}" +# ssh_args: "-o UserKnownHostsFile=/dev/null" - block: - name: Run beakerlib tests diff --git a/roles/standard-test-rhts/README.md b/roles/standard-test-rhts/README.md deleted file mode 100644 index 054068f..0000000 --- a/roles/standard-test-rhts/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Ansible role for RHTS (Red Hat Test Suite) tests - -Put this role in your test_local.yml playbook. You'll need -to have the following variables defined: - - * tests: A list of RHTS test directories - * 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 RHTS tests - * rpms: Space separated list of RPMs to install (optional, may include SRPMs) - * 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-rhts - 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-rhts/defaults/main.yml b/roles/standard-test-rhts/defaults/main.yml deleted file mode 100644 index dfab937..0000000 --- a/roles/standard-test-rhts/defaults/main.yml +++ /dev/null @@ -1,17 +0,0 @@ ---- -artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}" -rpms: [] - -# -# This variable controls if the role will install, resolve test dependencies from Makefiles -# and use beakerlib libaries when executing beakerlib tests. -# -# Beakerlib libaries are installed from this copr repository -# -# https://copr.fedorainfracloud.org/coprs/mvadkert/beakerlib-libraries -# -# The libraries are hosted on pagure.io, see the project README for more information -# -# https://pagure.io/beakerlib-libraries -# -use_beakerlib_libraries: false diff --git a/roles/standard-test-rhts/files/job2text.xsl b/roles/standard-test-rhts/files/job2text.xsl deleted file mode 100644 index c8eb693..0000000 --- a/roles/standard-test-rhts/files/job2text.xsl +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - diff --git a/roles/standard-test-rhts/files/resolve-test-dependencies b/roles/standard-test-rhts/files/resolve-test-dependencies deleted file mode 100755 index 46a03a7..0000000 --- a/roles/standard-test-rhts/files/resolve-test-dependencies +++ /dev/null @@ -1,141 +0,0 @@ -#!/bin/bash -# -# Description: -# This script resolves dependencies of the given beakerlib libraries installed -# in BEAKER_LIBRARY_PATH. Dependencies are resolved from Makefiles which contains -# Requires and RhtsRequires fields specifying RPM dependencies. -# -# RhtsRequires are mandatory RPM requirements that need to be installed before -# running the test. -# -# Requires are optional RPM requirements that the harness should try to install -# on the system-under-test (SUT), but they are not mandatory. -# -# Return value: -# After the script finishes, it prints two lines, with space delimited list -# of components from RhtsRequires and Requires. -# -# BEAKERLIB_LIBRARY_PATH - path with the libraries -# -# Authors: -# Jakub Heger -# Martin Kyral -# Miroslav Vadkerti -# - -[ -z "$BEAKERLIB_LIBRARY_PATH" ] && BEAKERLIB_LIBRARY_PATH="/mnt/libraries" - -# options -OPTS="h" - -# -# helpers -# - -function print_info() { - printf ":: %s\n" "$@" -} - -function print_error() { - printf "Error: %s\n" "$@" -} - -function exit_error() { - print_error "$@" - exit 1 -} - -function help() { -cat < - Martin Kyral - Miroslav Vadkerti - - Options: - -h Print this help. -EOF -} - -# -# Main -# - -while getopts $OPTS OPTION -do - case $OPTION in - h) - help - exit - ;; - esac -done - -TEST=$1 -[ -z "$TEST" ] && exit_error "No test specified" -[ -f "$TEST/Makefile" ] || exit_error "Makefile not found @ $TEST/Makefile" - -REQUIRES_DEPS= -RHTSREQUIRES_DEPS= -PROCESSED_LIBS= - -# -# Process a beakerlib library and recursively resolve it's dependencies. -# -# Params: -# $1 - library name - e.g. httpd/http -# -function process_library() { - # skip already processed beakerlib libraries - grep -wq "$1" <<< "$PROCESSED_LIBS" && return - PROCESSED_LIBS="$PROCESSED_LIBS $1" - - local COMPONENT=${1///*} - local LIBRARY=${1##*/} - - # check if library exists - if [ ! -d "${BEAKERLIB_LIBRARY_PATH}/$COMPONENT/Library/$LIBRARY" ]; then - print_error "Could not find library '$1' in '$BEAKERLIB_LIBRARY_PATH'" - return - fi - - resolve_deps "${BEAKERLIB_LIBRARY_PATH}/$COMPONENT/Library/$LIBRARY" -} - -# -# Recursively resolves test dependencies of beakerlib test specified with a path. -# -# Params: -# $1 - path to a beakerlib test -# -function resolve_deps() { - local REQUIRES=$(sed -n 's/.*\"Requires:[[:space:]]*\(.*\)".*/\1/p' "$1/Makefile") - local RHTSREQUIRES=$(sed -n 's/.*RhtsRequires:[[:space:]]*\(.*\)".*/\1/p' "$1/Makefile") - # sed -n 's/.*Requires:[[:space:]]*\(.*\)".*/\1/p' $1/Makefile - - for REQ in $REQUIRES; do - if egrep -qv '^\$\(' <<< "$REQ"; then - REQUIRES_DEPS="$REQUIRES_DEPS $REQ" - fi - done - - for RHTSREQ in $RHTSREQUIRES; do - if egrep -q "^library\(" <<< "$RHTSREQ"; then - process_library $(sed 's/library(\(.*\))/\1/' <<< "$RHTSREQ") - elif egrep -qv '^\$\(' <<< "$RHTSREQ"; then - RHTSREQUIRES_DEPS="$RHTSREQUIRES_DEPS $RHTSREQ" - fi - done -} - -resolve_deps "$TEST" - -echo "$RHTSREQUIRES_DEPS" | xargs -n1 | sort | uniq | tr '\n' ' ' -echo -echo "$REQUIRES_DEPS" | xargs -n1 | sort | uniq | tr '\n' ' ' -echo - -# vim: ts=2 sw=2 sts=2 ft=sh et ai: diff --git a/roles/standard-test-rhts/tasks/main.yml b/roles/standard-test-rhts/tasks/main.yml deleted file mode 100644 index 8aa0c4c..0000000 --- a/roles/standard-test-rhts/tasks/main.yml +++ /dev/null @@ -1,266 +0,0 @@ ---- -- name: Install the Ansible and RHTS pre-requirements - package: name={{item}} state=latest - with_items: - - rsync # need rsync for Ansible synchronize module - - dnf-plugins-core # need COPR plugin - - openssh-server - - beakerlib - - make - - createrepo - -- name: Enable COPR repo for restraint - shell: dnf copr -y enable bpeck/restraint - ignore_errors: True - -- name: Enable COPR repo for beakerlib-libraries - shell: dnf copr -y enable mvadkert/beakerlib-libraries - ignore_errors: True - when: use_beakerlib_libraries - -- name: Install restraint from COPR repo - package: name={{item}} state=latest - with_items: - - restraint - - restraint-rhts - - restraint-client - -- name: Install beakerlib libraries from mvadkert/beakerlib-libraries COPR repo - package: name={{item}} state=latest - with_items: - - beakerlib-libraries - when: use_beakerlib_libraries - -- name: Install any test-specific package requirements - package: name={{item}} state=latest - with_items: - - "{{ required_packages }}" - -- 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 - -- name: Define remote_artifacts if it is not already defined - set_fact: - remote_artifacts: /tmp/artifacts - when: remote_artifacts is not defined - -- name: Create legacy beakerlib directories - file: - dest: "{{ item }}" - state: directory - with_items: - - /usr/lib/beakerlib - - /usr/share/rhts-library - -- name: Create legacy beakerlib links - file: - src: /usr/share/beakerlib/beakerlib.sh - dest: "{{ item }}" - state: link - with_items: - - /usr/lib/beakerlib/beakerlib.sh - - /usr/share/rhts-library/rhtslib.sh - -- name: Create RPM repo directory - file: - dest: "{{ repo_dir }}" - state: directory - -- name: Initialize RPM list - set_fact: - my_rpm_list: [] - -- name: Split 'rpms' argument into a list - set_fact: - my_rpm_list: "{{ rpms.split(' ') | unique }}" - when: rpms is defined and rpms|length > 0 - -- name: Copy RPMs to target - copy: - src: "{{ item }}" - dest: "{{ repo_dir }}/" - with_items: - - "{{ my_rpm_list }}" - -- name: Generate RPM repo metadata - shell: createrepo "{{ repo_dir }}" - -- name: Add RPM repo - yum_repository: - name: local - description: local repo - baseurl: "file://{{ repo_dir }}" - gpgcheck: no - -- name: Set list of SRPMs - set_fact: - my_srpm_list: "{{ my_rpm_list - | map('regex_search', '^.*\\.src\\.rpm$') - | select('string') | list }}" - -- name: Set list of non-SRPMs - set_fact: - my_nonsrpm_list: "{{ my_rpm_list | difference(my_srpm_list) }}" - -- name: Map non-SRPMs to target paths to be installed - set_fact: - my_install_rpm_list: "{{ my_nonsrpm_list | map('basename') - | map('regex_replace', '^', repo_dir ~ '/') - | list }}" - -- name: Install RPMs - shell: dnf install -y {{ my_install_rpm_list | join(' ') }} - when: my_install_rpm_list|length > 0 - -- name: Create tests directory - file: - dest: "{{ test_dir }}" - state: directory - -- name: Copy tests to target - synchronize: - src: "{{ playbook_dir }}/{{ item }}" - dest: "{{ test_dir }}/" - recursive: yes - ssh_args: "-o UserKnownHostsFile=/dev/null" - with_items: - - "{{ tests }}" - -- block: - - name: Resolve test dependencies of beakerlib libraries - script: "{{ role_path }}/files/resolve-test-dependencies {{ test_dir }}/{{ item }}" - with_items: - - "{{ tests }}" - register: deps - environment: - BEAKERLIB_LIBRARY_PATH: /usr/share/beakerlib-libraries - - - name: Install required packages from RhtsRequires - package: name={{ item }} state=latest - with_items: - - "{{ deps.results[0].stdout_lines[0].split() }}" - - - name: Install packages from Requires, skip those not available packages - command: dnf -y install --skip-broken {{ deps.results[0].stdout_lines[1] }} - when: deps.results[0].stdout_lines[1].strip() != "" - - when: use_beakerlib_libraries - -- name: Generate test archives for restraint - shell: tar czf "{{ test_dir }}/{{ item | basename }}.tgz" -C "{{ test_dir }}" "{{ item | basename }}" - with_items: - - "{{ tests }}" - -- name: Generate restraint job XML file - template: - # template references variables 'tests' and 'local_www_port' - src: job.xml.j2 - dest: "{{ job_xml_file }}" - -- name: Copy restraint results conversion stylesheet to target - copy: - src: job2text.xsl - dest: /usr/local/share/ - -- name: Create root SSH directory - file: - dest: /root/.ssh - state: directory - mode: 0700 - -- name: Create root SSH key pair - shell: ssh-keygen -q -t rsa -N '' -f /root/.ssh/id_rsa - args: - creates: /root/.ssh/id_rsa - -- name: Create root SSH public key - shell: ssh-keygen -y -f /root/.ssh/id_rsa > /root/.ssh/id_rsa.pub - args: - creates: /root/.ssh/id_rsa.pub - -- name: Procure root public key - shell: cat /root/.ssh/id_rsa.pub - register: my_pub_key_output - -- name: Configure password-less local SSH for restraint - authorized_key: - user: root - state: present - key: "{{ my_pub_key_output.stdout }}" - -- name: Check if SSHD is running - wait_for: port=22 search_regex=OpenSSH timeout=3 - ignore_errors: true - register: sshd_check - -- block: # SSHD not running; configure and start it - - - name: Create host SSH key pair - shell: ssh-keygen -q -t rsa -N '' -f /etc/ssh/ssh_host_rsa_key - args: - creates: /etc/ssh/ssh_host_rsa_key - - - name: Start SSHD in background - shell: /usr/sbin/sshd - - - name: Wait for SSHD to start - wait_for: port=22 search_regex=OpenSSH - - when: sshd_check|failed - -- name: Make artifacts directory - file: path={{ remote_artifacts }} state=directory owner=root mode=755 recurse=yes - -- name: Start restraintd - # instead of using service module, daemon is started directly since we want the - # output as an artifact (and this could be running in a container) - shell: nohup /usr/bin/restraintd >"{{ remote_artifacts }}/restraintd.log" 2>&1 & - -- name: Start local web server for restraint - shell: nohup /usr/bin/python -m SimpleHTTPServer "{{ local_www_port }}" >"{{ remote_artifacts }}/httpd.log" 2>&1 & - args: - chdir: "{{ local_www_dir }}/" - -- block: - - name: Execute RHTS tests using restraint - shell: /usr/bin/restraint --host localhost --job "{{ job_xml_file }}" >"{{ remote_artifacts }}/restraint.log" 2>&1 - args: - chdir: "{{ remote_artifacts }}/" - ignore_errors: True - register: restraint_result - -- always: - - name: Extract job output directory from restraint logfile - shell: sed -n 's/^Using \([^ ]*\).*$/\1/p' "{{ remote_artifacts }}/restraint.log" - register: restraint_job_dir - - - name: Make job ouput directory tree readable by all - file: - path: "{{ remote_artifacts }}/{{restraint_job_dir.stdout}}" - mode: u=rwX,g=rX,o=rX - recurse: yes - - - name: Set name of restraint XML job results file - set_fact: results_xml="{{ remote_artifacts }}/{{restraint_job_dir.stdout}}/job.xml" - - - name: Convert restraint XML job results to text as main output artifact - shell: xsltproc /usr/local/share/job2text.xsl "{{ results_xml }}" >"{{ remote_artifacts }}/test.log" - - - name: Pull out the logs - synchronize: - dest: "{{ artifacts }}/" - src: "{{ remote_artifacts }}/" - mode: pull - ssh_args: "-o UserKnownHostsFile=/dev/null" - when: artifacts|default("") != "" - - - name: Check the results for failures - shell: egrep '^(FAIL|WARN|None) ' "{{ remote_artifacts }}/test.log" - register: test_fails - failed_when: test_fails.stdout or test_fails.stderr or restraint_result.rc != 0 diff --git a/roles/standard-test-rhts/templates/job.xml.j2 b/roles/standard-test-rhts/templates/job.xml.j2 deleted file mode 100644 index 5fddd1f..0000000 --- a/roles/standard-test-rhts/templates/job.xml.j2 +++ /dev/null @@ -1,16 +0,0 @@ - - - -{% for item in tests %} - - - {% if use_beakerlib_libraries %} - - - - {% endif %} - -{% endfor %} - - - diff --git a/roles/standard-test-rhts/vars/main.yml b/roles/standard-test-rhts/vars/main.yml deleted file mode 100644 index d0486b2..0000000 --- a/roles/standard-test-rhts/vars/main.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -remote_artifacts: /tmp/artifacts -tests: [] -required_packages: [] -local_www_dir: "/var/www-test" -local_www_port: 8888 -test_dir: "{{local_www_dir}}" -repo_dir: "/var/tmp/local_repo" -job_xml_file: "{{local_www_dir}}/job.xml" diff --git a/roles/str-common-init/tasks/main.yml b/roles/str-common-init/tasks/main.yml index f259710..8b88da4 100644 --- a/roles/str-common-init/tasks/main.yml +++ b/roles/str-common-init/tasks/main.yml @@ -13,7 +13,14 @@ verbosity: 1 - import_tasks: trunner.yml -- import_tasks: pkgs.yml + +- name: Install packages requested in `required_packages` section from tests.yml + include_role: + name: str-common-pkgs + vars: + param_req_pkgs: + - "{{ required_packages|d|list|flatten }}" + - "{{ role_pkgs_req|d|list|flatten }}" - name: Make artifacts directory file: path={{ remote_artifacts }} state=directory owner=root mode=755 recurse=yes diff --git a/roles/str-common-init/tasks/pkgs-dnf.yml b/roles/str-common-init/tasks/pkgs-dnf.yml deleted file mode 100644 index a030c16..0000000 --- a/roles/str-common-init/tasks/pkgs-dnf.yml +++ /dev/null @@ -1,33 +0,0 @@ -- name: Install test-specific package requirements - # Note, this method cannot install -debuginfo packages. - package: name={{item}} state=present - with_flattened: - - "{{ pkgs_ordinary_req|d|list|flatten }}" - - "{{ role_pkgs_req|d|list|flatten }}" - -- 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. - # 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|d|list }}" - -- block: - - package: name=dnf-plugins-core state=present - - shell: dnf copr enable -y {{item}} - with_items: - - "{{copr_repos}}" - name: Enable copr repos using DNF - ignore_errors: True - when: copr_repos is defined diff --git a/roles/str-common-init/tasks/pkgs-rpm-ostree.yml b/roles/str-common-init/tasks/pkgs-rpm-ostree.yml deleted file mode 100644 index 3bbb099..0000000 --- a/roles/str-common-init/tasks/pkgs-rpm-ostree.yml +++ /dev/null @@ -1,20 +0,0 @@ -- block: - - name: Make a list of requested packages for Atomic Host - set_fact: - pkgs_atomic_req: "{{ pkgs_ordinary_req|d|flatten|join(' ') }} {{ role_pkgs_req|d|list|flatten|join(' ') }}" - - debug: - msg: "Requested packages for Atomic Host: {{ pkgs_atomic_req }}" - verbosity: 1 - - name: Check presence of test-specific package requirements - shell: rpm -q {{ pkgs_atomic_req }} - register: package_check - changed_when: False - failed_when: False - args: { warn: no } - - name: Install test-specific package requirements - shell: - rpm-ostree install {{ pkgs_atomic_req }} - && rpm-ostree ex livefs - when: package_check.rc != 0 - when: (pkgs_ordinary_req|d(false)) or - (role_pkgs_req|d(false)) diff --git a/roles/str-common-init/tasks/pkgs-yum.yml b/roles/str-common-init/tasks/pkgs-yum.yml deleted file mode 100644 index f1c9060..0000000 --- a/roles/str-common-init/tasks/pkgs-yum.yml +++ /dev/null @@ -1,31 +0,0 @@ -- name: Install test-specific package requirements - # Note, this method cannot install -debuginfo packages. - package: name={{item}} state=present - with_flattened: - - "{{ pkgs_ordinary_req|d|list|flatten }}" - - "{{ role_pkgs_req|d|list|flatten }}" - -- 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 - when: ansible_pkg_mgr == "yum" - - - name: Care about debuginfo packages for YUM systems - shell: | - debuginfo-install --assumeyes {{item}} - with_items: - - "{{ pkgs_debuginfo_req|d|list }}" - -- block: - - package: name=yum-plugin-copr state=present - - shell: yum copr -y {{item}} - with_items: - - "{{copr_repos}}" - name: Enable copr repos using YUM - ignore_errors: True - when: copr_repos is defined diff --git a/roles/str-common-init/tasks/pkgs.yml b/roles/str-common-init/tasks/pkgs.yml deleted file mode 100644 index ae9a0c9..0000000 --- a/roles/str-common-init/tasks/pkgs.yml +++ /dev/null @@ -1,31 +0,0 @@ -- 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 (is_atomic and - (ansible_pkg_mgr == 'unknown' or - ansible_pkg_mgr == 'atomic_container')) 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-pkgs/defaults/main.yml b/roles/str-common-pkgs/defaults/main.yml new file mode 100644 index 0000000..9981d95 --- /dev/null +++ b/roles/str-common-pkgs/defaults/main.yml @@ -0,0 +1,12 @@ +--- + +tests: [] +required_packages: [] +tenv_workdir: /var/str/ +remote_artifacts: /tmp/artifacts/ +test_runner_inventory_name: test-runner +artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}" +# distro_name: rhel, centos, fedora +distro_name: "{{ansible_distribution|lower}}" +# distro_name_ver: rhel_7, centos_7, fedora_22 +distro_name_ver: "{{ansible_distribution|lower}}_{{ansible_distribution_major_version}}" diff --git a/roles/str-common-pkgs/tasks/inspect.yml b/roles/str-common-pkgs/tasks/inspect.yml new file mode 100644 index 0000000..74d7a86 --- /dev/null +++ b/roles/str-common-pkgs/tasks/inspect.yml @@ -0,0 +1,35 @@ +- 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' + delegate_facts: True + set_fact: + is_atomic : "{{ os_release_atomic.found > 0 }}" + +- name: Set facts about system + delegate_facts: True + set_fact: + is_yum_os: >- + {{ ansible_pkg_mgr == 'yum' }} + is_dnf_os: >- + {{ ansible_pkg_mgr == 'dnf' }} + is_rhel8_based: >- + {{ + ( ['ansible_distribution'] | + intersect(['RedHat', 'CentOS']) | bool ) and + ansible_distribution_version|int == 8 + }} + +# Fix python ansible interpreter when running on RHEL8. Currently RHEL8 +# uses python2, but it does miss some python2 modules, such as python2-dnf. +# This can be removed once RHEL8 uses by default Python3 +- name: Hardcode Python interpreter for ansible modules on RHEL8 based OS + set_fact: + ansible_python_interpreter: /usr/bin/env python3 + when: is_rhel8_based diff --git a/roles/str-common-pkgs/tasks/main.yml b/roles/str-common-pkgs/tasks/main.yml new file mode 100644 index 0000000..6852766 --- /dev/null +++ b/roles/str-common-pkgs/tasks/main.yml @@ -0,0 +1,32 @@ +- 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: > + {{ + param_req_pkgs | flatten | + reject('match', '.*-debuginfo$') | + list + }} + pkgs_debuginfo_req: > + {{ + param_req_pkgs | flatten | + select('match', '.*-debuginfo$') | + list | + regex_replace('-debuginfo') + }} + pkg_mgr: > + {{ + 'rpm-ostree' if (is_atomic and + (ansible_pkg_mgr == 'unknown' or + ansible_pkg_mgr == 'atomic_container')) 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-pkgs/tasks/pkgs-dnf.yml b/roles/str-common-pkgs/tasks/pkgs-dnf.yml new file mode 100644 index 0000000..8665637 --- /dev/null +++ b/roles/str-common-pkgs/tasks/pkgs-dnf.yml @@ -0,0 +1,29 @@ +- name: Remove yum-utils for dnf system + package: name=yum-utils state=absent + +- name: Install additional dnf packages + package: name={{ item }} state=present + with_items: + - dnf-plugins-core + - dnf-utils + +- name: Enable copr repos + shell: dnf copr enable -y {{ item }} + with_flattened: + # Copr repos required by tests + - "{{ copr_repos_req|d|list|flatten }}" + # Copr repos required by roles + - "{{ role_copr_repos_req|d|list|flatten }}" + ignore_errors: True + +- name: Install test-specific package requirements + # Note, this method cannot install -debuginfo packages. + package: name={{ item }} state=present + with_flattened: + - "{{ pkgs_ordinary_req|d|list|flatten }}" + +- name: Install debuginfo packages + shell: | + debuginfo-install --assumeyes {{item}} + with_items: + - "{{ pkgs_debuginfo_req|d|list }}" diff --git a/roles/str-common-pkgs/tasks/pkgs-rpm-ostree.yml b/roles/str-common-pkgs/tasks/pkgs-rpm-ostree.yml new file mode 100644 index 0000000..0748d45 --- /dev/null +++ b/roles/str-common-pkgs/tasks/pkgs-rpm-ostree.yml @@ -0,0 +1,57 @@ +- name: Enable copr repos on Atomic Host + # It is possible to add .repo file to /etc/yum.repos.d/ and install required + # packages. + shell: | + # This code was traslitirated from /usr/lib/yum-plugins/copr.py + # item == mvadkert/beakerlib-libraries + PROJECT="{{ item }}" + REPO_FILE="${PROJECT//\//-}" + REPO_FILE="/etc/yum.repos.d/_copr_${REPO_FILE}.repo" + if [ -e "$REPO_FILE" ]; then + echo "Warning: $REPO_FILE already exists. Exit." + exit + fi + VERSION_ID="$(source /etc/os-release; echo $VERSION_ID)" # 7, 27, Rawhide has: next release + VERSION="$(source /etc/os-release; echo $VERSION)" # "7 (Core)" "27 (Atomic Host)" "29 (Rawhide)" + ID="$(source /etc/os-release; echo $ID)" # centos, fedora + ARCH="$(uname -m)" + CHROOT="epel-$VERSION_ID-$ARCH" + if [ "$ID" = "fedora" ]; then + case "$VERSION" in + *Rawhide*) + CHROOT="fedora-rawhide-$ARCH" + ;; + *) + CHROOT="fedora-$VERSION_ID-$ARCH" + ;; + esac + fi + URL="http://copr.fedoraproject.org/coprs/$PROJECT/repo/$CHROOT/" + echo "$URL" + curl "$URL" -L --retry 5 --output "$REPO_FILE" + with_flattened: + # Copr repos required by tests + - "{{ copr_repos_req|d|list|flatten }}" + # Copr repos required by roles + - "{{ role_copr_repos_req|d|list|flatten }}" + ignore_errors: True + +- block: + - name: Make a list of requested packages for Atomic Host + set_fact: + pkgs_atomic_req: "{{ pkgs_ordinary_req|d|flatten|join(' ') }} " + - debug: + msg: "Requested packages for Atomic Host: {{ pkgs_atomic_req }}" + verbosity: 1 + - name: Check presence of test-specific package requirements + shell: rpm -q {{ pkgs_atomic_req }} + register: package_check + changed_when: False + failed_when: False + args: { warn: no } + - name: Install test-specific package requirements + shell: + rpm-ostree install {{ pkgs_atomic_req }} + && rpm-ostree ex livefs + when: package_check.rc != 0 + when: pkgs_ordinary_req|d(false) diff --git a/roles/str-common-pkgs/tasks/pkgs-yum.yml b/roles/str-common-pkgs/tasks/pkgs-yum.yml new file mode 100644 index 0000000..ade5da0 --- /dev/null +++ b/roles/str-common-pkgs/tasks/pkgs-yum.yml @@ -0,0 +1,27 @@ +- name: Install additional yum packages + package: name={{ item }} state=present + with_items: + - yum-plugin-copr + - yum-utils + +- name: Enable copr repos + shell: yum copr enable -y {{ item }} + with_flattened: + # Copr repos required by tests + - "{{ copr_repos_req|d|list|flatten }}" + # Copr repos required by roles + - "{{ role_copr_repos_req|d|list|flatten }}" + ignore_errors: True + +- name: Install test-specific package requirements + # Note, this method cannot install -debuginfo packages. + package: name={{ item }} state=present + with_flattened: + - "{{ pkgs_ordinary_req|d|list|flatten }}" + +- name: Install debuginfo packages + shell: | + debuginfo-install --assumeyes {{item}} + with_items: + - "{{ pkgs_debuginfo_req|d|list }}" +