From aacccd441b11706eef5dd736a8371253b3771f17 Mon Sep 17 00:00:00 2001 From: James Laska Date: Fri, 14 Mar 2014 13:04:25 -0400 Subject: [PATCH] Add integration test for apt_repository Tests several ways to specify the repository. For every repo added, the test asserts that: * the apt-cache was updated as expected (depends on `update_cache` parameter) * the PPA key was installed (depends on `repo` format) --- test/integration/destructive.yml | 4 +- .../roles/test_apt_repository/meta/main.yml | 2 + .../roles/test_apt_repository/tasks/apt.yml | 137 ++++++++++++++++++ .../test_apt_repository/tasks/cleanup.yml | 18 +++ .../roles/test_apt_repository/tasks/main.yml | 21 +++ 5 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 test/integration/roles/test_apt_repository/meta/main.yml create mode 100644 test/integration/roles/test_apt_repository/tasks/apt.yml create mode 100644 test/integration/roles/test_apt_repository/tasks/cleanup.yml create mode 100644 test/integration/roles/test_apt_repository/tasks/main.yml diff --git a/test/integration/destructive.yml b/test/integration/destructive.yml index 8d0b11c6ac..406db63906 100644 --- a/test/integration/destructive.yml +++ b/test/integration/destructive.yml @@ -1,9 +1,9 @@ - hosts: testhost gather_facts: True - roles: + roles: - { role: test_service, tags: test_service } - { role: test_pip, tags: test_pip } - { role: test_gem, tags: test_gem } - { role: test_yum, tags: test_yum } - { role: test_apt, tags: test_apt } - + - { role: test_apt_repository, tags: test_apt_repository } diff --git a/test/integration/roles/test_apt_repository/meta/main.yml b/test/integration/roles/test_apt_repository/meta/main.yml new file mode 100644 index 0000000000..07faa21776 --- /dev/null +++ b/test/integration/roles/test_apt_repository/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_tests diff --git a/test/integration/roles/test_apt_repository/tasks/apt.yml b/test/integration/roles/test_apt_repository/tasks/apt.yml new file mode 100644 index 0000000000..7cbc9d2128 --- /dev/null +++ b/test/integration/roles/test_apt_repository/tasks/apt.yml @@ -0,0 +1,137 @@ +--- + +- set_fact: + test_ppa_name: 'ppa:menulibre-dev/devel' + test_ppa_spec: 'deb http://ppa.launchpad.net/menulibre-dev/devel/ubuntu {{ansible_distribution_release}} main' + test_ppa_key: 'A7AD98A1' # http://keyserver.ubuntu.com:11371/pks/lookup?search=0xD06AAF4C11DAB86DF421421EFE6B20ECA7AD98A1&op=index + +# +# TEST: apt_repository: repo= +# +- include: 'cleanup.yml' + +- name: 'record apt cache mtime' + stat: path='/var/cache/apt/pkgcache.bin' + register: cache_before + +- name: 'name= (expect: pass)' + apt_repository: repo='{{test_ppa_name}}' state=present + register: result + +- name: 'assert the apt cache did *NOT* change' + assert: + that: + - 'result.changed' + - 'result.state == "present"' + - 'result.repo == "{{test_ppa_name}}"' + +- name: 'examine apt cache mtime' + stat: path='/var/cache/apt/pkgcache.bin' + register: cache_after + +- name: 'assert the apt cache did change' + assert: + that: + - 'cache_before.stat.mtime != cache_after.stat.mtime' + +- name: 'ensure ppa key is installed (expect: pass)' + apt_key: id='{{test_ppa_key}}' state=present + +# +# TEST: apt_repository: repo= update_cache=no +# +- include: 'cleanup.yml' + +- name: 'record apt cache mtime' + stat: path='/var/cache/apt/pkgcache.bin' + register: cache_before + +- name: 'name= update_cache=no (expect: pass)' + apt_repository: repo='{{test_ppa_name}}' state=present update_cache=no + register: result + +- assert: + that: + - 'result.changed' + - 'result.state == "present"' + - 'result.repo == "{{test_ppa_name}}"' + +- name: 'examine apt cache mtime' + stat: path='/var/cache/apt/pkgcache.bin' + register: cache_after + +- name: 'assert the apt cache did *NOT* change' + assert: + that: + - 'cache_before.stat.mtime == cache_after.stat.mtime' + +- name: 'ensure ppa key is installed (expect: pass)' + apt_key: id='{{test_ppa_key}}' state=present + +# +# TEST: apt_repository: repo= update_cache=yes +# +- include: 'cleanup.yml' + +- name: 'record apt cache mtime' + stat: path='/var/cache/apt/pkgcache.bin' + register: cache_before + +- name: 'name= update_cache=yes (expect: pass)' + apt_repository: repo='{{test_ppa_name}}' state=present update_cache=yes + register: result + +- assert: + that: + - 'result.changed' + - 'result.state == "present"' + - 'result.repo == "{{test_ppa_name}}"' + +- name: 'examine apt cache mtime' + stat: path='/var/cache/apt/pkgcache.bin' + register: cache_after + +- name: 'assert the apt cache did change' + assert: + that: + - 'cache_before.stat.mtime != cache_after.stat.mtime' + +- name: 'ensure ppa key is installed (expect: pass)' + apt_key: id='{{test_ppa_key}}' state=present + +# +# TEST: apt_repository: repo= +# +- include: 'cleanup.yml' + +- name: 'record apt cache mtime' + stat: path='/var/cache/apt/pkgcache.bin' + register: cache_before + +- name: 'name= (expect: pass)' + apt_repository: repo='{{test_ppa_spec}}' state=present + register: result + +- assert: + that: + - 'result.changed' + - 'result.state == "present"' + - 'result.repo == "{{test_ppa_spec}}"' + +- name: 'examine apt cache mtime' + stat: path='/var/cache/apt/pkgcache.bin' + register: cache_after + +- name: 'assert the apt cache did change' + assert: + that: + - 'cache_before.stat.mtime != cache_after.stat.mtime' + +# When installing a repo with the spec, the key is *NOT* added +- name: 'ensure ppa key is absent (expect: pass)' + apt_key: id='{{test_ppa_key}}' state=absent + +# +# TEARDOWN +# +- include: 'cleanup.yml' diff --git a/test/integration/roles/test_apt_repository/tasks/cleanup.yml b/test/integration/roles/test_apt_repository/tasks/cleanup.yml new file mode 100644 index 0000000000..86a09dd5ae --- /dev/null +++ b/test/integration/roles/test_apt_repository/tasks/cleanup.yml @@ -0,0 +1,18 @@ +--- +# tasks to cleanup a repo and assert it is gone + +- name: remove existing ppa + apt_repository: repo={{test_ppa_name}} state=absent + ignore_errors: true + +- name: test that ppa does not exist (expect pass) + shell: cat /etc/apt/sources.list /etc/apt/sources.list.d/* | grep "{{test_ppa_spec}}" + register: command + failed_when: command.rc == 0 + changed_when: false + +# Should this use apt-key, maybe? +- name: remove ppa key + apt_key: id={{test_ppa_key}} state=absent + ignore_errors: true + diff --git a/test/integration/roles/test_apt_repository/tasks/main.yml b/test/integration/roles/test_apt_repository/tasks/main.yml new file mode 100644 index 0000000000..8a16a061bd --- /dev/null +++ b/test/integration/roles/test_apt_repository/tasks/main.yml @@ -0,0 +1,21 @@ +# test code for the apt_repository module +# (c) 2014, James Laska + +# This file is part of Ansible +# +# 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. +# +# 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 Ansible. If not, see . + +- include: 'apt.yml' + when: ansible_distribution in ('Ubuntu', 'Debian') +