Skip to content

Commit

Permalink
tests: enable locale_gen not only for Debian
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Shalygin <k0ste@k0ste.ru>
  • Loading branch information
k0ste committed Feb 18, 2025
1 parent 69eceb0 commit 9784dfc
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bugfixes:
- "locale_gen - use ``glibc_ubuntu`` mode only if files for that exists (https://github.com/ansible-collections/community.general/pull/9735)."
- "locale_gen - use ``glibc`` mode only if files for that exists. In other case us ``other_glibc`` mode (https://github.com/ansible-collections/community.general/pull/9735)."
12 changes: 6 additions & 6 deletions plugins/modules/locale_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
description: Mechanism used to deploy the locales.
type: str
choices:
- ubuntu_glibc
- ubuntu_legacy
- glibc
- ubuntu_legacy
- other_glibc
returned: success
sample: glibc
version_added: 10.2.0
Expand Down Expand Up @@ -120,22 +120,22 @@ def __init_module__(self):
available=SUPPORTED_LOCALES,
apply_change=self.apply_change_ubuntu_legacy,
),
ubuntu_glibc=dict(
glibc=dict(
available=SUPPORTED_LOCALES,
apply_change=self.apply_change_glibc,
),
glibc=dict(
other_glibc=dict(
available=ETC_LOCALE_GEN,
apply_change=self.apply_change_glibc,
),
)

if os.path.exists(ETC_LOCALE_GEN) and os.path.exists(SUPPORTED_LOCALES):
self.vars.ubuntu_mode = False
self.vars.mechanism = "ubuntu_glibc"
self.vars.mechanism = "glibc"
elif os.path.exists(ETC_LOCALE_GEN):
self.vars.ubuntu_mode = False
self.vars.mechanism = "glibc"
self.vars.mechanism = "other_glibc"
elif os.path.exists(VAR_LIB_LOCALES):
self.vars.ubuntu_mode = True
self.vars.mechanism = "ubuntu_legacy"
Expand Down
13 changes: 11 additions & 2 deletions tests/integration/targets/locale_gen/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@

- name: Bail out if not supported
ansible.builtin.meta: end_play
when: ansible_distribution not in ('Ubuntu', 'Debian')
when:
- "ansible_distribution not in ('Ubuntu', 'Debian', 'Archlinux', 'Fedora')"

- name: Run tests auto-detecting mechanism
- name: Run tests auto-detecting mechanism [Debian]
ansible.builtin.include_tasks: basic.yml
loop: "{{ locale_list_basic }}"
loop_control:
loop_var: locale_basic
when:
- "ansible_distribution in ('Ubuntu', 'Debian')"

- name: Run tests auto-detecting mechanism [Archlinux, RedHat]
ansible.builtin.include_tasks:
file: "non_debian.yml"
when:
- "ansible_os_family in ('RedHat', 'Archlinux')"
52 changes: 52 additions & 0 deletions tests/integration/targets/locale_gen/tasks/non_debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later

- name: "Non dnf RedHat systemd are not supported"
ansible.builtin.meta: "end_play"
when:
- "ansible_pkg_mgr == 'yum'"

- name: "Prepare locale packages"
block:
- name: "Install locale packages for RedHat"
ansible.builtin.dnf:
name:
- "glibc-langpack-pl"
- "glibc-langpack-en"
state: "present"
update_cache: "yes"
when:
- "ansible_os_family == 'RedHat'"
- name: "Install locale packages for Archlinux"
ansible.builtin.dnf:
name: "glibc-locales"
state: "present"
update_cache: "yes"
when:
- "ansible_os_family == 'Archlinux'"

- name: "Prepare locale.gen file for RedHat or Archlinux"
ansible.builtin.template:
src: "locale_gen.j2"
dest: "/etc/locale.gen"
owner: "root"
group: "root"
mode: "0644"
force: "yes"

- name: "Check for locale that pack are not installed"
locale_gen:
name: "ansible.UTF-8"
state: "present"
register: "locale_gen_locale_missed_result"
ignore_errors: true

- name: "Deploy locales"
locale_gen:
name: "{{ item['locale'] + '.' + item['charset'] }}"
state: "present"
loop: "{{ vars['locale_list_simple'] | flatten(levels=1) }}"
loop_control:
label: "{{ 'Deploy locale: ' + item['locale'] }}"
9 changes: 9 additions & 0 deletions tests/integration/targets/locale_gen/templates/locale_gen.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{#
Copyright (c) Ansible Project
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
SPDX-License-Identifier: GPL-3.0-or-later
#}

{% for l in vars['locale_list_simple'] %}
{{ l['locale'] + '.' + l['charset'] + ' ' + l['charset'] }}
{% endfor %}
8 changes: 8 additions & 0 deletions tests/integration/targets/locale_gen/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,11 @@ locale_list_basic:
- localegen: de_CH.UTF-8
locales: [de_CH.utf8]
skip_removal: false

# Simple locales list for non Debian distro

locale_list_simple:
- locale: 'en_US'
charset: 'UTF-8'
- locale: 'pl_PL'
charset: 'UTF-8'

0 comments on commit 9784dfc

Please sign in to comment.