Improve software upload-dir error handling
This commit is to enhance the 'software upload-dir' to handle when the given parameter is invalid, and to improve the error messages to indicate the error that occurred. [sysadmin@controller-0 ~(keystone_admin)]$ software upload-dir abc Invalid release directory: abc No files to upload [sysadmin@controller-0 ~(keystone_admin)]$ Test Plan: PASS: run 'software upload-dir' with invalid directory PASS: run 'software upload-dir' with valid directory Task: 49527 Story: 2010676 Change-Id: I73a82eac713ec90e3df1ea70b033c3ddf1368910
This commit is contained in:
parent
005e7b29c6
commit
63b4a741c9
|
@ -868,16 +868,25 @@ def release_upload_dir_req(args):
|
||||||
|
|
||||||
# Find all files that need to be uploaded in given directories
|
# Find all files that need to be uploaded in given directories
|
||||||
for release_dir in release_dirs:
|
for release_dir in release_dirs:
|
||||||
raw_files = [f for f in os.listdir(release_dir)
|
if os.path.isdir(release_dir):
|
||||||
if os.path.isfile(os.path.join(release_dir, f))]
|
raw_files = [f for f in os.listdir(release_dir)
|
||||||
|
if os.path.isfile(os.path.join(release_dir, f))]
|
||||||
|
|
||||||
# Get absolute path of files
|
# Get absolute path of files
|
||||||
raw_files = [os.path.abspath(os.path.join(release_dir, f)) for f in raw_files]
|
raw_files = [os.path.abspath(os.path.join(release_dir, f)) for f in raw_files]
|
||||||
|
else:
|
||||||
|
print("Skipping invalid directory: %s" % release_dir, file=sys.stderr)
|
||||||
|
|
||||||
|
if len(raw_files) == 0:
|
||||||
|
print("No file to upload")
|
||||||
|
return 0
|
||||||
|
|
||||||
for software_file in sorted(set(raw_files)):
|
for software_file in sorted(set(raw_files)):
|
||||||
_, ext = os.path.splitext(software_file)
|
_, ext = os.path.splitext(software_file)
|
||||||
if ext in constants.SUPPORTED_UPLOAD_FILE_EXT:
|
if ext in constants.SUPPORTED_UPLOAD_FILE_EXT:
|
||||||
to_upload_files[software_file] = (software_file, open(software_file, 'rb'))
|
to_upload_files[software_file] = (software_file, open(software_file, 'rb'))
|
||||||
|
else:
|
||||||
|
print("Skipping unsupported file: %s" % software_file, file=sys.stderr)
|
||||||
|
|
||||||
encoder = MultipartEncoder(fields=to_upload_files)
|
encoder = MultipartEncoder(fields=to_upload_files)
|
||||||
url = "http://%s/v1/software/upload" % api_addr
|
url = "http://%s/v1/software/upload" % api_addr
|
||||||
|
|
|
@ -1001,7 +1001,7 @@ class PatchController(PatchService):
|
||||||
upgrade_files[constants.SIG_EXTENSION]):
|
upgrade_files[constants.SIG_EXTENSION]):
|
||||||
raise ReleaseValidationFailure("Invalid signature file")
|
raise ReleaseValidationFailure("Invalid signature file")
|
||||||
|
|
||||||
msg = ("iso and signature files uploaded completed\n"
|
msg = ("iso and signature files upload completed\n"
|
||||||
"Importing iso is in progress\n")
|
"Importing iso is in progress\n")
|
||||||
LOG.info(msg)
|
LOG.info(msg)
|
||||||
local_info += msg
|
local_info += msg
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TestSoftwareController(unittest.TestCase):
|
||||||
# Verify that the expected messages were returned
|
# Verify that the expected messages were returned
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
info,
|
info,
|
||||||
'iso and signature files uploaded completed\nImporting iso is in progress\nLoad import successful')
|
'iso and signature files upload completed\nImporting iso is in progress\nLoad import successful')
|
||||||
self.assertEqual(warning, '')
|
self.assertEqual(warning, '')
|
||||||
self.assertEqual(error, '')
|
self.assertEqual(error, '')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|
Loading…
Reference in New Issue