Return error code when a error occurred during package-import

With this fix Murano client import-package will return a error code
if something goes wrong during the package import.

In case some packages can be uploaded successfully will going to
send a Warning message about some error has occurred during importation.

Change-Id: I2702d16088f95a3f072c8a8f80a485030bc2ce75
Closes-Bug: #1645511
This commit is contained in:
Jose Phillips 2016-12-21 11:13:34 -05:00
parent 12c70b72d0
commit cd2126bbff
2 changed files with 17 additions and 7 deletions

View File

@ -1210,11 +1210,11 @@ class ShellPackagesOperations(ShellCommandTest):
@mock.patch('muranoclient.common.utils.Package.from_file')
def test_package_import_conflict_dep_update_ea(self, from_file):
self._test_conflict_dep(
self.client.packages,
from_file,
dep_exists_action='u',
)
self.assertRaises(SystemExit, self._test_conflict_dep,
self.client.packages,
from_file,
dep_exists_action='u',
)
self.assertTrue(self.client.packages.delete.called)

View File

@ -762,7 +762,7 @@ def do_package_import(mc, args):
present in murano.
"""
data = {"is_public": args.is_public}
exception_occurred = False
version = args.package_version
if version and len(args.filename) >= 2:
print("Requested to import more than one package, "
@ -792,6 +792,7 @@ def do_package_import(mc, args):
except Exception as e:
print("Failed to create package for '{0}', reason: {1}".format(
filename, e))
exception_occurred = True
continue
total_reqs.update(package.requirements(base_url=args.murano_repo_url))
main_packages_names.append(package.manifest['FullName'])
@ -818,6 +819,7 @@ def do_package_import(mc, args):
except Exception as e:
print("Error {0} occurred while installing "
"images for {1}".format(e, name))
exception_occurred = True
if name in main_packages_names:
exists_action = args.exists_action
else:
@ -830,9 +832,17 @@ def do_package_import(mc, args):
except Exception as e:
print("Error {0} occurred while installing package {1}".format(
e, name))
exception_occurred = True
if imported_list:
_print_package_list(imported_list)
if exception_occurred:
# NOTE(jose-phillips) Leave a Warning to users in case some packages
# can be uploaded successfully.
if imported_list:
print ("Warning: there were some errors during the operation.")
sys.exit(1)
else:
sys.exit(1)
@utils.arg("id", metavar="<ID>",