Merge "Add upgrade support to software upload-dir"
This commit is contained in:
@@ -809,18 +809,29 @@ def release_upload_dir_req(args):
|
|||||||
# Ignore interrupts during this function
|
# Ignore interrupts during this function
|
||||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||||
|
|
||||||
dirlist = {}
|
to_upload_files = {}
|
||||||
i = 0
|
raw_files = []
|
||||||
for d in sorted(list(set(release_dirs))):
|
|
||||||
dirlist["dir%d" % i] = os.path.abspath(d)
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
url = "http://%s/software/upload_dir" % api_addr
|
# Find all files that need to be uploaded in given directories
|
||||||
|
for release_dir in release_dirs:
|
||||||
|
raw_files = [f for f in os.listdir(release_dir)
|
||||||
|
if os.path.isfile(os.path.join(release_dir, f))]
|
||||||
|
|
||||||
headers = {}
|
# Get absolute path of files
|
||||||
|
raw_files = [os.path.abspath(os.path.join(release_dir, f)) for f in raw_files]
|
||||||
|
|
||||||
|
for software_file in sorted(set(raw_files)):
|
||||||
|
_, ext = os.path.splitext(software_file)
|
||||||
|
if ext in constants.SUPPORTED_UPLOAD_FILE_EXT:
|
||||||
|
to_upload_files[software_file] = (software_file, open(software_file, 'rb'))
|
||||||
|
|
||||||
|
encoder = MultipartEncoder(fields=to_upload_files)
|
||||||
|
url = "http://%s/software/upload" % api_addr
|
||||||
|
headers = {'Content-Type': encoder.content_type}
|
||||||
append_auth_token_if_required(headers)
|
append_auth_token_if_required(headers)
|
||||||
req = requests.post(url, params=dirlist, headers=headers)
|
req = requests.post(url,
|
||||||
|
data=encoder,
|
||||||
|
headers=headers)
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print_result_debug(req)
|
print_result_debug(req)
|
||||||
else:
|
else:
|
||||||
|
@@ -5,7 +5,6 @@ SPDX-License-Identifier: Apache-2.0
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import cgi
|
import cgi
|
||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from pecan import expose
|
from pecan import expose
|
||||||
@@ -188,31 +187,6 @@ class SoftwareAPIController(object):
|
|||||||
sc.software_sync()
|
sc.software_sync()
|
||||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||||
|
|
||||||
@expose('json')
|
|
||||||
def upload_dir(self, **kwargs):
|
|
||||||
# todo(abailey): extensions should be configurable or
|
|
||||||
# registered in setup.cfg
|
|
||||||
extensions = ['*.patch', '*.tar', '*.iso']
|
|
||||||
files = []
|
|
||||||
# todo(abailey): investigate an alternative to glob
|
|
||||||
for path in kwargs.values():
|
|
||||||
LOG.info("upload-dir: Uploading software from: %s", path)
|
|
||||||
for ext in extensions:
|
|
||||||
for f in glob.glob(path + "/" + ext):
|
|
||||||
if os.path.isfile(f):
|
|
||||||
LOG.info("upload-dir: Uploading : %s", f)
|
|
||||||
files.append(f)
|
|
||||||
|
|
||||||
if len(files) == 0:
|
|
||||||
return dict(error="No software found matching %s" % extensions)
|
|
||||||
|
|
||||||
try:
|
|
||||||
result = sc.software_release_upload(sorted(files))
|
|
||||||
except SoftwareError as e:
|
|
||||||
return dict(error=str(e))
|
|
||||||
sc.software_sync()
|
|
||||||
return result
|
|
||||||
|
|
||||||
@expose('json')
|
@expose('json')
|
||||||
@expose('query.xml', content_type='application/xml')
|
@expose('query.xml', content_type='application/xml')
|
||||||
def query(self, **kwargs):
|
def query(self, **kwargs):
|
||||||
|
Reference in New Issue
Block a user