#95 Adding standard-test-behave-role for running behave tests
Opened 3 years ago by esakaiev. Modified 3 years ago
esakaiev/standard-test-roles master  into  master

@@ -0,0 +1,16 @@ 

+ # Ansible role for Behave tests

+ 

+ Put this role in your test_local.yml playbook. 

+ You can redefine the following variables in 

+ roles/standard-test-behave/vars/main.yml:

+ 

+  * features: A list of behave test files

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

+      behave tests.

+  * tests_folder - ("." by default) - path folder, where need to execute tests

+  * run_in_background - (true/false) option for behave tests, if need to runall 

+    tests in parallel as daemon process

@@ -0,0 +1,112 @@ 

+ ---

+ - 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: 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=present

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

+            cd /usr/local/bin/{{ tests_folder }}

+            ./dnf-testing.sh run {{ item }} > test.{{ item }}.log 2>&1

+     with_items:

+     - "{{ features }}"

+     when: not run_in_background

+ 

+ 

+ - block:

+   - name: Running behave tests

+     shell: |

+            cd /usr/local/bin/{{ tests_folder }}

+            ./dnf-testing.sh run {{ item }} > test.{{ item }}.log 2>&1 &

+            echo $!

+     register: proc_id

+     with_items:

+     - "{{ features }}"

+     when: run_in_background

+ 

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

+     shell: |

+         while ps -p  {{ item.stdout }}| grep {{ item.stdout }}

+         do

+             sleep 2

+         done

+     when: run_in_background

+     with_items:

+     - "{{ proc_id.results }}"

+ 

+   - name: Move logs to the remote_artifacts

+     shell: |

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

+         cd /usr/local/bin/{{ tests_folder }}

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

+         sudo rm $logfile

+     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

+         echo FAIL

+       else

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

+         echo PASS

+       fi

+     register: test_results

+     failed_when: "'FAIL' in test_results.stdout"

+     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("") != ""

@@ -0,0 +1,6 @@ 

+ ---

+ remote_artifacts: /tmp/artifacts

+ tests_folder: '.' 

+ features: []

+ required_packages: []

+ run_in_background: false

Justification

  1. The main goal is to adopt current dnf_docker tests for ci_pipeline, see https://pagure.io/fedora-ci/AtomicCi/pull-request/74.

  2. Added new role standard-test-behave, which includes possibility to run tests in parallel, starting it as daemon.

1 new commit added

  • Improving standard-test-behave tasks
3 years ago

This is not role for Beakerlib tests.

This README.md isn't suit for this role.

restraint-rhts is it necessary ? restraint-rhts - is another test framework, why to install it?

Please change to: package: name={{item}} state=present

Do Behave test have runtest.sh ? runtest.sh is from beakerlib.

Do Behave test have Makefile ? runtest.sh is from Makefile.

Please add comment what this function does.

Need to find have Behave tests report about failed tests.

Hi,
Main purpose of using check_cpu_usage function is for running tests in parallel, to avoid of CPU overloading.

1 new commit added

  • Adding changes for standard-test-behave role in standart-test-roles, removed rpm and default folders
3 years ago

1 new commit added

  • Modified README.md for standard-behave-test
3 years ago

Hi, in 2.6 release we got a new role: standard-test-basic role
I wonder, if it is possible to use it?
In this case you need to modify tests.yml file.