mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 10:27:34 -02:30
bubble up an error code when something goes wrong with import/export
This commit is contained in:
@@ -144,6 +144,8 @@ class Import(CustomCommand):
|
||||
client.authenticate()
|
||||
client.v2.import_assets(data)
|
||||
|
||||
self._has_error = getattr(client.v2, '_has_error', False)
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
@@ -174,7 +176,11 @@ class Export(CustomCommand):
|
||||
kwargs = {resource: getattr(parsed, resource, None) for resource in EXPORTABLE_RESOURCES}
|
||||
|
||||
client.authenticate()
|
||||
return client.v2.export_assets(**kwargs)
|
||||
data = client.v2.export_assets(**kwargs)
|
||||
|
||||
self._has_error = getattr(client.v2, '_has_error', False)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def parse_resource(client, skip_deprecated=False):
|
||||
@@ -183,6 +189,8 @@ def parse_resource(client, skip_deprecated=False):
|
||||
metavar='resource',
|
||||
)
|
||||
|
||||
_system_exit = 0
|
||||
|
||||
# check if the user is running a custom command
|
||||
for command in CustomCommand.__subclasses__():
|
||||
client.subparsers[command.name] = subparsers.add_parser(command.name, help=command.help_text)
|
||||
@@ -210,6 +218,10 @@ def parse_resource(client, skip_deprecated=False):
|
||||
parser = client.subparsers[resource]
|
||||
command = CustomCommand.registry[resource]()
|
||||
response = command.handle(client, parser)
|
||||
|
||||
if getattr(command, '_has_error', False):
|
||||
_system_exit = 1
|
||||
|
||||
if response:
|
||||
_filter = client.get_config('filter')
|
||||
if resource == 'config' and client.get_config('format') == 'human':
|
||||
@@ -221,7 +233,7 @@ def parse_resource(client, skip_deprecated=False):
|
||||
connection = None
|
||||
formatted = format_response(Page.from_json(response, connection=connection), fmt=client.get_config('format'), filter=_filter)
|
||||
print(formatted)
|
||||
raise SystemExit()
|
||||
raise SystemExit(_system_exit)
|
||||
else:
|
||||
return resource
|
||||
|
||||
|
||||
Reference in New Issue
Block a user