Fix copying Swift ring files

Ring files are binary formatted and should not be templated. Attempting
to template them causes an error such as the following:

    Template source files must be utf-8 encoded

This change fixes the issue by implementing support for configuration
files that are listed as 'untemplated'.

Change-Id: I9c6b0d9d5e13e8b82ebb8e8a3a0f432efb865e28
Story: 2007297
Task: 38774
This commit is contained in:
Mark Goddard 2020-12-08 17:33:51 +00:00
parent d169b4f5c7
commit c847ef9157
4 changed files with 25 additions and 9 deletions

View File

@ -101,7 +101,7 @@
- item.0.item.enabled | bool - item.0.item.enabled | bool
- item.1.path | basename not in item.0.item.ignore | default([]) - item.1.path | basename not in item.0.item.ignore | default([])
- name: Ensure extra configuration files exist - name: Ensure templated extra configuration files exist
template: template:
src: "{{ item.1.path }}" src: "{{ item.1.path }}"
dest: "{{ item.0.item.dest }}/{{ item.1.path | relpath(item.0.item.src) }}" dest: "{{ item.0.item.dest }}/{{ item.1.path | relpath(item.0.item.src) }}"
@ -113,6 +113,21 @@
when: when:
- item.0.item.enabled | bool - item.0.item.enabled | bool
- item.1.path | basename not in item.0.item.ignore | default([]) - item.1.path | basename not in item.0.item.ignore | default([])
- item.1.path | basename not in item.0.item.untemplated | default([])
- name: Ensure untemplated extra configuration files exist
copy:
src: "{{ item.1.path }}"
dest: "{{ item.0.item.dest }}/{{ item.1.path | relpath(item.0.item.src) }}"
mode: 0640
with_subelements:
- "{{ find_src_result.results }}"
- files
- skip_missing: true
when:
- item.0.item.enabled | bool
- item.1.path | basename not in item.0.item.ignore | default([])
- item.1.path | basename in item.0.item.untemplated | default([])
- name: Ensure unnecessary extra configuration files are absent - name: Ensure unnecessary extra configuration files are absent
file: file:

View File

@ -120,7 +120,7 @@ def main():
build_path = sys.argv[2] build_path = sys.argv[2]
service_name = sys.argv[3] service_name = sys.argv[3]
with open(config_path) as f: with open(config_path) as f:
config = yaml.load(f) config = yaml.safe_load(f)
build_rings(config, build_path, service_name) build_rings(config, build_path, service_name)

View File

@ -6,11 +6,6 @@
# Execute the following commands on the ring build host. # Execute the following commands on the ring build host.
- block: - block:
# Facts required for ansible_user_uid and ansible_user_gid.
- name: Gather facts for swift ring build host
setup:
when: not module_setup | default(false)
- name: Ensure Swift ring build directory exists - name: Ensure Swift ring build directory exists
file: file:
path: "{{ swift_ring_build_path }}" path: "{{ swift_ring_build_path }}"
@ -20,6 +15,7 @@
copy: copy:
src: swift-ring-builder.py src: swift-ring-builder.py
dest: "{{ swift_ring_build_path }}" dest: "{{ swift_ring_build_path }}"
register: copy_result
- name: Ensure Swift ring builder configuration exists - name: Ensure Swift ring builder configuration exists
template: template:
@ -33,14 +29,14 @@
docker_container: docker_container:
cleanup: true cleanup: true
command: >- command: >-
python {{ swift_container_build_path }}/swift-ring-builder.py python3 {{ swift_container_build_path }}/swift-ring-builder.py
{{ swift_container_build_path }}/{{ item }}-ring.yml {{ swift_container_build_path }}/{{ item }}-ring.yml
{{ swift_container_build_path }} {{ swift_container_build_path }}
{{ item }} {{ item }}
detach: false detach: false
image: "{{ swift_ring_build_image }}" image: "{{ swift_ring_build_image }}"
name: "swift_{{ item }}_ring_builder" name: "swift_{{ item }}_ring_builder"
user: "{{ ansible_user_uid }}:{{ ansible_user_gid }}" user: "{{ copy_result.uid }}:{{ copy_result.gid }}"
volumes: volumes:
- "{{ swift_ring_build_path }}/:{{ swift_container_build_path }}/" - "{{ swift_ring_build_path }}/:{{ swift_container_build_path }}/"
with_items: "{{ swift_service_names }}" with_items: "{{ swift_service_names }}"

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fixes an issue with copying Swift ring files. See `story 2007297
<https://storyboard.openstack.org/#!/story/2007297>`__ for details.