From 6521f1b81adf9502bc2ab10fa72fd75b20348037 Mon Sep 17 00:00:00 2001 From: Daniel Bengtsson Date: Wed, 29 Apr 2020 11:40:06 +0200 Subject: [PATCH] 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 --- doc/source/roles/role-system_encoding.rst | 6 +++ playbooks/system_encoding.yaml | 13 +++++ roles/system_encoding/defaults/main.yml | 24 ++++++++++ .../molecule/default/Dockerfile | 37 ++++++++++++++ .../molecule/default/converge.yml | 47 ++++++++++++++++++ .../molecule/default/molecule.yml | 48 +++++++++++++++++++ roles/system_encoding/tasks/main.yml | 36 ++++++++++++++ zuul.d/molecule.yaml | 11 +++++ 8 files changed, 222 insertions(+) create mode 100644 doc/source/roles/role-system_encoding.rst create mode 100644 playbooks/system_encoding.yaml create mode 100644 roles/system_encoding/defaults/main.yml create mode 100644 roles/system_encoding/molecule/default/Dockerfile create mode 100644 roles/system_encoding/molecule/default/converge.yml create mode 100644 roles/system_encoding/molecule/default/molecule.yml create mode 100644 roles/system_encoding/tasks/main.yml diff --git a/doc/source/roles/role-system_encoding.rst b/doc/source/roles/role-system_encoding.rst new file mode 100644 index 000000000..abf53cee5 --- /dev/null +++ b/doc/source/roles/role-system_encoding.rst @@ -0,0 +1,6 @@ +====================== +Role - system_encoding +====================== + +.. ansibleautoplugin:: + :role: roles/system_encoding diff --git a/playbooks/system_encoding.yaml b/playbooks/system_encoding.yaml new file mode 100644 index 000000000..e99cbd831 --- /dev/null +++ b/playbooks/system_encoding.yaml @@ -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 diff --git a/roles/system_encoding/defaults/main.yml b/roles/system_encoding/defaults/main.yml new file mode 100644 index 000000000..1d8756523 --- /dev/null +++ b/roles/system_encoding/defaults/main.yml @@ -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' diff --git a/roles/system_encoding/molecule/default/Dockerfile b/roles/system_encoding/molecule/default/Dockerfile new file mode 100644 index 000000000..417c6c702 --- /dev/null +++ b/roles/system_encoding/molecule/default/Dockerfile @@ -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"] \ No newline at end of file diff --git a/roles/system_encoding/molecule/default/converge.yml b/roles/system_encoding/molecule/default/converge.yml new file mode 100644 index 000000000..ff916e3d7 --- /dev/null +++ b/roles/system_encoding/molecule/default/converge.yml @@ -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 diff --git a/roles/system_encoding/molecule/default/molecule.yml b/roles/system_encoding/molecule/default/molecule.yml new file mode 100644 index 000000000..106126d92 --- /dev/null +++ b/roles/system_encoding/molecule/default/molecule.yml @@ -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 diff --git a/roles/system_encoding/tasks/main.yml b/roles/system_encoding/tasks/main.yml new file mode 100644 index 000000000..fc326ccc4 --- /dev/null +++ b/roles/system_encoding/tasks/main.yml @@ -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 diff --git a/zuul.d/molecule.yaml b/zuul.d/molecule.yaml index ad6ffafd9..66d51a0fa 100644 --- a/zuul.d/molecule.yaml +++ b/zuul.d/molecule.yaml @@ -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