1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

dnf: Call dnf.Base.close() before exit to cleanup. (#41810)

This commit is contained in:
Orion Poplawski 2018-07-18 13:11:32 -06:00 committed by ansibot
parent 67cf2da2a1
commit 32436ea9a5

View file

@ -287,6 +287,7 @@ def list_items(module, base, command):
packages = dnf.subject.Subject(command).get_best_query(base.sack) packages = dnf.subject.Subject(command).get_best_query(base.sack)
results = [_package_dict(package) for package in packages] results = [_package_dict(package) for package in packages]
base.close()
module.exit_json(results=results) module.exit_json(results=results)
@ -295,6 +296,7 @@ def _mark_package_install(module, base, pkg_spec):
try: try:
base.install(pkg_spec) base.install(pkg_spec)
except dnf.exceptions.MarkingError: except dnf.exceptions.MarkingError:
base.close()
module.fail_json(msg="No package {0} available.".format(pkg_spec)) module.fail_json(msg="No package {0} available.".format(pkg_spec))
@ -353,6 +355,7 @@ def ensure(module, base, state, names, autoremove):
if environment: if environment:
environments.append(environment.id) environments.append(environment.id)
else: else:
base.close()
module.fail_json( module.fail_json(
msg="No group {0} available.".format(group_spec)) msg="No group {0} available.".format(group_spec))
@ -419,6 +422,7 @@ def ensure(module, base, state, names, autoremove):
base.conf.clean_requirements_on_remove = autoremove base.conf.clean_requirements_on_remove = autoremove
if filenames: if filenames:
base.close()
module.fail_json( module.fail_json(
msg="Cannot remove paths -- please specify package name.") msg="Cannot remove paths -- please specify package name.")
@ -450,16 +454,20 @@ def ensure(module, base, state, names, autoremove):
if not base.resolve(allow_erasing=allow_erasing): if not base.resolve(allow_erasing=allow_erasing):
if failures: if failures:
base.close()
module.fail_json(msg='Failed to install some of the ' module.fail_json(msg='Failed to install some of the '
'specified packages', 'specified packages',
failures=failures) failures=failures)
base.close()
module.exit_json(msg="Nothing to do") module.exit_json(msg="Nothing to do")
else: else:
if module.check_mode: if module.check_mode:
if failures: if failures:
base.close()
module.fail_json(msg='Failed to install some of the ' module.fail_json(msg='Failed to install some of the '
'specified packages', 'specified packages',
failures=failures) failures=failures)
base.close()
module.exit_json(changed=True) module.exit_json(changed=True)
base.download_packages(base.transaction.install_set) base.download_packages(base.transaction.install_set)
@ -471,9 +479,11 @@ def ensure(module, base, state, names, autoremove):
response['results'].append("Removed: {0}".format(package)) response['results'].append("Removed: {0}".format(package))
if failures: if failures:
base.close()
module.fail_json(msg='Failed to install some of the ' module.fail_json(msg='Failed to install some of the '
'specified packages', 'specified packages',
failures=failures) failures=failures)
base.close()
module.exit_json(**response) module.exit_json(**response)