Merge pull request #2746 from YunfanZhang42/fix-license-error

Fixing incorrect license_error value in inventory_sync
This commit is contained in:
Yunfan Zhang
2018-08-02 15:20:35 -04:00
committed by GitHub

View File

@@ -1005,37 +1005,43 @@ class Command(BaseCommand):
self.all_group.debug_tree() self.all_group.debug_tree()
with batch_role_ancestor_rebuilding(): with batch_role_ancestor_rebuilding():
# Ensure that this is managed as an atomic SQL transaction, # If using with transaction.atomic() with try ... catch,
# and thus properly rolled back if there is an issue. # with transaction.atomic() must be inside the try section of the code as per Django docs
with transaction.atomic(): try:
# Merge/overwrite inventory into database. # Ensure that this is managed as an atomic SQL transaction,
if settings.SQL_DEBUG: # and thus properly rolled back if there is an issue.
logger.warning('loading into database...') with transaction.atomic():
with ignore_inventory_computed_fields(): # Merge/overwrite inventory into database.
if getattr(settings, 'ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC', True): if settings.SQL_DEBUG:
self.load_into_database() logger.warning('loading into database...')
else: with ignore_inventory_computed_fields():
with disable_activity_stream(): if getattr(settings, 'ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC', True):
self.load_into_database() self.load_into_database()
if settings.SQL_DEBUG: else:
queries_before2 = len(connection.queries) with disable_activity_stream():
self.inventory.update_computed_fields() self.load_into_database()
if settings.SQL_DEBUG: if settings.SQL_DEBUG:
logger.warning('update computed fields took %d queries', queries_before2 = len(connection.queries)
len(connection.queries) - queries_before2) self.inventory.update_computed_fields()
try: 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() self.check_license()
except CommandError as e: except CommandError as e:
self.mark_license_failure(save=True) self.mark_license_failure()
raise e raise e
if settings.SQL_DEBUG: if settings.SQL_DEBUG:
logger.warning('Inventory import completed for %s in %0.1fs', logger.warning('Inventory import completed for %s in %0.1fs',
self.inventory_source.name, time.time() - begin) self.inventory_source.name, time.time() - begin)
else: else:
logger.info('Inventory import completed for %s in %0.1fs', logger.info('Inventory import completed for %s in %0.1fs',
self.inventory_source.name, time.time() - begin) self.inventory_source.name, time.time() - begin)
status = 'successful' status = 'successful'
# If we're in debug mode, then log the queries and time # If we're in debug mode, then log the queries and time
# used to do the operation. # used to do the operation.