summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYunfan Zhang <yz322@duke.edu>2018-08-02 20:19:13 +0200
committerYunfan Zhang <yz322@duke.edu>2018-08-02 20:19:13 +0200
commit7001c67c84f06b319e71a37dc0f72ee2423c1510 (patch)
treeba688cc1845a777500f8943f5265177016ad9fdc
parentMerge pull request #2737 from wwitzel3/release_3.3.0 (diff)
downloadawx-7001c67c84f06b319e71a37dc0f72ee2423c1510.tar.xz
awx-7001c67c84f06b319e71a37dc0f72ee2423c1510.zip
Fixing incorrect license_error value in inventory_sync.
Signed-off-by: Yunfan Zhang <yz322@duke.edu>
-rw-r--r--awx/main/management/commands/inventory_import.py62
1 files changed, 34 insertions, 28 deletions
diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py
index 9638062c68..d3ac4960d2 100644
--- a/awx/main/management/commands/inventory_import.py
+++ b/awx/main/management/commands/inventory_import.py
@@ -1005,37 +1005,43 @@ class Command(BaseCommand):
self.all_group.debug_tree()
with batch_role_ancestor_rebuilding():
- # Ensure that this is managed as an atomic SQL transaction,
- # and thus properly rolled back if there is an issue.
- with transaction.atomic():
- # Merge/overwrite inventory into database.
- if settings.SQL_DEBUG:
- logger.warning('loading into database...')
- with ignore_inventory_computed_fields():
- if getattr(settings, 'ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC', True):
- self.load_into_database()
- else:
- with disable_activity_stream():
- self.load_into_database()
- if settings.SQL_DEBUG:
- queries_before2 = len(connection.queries)
- self.inventory.update_computed_fields()
+ # If using with transaction.atomic() with try ... catch,
+ # with transaction.atomic() must be inside the try section of the code as per Django docs
+ try:
+ # Ensure that this is managed as an atomic SQL transaction,
+ # and thus properly rolled back if there is an issue.
+ with transaction.atomic():
+ # Merge/overwrite inventory into database.
if settings.SQL_DEBUG:
- logger.warning('update computed fields took %d queries',
- len(connection.queries) - queries_before2)
- try:
+ logger.warning('loading into database...')
+ with ignore_inventory_computed_fields():
+ if getattr(settings, 'ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC', True):
+ self.load_into_database()
+ else:
+ with disable_activity_stream():
+ self.load_into_database()
+ if settings.SQL_DEBUG:
+ queries_before2 = len(connection.queries)
+ self.inventory.update_computed_fields()
+ if settings.SQL_DEBUG:
+ logger.warning('update computed fields took %d queries',
+ len(connection.queries) - queries_before2)
+ # Check if the license is valid.
+ # If the license is not valid, a CommandError will be thrown,
+ # and inventory update will be marked as invalid.
+ # with transaction.atomic() will roll back the changes.
self.check_license()
- except CommandError as e:
- self.mark_license_failure(save=True)
- raise e
+ except CommandError as e:
+ self.mark_license_failure()
+ raise e
- if settings.SQL_DEBUG:
- logger.warning('Inventory import completed for %s in %0.1fs',
- self.inventory_source.name, time.time() - begin)
- else:
- logger.info('Inventory import completed for %s in %0.1fs',
- self.inventory_source.name, time.time() - begin)
- status = 'successful'
+ if settings.SQL_DEBUG:
+ logger.warning('Inventory import completed for %s in %0.1fs',
+ self.inventory_source.name, time.time() - begin)
+ else:
+ logger.info('Inventory import completed for %s in %0.1fs',
+ self.inventory_source.name, time.time() - begin)
+ status = 'successful'
# If we're in debug mode, then log the queries and time
# used to do the operation.