mirror of
https://github.com/ansible/awx.git
synced 2026-03-20 18:37:39 -02:30
Change import/export logging detection to detect errors vs warnings
This commit is contained in:
@@ -82,9 +82,11 @@ EXAMPLES = '''
|
|||||||
- name: Export all tower assets
|
- name: Export all tower assets
|
||||||
tower_export:
|
tower_export:
|
||||||
all: True
|
all: True
|
||||||
|
|
||||||
- name: Export all inventories
|
- name: Export all inventories
|
||||||
tower_export:
|
tower_export:
|
||||||
inventory: 'all'
|
inventory: 'all'
|
||||||
|
|
||||||
- name: Export a job template named "My Template" and all Credentials
|
- name: Export a job template named "My Template" and all Credentials
|
||||||
tower_export:
|
tower_export:
|
||||||
job_template: "My Template"
|
job_template: "My Template"
|
||||||
@@ -135,27 +137,27 @@ def main():
|
|||||||
# Otherwise we take either the string or None (if the parameter was not passed) to get one or no items
|
# Otherwise we take either the string or None (if the parameter was not passed) to get one or no items
|
||||||
export_args[resource] = module.params.get(resource)
|
export_args[resource] = module.params.get(resource)
|
||||||
|
|
||||||
# Currently the import process does not return anything on error
|
# Currently the export process does not return anything on error
|
||||||
# It simply just logs to pythons logger
|
# It simply just logs to Python's logger
|
||||||
# Setup a log gobbler to get error messages from import_assets
|
# Set up a log gobbler to get error messages from export_assets
|
||||||
log_capture_string = StringIO()
|
log_capture_string = StringIO()
|
||||||
ch = logging.StreamHandler(log_capture_string)
|
ch = logging.StreamHandler(log_capture_string)
|
||||||
for logger_name in ['awxkit.api.pages.api', 'awxkit.api.pages.page']:
|
for logger_name in ['awxkit.api.pages.api', 'awxkit.api.pages.page']:
|
||||||
logger = logging.getLogger(logger_name)
|
logger = logging.getLogger(logger_name)
|
||||||
logger.setLevel(logging.WARNING)
|
logger.setLevel(logging.ERROR)
|
||||||
ch.setLevel(logging.WARNING)
|
ch.setLevel(logging.ERROR)
|
||||||
|
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
log_contents = ''
|
log_contents = ''
|
||||||
|
|
||||||
# Run the import process
|
# Run the export process
|
||||||
try:
|
try:
|
||||||
module.json_output['assets'] = module.get_api_v2_object().export_assets(**export_args)
|
module.json_output['assets'] = module.get_api_v2_object().export_assets(**export_args)
|
||||||
module.exit_json(**module.json_output)
|
module.exit_json(**module.json_output)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg="Failed to export assets {0}".format(e))
|
module.fail_json(msg="Failed to export assets {0}".format(e))
|
||||||
finally:
|
finally:
|
||||||
# Finally consume the logs incase there were any errors and die if there were
|
# Finally, consume the logs in case there were any errors and die if there were
|
||||||
log_contents = log_capture_string.getvalue()
|
log_contents = log_capture_string.getvalue()
|
||||||
log_capture_string.close()
|
log_capture_string.close()
|
||||||
if log_contents != '':
|
if log_contents != '':
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ EXAMPLES = '''
|
|||||||
- name: Export all assets
|
- name: Export all assets
|
||||||
tower_export:
|
tower_export:
|
||||||
all: True
|
all: True
|
||||||
registeR: export_output
|
register: export_output
|
||||||
|
|
||||||
- name: Import all tower assets from our export
|
- name: Import all tower assets from our export
|
||||||
tower_import:
|
tower_import:
|
||||||
@@ -51,7 +51,7 @@ EXAMPLES = '''
|
|||||||
|
|
||||||
from ..module_utils.tower_awxkit import TowerAWXKitModule
|
from ..module_utils.tower_awxkit import TowerAWXKitModule
|
||||||
|
|
||||||
# These two lines are not needed if awxkit changes to do progamatic notifications on issues
|
# These two lines are not needed if awxkit changes to do programatic notifications on issues
|
||||||
from ansible.module_utils.six.moves import StringIO
|
from ansible.module_utils.six.moves import StringIO
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -76,13 +76,15 @@ def main():
|
|||||||
module.fail_json(msg="Your version of awxkit does not appear to have import/export")
|
module.fail_json(msg="Your version of awxkit does not appear to have import/export")
|
||||||
|
|
||||||
# Currently the import process does not return anything on error
|
# Currently the import process does not return anything on error
|
||||||
# It simply just logs to pythons logger
|
# It simply just logs to Python's logger
|
||||||
# Setup a log gobbler to get error messages from import_assets
|
# Set up a log gobbler to get error messages from import_assets
|
||||||
logger = logging.getLogger('awxkit.api.pages.api')
|
logger = logging.getLogger('awxkit.api.pages.api')
|
||||||
logger.setLevel(logging.WARNING)
|
logger.setLevel(logging.ERROR)
|
||||||
|
|
||||||
log_capture_string = StringIO()
|
log_capture_string = StringIO()
|
||||||
ch = logging.StreamHandler(log_capture_string)
|
ch = logging.StreamHandler(log_capture_string)
|
||||||
ch.setLevel(logging.WARNING)
|
ch.setLevel(logging.ERROR)
|
||||||
|
|
||||||
logger.addHandler(ch)
|
logger.addHandler(ch)
|
||||||
log_contents = ''
|
log_contents = ''
|
||||||
|
|
||||||
@@ -92,7 +94,7 @@ def main():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg="Failed to import assets {0}".format(e))
|
module.fail_json(msg="Failed to import assets {0}".format(e))
|
||||||
finally:
|
finally:
|
||||||
# Finally consume the logs incase there were any errors and die if there were
|
# Finally, consume the logs in case there were any errors and die if there were
|
||||||
log_contents = log_capture_string.getvalue()
|
log_contents = log_capture_string.getvalue()
|
||||||
log_capture_string.close()
|
log_capture_string.close()
|
||||||
if log_contents != '':
|
if log_contents != '':
|
||||||
|
|||||||
Reference in New Issue
Block a user