Add a switch to patching proxy
Add a switch to patching to allow the proxy to handle patch api and usm requests. Once the usm is fully integrated, this parameter will be removed(Task 48986). Depends-on: https://review.opendev.org/c/starlingx/stx-puppet/+/891343 Story: 2010676 Task: 48615 Test Case: PASS: Turn the switch on and upload a patch using the software upload command and verify that the patch is uploaded to dc-vault PASS: Turn the switch on and upload a patch using the software upload-dir command and verify that the patch is uploaded to dc-vault PASS: Turn the switch off and upload a patch using the sw-patch upload command and verify that the patch is uploaded to dc-vault PASS: Turn the switch off and upload a patch using the sw-patch upload-dir command and verify that the patch is uploaded to dc-vault PASS: Turn the switch off and delete a patch using the sw-patch delete command and verify that the patch is removed from dc-vault PASS: Turn the switch on and delete a patch using the software delete command and verify that the patch is removed from dc-vault PASS: turn the switch on and commit a patch and verify that the usm status is set to unknown. Signed-off-by: Christopher Souza <Christopher.DeOliveiraSouza@windriver.com> Change-Id: I202df4beb4979ddcbbf5a926b9b53e265aa77333
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Copyright 2018-2022 Wind River
|
||||
# Copyright 2018-2023 Wind River
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -39,20 +39,30 @@ from dcmanager.rpc import client as dcmanager_rpc_client
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
patch_opts = [
|
||||
cfg.StrOpt('patch_vault',
|
||||
default='/opt/dc-vault/patches/',
|
||||
help='file system for patch storage on SystemController'),
|
||||
]
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
if cfg.CONF.use_usm:
|
||||
patch_opts = [
|
||||
cfg.StrOpt('patch_vault',
|
||||
default='/opt/dc-vault/software/',
|
||||
help='file system for software storage on SystemController'),
|
||||
]
|
||||
else:
|
||||
patch_opts = [
|
||||
cfg.StrOpt('patch_vault',
|
||||
default='/opt/dc-vault/patches/',
|
||||
help='file system for patch storage on SystemController'),
|
||||
]
|
||||
|
||||
CONF.register_opts(patch_opts, CONF.type)
|
||||
|
||||
|
||||
class PatchAPIController(Middleware):
|
||||
|
||||
ENDPOINT_TYPE = dccommon_consts.ENDPOINT_TYPE_PATCHING
|
||||
if cfg.CONF.use_usm:
|
||||
ENDPOINT_TYPE = dccommon_consts.ENDPOINT_TYPE_SOFTWARE
|
||||
else:
|
||||
ENDPOINT_TYPE = dccommon_consts.ENDPOINT_TYPE_PATCHING
|
||||
|
||||
OK_STATUS_CODE = [
|
||||
webob.exc.HTTPOk.code,
|
||||
]
|
||||
@@ -65,14 +75,22 @@ class PatchAPIController(Middleware):
|
||||
self.ctxt = context.get_admin_context()
|
||||
self._default_dispatcher = APIDispatcher(app)
|
||||
self.dcmanager_state_rpc_client = dcmanager_rpc_client.SubcloudStateClient()
|
||||
self.response_hander_map = {
|
||||
proxy_consts.PATCH_ACTION_UPLOAD: self.patch_upload_req,
|
||||
proxy_consts.PATCH_ACTION_UPLOAD_DIR: self.patch_upload_dir_req,
|
||||
proxy_consts.PATCH_ACTION_DELETE: self.patch_delete_req,
|
||||
proxy_consts.PATCH_ACTION_APPLY: self.notify,
|
||||
proxy_consts.PATCH_ACTION_COMMIT: self.notify,
|
||||
proxy_consts.PATCH_ACTION_REMOVE: self.notify,
|
||||
}
|
||||
if cfg.CONF.use_usm:
|
||||
self.response_hander_map = {
|
||||
proxy_consts.SOFTWARE_ACTION_UPLOAD: self.patch_upload_usm_req,
|
||||
proxy_consts.SOFTWARE_ACTION_UPLOAD_DIR: self.patch_upload_dir_req,
|
||||
proxy_consts.SOFTWARE_ACTION_DELETE: self.patch_delete_req,
|
||||
proxy_consts.SOFTWARE_ACTION_COMMIT_PATCH: self.notify,
|
||||
}
|
||||
else:
|
||||
self.response_hander_map = {
|
||||
proxy_consts.PATCH_ACTION_UPLOAD: self.patch_upload_req,
|
||||
proxy_consts.PATCH_ACTION_UPLOAD_DIR: self.patch_upload_dir_req,
|
||||
proxy_consts.PATCH_ACTION_DELETE: self.patch_delete_req,
|
||||
proxy_consts.PATCH_ACTION_APPLY: self.notify,
|
||||
proxy_consts.PATCH_ACTION_COMMIT: self.notify,
|
||||
proxy_consts.PATCH_ACTION_REMOVE: self.notify,
|
||||
}
|
||||
|
||||
@webob.dec.wsgify(RequestClass=Request)
|
||||
def __call__(self, req):
|
||||
@@ -97,6 +115,8 @@ class PatchAPIController(Middleware):
|
||||
def copy_patch_to_version_vault(self, patch):
|
||||
try:
|
||||
sw_version = get_release_from_patch(patch)
|
||||
if cfg.CONF.use_usm:
|
||||
sw_version = ".".join(sw_version.split('.', 2)[:2])
|
||||
except Exception:
|
||||
msg = "Unable to fetch release version from patch"
|
||||
LOG.error(msg)
|
||||
@@ -169,6 +189,31 @@ class PatchAPIController(Middleware):
|
||||
proxy_utils.cleanup(request.environ)
|
||||
return response
|
||||
|
||||
# TODO(cdeolive): update to handle upload and delete of loads
|
||||
# when USM upgrade API is ready. Rename de iso and sig with
|
||||
# metadata ID
|
||||
def patch_upload_usm_req(self, request, response):
|
||||
# stores release in the release storage
|
||||
file_items = []
|
||||
for key in request.POST.keys():
|
||||
file_items.append(request.POST[key])
|
||||
try:
|
||||
for file_item in file_items:
|
||||
self.store_patch_file(file_item.filename, file_item.file.fileno())
|
||||
except Exception:
|
||||
LOG.exception("Failed to store the release to vault")
|
||||
# return a warning and prompt the user to try again
|
||||
if hasattr(response, 'text'):
|
||||
from builtins import str as text
|
||||
data = json.loads(response.text)
|
||||
if 'warning' in data:
|
||||
msg = _('The release file could not be stored in the vault, '
|
||||
'please upload the release again!')
|
||||
data['warning'] += msg
|
||||
response.text = text(json.dumps(data))
|
||||
proxy_utils.cleanup(request.environ)
|
||||
return response
|
||||
|
||||
def patch_upload_dir_req(self, request, response):
|
||||
files = []
|
||||
for key, path in request.GET.items():
|
||||
@@ -193,8 +238,12 @@ class PatchAPIController(Middleware):
|
||||
return response
|
||||
|
||||
def patch_delete_req(self, request, response):
|
||||
patch_ids = proxy_utils.get_routing_match_value(request.environ,
|
||||
'patch_id')
|
||||
if cfg.CONF.use_usm:
|
||||
patch_ids = proxy_utils.get_routing_match_value(request.environ,
|
||||
'release_id')
|
||||
else:
|
||||
patch_ids = proxy_utils.get_routing_match_value(request.environ,
|
||||
'patch_id')
|
||||
LOG.info("Deleting patches: %s", patch_ids)
|
||||
patch_list = os.path.normpath(patch_ids).split(os.path.sep)
|
||||
for patch_file in patch_list:
|
||||
|
||||
Reference in New Issue
Block a user