diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..eae05e5 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1,3 @@ +*.retry +artifacts/ +source/ diff --git a/tests/roles/standard-test-overlay/README.md b/tests/roles/standard-test-overlay/README.md new file mode 100644 index 0000000..17ac2f4 --- /dev/null +++ b/tests/roles/standard-test-overlay/README.md @@ -0,0 +1,12 @@ +# Ansible role for overlaying Atomic Host packages + +Certain Atomic Host use cases require that packages are +overlaid onto the host. This role allows you to do that. + +You should not use this role to indiscriminately overlay test +dependencies into the Atomic Host unless those dependencies are +part of a real end user story. + +You should define the following variables: + + * packages: A list of packages to overlay diff --git a/tests/roles/standard-test-overlay/tasks/main.yml b/tests/roles/standard-test-overlay/tasks/main.yml new file mode 100644 index 0000000..51b6a0b --- /dev/null +++ b/tests/roles/standard-test-overlay/tasks/main.yml @@ -0,0 +1,17 @@ +--- +- block: + - name: Overlaying end user packages onto Atomic Host + shell: rpm-ostree install {{ packages | join(" ") }} + + - name: Reboot the Atomic Host + shell: sleep 2 && systemctl reboot + ignore_errors: true + async: 1 + poll: 0 + + - name: Waiting for Atomic Host to restart + local_action: wait_for host={{ ansible_ssh_host }} search_regex=OpenSSH port={{ ansible_ssh_port }} timeout=300 delay=20 connect_timeout=20 + become: false + + # All these commands only apply to Atomic Host + tags: atomic diff --git a/tests/roles/standard-test-overlay/vars/main.yml b/tests/roles/standard-test-overlay/vars/main.yml new file mode 100644 index 0000000..b6e94dd --- /dev/null +++ b/tests/roles/standard-test-overlay/vars/main.yml @@ -0,0 +1,2 @@ +--- +packages: [] diff --git a/tests/roles/standard-test-scripts/README.md b/tests/roles/standard-test-scripts/README.md new file mode 100644 index 0000000..c10c34d --- /dev/null +++ b/tests/roles/standard-test-scripts/README.md @@ -0,0 +1,17 @@ +# Ansible role for executing test scripts + +Put this role in your tests.yml playbook and specify a +number of test scripts to execute as tests. The results +of each script will be piped into log file in the artifacts +directory. If any script exits with a non-zero exit code +the role will fail. + +In the case of test subjects such a host or container, these +test scripts and related files will be copied to the target into +/usr/local/bin before execution. + +You should define the following variables: + + * tests: An array of scripts to run + * files: A list of files or directories needed by the scripts + diff --git a/tests/roles/standard-test-scripts/defaults/main.yml b/tests/roles/standard-test-scripts/defaults/main.yml new file mode 100644 index 0000000..ceb88f4 --- /dev/null +++ b/tests/roles/standard-test-scripts/defaults/main.yml @@ -0,0 +1,2 @@ +--- +artifacts: "{{ lookup('env', 'TEST_ARTIFACTS') | default('./artifacts', true) }}" diff --git a/tests/roles/standard-test-scripts/tasks/main.yml b/tests/roles/standard-test-scripts/tasks/main.yml new file mode 100644 index 0000000..cb25ba5 --- /dev/null +++ b/tests/roles/standard-test-scripts/tasks/main.yml @@ -0,0 +1,33 @@ +--- +- name: Copy test scripts to target + synchronize: + src: "{{ item }}" + dest: /usr/local/bin/ + ssh_args: "-o UserKnownHostsFile=/dev/null" + with_items: + - "{{ tests }}" + - "{{ files }}" + +- block: + - name: Execute test scripts + shell: | + mkdir -p /tmp/artifacts + logfile=/tmp/artifacts/test.$(echo {{ item }} | sed -e 's/\//-/g').log + exec 2>>$logfile 1>>$logfile + cd /usr/local/bin + if [ -x {{ item }} ]; then + ./$(basename {{ item }}) && result="PASS" || result="FAIL" + else + /bin/sh -e ./$(basename {{ item }}) && result="PASS" || result="FAIL" + fi + echo "$result {{ item }}" >> /tmp/artifacts/test.log + with_items: + - "{{ tests }}" + + always: + - name: Pull out the logs + synchronize: + dest: "{{ artifacts }}" + src: "/tmp/artifacts/./" + mode: pull + when: artifacts|default("") != "" diff --git a/tests/roles/standard-test-scripts/vars/main.yml b/tests/roles/standard-test-scripts/vars/main.yml new file mode 100644 index 0000000..81108ab --- /dev/null +++ b/tests/roles/standard-test-scripts/vars/main.yml @@ -0,0 +1,3 @@ +--- +tests: [] +files: [] diff --git a/tests/roles/standard-test-source/README.md b/tests/roles/standard-test-source/README.md new file mode 100644 index 0000000..49b1245 --- /dev/null +++ b/tests/roles/standard-test-source/README.md @@ -0,0 +1,12 @@ +# 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/ diff --git a/tests/roles/standard-test-source/defaults/main.yml b/tests/roles/standard-test-source/defaults/main.yml new file mode 100644 index 0000000..ceb88f4 --- /dev/null +++ b/tests/roles/standard-test-source/defaults/main.yml @@ -0,0 +1,2 @@ +--- +artifacts: "{{ lookup('env', 'TEST_ARTIFACTS') | default('./artifacts', true) }}" diff --git a/tests/roles/standard-test-source/tasks/main.yml b/tests/roles/standard-test-source/tasks/main.yml new file mode 100644 index 0000000..cc2c4a9 --- /dev/null +++ b/tests/roles/standard-test-source/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- 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: | + shopt -s dotglob + set -e + rm -rf {{ srcdir }} + fedpkg --release=master prep --builddir={{ srcdir }} + mv {{ srcdir }}/*/* {{ srcdir }} + args: + chdir: "{{playbook_dir}}/.." diff --git a/tests/roles/standard-test-source/vars/main.yml b/tests/roles/standard-test-source/vars/main.yml new file mode 100644 index 0000000..12a4a4c --- /dev/null +++ b/tests/roles/standard-test-source/vars/main.yml @@ -0,0 +1,2 @@ +--- +srcdir: "{{ playbook_dir }}/source" diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..62e8575 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,20 @@ +--- +- hosts: localhost + roles: + - role: standard-test-source + tags: + - always + + - role: standard-test-overlay + tags: + - atomic + packages: + - cockpit-ws + - cockpit-dashboard + + - role: standard-test-scripts + tags: + - atomic + - classic + tests: + - ./source/tools/debian/tests/smoke