dnf: fix TypeError when env/group failed

(cherry picked from commit de299ef77c)
This commit is contained in:
Martin Krizek 2017-08-30 13:04:50 +02:00 committed by Toshio Kuratomi
parent f64c55e58f
commit 5db6b61cf0
2 changed files with 11 additions and 23 deletions

View file

@ -168,6 +168,7 @@ except ImportError:
HAS_DNF = False HAS_DNF = False
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
from ansible.module_utils.six import PY2 from ansible.module_utils.six import PY2
from distutils.version import LooseVersion from distutils.version import LooseVersion
@ -349,7 +350,7 @@ def ensure(module, base, state, names, autoremove):
for group_spec in (g.strip() for g in group_specs): for group_spec in (g.strip() for g in group_specs):
group = base.comps.group_by_pattern(group_spec) group = base.comps.group_by_pattern(group_spec)
if group: if group:
groups.append(group) groups.append(group.id)
else: else:
environment = base.comps.environment_by_pattern(group_spec) environment = base.comps.environment_by_pattern(group_spec)
if environment: if environment:
@ -365,18 +366,18 @@ def ensure(module, base, state, names, autoremove):
# Install groups. # Install groups.
for group in groups: for group in groups:
try: try:
base.group_install(group.id, dnf.const.GROUP_PACKAGE_TYPES) base.group_install(group, dnf.const.GROUP_PACKAGE_TYPES)
except dnf.exceptions.Error as e: except dnf.exceptions.Error as e:
# In dnf 2.0 if all the mandatory packages in a group do # In dnf 2.0 if all the mandatory packages in a group do
# not install, an error is raised. We want to capture # not install, an error is raised. We want to capture
# this but still install as much as possible. # this but still install as much as possible.
failures.append((group, e)) failures.append((group, to_native(e)))
for environment in environments: for environment in environments:
try: try:
base.environment_install(environment, dnf.const.GROUP_PACKAGE_TYPES) base.environment_install(environment, dnf.const.GROUP_PACKAGE_TYPES)
except dnf.exceptions.Error as e: except dnf.exceptions.Error as e:
failures.append((group, e)) failures.append((environment, to_native(e)))
# Install packages. # Install packages.
for pkg_spec in pkg_specs: for pkg_spec in pkg_specs:
@ -389,12 +390,12 @@ def ensure(module, base, state, names, autoremove):
for group in groups: for group in groups:
try: try:
try: try:
base.group_upgrade(group.id) base.group_upgrade(group)
except dnf.exceptions.CompsError: except dnf.exceptions.CompsError:
# If not already installed, try to install. # If not already installed, try to install.
base.group_install(group.id, dnf.const.GROUP_PACKAGE_TYPES) base.group_install(group, dnf.const.GROUP_PACKAGE_TYPES)
except dnf.exceptions.Error as e: except dnf.exceptions.Error as e:
failures.append((group, e)) failures.append((group, to_native(e)))
for environment in environments: for environment in environments:
try: try:
@ -402,9 +403,9 @@ def ensure(module, base, state, names, autoremove):
base.environment_upgrade(environment) base.environment_upgrade(environment)
except dnf.exceptions.CompsError: except dnf.exceptions.CompsError:
# If not already installed, try to install. # If not already installed, try to install.
base.environment_install(group, dnf.const.GROUP_PACKAGE_TYPES) base.environment_install(environment, dnf.const.GROUP_PACKAGE_TYPES)
except dnf.exceptions.Error as e: except dnf.exceptions.Error as e:
failures.append((group, e)) failures.append((environment, to_native(e)))
for pkg_spec in pkg_specs: for pkg_spec in pkg_specs:
# best effort causes to install the latest package # best effort causes to install the latest package
@ -423,7 +424,7 @@ def ensure(module, base, state, names, autoremove):
for group in groups: for group in groups:
try: try:
base.group_remove(group.id) base.group_remove(group)
except dnf.exceptions.CompsError: except dnf.exceptions.CompsError:
# Group is already uninstalled. # Group is already uninstalled.
pass pass

View file

@ -27,9 +27,6 @@
failed_when: False failed_when: False
register: rpm_result register: rpm_result
- debug: var=dnf_result
- debug: var=rpm_result
- name: verify uninstallation of sos - name: verify uninstallation of sos
assert: assert:
that: that:
@ -60,9 +57,6 @@
failed_when: False failed_when: False
register: rpm_result register: rpm_result
- debug: var=dnf_result
- debug: var=rpm_result
- name: verify installation of sos - name: verify installation of sos
assert: assert:
that: that:
@ -221,9 +215,6 @@
failed_when: False failed_when: False
register: rpm_result register: rpm_result
- debug: var=dnf_result
- debug: var=rpm_result
- name: verify installation of sos in / - name: verify installation of sos in /
assert: assert:
that: that:
@ -250,8 +241,6 @@
state: present state: present
register: dnf_result register: dnf_result
- debug: var=dnf_result
- name: verify installation of the group - name: verify installation of the group
assert: assert:
that: that:
@ -330,8 +319,6 @@
state: latest state: latest
register: dnf_result register: dnf_result
- debug: var=dnf_result
- name: verify installation of the group - name: verify installation of the group
assert: assert:
that: that: