#73 Review for standard test behave role to the standard-test-roles, which adopted to the dnf-dnf-docker tests
Opened 6 years ago by esakaiev. Modified 6 years ago
git://fedorapeople.org/~esakaiev/standard-test-behave standard_test_behave  into  master

Adding standard behave test role to the standard_test_behave branch
esaka • 6 years ago  
README.md
file added
+8
@@ -0,0 +1,8 @@

+ # Behave role for Running behave 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-behave/vars/main.yml:

+ 

defaults/main.yml
file added
+2
@@ -0,0 +1,2 @@

+ ---

+ artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}"

files/rpm.py
file added
+15
@@ -0,0 +1,15 @@

+ #!/usr/bin/env python

+ 

+ # The purpose of this file is to satisfy /usr/bin/beakerlib-journalling use of "import rpm",

+ # particularly on Atomic Host which doesn't have python2-rpm package. beakerlib-journalling

+ # does basically nothing interesting with the data, and just gets the version of the RPM.

+ 

+ # Although tests that have been looked at so far work just fine with TransactionSet.dbMatch()

+ # returning empty results, it may be the case this needs to be extended to add further shim code.

+ 

+ class TransactionSet:

+    def dbMatch(self, key, value):

+        return []

+ 

+ def ts():

+     return TransactionSet()

tasks/main.yml
file added
+146
@@ -0,0 +1,146 @@

+ ---

+ - name: Add executor host

+   add_host:

+     name: executor

+     ansible_connection: local

+     ansible_ssh_host: 127.0.0.1

+     ansible_ssh_connection: local

+ 

+ - block:

+   - name: Gather facts

+     setup:

+     delegate_facts: True

+ 

+   - name: Add restraint repo for restraint-rhts on Fedora hosts

+     get_url:

+       url: https://copr.fedorainfracloud.org/coprs/bpeck/restraint/repo/fedora-{{ansible_distribution_major_version}}/bpeck-restraint-fedora-{{ansible_distribution_major_version}}.repo

+       dest: /etc/yum.repos.d/restraint.repo

+     when: ansible_distribution == 'Fedora'

+ 

+   - name: Add restraint repo for restraint-rhts on RHEL/CentOS hosts

+     get_url:

+       url: https://copr.fedorainfracloud.org/coprs/bpeck/restraint/repo/epel-7/bpeck-restraint-epel-7.repo

+       dest: /etc/yum.repos.d/restraint.repo

+     when: ansible_distribution == 'RedHat' or ansible_distribution == 'CentOS'

+ 

+   - name: Install the behave requirements

+     package: name={{item}} state=latest

+     with_items:

+     - python2-behave

+   delegate_to: executor

+ 

+ - block:

+   - name: Install the behave requirements on target

+     package: name={{item}} state=latest

+     with_items:

+     - python2-behave

+ 

+   - name: Install any test-specific package requirements

+     package: name={{item}} state=latest

+     with_items:

+       - "{{ required_packages }}"

+ 

+   # Only manually install packages on non atomic hosts

+   when: ansible_pkg_mgr != 'unknown'

+ 

+ - 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: Running behave tests

+     shell: |

+       export OUTPUTFILE=/dev/stdout TEST={{ item }}

+       logfile={{ remote_artifacts }}/test.$(echo {{ item }} | sed -e 's/\//-/g').log

+       exec 2>>$logfile 1>>$logfile    

+       cd /usr/local/bin

+       cd {{ tests_folder }}

+       if [ -f runtest.sh ]; then

+          /bin/sh -e ./runtest.sh {{ item }}

+       elif [ -f Makefile ]; then

+         make ARGS="{{item}}" run

+       else

+         echo "FAIL don't know how to run test {{ item }}"

+       fi

+     with_items:

+     - "{{ features }}"

+     when: not run_in_background

+ 

+ 

+ - block:

+   - name: Running behave tests

+     shell: |

+       export OUTPUTFILE=/dev/stdout TEST={{ item }}

+       exec 2>>$logfile 1>>$logfile 

+       cd /usr/local/bin

+       cd {{ tests_folder }}

+       if [ -f runtest.sh ]; then

+          /bin/sh -e ./runtest.sh {{ item }} &

+       elif [ -f Makefile ]; then

+         make ARGS="{{item}}" run &

+       else

+         echo "FAIL don't know how to run test {{ item }}"

+       fi

+     with_items:

+     - "{{ features }}"

+     when: run_in_background

+ 

+   - name: Waiting to finish of the behave background processes

+     shell: |

+         echo {{ item }}

+         while  docker ps | grep {{ item }} 

+         do

+             sleep 2

+         done

+     when: run_in_background

+     with_items:

+     - "{{ features }}"

+ 

+   - name: Move logs to the remote_artifacts

+     shell: |

+         logfile=test.$(echo {{ item }} | sed -e 's/\//-/g').log

+         cd /usr/local/bin

+         cd {{ tests_folder }}

+         sudo cat $logfile >> {{ remote_artifacts }}/$logfile

+         sudo rm $logfile

+     when: run_in_background

+     with_items:

+     - "{{ features }}"

+ 

+ 

+   always:

+   - name: Make the master test summary log artifact

+     shell: |

+       logfile={{ remote_artifacts }}/test.$(echo {{ item }} | sed -e 's/\//-/g').log

+       if grep -P ', ([1-9]*) (failed)' "$logfile"; then

+         echo "FAIL {{ item }}" >> {{ remote_artifacts }}/test.log

+       else

+         echo "PASS {{ item }}" >> {{ remote_artifacts }}/test.log

+       fi

+     with_items:

+     - "{{ features }}"

+ 

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

vars/main.yml
file added
+6
@@ -0,0 +1,6 @@

+ ---

+ remote_artifacts: /tmp/artifacts

+ tests_folder: '.' 

+ features: []

+ required_packages: []

+ run_in_background: false

no initial comment

!!!! Do not merge it with standard-test-roles.

Standard-test-behave role is adopted to the dnf-docker tests.

  1. tasks includes steps to run runtest.sh script, which will run behave tests under separate docker image, if run_in_background var is defined.

  2. run_in_background variable is added with aim for adding possibility to run tests in parallel.

  3. Added tests_folder var, specifying folder with runtest.sh script, which takes feature name.

  4. Added steps for monitoring of the background docker processes to gather all results for each tests from containers

  5. standard_inventory_behave script will be added with dnf_tests, because it adopted for specific needs.