mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
pkgng: check_mode should count queued actions
Writing tests caught a bug in PR #3393, which enabled installing more than one package per `pkg` execution. In converting the module's install/upgrade code to a queue structure, check_mode got broken because the count of actions performed was only updated in the `if not check_mode` block that invokes `pkg`. This two-line change counts the number of actions in the queue when check mode is enabled.
This commit is contained in:
parent
4fe3aea3a9
commit
5aff694dc4
2 changed files with 29 additions and 22 deletions
|
@ -1,2 +1,3 @@
|
|||
bugfixes:
|
||||
- 'pkgng - `name=* state=latest` check for upgrades did not count "Number of packages to be reinstalled" as a `changed` action, giving incorrect results in both regular and check mode'
|
||||
- 'pkgng - PR #3393 (https://github.com/ansible-collections/community.general/pull/3393) broke `check_mode` so that the module always reports `not changed`; fix regression so module reports number of upgrade or install actions that would be performed'
|
||||
|
|
|
@ -277,29 +277,35 @@ def install_packages(module, pkgng_path, packages, cached, pkgsite, dir_arg, sta
|
|||
else:
|
||||
action_queue["install"].append(package)
|
||||
|
||||
if not module.check_mode:
|
||||
# install/upgrade all named packages with one pkg command
|
||||
for (action, package_list) in action_queue.items():
|
||||
packages = ' '.join(package_list)
|
||||
if old_pkgng:
|
||||
rc, out, err = module.run_command("%s %s %s %s -g -U -y %s" % (batch_var, pkgsite, pkgng_path, action, packages))
|
||||
# install/upgrade all named packages with one pkg command
|
||||
for (action, package_list) in action_queue.items():
|
||||
if module.check_mode:
|
||||
# Do nothing, but count up how many actions
|
||||
# would be performed so that the changed/msg
|
||||
# is correct.
|
||||
action_count[action] += len(package_list)
|
||||
continue
|
||||
|
||||
packages = ' '.join(package_list)
|
||||
if old_pkgng:
|
||||
rc, out, err = module.run_command("%s %s %s %s -g -U -y %s" % (batch_var, pkgsite, pkgng_path, action, packages))
|
||||
else:
|
||||
rc, out, err = module.run_command("%s %s %s %s %s -g -U -y %s" % (batch_var, pkgng_path, dir_arg, action, pkgsite, packages))
|
||||
stdout += out
|
||||
stderr += err
|
||||
|
||||
# individually verify packages are in requested state
|
||||
for package in package_list:
|
||||
verified = False
|
||||
if action == 'install':
|
||||
verified = query_package(module, pkgng_path, package, dir_arg)
|
||||
elif action == 'upgrade':
|
||||
verified = not query_update(module, pkgng_path, package, dir_arg, old_pkgng, pkgsite)
|
||||
|
||||
if verified:
|
||||
action_count[action] += 1
|
||||
else:
|
||||
rc, out, err = module.run_command("%s %s %s %s %s -g -U -y %s" % (batch_var, pkgng_path, dir_arg, action, pkgsite, packages))
|
||||
stdout += out
|
||||
stderr += err
|
||||
|
||||
# individually verify packages are in requested state
|
||||
for package in package_list:
|
||||
verified = False
|
||||
if action == 'install':
|
||||
verified = query_package(module, pkgng_path, package, dir_arg)
|
||||
elif action == 'upgrade':
|
||||
verified = not query_update(module, pkgng_path, package, dir_arg, old_pkgng, pkgsite)
|
||||
|
||||
if verified:
|
||||
action_count[action] += 1
|
||||
else:
|
||||
module.fail_json(msg="failed to %s %s" % (action, package), stdout=stdout, stderr=stderr)
|
||||
module.fail_json(msg="failed to %s %s" % (action, package), stdout=stdout, stderr=stderr)
|
||||
|
||||
if sum(action_count.values()) > 0:
|
||||
past_tense = {'install': 'installed', 'upgrade': 'upgraded'}
|
||||
|
|
Loading…
Reference in a new issue