Add a validation to check the local.

I don't know how to explain how it happens, but we have had several
customers case[1], for example, different local for writing to the database
and reading. What causes an error during minor update, the keystone
client calls the command to list the openstack projects. So we have a
python unicode error. For rabbitmq we force the utf-8 local, so we
decided that we assume that we must be in utf-8 everywhere. Add this
validation to ensure the local system is configure with the good local.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1824513

Change-Id: I8b8f2a17a4963af46dd2c5407fb089414a804247
This commit is contained in:
Daniel Bengtsson 2020-04-29 11:40:06 +02:00
parent a06dab904f
commit 6521f1b81a
8 changed files with 222 additions and 0 deletions

View File

@ -0,0 +1,6 @@
======================
Role - system_encoding
======================
.. ansibleautoplugin::
:role: roles/system_encoding

View File

@ -0,0 +1,13 @@
---
- hosts: all
vars:
metadata:
name: System encoding
description: >-
Ensure the local is unicode
groups:
- pre-deployment
- pre-upgrade
system_encoding_debug: false
roles:
- system_encoding

View File

@ -0,0 +1,24 @@
---
# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# All variables intended for modification should place placed in this file.
# All variables within this role should have a prefix of "system_encoding"
system_encoding_debug: false
system_encoding_wanted:
- 'utf8'
- 'utf-8'

View File

@ -0,0 +1,37 @@
# Molecule managed
# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \
elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install sudo python*-devel python*-dnf bash {{ item.pkg_extras | default('') }} && dnf clean all; \
elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl python-setuptools bash {{ item.pkg_extras | default('') }} && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \
elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml {{ item.pkg_extras | default('') }} && zypper clean -a; \
elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates {{ item.pkg_extras | default('') }}; \
elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates {{ item.pkg_extras | default('') }} && xbps-remove -O; fi
{% for pkg in item.easy_install | default([]) %}
# install pip for centos where there is no python-pip rpm in default repos
RUN easy_install {{ pkg }}
{% endfor %}
CMD ["sh", "-c", "while true; do sleep 10000; done"]

View File

@ -0,0 +1,47 @@
---
# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Converge
hosts: all
tasks:
- name: Test good values
vars:
system_encoding_locale: 'en_us.UTF-8'
include_role:
name: system_encoding
- name: Test failing
block:
- name: Validate against wrong locale
vars:
system_encoding_locale: 'C'
include_role:
name: system_encoding
rescue:
- name: Clear host errors
meta: clear_host_errors
- debug:
msg: The validation works! End the playbook run
- name: End play
meta: end_play
- name: Fail the test
fail:
msg: |
The system_encoding validation didn't properly detect wrong locale

View File

@ -0,0 +1,48 @@
---
driver:
name: docker
log: true
platforms:
- name: centos7
hostname: centos7
image: centos:7
dockerfile: Dockerfile
pkg_extras: python-setuptools
volumes:
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
easy_install:
- pip
environment: &env
http_proxy: "{{ lookup('env', 'http_proxy') }}"
https_proxy: "{{ lookup('env', 'https_proxy') }}"
- name: centos8
hostname: centos8
image: centos:8
dockerfile: Dockerfile
pkg_extras: python*-setuptools
volumes:
- /etc/ci/mirror_info.sh:/etc/ci/mirror_info.sh:ro
environment:
<<: *env
provisioner:
name: ansible
log: true
env:
ANSIBLE_STDOUT_CALLBACK: yaml
ANSIBLE_LIBRARY: "../../../../library"
scenario:
test_sequence:
- destroy
- create
- prepare
- converge
- verify
- destroy
verifier:
name: testinfra

View File

@ -0,0 +1,36 @@
---
# Copyright 2020 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Get local lang
set_fact:
locale_lang: "{{ (lookup('env', 'LANG')) }}"
when:
system_encoding_locale is not defined
- name: Set value to check
set_fact:
locale_to_check: >-
{%- if system_encoding_locale is defined -%}
{{ (system_encoding_locale | lower).split('.')[-1] }}
{%- else -%}
{{ (locale_lang | lower).split('.')[-1] }}
{%- endif -%}
- name: Verify the local
fail:
msg: >-
The local must be unicode ({{ system_encoding_wanted|join(', ') }}).
Got {{ locale_to_check }}
failed_when: locale_to_check not in system_encoding_wanted

View File

@ -2,6 +2,7 @@
- project-template:
check:
jobs:
- tripleo-validations-centos-8-molecule-system_encoding
- tripleo-validations-centos-8-molecule-ceph
- tripleo-validations-centos-8-molecule-check_latest_packages_version
- tripleo-validations-centos-8-molecule-check_network_gateway
@ -24,6 +25,7 @@
- tripleo-validations-centos-8-molecule-validate_selinux
gate:
jobs:
- tripleo-validations-centos-8-molecule-system_encoding
- tripleo-validations-centos-8-molecule-ceph
- tripleo-validations-centos-8-molecule-check_latest_packages_version
- tripleo-validations-centos-8-molecule-check_network_gateway
@ -33,6 +35,8 @@
- tripleo-validations-centos-8-molecule-dns
- tripleo-validations-centos-8-molecule-haproxy
- tripleo-validations-centos-8-molecule-image_serve
- tripleo-validations-centos-8-molecule-image_serve
- tripleo-validations-centos-8-molecule-nova_status
- tripleo-validations-centos-8-molecule-nova_status
- tripleo-validations-centos-8-molecule-rabbitmq_limits
- tripleo-validations-centos-8-molecule-repos
@ -386,3 +390,10 @@
parent: tripleo-validations-centos-8-base
vars:
tripleo_validations_role_name: ceph
- job:
files:
- ^roles/system_encoding/.*
name: tripleo-validations-centos-8-molecule-system_encoding
parent: tripleo-validations-centos-8-base
vars:
tripleo_validations_role_name: system_encoding