From e2fc61c5543db55dfd723f36dfe8471999b93f43 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 18 Oct 2017 13:07:48 +0200 Subject: [PATCH] Add yum integration tests using fake repo (#31646) --- .../targets/yum/files/create-repo.py | 41 ++ test/integration/targets/yum/tasks/main.yml | 5 + test/integration/targets/yum/tasks/repo.yml | 501 ++++++++++++++++++ .../targets/yum/tasks/yum_group_remove.yml | 4 - .../targets/yum/tasks/yuminstallroot.yml | 3 - 5 files changed, 547 insertions(+), 7 deletions(-) create mode 100644 test/integration/targets/yum/files/create-repo.py create mode 100644 test/integration/targets/yum/tasks/repo.yml diff --git a/test/integration/targets/yum/files/create-repo.py b/test/integration/targets/yum/files/create-repo.py new file mode 100644 index 0000000000..6d5e1db312 --- /dev/null +++ b/test/integration/targets/yum/files/create-repo.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python + + +import sys +from collections import namedtuple +import rpmfluff + + +RPM = namedtuple('RPM', ['name', 'version', 'release', 'epoch']) + + +SPECS = [ + RPM('foo', '1.0', '1', None), + RPM('foo', '1.0', '2', '1'), + RPM('foo', '1.1', '1', '1'), +] + + +def main(): + try: + arch = sys.argv[1] + except IndexError: + arch = 'x86_64' + + pkgs = [] + for spec in SPECS: + pkg = rpmfluff.SimpleRpmBuild(spec.name, spec.version, spec.release, [arch]) + pkg.epoch = spec.epoch + pkgs.append(pkg) + + repo = rpmfluff.YumRepoBuild(pkgs) + repo.make(arch) + + for pkg in pkgs: + pkg.clean() + + print(repo.repoDir) + + +if __name__ == "__main__": + main() diff --git a/test/integration/targets/yum/tasks/main.yml b/test/integration/targets/yum/tasks/main.yml index cd153f5f9a..0bcb241eef 100644 --- a/test/integration/targets/yum/tasks/main.yml +++ b/test/integration/targets/yum/tasks/main.yml @@ -23,6 +23,11 @@ - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] - ansible_python.version.major == 2 +- include: 'repo.yml' + when: + - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] + - ansible_python.version.major == 2 + # We can't run yum --installroot tests on dnf systems. Dnf systems revert to # yum-deprecated, and yum-deprecated refuses to run if yum.conf exists # so we cannot configure yum-deprecated correctly in an empty /tmp/fake.root/ diff --git a/test/integration/targets/yum/tasks/repo.yml b/test/integration/targets/yum/tasks/repo.yml new file mode 100644 index 0000000000..9116971959 --- /dev/null +++ b/test/integration/targets/yum/tasks/repo.yml @@ -0,0 +1,501 @@ +- name: Install epel repo which is missing on rhel-7 and is needed for rpmfluff + yum: + name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm + when: + - ansible_distribution in ['RedHat'] + +- name: Install rpmfluff and deps + yum: + name: "{{ item }}" + with_items: + - python-rpmfluff + - createrepo_c + - createrepo # used by el6 version of rpmfluff + +- name: Copy script for creating a repo + copy: + src: create-repo.py + dest: /tmp/create-repo.py + mode: 0755 + +- name: Create RPMs and put them into a repo + shell: "python /tmp/create-repo.py {{ ansible_architecture }}" + register: repo + +- set_fact: + repodir: "{{ repo.stdout_lines[-1] }}" + +- name: Install the repo + yum_repository: + name: "fake-{{ ansible_architecture }}" + description: "fake-{{ ansible_architecture }}" + baseurl: "file://{{ repodir }}" + gpgcheck: no + +- name: Create RPMs and put them into a repo (ppc64) + shell: "python /tmp/create-repo.py ppc64" + register: repo_ppc64 + +- set_fact: + repodir_ppc64: "{{ repo_ppc64.stdout_lines[-1] }}" + +- name: Install the repo (ppc64) + yum_repository: + name: "fake-ppc64" + description: "fake-ppc64" + baseurl: "file://{{ repodir_ppc64 }}" + gpgcheck: no +# ============================================================================ +- name: Install foo-1.0-1 + yum: + name: foo-1.0-1 + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-1')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Install foo-1.0-1 again + yum: + name: foo-1.0-1 + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "not yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-1')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Install foo-1:1.0-2 + yum: + name: "foo-1:1.0-2.{{ ansible_architecture }}" + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-2')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + +- name: Remove foo + yum: + name: foo + state: absent +# ============================================================================ +- name: Install 1:foo-1.0-2 + yum: + name: "1:foo-1.0-2.{{ ansible_architecture }}" + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-2')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Install foo-1.0-2 again + yum: + name: foo-1.0-2 + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "not yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-2')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Update to the latest foo + yum: + name: foo + state: latest + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.1-1')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Install foo-1.0-1 from a file (higher version is already installed) + yum: + name: "{{ repodir }}/foo-1.0-1.{{ ansible_architecture }}.rpm" + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "not yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.1-1')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + +- name: Remove foo + yum: + name: foo + state: absent +# ============================================================================ +- name: Install foo-1.0-1 from a file + yum: + name: "{{ repodir }}/foo-1.0-1.{{ ansible_architecture }}.rpm" + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-1')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Install foo-1.0-1 from a file again + yum: + name: "{{ repodir }}/foo-1.0-1.{{ ansible_architecture }}.rpm" + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "not yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-1')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Install foo-1.0-2 from a file + yum: + name: "{{ repodir }}/foo-1.0-2.{{ ansible_architecture }}.rpm" + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-2')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Install foo-1.0-2 from a file again + yum: + name: "{{ repodir }}/foo-1.0-2.{{ ansible_architecture }}.rpm" + state: present + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "not yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-2')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Try to downgrade foo without allow_downgrade being set + yum: + name: foo-1.0-1 + state: present + allow_downgrade: no + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "not yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-2')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Downgrade foo + yum: + name: foo-1.0-1 + state: present + allow_downgrade: yes + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.0-1')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Update foo with update_only set + yum: + name: foo + state: latest + update_only: yes + register: yum_result + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 0" + - "yum_result.rc == 0" + - "yum_result.changed" + - "not yum_result|failed" + - "rpm_result.stdout.startswith('foo-1.1-1')" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" + +- name: Remove foo + yum: + name: foo + state: absent +# ============================================================================ +- name: Try to update foo which is not installed, update_only is set + yum: + name: foo + state: latest + update_only: yes + register: yum_result + ignore_errors: yes + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + ignore_errors: yes + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 1" + - "yum_result.rc == 0" + - "not yum_result.changed" + - "not yum_result|failed" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ +- name: Try to install incompatible arch + yum: + name: "{{ repodir_ppc64 }}/foo-1.0-1.ppc64.rpm" + state: present + register: yum_result + ignore_errors: yes + +- name: Check foo with rpm + shell: rpm -q foo + register: rpm_result + ignore_errors: yes + +- name: Verify installation + assert: + that: + - "rpm_result.rc == 1" + - "yum_result.rc == 1" + - "not yum_result.changed" + - "yum_result|failed" + +- name: Verify yum module outputs + assert: + that: + - "'changed' in yum_result" + - "'msg' in yum_result" + - "'rc' in yum_result" + - "'results' in yum_result" +# ============================================================================ diff --git a/test/integration/targets/yum/tasks/yum_group_remove.yml b/test/integration/targets/yum/tasks/yum_group_remove.yml index 3e546c4ff1..96a7dc5266 100644 --- a/test/integration/targets/yum/tasks/yum_group_remove.yml +++ b/test/integration/targets/yum/tasks/yum_group_remove.yml @@ -85,10 +85,6 @@ state: present register: yum_output -- debug: - var: yum_output - verbosity: 1 - - name: check mode remove the group along with the package yum: name: "@Development Tools,sos" diff --git a/test/integration/targets/yum/tasks/yuminstallroot.yml b/test/integration/targets/yum/tasks/yuminstallroot.yml index 0ff302ebd6..13fc300200 100644 --- a/test/integration/targets/yum/tasks/yuminstallroot.yml +++ b/test/integration/targets/yum/tasks/yuminstallroot.yml @@ -40,9 +40,6 @@ failed_when: False register: rpm_result -- debug: var=yum_result -- debug: var=rpm_result - - name: verify installation of sos assert: that: