diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
commit | a453ac31f3428614cceb99027f8efbdb9258a40b (patch) | |
tree | f61f87408f32a8511cbd91799f9cececb53e0374 /test/integration/targets/setup_rpm_repo | |
parent | Initial commit. (diff) | |
download | ansible-upstream.tar.xz ansible-upstream.zip |
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/setup_rpm_repo')
13 files changed, 329 insertions, 0 deletions
diff --git a/test/integration/targets/setup_rpm_repo/aliases b/test/integration/targets/setup_rpm_repo/aliases new file mode 100644 index 00000000..65e83152 --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/aliases @@ -0,0 +1 @@ +needs/target/setup_epel diff --git a/test/integration/targets/setup_rpm_repo/defaults/main.yml b/test/integration/targets/setup_rpm_repo/defaults/main.yml new file mode 100644 index 00000000..19c033b9 --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/defaults/main.yml @@ -0,0 +1 @@ +install_repos: yes diff --git a/test/integration/targets/setup_rpm_repo/files/comps.xml b/test/integration/targets/setup_rpm_repo/files/comps.xml new file mode 100644 index 00000000..e9391829 --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/files/comps.xml @@ -0,0 +1,36 @@ +<!DOCTYPE comps PUBLIC "-//Red Hat, Inc.//DTD Comps info//EN" "comps.dtd"> +<comps> + <group> + <id>customgroup</id> + <name>Custom Group</name> + <description></description> + <default>false</default> + <uservisible>true</uservisible> + <display_order>1024</display_order> + <packagelist> + <packagereq type="mandatory">dinginessentail</packagereq> + </packagelist> + </group> + + <group> + <id>customenvgroup</id> + <name>Custom Environment Group</name> + <description></description> + <default>false</default> + <uservisible>false</uservisible> + <display_order>1024</display_order> + <packagelist> + <packagereq type="mandatory">landsidescalping</packagereq> + </packagelist> + </group> + + <environment> + <id>customenvgroup-environment</id> + <name>Custom Environment Group</name> + <description></description> + <display_order>1024</display_order> + <grouplist> + <groupid>customenvgroup</groupid> + </grouplist> + </environment> +</comps> diff --git a/test/integration/targets/setup_rpm_repo/files/create-repo.py b/test/integration/targets/setup_rpm_repo/files/create-repo.py new file mode 100644 index 00000000..2033fdf8 --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/files/create-repo.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python + + +import sys +from collections import namedtuple + +try: + from rpmfluff import SimpleRpmBuild + from rpmfluff import YumRepoBuild +except ImportError: + from rpmfluff.rpmbuild import SimpleRpmBuild + from rpmfluff.yumrepobuild import YumRepoBuild + +try: + from rpmfluff import can_use_rpm_weak_deps +except ImportError: + try: + from rpmfluff.utils import can_use_rpm_weak_deps + except ImportError: + can_use_rpm_weak_deps = None + +RPM = namedtuple('RPM', ['name', 'version', 'release', 'epoch', 'recommends']) + + +SPECS = [ + RPM('dinginessentail', '1.0', '1', None, None), + RPM('dinginessentail', '1.0', '2', '1', None), + RPM('dinginessentail', '1.1', '1', '1', None), + RPM('dinginessentail-olive', '1.0', '1', None, None), + RPM('dinginessentail-olive', '1.1', '1', None, None), + RPM('landsidescalping', '1.0', '1', None, None), + RPM('landsidescalping', '1.1', '1', None, None), + RPM('dinginessentail-with-weak-dep', '1.0', '1', None, ['dinginessentail-weak-dep']), + RPM('dinginessentail-weak-dep', '1.0', '1', None, None), +] + + +def main(): + try: + arch = sys.argv[1] + except IndexError: + arch = 'x86_64' + + pkgs = [] + for spec in SPECS: + pkg = SimpleRpmBuild(spec.name, spec.version, spec.release, [arch]) + pkg.epoch = spec.epoch + + if spec.recommends: + # Skip packages that require weak deps but an older version of RPM is being used + if not can_use_rpm_weak_deps or not can_use_rpm_weak_deps(): + continue + + for recommend in spec.recommends: + pkg.add_recommends(recommend) + + pkgs.append(pkg) + + repo = YumRepoBuild(pkgs) + repo.make(arch) + + for pkg in pkgs: + pkg.clean() + + print(repo.repoDir) + + +if __name__ == "__main__": + main() diff --git a/test/integration/targets/setup_rpm_repo/handlers/main.yml b/test/integration/targets/setup_rpm_repo/handlers/main.yml new file mode 100644 index 00000000..a0af3c92 --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/handlers/main.yml @@ -0,0 +1,5 @@ +- name: remove repos + yum_repository: + state: absent + name: "{{ item }}" + loop: "{{ repos }}" diff --git a/test/integration/targets/setup_rpm_repo/library/create_repo.py b/test/integration/targets/setup_rpm_repo/library/create_repo.py new file mode 100644 index 00000000..6dc1e457 --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/library/create_repo.py @@ -0,0 +1,94 @@ +#!/usr/bin/python + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os +import sys +import tempfile + +from collections import namedtuple + +from ansible.module_utils.basic import AnsibleModule + +try: + from rpmfluff import SimpleRpmBuild + from rpmfluff import YumRepoBuild +except ImportError: + from rpmfluff.rpmbuild import SimpleRpmBuild + from rpmfluff.yumrepobuild import YumRepoBuild + +try: + from rpmfluff import can_use_rpm_weak_deps +except ImportError: + try: + from rpmfluff.utils import can_use_rpm_weak_deps + except ImportError: + can_use_rpm_weak_deps = None + +RPM = namedtuple('RPM', ['name', 'version', 'release', 'epoch', 'recommends']) + + +SPECS = [ + RPM('dinginessentail', '1.0', '1', None, None), + RPM('dinginessentail', '1.0', '2', '1', None), + RPM('dinginessentail', '1.1', '1', '1', None), + RPM('dinginessentail-olive', '1.0', '1', None, None), + RPM('dinginessentail-olive', '1.1', '1', None, None), + RPM('landsidescalping', '1.0', '1', None, None), + RPM('landsidescalping', '1.1', '1', None, None), + RPM('dinginessentail-with-weak-dep', '1.0', '1', None, ['dinginessentail-weak-dep']), + RPM('dinginessentail-weak-dep', '1.0', '1', None, None), +] + + +def create_repo(arch='x86_64'): + pkgs = [] + for spec in SPECS: + pkg = SimpleRpmBuild(spec.name, spec.version, spec.release, [arch]) + pkg.epoch = spec.epoch + + if spec.recommends: + # Skip packages that require weak deps but an older version of RPM is being used + if not can_use_rpm_weak_deps or not can_use_rpm_weak_deps(): + continue + + for recommend in spec.recommends: + pkg.add_recommends(recommend) + + pkgs.append(pkg) + + repo = YumRepoBuild(pkgs) + repo.make(arch) + + for pkg in pkgs: + pkg.clean() + + return repo.repoDir + + +def main(): + module = AnsibleModule( + argument_spec={ + 'arch': {'required': True}, + 'tempdir': {'type': 'path'}, + } + ) + + arch = module.params['arch'] + tempdir = module.params['tempdir'] + + # Save current temp dir so we can set it back later + original_tempdir = tempfile.tempdir + tempfile.tempdir = tempdir + + try: + repo_dir = create_repo(arch) + finally: + tempfile.tempdir = original_tempdir + + module.exit_json(repo_dir=repo_dir, tmpfile=tempfile.gettempdir()) + + +if __name__ == "__main__": + main() diff --git a/test/integration/targets/setup_rpm_repo/meta/main.yml b/test/integration/targets/setup_rpm_repo/meta/main.yml new file mode 100644 index 00000000..1810d4be --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_remote_tmp_dir diff --git a/test/integration/targets/setup_rpm_repo/tasks/main.yml b/test/integration/targets/setup_rpm_repo/tasks/main.yml new file mode 100644 index 00000000..a6766f20 --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/tasks/main.yml @@ -0,0 +1,102 @@ +- block: + - name: Install epel repo which is missing on rhel-7 and is needed for rpmfluff + include_role: + name: setup_epel + when: + - ansible_distribution in ['RedHat', 'CentOS'] + - ansible_distribution_major_version is version('7', '==') + + - name: Include distribution specific variables + include_vars: "{{ lookup('first_found', params) }}" + vars: + params: + files: + - "{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml" + - "{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml" + - "{{ ansible_facts.distribution }}.yml" + - "{{ ansible_facts.os_family }}.yml" + - default.yml + paths: + - "{{ role_path }}/vars" + + - name: Install rpmfluff and deps + action: "{{ ansible_facts.pkg_mgr }}" + args: + name: "{{ rpm_repo_packages }}" + + - name: Install rpmfluff from pip on RHEL 8 and later + pip: + name: rpmfluff + when: + - ansible_facts.distribution in ['RedHat', 'CentOS'] + - ansible_facts.distribution_major_version is version('8', '>=') + + - set_fact: + repos: + - "fake-{{ ansible_architecture }}" + - "fake-i686" + - "fake-ppc64" + changed_when: yes + notify: remove repos + + - name: Create RPMs and put them into a repo + create_repo: + arch: "{{ ansible_architecture }}" + tempdir: "{{ remote_tmp_dir }}" + register: repo + + - set_fact: + repodir: "{{ repo.repo_dir }}" + + - name: Install the repo + yum_repository: + name: "fake-{{ ansible_architecture }}" + description: "fake-{{ ansible_architecture }}" + baseurl: "file://{{ repodir }}" + gpgcheck: no + when: install_repos | bool + + - name: Copy comps.xml file + copy: + src: comps.xml + dest: "{{ repodir }}" + register: repodir_comps + + - name: Register comps.xml on repo + command: createrepo -g {{ repodir_comps.dest | quote }} {{ repodir | quote }} + + - name: Create RPMs and put them into a repo (i686) + create_repo: + arch: i686 + tempdir: "{{ remote_tmp_dir }}" + register: repo_i686 + + - set_fact: + repodir_i686: "{{ repo_i686.repo_dir }}" + + - name: Install the repo (i686) + yum_repository: + name: "fake-i686" + description: "fake-i686" + baseurl: "file://{{ repodir_i686 }}" + gpgcheck: no + when: install_repos | bool + + - name: Create RPMs and put them into a repo (ppc64) + create_repo: + arch: ppc64 + tempdir: "{{ remote_tmp_dir }}" + register: repo_ppc64 + + - set_fact: + repodir_ppc64: "{{ repo_ppc64.repo_dir }}" + + - name: Install the repo (ppc64) + yum_repository: + name: "fake-ppc64" + description: "fake-ppc64" + baseurl: "file://{{ repodir_ppc64 }}" + gpgcheck: no + when: install_repos | bool + + when: ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] diff --git a/test/integration/targets/setup_rpm_repo/vars/Fedora.yml b/test/integration/targets/setup_rpm_repo/vars/Fedora.yml new file mode 100644 index 00000000..004f42bc --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/vars/Fedora.yml @@ -0,0 +1,4 @@ +rpm_repo_packages: + - "{{ 'python' ~ rpm_repo_python_major_version ~ '-rpmfluff' }}" + - createrepo + - rpm-build diff --git a/test/integration/targets/setup_rpm_repo/vars/RedHat-6.yml b/test/integration/targets/setup_rpm_repo/vars/RedHat-6.yml new file mode 100644 index 00000000..6edee17d --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/vars/RedHat-6.yml @@ -0,0 +1,5 @@ +rpm_repo_packages: + - rpm-build + - python-rpmfluff + - createrepo_c + - createrepo diff --git a/test/integration/targets/setup_rpm_repo/vars/RedHat-7.yml b/test/integration/targets/setup_rpm_repo/vars/RedHat-7.yml new file mode 100644 index 00000000..6edee17d --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/vars/RedHat-7.yml @@ -0,0 +1,5 @@ +rpm_repo_packages: + - rpm-build + - python-rpmfluff + - createrepo_c + - createrepo diff --git a/test/integration/targets/setup_rpm_repo/vars/RedHat-8.yml b/test/integration/targets/setup_rpm_repo/vars/RedHat-8.yml new file mode 100644 index 00000000..84849e23 --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/vars/RedHat-8.yml @@ -0,0 +1,4 @@ +rpm_repo_packages: + - rpm-build + - createrepo_c + - createrepo diff --git a/test/integration/targets/setup_rpm_repo/vars/main.yml b/test/integration/targets/setup_rpm_repo/vars/main.yml new file mode 100644 index 00000000..8e924fce --- /dev/null +++ b/test/integration/targets/setup_rpm_repo/vars/main.yml @@ -0,0 +1 @@ +rpm_repo_python_major_version: "{{ ansible_facts.python_version.split('.')[0] }}" |