Merge "Return error code when a error occurred during package-import"

This commit is contained in:
Jenkins 2017-01-04 01:39:17 +00:00 committed by Gerrit Code Review
commit e4b75e0dc9
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>",