From e98c0a3009bc8efe4d8b04a7edb44ef22fb06488 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 4 Jan 2017 00:22:32 -0800 Subject: [PATCH] Fix locale_gen to compare native strings rather than mixing byte and text strings Fixes #19426 --- lib/ansible/modules/system/locale_gen.py | 4 +- test/integration/destructive.yml | 1 + test/integration/targets/locale_gen/aliases | 3 + .../targets/locale_gen/meta/main.yml | 2 + .../targets/locale_gen/tasks/locale_gen.yml | 94 +++++++++++++++++++ .../targets/locale_gen/tasks/main.yml | 19 ++++ 6 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/locale_gen/aliases create mode 100644 test/integration/targets/locale_gen/meta/main.yml create mode 100644 test/integration/targets/locale_gen/tasks/locale_gen.yml create mode 100644 test/integration/targets/locale_gen/tasks/main.yml diff --git a/lib/ansible/modules/system/locale_gen.py b/lib/ansible/modules/system/locale_gen.py index b56a5e498e2..8e6a1835e2c 100644 --- a/lib/ansible/modules/system/locale_gen.py +++ b/lib/ansible/modules/system/locale_gen.py @@ -55,8 +55,9 @@ import os.path from subprocess import Popen, PIPE, call import re -from ansible.module_utils.basic import * +from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.pycompat24 import get_exception +from ansible.module_utils._text import to_native LOCALE_NORMALIZATION = { ".utf8": ".UTF-8", @@ -99,6 +100,7 @@ def is_available(name, ubuntuMode): def is_present(name): """Checks if the given locale is currently installed.""" output = Popen(["locale", "-a"], stdout=PIPE).communicate()[0] + output = to_native(output) return any(fix_case(name) == fix_case(line) for line in output.splitlines()) def fix_case(name): diff --git a/test/integration/destructive.yml b/test/integration/destructive.yml index 6af39154708..7832a08c2f2 100644 --- a/test/integration/destructive.yml +++ b/test/integration/destructive.yml @@ -22,3 +22,4 @@ - { role: apache2_module, tags: test_apache2_module } # This removes ~/.ssh/known_hosts and /etc/ssh/known_hosts - { role: git, tags: test_git } + - { role: locale_gen, tags: test_locale_gen } diff --git a/test/integration/targets/locale_gen/aliases b/test/integration/targets/locale_gen/aliases new file mode 100644 index 00000000000..5eee2325ce1 --- /dev/null +++ b/test/integration/targets/locale_gen/aliases @@ -0,0 +1,3 @@ +destructive +needs/root +posix/ci/group3 diff --git a/test/integration/targets/locale_gen/meta/main.yml b/test/integration/targets/locale_gen/meta/main.yml new file mode 100644 index 00000000000..07faa217762 --- /dev/null +++ b/test/integration/targets/locale_gen/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - prepare_tests diff --git a/test/integration/targets/locale_gen/tasks/locale_gen.yml b/test/integration/targets/locale_gen/tasks/locale_gen.yml new file mode 100644 index 00000000000..ae316977f50 --- /dev/null +++ b/test/integration/targets/locale_gen/tasks/locale_gen.yml @@ -0,0 +1,94 @@ +- name: Is the locale we're going to test against installed? + shell: locale -a | grep pt_BR + register: initial_state + ignore_errors: True + +- name: Make sure the locale is not installed + locale_gen: + name: pt_BR + state: absent + +- name: Is the locale present? + shell: locale -a | grep pt_BR + register: cleaned + ignore_errors: True + +- name: Make sure the locale is not present + assert: + that: + - "cleaned.rc == 1" + +- name: Install the locale + locale_gen: + name: pt_BR + state: present + register: output + +- name: Is the locale present? + shell: locale -a | grep pt_BR + register: post_check_output + ignore_errors: True + +- name: Make sure the locale is present and we say we installed it + assert: + that: + - "post_check_output.rc == 0" + - "output.changed" + +- name: Install the locale a second time + locale_gen: + name: pt_BR + state: present + register: output + +- name: Is the locale present? + shell: locale -a | grep pt_BR + register: post_check_output + ignore_errors: True + +- name: Make sure the locale is present and we reported no change + assert: + that: + - "post_check_output.rc == 0" + - "not output.changed" + +- name: Remove the locale + locale_gen: + name: pt_BR + state: absent + register: output + +- name: Is the locale present? + shell: locale -a | grep pt_BR + register: post_check_output + ignore_errors: True + +- name: Make sure the locale is absent and we reported a change + assert: + that: + - "post_check_output.rc == 1" + - "output.changed" + +- name: Remove the locale a second time + locale_gen: + name: pt_BR + state: absent + register: output + +- name: Is the locale present? + shell: locale -a | grep pt_BR + register: post_check_output + ignore_errors: True + +- name: Make sure the locale is absent and we reported no change + assert: + that: + - "post_check_output.rc == 1" + - "not output.changed" + +# Cleanup +- name: Reinstall the locale we tested against if it was initially installed + locale_gen: + name: pt_BR + state: present + when: initial_state.rc == 0 diff --git a/test/integration/targets/locale_gen/tasks/main.yml b/test/integration/targets/locale_gen/tasks/main.yml new file mode 100644 index 00000000000..4fb1b9dd28b --- /dev/null +++ b/test/integration/targets/locale_gen/tasks/main.yml @@ -0,0 +1,19 @@ +# (c) 2014, James Tanner + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- include: 'locale_gen.yml' + when: ansible_distribution in ('Ubuntu', 'Debian')