Fix update install-values for subclouds
Currently, all parameter values are being enclosed in quotes when parsing the subcloud update request. This works fine for string parameters (description, location, group-id, etc.), however it causes an issue with the install-values parameter, since it's an yaml file. This causes the yaml.safe_load() to return a string instead of a dictionary with the parsed install-values content. This fix simplifies the parsing function (_get_patch_data) by only applying the yaml.safe_load() function to the install-values parameter. Enclosing the fields in quotes is not necessary anymore (related to issue #1989619, change #857762). Test plan: PASS: Update the subcloud description and location through Horizon; PASS: Update the subcloud with the --install-values parameter through the CLI. PASS: Manage a subcloud with the --force parameter (the subcloud manage command uses the subcloud update endpoint and accepts the --force param.) Closes-Bug: #1995716 Related-bug: #1989619 Signed-off-by: Gustavo Herzmann <gustavo.herzmann@windriver.com> Change-Id: I40194f1b6bf7a8bd480914eac6b659be3e021d19
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
|
||||
from requests_toolbelt.multipart import decoder
|
||||
|
||||
import base64
|
||||
@@ -30,6 +31,7 @@ import os
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_messaging import RemoteError
|
||||
import re
|
||||
import yaml
|
||||
|
||||
import pecan
|
||||
@@ -110,6 +112,12 @@ MANDATORY_RESTORE_VALUES = [
|
||||
]
|
||||
|
||||
|
||||
def _get_multipart_field_name(part):
|
||||
content = part.headers[b"Content-Disposition"].decode("utf8")
|
||||
regex = 'name="([^"]*)"'
|
||||
return re.search(regex, content).group(1)
|
||||
|
||||
|
||||
class SubcloudsController(object):
|
||||
VERSION_ALIASES = {
|
||||
'Newton': '1.0',
|
||||
@@ -190,19 +198,20 @@ class SubcloudsController(object):
|
||||
|
||||
@staticmethod
|
||||
def _get_patch_data(request):
|
||||
fields = ['management-state', 'description', 'location', 'group_id',
|
||||
'bmc_password', INSTALL_VALUES, 'force']
|
||||
payload = dict()
|
||||
multipart_data = decoder.MultipartDecoder(
|
||||
request.body, pecan.request.headers.get('Content-Type'))
|
||||
for f in fields:
|
||||
for part in multipart_data.parts:
|
||||
for hk, hv in part.headers.items():
|
||||
if (hk.decode('utf8') == 'Content-Disposition' and
|
||||
f in hv.decode('utf8')):
|
||||
content = '"%s"' % part.content.decode('utf8')
|
||||
data = yaml.safe_load(content)
|
||||
payload.update({f: data})
|
||||
content_type = request.headers.get("Content-Type")
|
||||
multipart_data = decoder.MultipartDecoder(request.body, content_type)
|
||||
|
||||
for part in multipart_data.parts:
|
||||
field_name = _get_multipart_field_name(part)
|
||||
field_content = part.text
|
||||
|
||||
# only the install_values field is yaml, force should be bool
|
||||
if field_name in [INSTALL_VALUES, 'force']:
|
||||
field_content = yaml.safe_load(field_content)
|
||||
|
||||
payload[field_name] = field_content
|
||||
|
||||
return payload
|
||||
|
||||
@staticmethod
|
||||
|
Reference in New Issue
Block a user