#259 Proceed beakerlib tests dependency individually.
Merged 5 years ago by astepano. Opened 5 years ago by astepano.

@@ -1,144 +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.

- #

- # 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 <jheger@redhat.com>

- #  Martin Kyral <mkyral@redhat.com>

- #  Miroslav Vadkerti <mvadkert@redhat.com>

- #

- 

- [ -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 <<EOF

-     usage: $(basename $0) [-h] TEST_PATH

- 

- 

-     Authors:

-       Jakub Heger <jheger AT redhat.com>

-       Martin Kyral <mkyral AT redhat.com>

-       Miroslav Vadkerti <mvadkert AT redhat.com>

- 

-     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 0

- 

- 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:

@@ -1,36 +1,5 @@ 

  ---

  

- - name: Get list of RPM packages listed at beakerlib tests' requirements

-   command: "{{ role_path }}/files/resolve-test-dependencies {{ playbook_dir }}/{{ item }}"

-   with_flattened:

-     # tests - is defined at tests.yml playbook

-     - "{{ tests }}"

-     - "{{ filter_tests }}"

-   register: deps

-   delegate_to: "{{ test_runner_inventory_name }}"

-   delegate_facts: True

-   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) }}"

-   when: deps.results[0].stdout_lines | length > 1

- 

- - debug:

-     msg:

-       - "RhtsRequires entry from Makefile: {{ makefile_pkgs_req1|d('None', true) }}"

-       - "Requires entry from Makefile: {{ makefile_pkgs_req2|d('None', true) }}"

-     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.
@@ -81,13 +50,6 @@ 

      - "rhts-environment.sh"

      - "rhts-run-simple-test"

  

- # 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

      shell: |
@@ -101,6 +63,8 @@ 

           /bin/sh -e ./$(basename {{ item }})

        elif [ -d {{ item }} ]; then

          cd {{ item }}

+         # get-test-deps - is part of beakerlib-libraries

+         get-test-deps -i .

          if [ -f Makefile ] && command -p -v make >/dev/null 2>&1; then

            make run

          elif [ -f runtest.sh ]; then
@@ -114,6 +78,8 @@ 

      with_items:

      - "{{ tests }}"

      - "{{ filter_tests }}"

+     environment:

+       BEAKERLIB_LIBRARY_PATH: "{{ beakerlib_libraries_path }}"

  

    always:

    - name: Make the master tests summary log artifact

rebased onto 09f3dece90f12131a7dd19bba0c38095a79b80fe

5 years ago

rebased onto a654f66c3f64c83ba61e2c7d3ca1d972a8078cf3

5 years ago

As this checks deps by looking the Makefile, maybe this could be executed under the if Makefile.
Also, some comment saying this script is provided by beakerlib-libraries would be nice :)

Looks good.

rebased onto f19337719608498a840be0c96d9a9e76b2c453c0

5 years ago

get-test-deps - has internal logic to check if Makefile is present. If Makefile is absent that it silently exits .

Will this also add support for installing individual test dependencies specified in test Makefile? That would be very useful.

rebased onto bd71304

5 years ago

It should now with this PR.

Commit 215caca fixes this pull-request

Pull-Request has been merged by astepano

5 years ago

Pull-Request has been merged by astepano

5 years ago

It should now with this PR.

Very nice! Is there a package I could test with?