pkgng: fix error-handling when upgrading all (#5369) (#5410)

* pkgng: fix error-handling when upgrading all

* provide for rc=1 in check_mode + test

* fix name of task in test

* add changelog fragment

(cherry picked from commit baa8bd52ab)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2022-10-23 20:56:12 +02:00 committed by GitHub
commit 557594c392
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 10 deletions

View file

@ -37,7 +37,7 @@ options:
state:
description:
- State of the package.
- 'Note: "latest" added in 2.7'
- 'Note: C(latest) added in 2.7.'
choices: [ 'present', 'latest', 'absent' ]
required: false
default: present
@ -148,10 +148,7 @@ def query_package(module, run_pkgng, name):
rc, out, err = run_pkgng('info', '-g', '-e', name)
if rc == 0:
return True
return False
return rc == 0
def query_update(module, run_pkgng, name):
@ -161,10 +158,7 @@ def query_update(module, run_pkgng, name):
# rc = 1, updates available
rc, out, err = run_pkgng('upgrade', '-g', '-n', name)
if rc == 1:
return True
return False
return rc == 1
def pkgng_older_than(module, pkgng_path, compare_version):
@ -190,7 +184,7 @@ def upgrade_packages(module, run_pkgng):
pkgng_args = ['upgrade']
pkgng_args.append('-n' if module.check_mode else '-y')
rc, out, err = run_pkgng(*pkgng_args)
rc, out, err = run_pkgng(*pkgng_args, check_rc=(not module.check_mode))
matches = re.findall('^Number of packages to be (?:upgraded|reinstalled): ([0-9]+)', out, re.MULTILINE)
for match in matches: