Send the binary data instead of path

The issue is when it executes a system
application-upload in the remote cli it returns
an error "Application-upload rejected: application
tar file /wd/custom_apps/hello-kitty.tgz does not exist"
the reason is because the cgts-client sends the
path of the tarbal, the proposal solution sends
the binary data and save it in a path on controller

Closes-bug: 1926308
Signed-off-by: Rafael Jordão Jardim <RafaelJordao.Jardim@windriver.com>
Change-Id: I6dadef9e86612328ae68fc90564e929646e93dba
This commit is contained in:
Rafael Jordão Jardim 2021-04-23 13:26:49 -04:00 committed by Rafael Jardim
parent 416c209cde
commit 407a3e3748
4 changed files with 42 additions and 5 deletions

View File

@ -40,7 +40,7 @@ class AppManager(base.Manager):
def upload(self, data): def upload(self, data):
"""Stage the specified application, getting it ready for deployment. """Stage the specified application, getting it ready for deployment.
:param data: application name and location of tarfile :param data: application name and location of tarfile and the binary of the tarfile
""" """
return self._create(self._path(), data) return self._create(self._path(), data)

View File

@ -4,6 +4,7 @@
# #
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import base64
import os import os
import re import re
@ -105,6 +106,15 @@ def do_application_show(cc, args):
def do_application_upload(cc, args): def do_application_upload(cc, args):
"""Upload application Helm chart(s) and manifest""" """Upload application Helm chart(s) and manifest"""
data = _application_check(args) data = _application_check(args)
if not _is_url(data["tarfile"]):
try:
with open(data["tarfile"], 'rb') as tarfile:
binary_data = base64.urlsafe_b64encode(tarfile.read())
data.update({'binary_data': binary_data})
except Exception:
raise exc.CommandError("Error: Could not open file %s." % data["tarfile"])
response = cc.app.upload(data) response = cc.app.upload(data)
_print_application_show(response) _print_application_show(response)
_print_reminder_msg(response.name) _print_reminder_msg(response.name)

View File

@ -4,10 +4,13 @@
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
# #
import base64
import os import os
import hashlib import hashlib
import pecan import pecan
import pwd
from pecan import rest from pecan import rest
import time
import wsme import wsme
from wsme import types as wtypes from wsme import types as wtypes
import wsmeext.pecan as wsme_pecan import wsmeext.pecan as wsme_pecan
@ -199,10 +202,30 @@ class KubeAppController(rest.RestController):
@wsme_pecan.wsexpose(KubeApp, body=types.apidict) @wsme_pecan.wsexpose(KubeApp, body=types.apidict)
def post(self, body): def post(self, body):
"""Uploading an application to be deployed by Armada""" """Uploading an application to be deployed by Armada"""
tarfile = body.get('tarfile') tarfile_path = body.get('tarfile')
tarfile_binary = body.get('binary_data', '')
name = body.get('name', '') name = body.get('name', '')
version = body.get('app_version', '') version = body.get('app_version', '')
name, version, mname, mfile = self._check_tarfile(tarfile, name, version,
if not cutils.is_url(tarfile_path) and not os.path.exists(tarfile_path):
path_tarballs = '/tmp/tarball_uploads'
if not os.path.exists(path_tarballs):
os.makedirs(path_tarballs)
uid, gid = pwd.getpwnam('sysinv').pw_uid, pwd.getpwnam('sysinv').pw_uid
os.chown(path_tarballs, uid, gid)
# Keep unique tarball name to avoid conflicts
tarball_name = '{}-{}'.format(time.time(), os.path.basename(tarfile_path))
tarfile_path = os.path.join(path_tarballs, tarball_name)
try:
with open(tarfile_path, 'wb') as f:
f.write(base64.urlsafe_b64decode(tarfile_binary))
except Exception as e:
LOG.exception('Error: writing the tarfile: {}'.format(e))
raise wsme.exc.ClientSideError(_(
"Could not save the application on path {}".format(tarfile_path)))
name, version, mname, mfile = self._check_tarfile(tarfile_path, name, version,
constants.APP_UPLOAD_OP) constants.APP_UPLOAD_OP)
try: try:
@ -230,7 +253,7 @@ class KubeAppController(rest.RestController):
lifecycle_hook_info.mode = constants.APP_LIFECYCLE_MODE_MANUAL lifecycle_hook_info.mode = constants.APP_LIFECYCLE_MODE_MANUAL
pecan.request.rpcapi.perform_app_upload(pecan.request.context, pecan.request.rpcapi.perform_app_upload(pecan.request.context,
new_app, tarfile, new_app, tarfile_path,
lifecycle_hook_info=lifecycle_hook_info) lifecycle_hook_info=lifecycle_hook_info)
return KubeApp.convert_with_links(new_app) return KubeApp.convert_with_links(new_app)

View File

@ -126,7 +126,11 @@ class ApiDictType(wtypes.UserType):
name = 'apidict' name = 'apidict'
__name__ = name __name__ = name
basetype = {wtypes.text: apiutils.ValidTypes(wtypes.text, six.integer_types)} basetype = {wtypes.text: apiutils.ValidTypes(
wtypes.text,
six.integer_types,
wsme.types.bytes
)}
apidict = ApiDictType() apidict = ApiDictType()