mirror of https://github.com/ansible/ansible.git
[stable-2.10] Make yum_repository test more reliable (#73467)
* Improve setup_rpm_repo
- add handlers to remove repos
- add variable to control whethere or not repos are created
* Use local repo for all distros
* Change repo creation script to module.
(cherry picked from commit 997b2d2a19
)
Co-authored-by: Sam Doran <sdoran@redhat.com>
pull/73479/head
parent
985a395cd9
commit
457dcf1313
@ -0,0 +1 @@
|
||||
install_repos: yes
|
@ -0,0 +1,5 @@
|
||||
- name: remove repos
|
||||
yum_repository:
|
||||
state: absent
|
||||
name: "{{ item }}"
|
||||
loop: "{{ repos }}"
|
@ -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()
|
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- setup_remote_tmp_dir
|
@ -0,0 +1,5 @@
|
||||
yum_repository_test_package: dinginessentail
|
||||
yum_repository_test_repo:
|
||||
name: fakerepo
|
||||
description: Fake Repo
|
||||
baseurl: "file://{{ repodir }}"
|
@ -0,0 +1,4 @@
|
||||
- name: remove listtest repo
|
||||
yum_repository:
|
||||
name: listtest
|
||||
state: absent
|
@ -0,0 +1,4 @@
|
||||
dependencies:
|
||||
- role: setup_rpm_repo
|
||||
vars:
|
||||
install_repos: no
|
@ -1,10 +0,0 @@
|
||||
yum_repository_test_package: sshpass
|
||||
yum_repository_test_repo:
|
||||
name: epel
|
||||
description: EPEL yum repo
|
||||
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/Everything/$basearch
|
||||
|
||||
yum_repository_epel:
|
||||
description: Extra Packages for Enterprise Linux $releasever - $basearch
|
||||
metalink: https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
|
||||
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_facts.distribution_major_version }}
|
@ -1,10 +0,0 @@
|
||||
yum_repository_test_package: sl
|
||||
yum_repository_test_repo:
|
||||
name: epel
|
||||
description: EPEL yum repo
|
||||
baseurl: https://archives.fedoraproject.org/pub/archive/epel/{{ ansible_facts.distribution_major_version }}/$basearch
|
||||
|
||||
yum_repository_epel:
|
||||
description: Extra Packages for Enterprise Linux {{ ansible_facts.distribution_major_version }} - $basearch
|
||||
mirrorlist: https://mirrors.fedoraproject.org/metalink?repo=epel-{{ ansible_facts.distribution_major_version }}&arch=$basearch
|
||||
gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_facts.distribution_major_version }}
|
@ -1,5 +0,0 @@
|
||||
yum_repository_test_package: libbdplus
|
||||
yum_repository_test_repo:
|
||||
name: rpmfusion-free
|
||||
description: RPM Fusion for Fedora {{ ansible_distribution_major_version }} - Free
|
||||
baseurl: http://download1.rpmfusion.org/free/fedora/releases/{{ ansible_distribution_major_version }}/Everything/{{ ansible_architecture }}/os/
|
Loading…
Reference in New Issue