From 3533e88bb7bb548aaf1edc08932c4c1f70c8f7f8 Mon Sep 17 00:00:00 2001 From: Frank Berghaus Date: Fri, 29 Nov 2024 10:31:32 +0100 Subject: [PATCH] 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 --- heat/engine/clients/os/swift.py | 5 ++++- ...decode-files-read-from-containers-fe2bbb0b48a69717.yaml | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/heat-decode-files-read-from-containers-fe2bbb0b48a69717.yaml diff --git a/heat/engine/clients/os/swift.py b/heat/engine/clients/os/swift.py index 8919c84ac6..4dd59726b4 100644 --- a/heat/engine/clients/os/swift.py +++ b/heat/engine/clients/os/swift.py @@ -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, ' diff --git a/releasenotes/notes/heat-decode-files-read-from-containers-fe2bbb0b48a69717.yaml b/releasenotes/notes/heat-decode-files-read-from-containers-fe2bbb0b48a69717.yaml new file mode 100644 index 0000000000..45c8a893cb --- /dev/null +++ b/releasenotes/notes/heat-decode-files-read-from-containers-fe2bbb0b48a69717.yaml @@ -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.