From bf3ae914d331b0b12cbd8cd2769efeff4d00dc3d Mon Sep 17 00:00:00 2001 From: Miroslav Vadkerti Date: Oct 18 2017 17:34:19 +0000 Subject: standard-test-rhts: add support for beakerlib-libraries This patch adds optional resolving of test dependencies, including beakerlib libraries from beakerlib tests' Makefile. Note that the resolving of dependencires is required for beakerlib libraries (because they are packages without dependencies). To activate this feature pass to the role this variable: use_beakerlib_libraries: yes By default this feature is disabled (we might enable it after testing). Signed-off-by: Miroslav Vadkerti --- diff --git a/roles/standard-test-rhts/defaults/main.yml b/roles/standard-test-rhts/defaults/main.yml index fe31a1a..dfab937 100644 --- a/roles/standard-test-rhts/defaults/main.yml +++ b/roles/standard-test-rhts/defaults/main.yml @@ -1,3 +1,17 @@ --- 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/resolve-test-dependencies b/roles/standard-test-rhts/files/resolve-test-dependencies new file mode 100755 index 0000000..46a03a7 --- /dev/null +++ b/roles/standard-test-rhts/files/resolve-test-dependencies @@ -0,0 +1,141 @@ +#!/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 index 1e59415..6b83777 100644 --- a/roles/standard-test-rhts/tasks/main.yml +++ b/roles/standard-test-rhts/tasks/main.yml @@ -12,6 +12,10 @@ - name: Enable COPR repo for restraint shell: dnf copr -y enable bpeck/restraint +- name: Enable COPR repo for beakerlib-libraries + shell: dnf copr -y enable mvadkert/beakerlib-libraries + when: use_beakerlib_libraries + - name: Install restraint from COPR repo package: name={{item}} state=latest with_items: @@ -19,6 +23,12 @@ - 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: @@ -103,12 +113,34 @@ state: directory - name: Copy tests to target - copy: + 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: diff --git a/roles/standard-test-rhts/templates/job.xml.j2 b/roles/standard-test-rhts/templates/job.xml.j2 index 3f7bc99..5fddd1f 100644 --- a/roles/standard-test-rhts/templates/job.xml.j2 +++ b/roles/standard-test-rhts/templates/job.xml.j2 @@ -4,6 +4,11 @@ {% for item in tests %} + {% if use_beakerlib_libraries %} + + + + {% endif %} {% endfor %}