#58 standard-test-source: A new standard role to extract sources
Merged 6 years ago by merlinm. Opened 6 years ago by stefw.
stefw/standard-test-roles standard-test-source  into  master

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

@@ -0,0 +1,2 @@ 

+ ---

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

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

@@ -0,0 +1,3 @@ 

+ ---

+ srcdir: "{{ playbook_dir }}/source"

+ flatten: True

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/

rebased onto 84bdd68

6 years ago

Updated with a 'flatten' variable

Tested it out. Works as documented as long as (1) a current enough version of fedpkg is installed that supports the --release option and (2) tests are run from within a dist-git repo.

Pull-Request has been merged by merlinm

6 years ago

Thanks for merging.

  1. The test specification [0] says the tests must be run from within a dist-git repo.
  2. Which version doesn't support --dist? On Fedora 24 I see --release in fedpkg --help

The test specification [0] says the tests must be run from within a dist-git repo.

Right. When I first tried running it directly from an upstreamfirst repo, it didn't work. I think this is the first case I've run across that needs to be run from within a dist-git repo.

Which version doesn't support --dist? On Fedora 24 I see --release in fedpkg --help

The F25 host I happened to select as my testing system still had a very outdated version of fedpkg installed. Version 1.25-1 it seems. Upon updating to 1.29-4, all was well.