diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8b42eb --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.retry diff --git a/.zuul.yaml b/.zuul.yaml index 826fe24..8aadcf2 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -13,10 +13,54 @@ post-run: tests/website-post.yaml success-url: logs/build/ +- job: + name: ara-component-integration-base + parent: base + vars: + integration_ansible_name: "{{ ansible_user_dir }}/src/github.com/ansible/ansible" + integration_ansible_version: null + required-projects: + - openstack/ara-infra + - openstack/ara-server + - openstack/ara-plugins + - openstack/ara-clients + run: playbooks/integration-tests.yaml + post-run: tests/integration-post.yaml + +- job: + name: ara-integration-fedora-devel + parent: ara-component-integration-base + nodeset: fedora-latest + required-projects: + - name: github.com/ansible/ansible + override-checkout: devel + +- job: + name: ara-integration-fedora-2.7 + parent: ara-component-integration-base + nodeset: fedora-latest + required-projects: + - name: github.com/ansible/ansible + override-checkout: stable-2.7 + +- job: + name: ara-integration-ubuntu-2.6 + parent: ara-component-integration-base + nodeset: ubuntu-bionic + required-projects: + - name: github.com/ansible/ansible + override-checkout: stable-2.6 + - project: check: jobs: - ara-infra-website + - ara-integration-fedora-2.7 + - ara-integration-fedora-devel: + voting: false + - ara-integration-ubuntu-2.6 gate: jobs: - ara-infra-website + - ara-integration-fedora-2.7 + - ara-integration-ubuntu-2.6 diff --git a/playbooks/integration-tests.yaml b/playbooks/integration-tests.yaml new file mode 100644 index 0000000..a5335f0 --- /dev/null +++ b/playbooks/integration-tests.yaml @@ -0,0 +1,7 @@ +- name: Run ARA integration tests + hosts: all + gather_facts: yes + tasks: + - name: Include the integration-tests role + include_role: + name: integration-tests diff --git a/roles/integration-tests/defaults/main.yaml b/roles/integration-tests/defaults/main.yaml new file mode 100644 index 0000000..61cafe7 --- /dev/null +++ b/roles/integration-tests/defaults/main.yaml @@ -0,0 +1,37 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +# Root directory where integration tests will prepare and store data +integration_root: "/tmp/ara-integration-tests" + +# Directory where the virtualenv will be created +integration_virtualenv: "{{ integration_root }}/venv" + +# Directory where ARA_BASE_DIR will be set +integration_data: "{{ integration_root }}/data" + +# Whether the root directory should be cleaned up between runs +integration_cleanup: true + +# Name of the Ansible package +# This can be "ansible" which will use pip or it could be something like +# /home/user/git/ansible as well as git+https://github.com/ansible/ansible +integration_ansible_name: ansible + +# Version of Ansible from pypi to install +integration_ansible_version: latest diff --git a/roles/integration-tests/tasks/main.yaml b/roles/integration-tests/tasks/main.yaml new file mode 100644 index 0000000..f6585fa --- /dev/null +++ b/roles/integration-tests/tasks/main.yaml @@ -0,0 +1,139 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: Clean up integration test root + file: + path: "{{ integration_root }}" + state: absent + when: integration_cleanup | bool + +- name: Create integration test root + file: + path: "{{ integration_root }}" + state: directory + +# Zuul already prepares the src repository on the remote node +- name: Symlink Zuul repositories to integration test root + file: + src: "{{ item }}" + dest: "{{ integration_root }}/{{ item | basename }}" + state: link + loop: + - "{{ ansible_user_dir }}/src/git.openstack.org/openstack/ara-infra" + - "{{ ansible_user_dir }}/src/git.openstack.org/openstack/ara-clients" + - "{{ ansible_user_dir }}/src/git.openstack.org/openstack/ara-plugins" + - "{{ ansible_user_dir }}/src/git.openstack.org/openstack/ara-server" + when: zuul is defined + +- when: zuul is not defined + block: + - name: Prepare git repositories when not using Zuul + git: + repo: "{{ item }}" + dest: "{{ integration_root }}/{{ item | basename }}" + depth: 1 + force: yes + loop: + - "https://git.openstack.org/openstack/ara-clients" + - "https://git.openstack.org/openstack/ara-plugins" + - "https://git.openstack.org/openstack/ara-server" + + # git rev-parse --show-toplevel returns the root git directory + # We are synchronizing the current repository rather than cloning it in + # order to be able to test local (unmerged) code if necessary. + - name: Synchronize ara-infra to integration root + synchronize: + src: "{{ lookup('pipe', 'git rev-parse --show-toplevel') }}" + dest: "{{ integration_root }}/" + delete: yes + +# If a version is not explicitly set we want to make sure to +# completely omit the version argument to pip, as it will be coming +# from the long-form integration_ansible_name variable. Additionally, if +# the version is the special value "latest", then we also want to omit +# any version number, but also set the package state to "latest". +- name: Set Ansible version for installation + set_fact: + _install_ansible_version: "{{ integration_ansible_version }}" + when: integration_ansible_version not in ("", "latest") + +- name: Set Ansible package state for installation + set_fact: + _install_ansible_state: latest + when: integration_ansible_version == "latest" + +- name: Initialize virtual environment with Ansible + pip: + name: "{{ integration_ansible_name }}" + version: "{{ _install_ansible_version | default(omit, True) }}" + state: "{{ _install_ansible_state | default(omit, True) }}" + virtualenv: "{{ integration_virtualenv }}" + virtualenv_python: python3 + +- name: Install ARA packages in virtual environment for integration tests + pip: + name: + - "{{ integration_root }}/ara-clients" + - "{{ integration_root }}/ara-plugins" + - "{{ integration_root }}/ara-server" + state: present + virtualenv: "{{ integration_virtualenv }}" + virtualenv_python: python3 + +- name: Get ARA plugins directory + command: "{{ integration_root }}/venv/bin/python -m ara.plugins" + register: ara_plugins + +# These aren't in the same task (i.e, with loop) so we can tell individual test +# runs apart easily rather than keeping all the output bundled in a single task. +# TODO: Add validation for the tests +- environment: + ANSIBLE_CALLBACK_PLUGINS: "{{ ara_plugins.stdout }}/callback" + ANSIBLE_ACTION_PLUGINS: "{{ ara_plugins.stdout }}/action" + ARA_DEBUG: true + ARA_LOG_LEVEL: DEBUG + ARA_BASE_DIR: "{{ integration_data }}" + ARA_SECRET_KEY: testing + vars: + ansible_playbook: "{{ integration_virtualenv }}/bin/ansible-playbook -vvv" + test_root: "{{ integration_root }}/ara-infra/tests/integration" + block: + # smoke.yaml tests setting ara_playbook_name in one of three plays + - name: Run smoke.yaml integration test + command: "{{ ansible_playbook }} {{ test_root }}/smoke.yaml" + + - name: Run hosts.yaml integration test + command: "{{ ansible_playbook }} {{ test_root }}/hosts.yaml" + + - name: Run import.yaml integration test + command: "{{ ansible_playbook }} {{ test_root }}/import.yaml" + + # Tests setting ara_playbook_name as an extra var + - name: Run failed.yaml integration test + command: > + {{ ansible_playbook }} {{ test_root }}/failed.yaml -e ara_playbook_name="Failed playbook" + ignore_errors: yes + + - name: Run incomplete.yaml integration test + shell: | + {{ ansible_playbook }} {{ test_root }}/incomplete.yaml & + sleep 5 + kill $! + args: + executable: /bin/bash + ignore_errors: yes diff --git a/tests/integration-post.yaml b/tests/integration-post.yaml new file mode 100644 index 0000000..ad097a8 --- /dev/null +++ b/tests/integration-post.yaml @@ -0,0 +1,37 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: Integration tests post-run + hosts: all + gather_facts: yes + tasks: + - name: Create server log directory + file: + path: "{{ ansible_user_dir }}/workspace/logs" + state: directory + recurse: yes + + - name: Recover integration test data + command: cp -rp /tmp/ara-integration-tests/data {{ ansible_user_dir }}/workspace/logs/data + + - name: Upload log artifacts + synchronize: + src: "{{ ansible_user_dir }}/workspace/logs" + dest: "{{ zuul.executor.log_root }}" + mode: pull + verify_host: true diff --git a/tests/integration/failed.yaml b/tests/integration/failed.yaml new file mode 100644 index 0000000..c57fe3a --- /dev/null +++ b/tests/integration/failed.yaml @@ -0,0 +1,25 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: Failed playbook + hosts: localhost + tasks: + - fail: + msg: "This is a failed playbook" + tags: + - skip_ansible_lint diff --git a/tests/integration/hosts.yaml b/tests/integration/hosts.yaml new file mode 100644 index 0000000..496e77e --- /dev/null +++ b/tests/integration/hosts.yaml @@ -0,0 +1,48 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: Create fake hosts for host tests + hosts: localhost + gather_facts: yes + tasks: + - name: Add fake hosts in inventory + add_host: + name: "{{ item }}" + ansible_host: "127.0.0.1" + ansible_connection: "local" + with_items: + - host1 + - host2 + - host3 + +- name: ARA Hosts test play + hosts: all + gather_facts: yes + tasks: + - name: Ping + ping: + + - name: Do something only on host1 + set_fact: + something: 'done' + when: inventory_hostname == 'host1' + + - name: Fail something only on host2 + command: /bin/false + when: inventory_hostname == 'host2' + ignore_errors: true diff --git a/tests/integration/import.yaml b/tests/integration/import.yaml new file mode 100644 index 0000000..fe9c623 --- /dev/null +++ b/tests/integration/import.yaml @@ -0,0 +1,20 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- import_playbook: imported.yaml + diff --git a/tests/integration/imported.yaml b/tests/integration/imported.yaml new file mode 100644 index 0000000..c7d1d01 --- /dev/null +++ b/tests/integration/imported.yaml @@ -0,0 +1,34 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +# Tests for the new import tasks from Ansible 2.4 +- name: Import a role + hosts: localhost + gather_facts: no + tasks: + - name: Import role + import_role: + name: imported-role + +- name: Include a role + hosts: localhost + gather_facts: no + tasks: + - name: Include role + include_role: + name: imported-role diff --git a/tests/integration/include_role.yaml b/tests/integration/include_role.yaml new file mode 100644 index 0000000..19fe230 --- /dev/null +++ b/tests/integration/include_role.yaml @@ -0,0 +1,34 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +# Tests for https://github.com/ansible/ansible/issues/30385 +- name: Test include role without static + hosts: localhost + gather_facts: no + tasks: + - name: Include role without static + include_role: + name: included-role + +- name: Test include role with static + hosts: localhost + gather_facts: no + tasks: + - name: Include role with static + include_role: + name: included-role diff --git a/tests/integration/incomplete.yaml b/tests/integration/incomplete.yaml new file mode 100644 index 0000000..2be5012 --- /dev/null +++ b/tests/integration/incomplete.yaml @@ -0,0 +1,27 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: Incomplete playbook + hosts: localhost + gather_facts: no + tasks: + - debug: + msg: "This playbook is meant to be interrupted" + - name: Sleep for thirty seconds + command: sleep 30 + changed_when: false diff --git a/tests/integration/roles/imported-role/defaults/main.yaml b/tests/integration/roles/imported-role/defaults/main.yaml new file mode 100644 index 0000000..ed89202 --- /dev/null +++ b/tests/integration/roles/imported-role/defaults/main.yaml @@ -0,0 +1,20 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +role_message: "This message is from an imported role" +task_message: "This message is from an imported task in an imported role" diff --git a/tests/integration/roles/imported-role/tasks/imported-task.yaml b/tests/integration/roles/imported-role/tasks/imported-task.yaml new file mode 100644 index 0000000..6a5d3a0 --- /dev/null +++ b/tests/integration/roles/imported-role/tasks/imported-task.yaml @@ -0,0 +1,20 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- debug: + msg: "{{ task_message }}" diff --git a/tests/integration/roles/imported-role/tasks/main.yaml b/tests/integration/roles/imported-role/tasks/main.yaml new file mode 100644 index 0000000..be48fd7 --- /dev/null +++ b/tests/integration/roles/imported-role/tasks/main.yaml @@ -0,0 +1,23 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: Import task + import_tasks: imported-task.yaml + +- name: Include task + include_tasks: imported-task.yaml diff --git a/tests/integration/roles/included-role/defaults/main.yaml b/tests/integration/roles/included-role/defaults/main.yaml new file mode 100644 index 0000000..1d07a2e --- /dev/null +++ b/tests/integration/roles/included-role/defaults/main.yaml @@ -0,0 +1,20 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +role_message: "This message is from an included role" +task_message: "This message is from an included task in an included role" diff --git a/tests/integration/roles/included-role/tasks/included-task.yaml b/tests/integration/roles/included-role/tasks/included-task.yaml new file mode 100644 index 0000000..6a5d3a0 --- /dev/null +++ b/tests/integration/roles/included-role/tasks/included-task.yaml @@ -0,0 +1,20 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- debug: + msg: "{{ task_message }}" diff --git a/tests/integration/roles/included-role/tasks/main.yaml b/tests/integration/roles/included-role/tasks/main.yaml new file mode 100644 index 0000000..cb3b085 --- /dev/null +++ b/tests/integration/roles/included-role/tasks/main.yaml @@ -0,0 +1,20 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- debug: + msg: "{{ role_message }}" diff --git a/tests/integration/roles/smoke-tests/defaults/main.yaml b/tests/integration/roles/smoke-tests/defaults/main.yaml new file mode 100644 index 0000000..51ff67f --- /dev/null +++ b/tests/integration/roles/smoke-tests/defaults/main.yaml @@ -0,0 +1,29 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +list_items: + - one + - two + +dict_items: + one: + name: "key-one" + value: "value-one" + two: + name: "key-two" + value: "value-two" diff --git a/tests/integration/roles/smoke-tests/tasks/ara-ops.yaml b/tests/integration/roles/smoke-tests/tasks/ara-ops.yaml new file mode 100644 index 0000000..23723b4 --- /dev/null +++ b/tests/integration/roles/smoke-tests/tasks/ara-ops.yaml @@ -0,0 +1,199 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +# Ensure no_log is respected +- name: Print normal data + debug: + msg: "normal data" + +- name: Print confidential data + debug: + msg: "confidential data" + no_log: "yes" + +# ARA record and read modules specific tests +- name: Record data with no type + ara_record: + key: "notype" + value: "text" + register: notype + +- name: Validate notype key + assert: + that: + - notype.key == "notype" + - notype.value == "text" + - notype.type == "text" + +- name: Update notype key with specified playbook + ara_record: + playbook_id: "{{ notype.playbook_id }}" + key: "notype" + value: "updated text" + type: "text" + register: notype_update + +- name: Validate notype key + assert: + that: + - notype_update.key == "notype" + - notype_update.value == "updated text" + - notype_update.type == "text" + +- name: Record data with text type + ara_record: + key: "foo" + value: "bar" + type: "text" + +- name: Update existing key's value and type + ara_record: + key: "foo" + value: "http://barfoo" + type: "url" + register: foo + +- name: Validate foo key + assert: + that: + - foo.key == "foo" + - foo.value == "http://barfoo" + - foo.type == "url" + +- name: Add another k/v pair with ara_record + ara_record: + key: "bar" + value: '{ "foo": "bar" }' + type: "json" + register: bar + +- name: Validate bar key + assert: + that: + - bar.key == "bar" + - "bar.value == '{ \"foo\": \"bar\" }'" + - bar.type == "json" + +- name: Record a list value + vars: + someitems: + - one + - two + - three + - go + ara_record: + key: "somelist" + value: "{{ someitems }}" + type: "list" + register: somelist + +- name: Validate somelist key + vars: + someitems: + - one + - two + - three + - go + assert: + that: + - somelist.key == "somelist" + - somelist.value == someitems + - somelist.type == "list" + +- name: Record a dict value + vars: + dictdata: + foo: "bar" + bar: "foo" + ara_record: + key: "somedict" + value: "{{ dictdata }}" + type: "dict" + register: somedict + +- name: Validate somedict key + vars: + dictdata: + foo: "bar" + bar: "foo" + assert: + that: + - somedict.key == "somedict" + - somedict.value == dictdata + - somedict.type == "dict" + +- name: Record a list as a text type + vars: + list: + - foo + - bar + ara_record: + key: "list_as_text" + value: "{{ list }}" + type: "text" + register: list_as_text + +# The key is still recorded as an actual list, however, it will be rendered +# as text in the UI. +- name: Validate list_as_text key + vars: + list: + - foo + - bar + assert: + that: + - list_as_text.key == "list_as_text" + - list_as_text.value == list + - list_as_text.value != "[u'foo', u'bar']" + - list_as_text.type == "text" + +# Things that should fail +- name: Record with no key + ara_record: + value: "value" + ignore_errors: "yes" + register: nokey + +- name: Validate nokey failure + assert: + that: + - nokey.failed + +- name: Record with no value + ara_record: + key: "key" + ignore_errors: "yes" + register: novalue + +- name: Validate novalue failure + assert: + that: + - novalue.failed + +- name: Record with invalid type + ara_record: + key: "key" + value: "value" + type: "hadoop" + ignore_errors: "yes" + register: invalid + +- name: Validate invalid failure + assert: + that: + - invalid.failed diff --git a/tests/integration/roles/smoke-tests/tasks/main.yaml b/tests/integration/roles/smoke-tests/tasks/main.yaml new file mode 100644 index 0000000..86c01da --- /dev/null +++ b/tests/integration/roles/smoke-tests/tasks/main.yaml @@ -0,0 +1,23 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: Deferred setup + setup: + +- include_tasks: ara-ops.yaml +- include_tasks: test-ops.yaml diff --git a/tests/integration/roles/smoke-tests/tasks/test-ops.yaml b/tests/integration/roles/smoke-tests/tasks/test-ops.yaml new file mode 100644 index 0000000..3c300dc --- /dev/null +++ b/tests/integration/roles/smoke-tests/tasks/test-ops.yaml @@ -0,0 +1,56 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +# Tests some things around blocks, failures and rescues + +- block: + - name: Debug message + debug: + msg: "Successful debug task" + - name: Return false + command: /bin/false + - name: Command that should not run + debug: + msg: "This should never run" + rescue: + - name: Rescue task + debug: + msg: "Rescue was called successfully" + always: + - name: Task that should always run + debug: + msg: "This should always be printed" + +- name: Test a skipped task + debug: + msg: "This is skipped" + when: false + +- name: Test with_items + debug: + msg: "{{ item }}" + with_items: "{{ list_items }}" + +- name: Test with_dict + debug: + msg: "{{ item.value.name }}: {{ item.value.value }}" + with_dict: "{{ dict_items }}" + +- name: Test for XSS + command: echo "" + changed_when: False diff --git a/tests/integration/smoke.yaml b/tests/integration/smoke.yaml new file mode 100644 index 0000000..1c278cb --- /dev/null +++ b/tests/integration/smoke.yaml @@ -0,0 +1,55 @@ +--- +# Copyright (c) 2018 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ARA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with ARA. If not, see . + +- name: ARA Tasks test play + hosts: localhost + gather_facts: no + vars: + ara_playbook_name: Smoke tests + tasks: + - name: ARA Integration test + debug: + msg: "ARA Integration test" + tags: + - tagged + roles: + - { role: "smoke-tests" } + +- name: Add a host with non-ascii characters + hosts: localhost + gather_facts: no + tasks: + - name: Add a host with non-ascii character + add_host: + name: "höstñämë" + ansible_host: "127.0.0.1" + ansible_connection: "local" + tags: + - untag + - verytag + +- name: Play with non-ascii characters - ä, ö, ü + hosts: höstñämë + gather_facts: yes + tasks: + - name: Task with non-ascii characters - ä, ö, ü + debug: + msg: "This is a task result with non-ascii characters: ä, ö, ü" + tags: + - untag + - verytag