Fix load-import --local with proxy

When load-import is called with --local the load is imported locally
from the active controller. When it's called with "--os-region-name
SystemController", the request is intercepted by the dc-api-proxy.

This commit fixes a bug that happens when the request is intercepted
by the dc-api-proxy. When using --local, the function receives the
params through "request.body" and when not using it the params come
through request.POST. Only the second way was being treated.

Test plan:
  PASS: load-import with --os-region-name SystemController,
  --inactive and --local should be completed if using an upgradable
  load
  PASS: load-import with --os-region-name SystemController,
  --inactive and --local should fail if using a non-upgradable load
  PASS: load-import with --os-region-name SystemController, --active,
  and --local should complete using a load from the same version
  PASS: load-import with --os-region-name SystemController and
  --inactive should be completed if using an upgradable load
  PASS: load-import with --os-region-name SystemController and
  --inactive should fail if using a non-upgradable load

Closes-bug: 2043511

Change-Id: Id5c02fdc35c43b4134fd34592de36d35f9fc88b6
Signed-off-by: Lindley Werner <Lindley.Vieira@windriver.com>
This commit is contained in:
Lindley Werner 2023-11-14 15:15:43 -03:00
parent 87653b7890
commit c5e1d7c131

View File

@ -407,11 +407,22 @@ class SysinvAPIController(APIController):
# folder to be processed by sysinv
if self._is_load_import(request.path) and not cfg.CONF.use_usm:
req_body = self._store_load_to_vault(req)
if 'active' in request.POST:
req_body['active'] = request.POST['active']
params_dict = request.POST
try:
# If load import is done with --local, the params active
# and inactive comes from the request body.
# If not done with --local, the params comes from request.POST
# in this case, the decode below will raise an exception
# and params_dict will continue point to request.POST
params_dict = json.loads(request.body.decode('utf-8'))
except UnicodeDecodeError:
pass
if 'inactive' in request.POST:
req_body['inactive'] = request.POST['inactive']
if 'active' in params_dict:
req_body['active'] = params_dict['active']
if 'inactive' in params_dict:
req_body['inactive'] = params_dict['inactive']
# sysinv will handle a simple application/json request
# with the file location