From 6037b0f8ec62eaad728ee617418968ea324eb44c Mon Sep 17 00:00:00 2001 From: Paul B Date: Mon, 28 Jan 2019 16:03:15 +0100 Subject: [PATCH] tests: fix test playbook due to barman <-> postgres circle dependencies --- .travis.yml | 9 ++++++++- test/main.yml | 28 ++++++++++++++-------------- test/requirements.yml | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index c424411..ddf6fb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,10 @@ addons: packages: - python-pip +# Tests are using docker to spawn fake instances +services: + - docker + install: # Install ansible - pip install ansible docker-py docker @@ -22,7 +26,10 @@ script: # Basic role syntax check - ansible-playbook test/main.yml -i test/hosts --syntax-check # Run the tests - - ansible-playbook test/main.yml -i test/hosts + # FAILS - ansible-playbook test/main.yml -i test/hosts + # Even if Docker and docker-py module are present, the tests fail on Travis + # The error on Travis is: + # => {"changed": false, "item": {"image": "python:3.7-stretch", "links": ["postgres_barman", "postgres_one"], "name": "postgres_three"}, "msg": "Failed to import docker or docker-py - No module named docker. Try `pip install docker` or `pip install docker-py` (Python 2.6)"} notifications: webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/test/main.yml b/test/main.yml index bc9d27c..a4834be 100644 --- a/test/main.yml +++ b/test/main.yml @@ -117,33 +117,25 @@ - name: "{{ postgres_barman_directory }}" description: 'Main database' primary_host: postgres_one - primary_barman_password: "secret_cocktail" + postgres_barman_password: "secret_cocktail" backup_method: rsync - ansible_group: db-all + standby_hosts: "{{ groups['db-all'][1:] }}" retention_policy: 'RECOVERY WINDOW OF 7 DAYS' with_items: - postgres_barman tags: provision_docker -- name: Test installing Barman role - hosts: barman +- name: Test installing Postgresql role + hosts: primary:secondary connection: docker - vars: {} + vars: + postgres_listen_addresses: "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}" pre_tasks: &pre_tasks - name: "Build hosts file" shell: 'echo "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }} {{inventory_hostname}}" >> /etc/hosts' when: hostvars[inventory_hostname].ansible_default_ipv4.address is defined - debug: msg="Running on host {{inventory_hostname}} ({{ hostvars[inventory_hostname].ansible_default_ipv4.address }})" - roles: - - { role: barman, tags: ['barman'] } - -- name: Test installing Postgresql role - hosts: primary:secondary - connection: docker - vars: - postgres_listen_addresses: "{{ hostvars[inventory_hostname].ansible_default_ipv4.address }}" - pre_tasks: *pre_tasks roles: - { role: ansible-postgresql-role, tags: ['postgres'] } tasks: @@ -157,6 +149,14 @@ command: psql --port=5432 --command='select NOW()' +- name: Test installing Barman role + hosts: barman + connection: docker + vars: {} + pre_tasks: *pre_tasks + roles: + - { role: barman, tags: ['barman'] } + - name: Test running Postgresql role when database is started connection: docker hosts: primary:secondary diff --git a/test/requirements.yml b/test/requirements.yml index 4c72838..f9d7099 100644 --- a/test/requirements.yml +++ b/test/requirements.yml @@ -3,4 +3,4 @@ version: 7a6243dfcf69f9d262877eca487bc14b62ba6960 - src: trainline-eu.ansible_barman_role name: barman - version: 1.0.0 + version: 1.1.0 -- 2.41.0