From b1f23c766ac754b1fd7b8532b2a3f9348c7cd966 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Wed, 11 Dec 2019 13:57:00 -0500 Subject: [PATCH] ara_api role: add support for installing from fedora packages This patch is self tested by the addition of a new job that exercises the role with the packages but it does not test the current source yet. In order to test the current source, we'll need to set up a job that builds a package from the current source and then configure the job to install from these built packages. Change-Id: Ic326a5243b55b415cd31b8a5702fe92d5dfe0651 --- .zuul.d/project.yaml | 2 + .zuul.d/role-jobs.yaml | 7 ++ roles/ara_api/defaults/main.yaml | 1 + roles/ara_api/tasks/install/distribution.yaml | 29 ++++++++ roles/ara_api/vars/Fedora.yaml | 4 ++ roles/ara_api/vars/Ubuntu.yaml | 3 + tests/test_tasks.yaml | 72 ++++++++++--------- tests/with_fedora_packages.yaml | 45 ++++++++++++ 8 files changed, 131 insertions(+), 32 deletions(-) create mode 100644 roles/ara_api/tasks/install/distribution.yaml create mode 100644 tests/with_fedora_packages.yaml diff --git a/.zuul.d/project.yaml b/.zuul.d/project.yaml index 22b932a5..f00949a5 100644 --- a/.zuul.d/project.yaml +++ b/.zuul.d/project.yaml @@ -12,6 +12,8 @@ - ansible-role-ara-api-ubuntu-postgresql - ansible-role-ara-api-ubuntu-mysql - ansible-role-ara-api-fedora-distributed-sqlite + - ansible-role-ara-api-fedora-packages: + voting: false - ansible-role-ara-web-ubuntu - ansible-role-ara-web-fedora - ara-basic-ansible-integration diff --git a/.zuul.d/role-jobs.yaml b/.zuul.d/role-jobs.yaml index c4941573..83b1c28c 100644 --- a/.zuul.d/role-jobs.yaml +++ b/.zuul.d/role-jobs.yaml @@ -98,6 +98,13 @@ - zuul: zuul/zuul-jobs run: tests/with_distributed_sqlite.yaml +# Distribution package tests + +- job: + name: ansible-role-ara-api-fedora-packages + parent: ansible-role-ara-api-fedora + run: tests/with_fedora_packages.yaml + # ara-web jobs - job: name: ansible-role-ara-web-base diff --git a/roles/ara_api/defaults/main.yaml b/roles/ara_api/defaults/main.yaml index 61c90fc0..dfb03332 100644 --- a/roles/ara_api/defaults/main.yaml +++ b/roles/ara_api/defaults/main.yaml @@ -32,6 +32,7 @@ ara_api_venv_path: "{{ ara_api_root_dir }}/virtualenv" # How ARA will be installed # - source [default]: installs from a local or remote git repository +# - distribution: installs from distribution packages, if available # - pypi [planned]: installs from pypi ara_api_install_method: source diff --git a/roles/ara_api/tasks/install/distribution.yaml b/roles/ara_api/tasks/install/distribution.yaml new file mode 100644 index 00000000..be99dfac --- /dev/null +++ b/roles/ara_api/tasks/install/distribution.yaml @@ -0,0 +1,29 @@ +--- +# Copyright (c) 2019 Red Hat, Inc. +# +# This file is part of ARA Records Ansible. +# +# ARA Records Ansible 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 Records Ansible 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 Records Ansible. If not, see . + +- name: Validate if the distribution is supported + fail: + msg: | + {{ ansible_distribution }} does not support installation from distribution packages yet. + when: ara_distribution_packages | length == 0 + +- name: Install ara from distribution packages + become: yes + package: + name: "{{ ara_distribution_packages }}" + state: present diff --git a/roles/ara_api/vars/Fedora.yaml b/roles/ara_api/vars/Fedora.yaml index e877572e..f72e93fe 100644 --- a/roles/ara_api/vars/Fedora.yaml +++ b/roles/ara_api/vars/Fedora.yaml @@ -16,6 +16,10 @@ # You should have received a copy of the GNU General Public License # along with ARA Records Ansible. If not, see . +ara_distribution_packages: + - ara + - ara-server + ara_api_required_packages: - git - python3-virtualenv diff --git a/roles/ara_api/vars/Ubuntu.yaml b/roles/ara_api/vars/Ubuntu.yaml index 737c2264..72aac05e 100644 --- a/roles/ara_api/vars/Ubuntu.yaml +++ b/roles/ara_api/vars/Ubuntu.yaml @@ -16,6 +16,9 @@ # You should have received a copy of the GNU General Public License # along with ARA Records Ansible. If not, see . +# ARA has not been packaged for Ubuntu yet +ara_distribution_packages: [] + ara_api_required_packages: - git - python3-venv diff --git a/tests/test_tasks.yaml b/tests/test_tasks.yaml index fff1fb98..5dbc845b 100644 --- a/tests/test_tasks.yaml +++ b/tests/test_tasks.yaml @@ -19,33 +19,42 @@ # as post_tasks inside the same play context as our roles so they have access # to the play and role variables. -- name: Set defaults for Ansible package name and version - set_fact: - ara_tests_ansible_name: "{{ ara_tests_ansible_name | default('ansible') }}" - ara_tests_ansible_version: "{{ ara_tests_ansible_version | default('latest') }}" +- when: ara_api_install_method == "source" + block: + - name: Set defaults for Ansible package name and version + set_fact: + ara_tests_ansible_name: "{{ ara_tests_ansible_name | default('ansible') }}" + ara_tests_ansible_version: "{{ ara_tests_ansible_version | default('latest') }}" -# 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: "{{ ara_tests_ansible_version }}" - when: ara_tests_ansible_version not in ("", "latest") + # 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: "{{ ara_tests_ansible_version }}" + when: ara_tests_ansible_version not in ("", "latest") -- name: Set Ansible package state for installation - set_fact: - _install_ansible_state: latest - when: ara_tests_ansible_version == "latest" + - name: Set Ansible package state for installation + set_fact: + _install_ansible_state: latest + when: ara_tests_ansible_version == "latest" -- name: Install Ansible alongside ARA - pip: - name: "{{ ara_tests_ansible_name }}" - version: "{{ _install_ansible_version | default(omit, True) }}" - state: "{{ _install_ansible_state | default(omit, True) }}" - virtualenv: "{{ ara_api_venv | bool | ternary(ara_api_venv_path, omit) }}" - virtualenv_command: /usr/bin/python3 -m venv + - name: Install Ansible alongside ARA + pip: + name: "{{ ara_tests_ansible_name }}" + version: "{{ _install_ansible_version | default(omit, True) }}" + state: "{{ _install_ansible_state | default(omit, True) }}" + virtualenv: "{{ ara_api_venv | bool | ternary(ara_api_venv_path, omit) }}" + virtualenv_command: /usr/bin/python3 -m venv + +- name: Install Ansible from distribution packages + become: yes + package: + name: ansible + state: present + when: ara_api_install_method == "distribution" - name: Get ARA plugins directory environment: @@ -62,29 +71,29 @@ ARA_SETTINGS: "{{ ara_api_settings }}" ARA_API_CLIENT: "{{ ara_api_client | default('offline') }}" ARA_API_SERVER: "{{ ara_api_server | default('http://127.0.0.1:8000') }}" + PATH: "{{ path_with_virtualenv | default('/usr/bin:/usr/local/bin') }}" vars: - _ansible_playbook: "{{ ara_api_venv_path }}/bin/ansible-playbook -vvv" _test_root: "{{ ara_api_source_checkout }}/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" + command: "ansible-playbook -vvv {{ _test_root }}/smoke.yaml" - name: Run hosts.yaml integration test - command: "{{ _ansible_playbook }} {{ _test_root }}/hosts.yaml" + command: "ansible-playbook -vvv {{ _test_root }}/hosts.yaml" - name: Run import.yaml integration test - command: "{{ _ansible_playbook }} {{ _test_root }}/import.yaml" + command: "ansible-playbook -vvv {{ _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" + ansible-playbook -vvv {{ _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 & + ansible-playbook -vvv {{ _test_root }}/incomplete.yaml & sleep 5 kill $! args: @@ -92,8 +101,7 @@ ignore_errors: yes - name: Generate static report - command: > - {{ ara_api_venv_path }}/bin/ara-manage generate {{ ara_api_root_dir }}/static + command: ara-manage generate {{ ara_api_root_dir }}/static - name: List static report files command: ls -alR {{ ara_api_root_dir }}/static diff --git a/tests/with_fedora_packages.yaml b/tests/with_fedora_packages.yaml new file mode 100644 index 00000000..8722a505 --- /dev/null +++ b/tests/with_fedora_packages.yaml @@ -0,0 +1,45 @@ +# Copyright (c) 2019 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: Test the ARA API with fedora packages + hosts: all + gather_facts: yes + vars: + ara_api_install_method: distribution + ara_api_version: latest + ara_api_root_dir: "{{ ansible_user_dir }}/.ara-tests" + ara_api_secret_key: testing + ara_api_debug: true + ara_api_log_level: DEBUG + tasks: + - block: + - name: Set up the API with the ara_api role + include_role: + name: ara_api + public: yes + + # Despite installing from packages, we need access to the source for + # running tests + - name: Prepare git repository for ara + git: + repo: "{{ ara_api_source }}" + dest: "{{ ara_api_source_checkout }}" + version: "{{ (ara_api_version == 'latest') | ternary('HEAD', ara_api_version) }}" + + # These are tasks rather than a standalone playbook to give us an easy + # access to all the variables within the same play. + - include_tasks: test_tasks.yaml