From 84bdd683fe79f5a90e24510c736abec1c76e9e06 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sep 22 2017 11:51:31 +0000 Subject: standard-test-source: A new standard role to extract sources This logic is used when invoking tests that are packaged in the upstream tarball or sources. It is a technique used by the rpm-ostree and cockpit tests. Put this role in your tests.yml playbook. The playbook will extract the upstream source tarball as described in the package spec file into a test/source/ directory. You can then use or execute files (usually tests) from the upstream sources in your playbook. You can redefine the following variables: * srcdir: A directory to extract sources into. This defaults to {{ playbook_dir }}/source/ * flatten: Strip one level of path prefix in source tree. This defaults to True --- diff --git a/roles/standard-test-source/README.md b/roles/standard-test-source/README.md new file mode 100644 index 0000000..2b8e9a3 --- /dev/null +++ b/roles/standard-test-source/README.md @@ -0,0 +1,14 @@ +# Ansible role for Upstream source tarball tests + +Put this role in your tests.yml playbook. The playbook +will extract the upstream source tarball as described in +the package spec file into a test/source/ directory. You +can then use or execute files (usually tests) from the +upstream sources in your playbook. + +You can redefine the following variables: + + * srcdir: A directory to extract sources into. This defaults + to {{ playbook_dir }}/source/ + * flatten: Strip one level of path prefix in source tree. This + defaults to True diff --git a/roles/standard-test-source/defaults/main.yml b/roles/standard-test-source/defaults/main.yml new file mode 100644 index 0000000..ceb88f4 --- /dev/null +++ b/roles/standard-test-source/defaults/main.yml @@ -0,0 +1,2 @@ +--- +artifacts: "{{ lookup('env', 'TEST_ARTIFACTS') | default('./artifacts', true) }}" diff --git a/roles/standard-test-source/tasks/main.yml b/roles/standard-test-source/tasks/main.yml new file mode 100644 index 0000000..a186f7e --- /dev/null +++ b/roles/standard-test-source/tasks/main.yml @@ -0,0 +1,34 @@ +--- +- name: Add executor host + add_host: + name: executor + ansible_connection: local + ansible_ssh_host: 127.0.0.1 + ansible_ssh_connection: local + +- name: Extract package source code + delegate_to: executor + block: + - name: Gather facts + setup: + delegate_facts: True + + - name: Install requirements + package: name={{item}} state=present + with_items: + - fedpkg + + # The dist doesn't actually matter here + - name: Download sources, extract, and strip leading path + shell: | + set -e + rm -rf {{ srcdir }} + fedpkg --release=master prep --builddir={{ srcdir }} + args: + chdir: "{{playbook_dir}}/.." + + - name: Flatten sources + shell: | + shopt -s dotglob + mv {{ srcdir }}/*/* {{ srcdir }} + when: flatten diff --git a/roles/standard-test-source/vars/main.yml b/roles/standard-test-source/vars/main.yml new file mode 100644 index 0000000..51a578d --- /dev/null +++ b/roles/standard-test-source/vars/main.yml @@ -0,0 +1,3 @@ +--- +srcdir: "{{ playbook_dir }}/source" +flatten: True