Fix subcloud fields update

This commit addresses the issue encountered when updating the
subcloud fields directly with a file. This caused issues because
the file would be closed, making the content inaccessible. Now,
we create a variable containing the content and update the fields
using only this content.

Test Plan:
TODO: Create a subcloud
TODO: Update a subcloud
TODO: Redeploy a subcloud
TODO: Create a subcloud backup
TODO: Subcloud deploy upload

Closes-bug: 2055446

Change-Id: Ib8b831353dba9d073131eb1c12ccd57513c63e7f
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
This commit is contained in:
Hugo Brito 2024-02-29 14:25:49 -03:00
parent a507c6449d
commit 819ab4d8ef
4 changed files with 14 additions and 7 deletions

View File

@ -28,7 +28,8 @@ class phased_subcloud_deploy_manager(base.ResourceManager):
fields = {}
for k, v in body.items():
with open(v, "rb") as file:
fields.update({k: (v, file)})
file_content = file.read()
fields.update({k: (v, file_content)})
fields.update(data)
enc = MultipartEncoder(fields=fields)
headers = {"content-type": enc.content_type}

View File

@ -24,7 +24,8 @@ class subcloud_backup_manager(base.ResourceManager):
if files:
for k, v in files.items():
with open(v, "rb") as file:
fields.update({k: (v, file)})
file_content = file.read()
fields.update({k: (v, file_content)})
fields.update(data)
enc = MultipartEncoder(fields=fields)
headers = {"content-type": enc.content_type}
@ -57,7 +58,8 @@ class subcloud_backup_manager(base.ResourceManager):
if files:
for k, v in files.items():
with open(v, "rb") as file:
fields.update({k: (v, file)})
file_content = file.read()
fields.update({k: (v, file_content)})
fields.update(data)
enc = MultipartEncoder(fields=fields)
headers = {"content-type": enc.content_type}

View File

@ -74,7 +74,8 @@ class subcloud_deploy_manager(base.ResourceManager):
fields = {}
for k, v in files.items():
with open(v, "rb") as file:
fields.update({k: (v, file)})
file_content = file.read()
fields.update({k: (v, file_content)})
fields.update(data)
enc = MultipartEncoder(fields=fields)
headers = {"content-type": enc.content_type}

View File

@ -33,7 +33,8 @@ class subcloud_manager(base.ResourceManager):
fields = {}
for k, v in body.items():
with open(v, "rb") as file:
fields.update({k: (v, file)})
file_content = file.read()
fields.update({k: (v, file_content)})
fields.update(data)
enc = MultipartEncoder(fields=fields)
headers = {"content-type": enc.content_type}
@ -50,7 +51,8 @@ class subcloud_manager(base.ResourceManager):
if body:
for k, v in body.items():
with open(v, "rb") as file:
fields.update({k: (v, file)})
file_content = file.read()
fields.update({k: (v, file_content)})
fields.update(data)
enc = MultipartEncoder(fields=fields)
headers = {"content-type": enc.content_type}
@ -66,7 +68,8 @@ class subcloud_manager(base.ResourceManager):
fields = {}
for k, v in body.items():
with open(v, "rb") as file:
fields.update({k: (v, file)})
file_content = file.read()
fields.update({k: (v, file_content)})
fields.update(data)
enc = MultipartEncoder(fields=fields)
headers = {"content-type": enc.content_type}