From cac51e6da866d0b341c49783c01f9ff0d2965dd9 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Wed, 29 Aug 2018 10:48:57 -0700 Subject: [PATCH] Restore repos after zypper_repository test runs. This also allows the test to run on newer containers by not manipulating any of the pre-configured repositories. --- .../targets/zypper_repository/tasks/main.yml | 2 +- .../targets/zypper_repository/tasks/test.yml | 33 ++++++++++++++ .../tasks/zypper_repository.yml | 43 ++++--------------- 3 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 test/integration/targets/zypper_repository/tasks/test.yml diff --git a/test/integration/targets/zypper_repository/tasks/main.yml b/test/integration/targets/zypper_repository/tasks/main.yml index a1fb69d22c..a94ed4ba91 100644 --- a/test/integration/targets/zypper_repository/tasks/main.yml +++ b/test/integration/targets/zypper_repository/tasks/main.yml @@ -17,5 +17,5 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -- include: 'zypper_repository.yml' +- include: 'test.yml' when: ansible_os_family == 'Suse' diff --git a/test/integration/targets/zypper_repository/tasks/test.yml b/test/integration/targets/zypper_repository/tasks/test.yml new file mode 100644 index 0000000000..14343ee5a4 --- /dev/null +++ b/test/integration/targets/zypper_repository/tasks/test.yml @@ -0,0 +1,33 @@ +- name: collect repo configuration before test + shell: "grep . /etc/zypp/repos.d/*" + register: before + +- name: ensure zypper ref works + command: zypper -n ref + +- block: + - include: 'zypper_repository.yml' + always: + - name: remove repositories added during test + zypper_repository: + name: "{{item}}" + state: absent + with_items: + - chrome1 + - chrome2 + - test + - testrefresh + - testprio + - Apache_Modules + + - name: collect repo configuration after test + shell: "grep . /etc/zypp/repos.d/*" + register: after + + - name: verify repo configuration has been restored + assert: + that: + - before.stdout == after.stdout + + - name: ensure zypper ref still works + command: zypper -n ref diff --git a/test/integration/targets/zypper_repository/tasks/zypper_repository.yml b/test/integration/targets/zypper_repository/tasks/zypper_repository.yml index 7a98201fd2..f13bb08357 100644 --- a/test/integration/targets/zypper_repository/tasks/zypper_repository.yml +++ b/test/integration/targets/zypper_repository/tasks/zypper_repository.yml @@ -1,8 +1,3 @@ ---- - -- name: ensure zypper ref works - command: zypper -n ref - - name: Delete test repo zypper_repository: name: test @@ -16,8 +11,6 @@ repo: http://dl.google.com/linux/chrome/rpm/stable/x86_64 register: zypper_result -- debug: var=zypper_result - - name: verify repo addition assert: that: @@ -47,17 +40,12 @@ that: - "zypper_result.changed" -- name: Remove repo by name (also to not mess up later tasks) - zypper_repository: - name: test - state: absent - - name: use refresh option zypper_repository: name: testrefresh refresh: no state: present - repo: http://download.opensuse.org/distribution/leap/{{ ansible_distribution_version }}/repo/oss/ + repo: http://download.videolan.org/pub/vlc/SuSE/Leap_{{ ansible_distribution_version }}/ - name: check refreshoption command: zypper -x lr testrefresh @@ -72,7 +60,7 @@ name: testprio priority: 55 state: present - repo: http://download.opensuse.org/distribution/leap/{{ ansible_distribution_version }}/repo/oss/ + repo: http://download.videolan.org/pub/vlc/SuSE/Leap_{{ ansible_distribution_version }}/ - name: check refreshoption command: zypper -x lr testprio @@ -86,18 +74,18 @@ zypper_repository: name: "{{item}}" state: present - repo: http://download.opensuse.org/distribution/leap/{{ ansible_distribution_version }}/repo/oss/ + repo: http://dl.google.com/linux/chrome/rpm/stable/x86_64 with_items: - - oss1 - - oss2 + - chrome1 + - chrome2 - name: check repo is updated by url - command: zypper lr oss1 + command: zypper lr chrome1 register: zypper_result1 ignore_errors: yes - name: check repo is updated by url - command: zypper lr oss2 + command: zypper lr chrome2 register: zypper_result2 - assert: @@ -105,16 +93,7 @@ - "zypper_result1.rc == 6" - "'not found' in zypper_result1.stderr" - "zypper_result2.rc == 0" - - "'http://download.opensuse.org/distribution/leap/{{ ansible_distribution_version }}/repo/oss/' in zypper_result2.stdout" - - -- name: reset oss repo (to not break zypper later) - zypper_repository: - name: OSS - state: present - repo: http://download.opensuse.org/distribution/leap/{{ ansible_distribution_version }}/repo/oss/ - priority: 99 - refresh: yes + - "'http://dl.google.com/linux/chrome/rpm/stable/x86_64' in zypper_result2.stdout" - name: add two repos with same name zypper_repository: @@ -139,9 +118,6 @@ repo: http://download.opensuse.org/repositories/devel:/languages:/ruby/openSUSE_Leap_{{ ansible_distribution_version }}/ state: absent -- name: ensure zypper ref still works - command: zypper -n ref - - name: "Test adding a repo with custom GPG key" zypper_repository: name: "Apache_Modules" @@ -149,6 +125,3 @@ priority: 100 auto_import_keys: true state: "present" - -- name: ensure zypper ref still works - command: zypper -n ref