Decode object content to string

HEAT expects values in the file map to be strings. Contents of swift
objects are returned as bytes and therefor must be decoded. Add logic to
decode the returned object if it is bytes, otherwise return it as is.

Story: 2011302
Task: 51427
Change-Id: I01a2d3f9191ba1d7382c7cdcb033cb0936e113f6
This commit is contained in:
Frank Berghaus
2024-11-29 10:31:32 +01:00
committed by Takashi Kajinami
parent 8dfa34307d
commit 3533e88bb7
2 changed files with 11 additions and 1 deletions

View File

@@ -166,7 +166,10 @@ class SwiftClientPlugin(client_plugin.ClientPlugin):
file_name = obj['name']
if file_name not in files_to_skip:
contents = client.get_object(files_container, file_name)[1]
files[file_name] = contents
if isinstance(contents, bytes):
files[file_name] = contents.decode(encoding='utf-8')
else:
files[file_name] = contents
except exceptions.ClientException as cex:
raise exception.NotFound(_('Could not fetch files from '
'container %(container)s, '

View File

@@ -0,0 +1,7 @@
---
fixes:
- |
Fixed the consistent type mismatch error caused by creating or updating
a stack with files stored in OpenStack Swift containers, using
the `files_container` parameter. Now file content is always decoded and
can be used as a string value.