diff options
author | Chris Church <chris@ninemoreminutes.com> | 2014-02-06 21:25:49 +0100 |
---|---|---|
committer | Chris Church <chris@ninemoreminutes.com> | 2014-02-06 21:25:58 +0100 |
commit | ae4743724a505f414cd5da7c2472161c205cc6dd (patch) | |
tree | daea60cea4054d62f552fb5efb7d670557f9bba5 | |
parent | AC-1023 AC-1025 fixed drag-n-drop issues. Linting exposed a datatype mismatch... (diff) | |
download | awx-ae4743724a505f414cd5da7c2472161c205cc6dd.tar.xz awx-ae4743724a505f414cd5da7c2472161c205cc6dd.zip |
AC-982 Added configuration options to disable activity stream logging entirely, or disable only when running inventory import.
-rw-r--r-- | awx/main/management/commands/inventory_import.py | 8 | ||||
-rw-r--r-- | awx/main/registrar.py | 3 | ||||
-rw-r--r-- | awx/main/signals.py | 30 | ||||
-rw-r--r-- | awx/settings/defaults.py | 4 | ||||
-rw-r--r-- | awx/settings/license.json | 1 | ||||
-rw-r--r-- | config/deb/settings.py | 3 | ||||
-rw-r--r-- | config/rpm/settings.py | 3 |
7 files changed, 49 insertions, 3 deletions
diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index 9416f070d0..7dbf0e8d5b 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -24,7 +24,7 @@ from django.contrib.auth.models import User # AWX from awx.main.models import * -from awx.main.signals import ignore_inventory_computed_fields +from awx.main.signals import ignore_inventory_computed_fields, disable_activity_stream from awx.main.licenses import LicenseReader logger = logging.getLogger('awx.main.commands.inventory_import') @@ -755,7 +755,11 @@ class Command(NoArgsCommand): # Merge/overwrite inventory into database. with ignore_inventory_computed_fields(): - self.load_into_database() + if getattr(settings, 'ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC', True): + self.load_into_database() + else: + with disable_activity_stream(): + self.load_into_database() self.inventory.update_computed_fields() self.check_license() diff --git a/awx/main/registrar.py b/awx/main/registrar.py index 024a59df29..dd28844528 100644 --- a/awx/main/registrar.py +++ b/awx/main/registrar.py @@ -3,6 +3,7 @@ import logging +from django.conf import settings from django.db.models.signals import pre_save, post_save, post_delete, m2m_changed logger = logging.getLogger('awx.main.registrar') @@ -13,6 +14,8 @@ class ActivityStreamRegistrar(object): self.models = [] def connect(self, model): + if not getattr(settings, 'ACTIVITY_STREAM_ENABLED', True): + return from awx.main.signals import activity_stream_create, activity_stream_update, activity_stream_delete, activity_stream_associate #(receiver, sender=model, dispatch_uid=self._dispatch_uid(signal, model)) diff --git a/awx/main/signals.py b/awx/main/signals.py index ff408d928b..a0fdd61c62 100644 --- a/awx/main/signals.py +++ b/awx/main/signals.py @@ -8,6 +8,7 @@ import threading import json # Django +from django.conf import settings from django.db.models.signals import pre_save, post_save, pre_delete, post_delete, m2m_changed from django.dispatch import receiver @@ -239,6 +240,27 @@ def update_host_last_job_after_job_deleted(sender, **kwargs): # Set via ActivityStreamRegistrar to record activity stream events +class ActivityStreamEnabled(threading.local): + def __init__(self): + self.enabled = getattr(settings, 'ACTIVITY_STREAM_ENABLED', True) + def __nonzero__(self): + return bool(self.enabled) + +activity_stream_enabled = ActivityStreamEnabled() + +@contextlib.contextmanager +def disable_activity_stream(): + ''' + Context manager to disable capturing activity stream changes. + ''' + try: + previous_value = activity_stream_enabled.enabled + activity_stream_enabled.enabled = False + yield + finally: + activity_stream_enabled.enabled = previous_value + + model_serializer_mapping = {Organization: OrganizationSerializer, Inventory: InventorySerializer, Host: HostSerializer, @@ -252,7 +274,7 @@ model_serializer_mapping = {Organization: OrganizationSerializer, Job: JobSerializer} def activity_stream_create(sender, instance, created, **kwargs): - if created: + if created and activity_stream_enabled: # Skip recording any inventory source directly associated with a group. if isinstance(instance, InventorySource) and instance.group: return @@ -268,6 +290,8 @@ def activity_stream_create(sender, instance, created, **kwargs): def activity_stream_update(sender, instance, **kwargs): if instance.id is None: return + if not activity_stream_enabled: + return try: old = sender.objects.get(id=instance.id) except sender.DoesNotExist: @@ -291,6 +315,8 @@ def activity_stream_update(sender, instance, **kwargs): getattr(activity_entry, object1).add(instance) def activity_stream_delete(sender, instance, **kwargs): + if not activity_stream_enabled: + return try: old = sender.objects.get(id=instance.id) except sender.DoesNotExist: @@ -307,6 +333,8 @@ def activity_stream_delete(sender, instance, **kwargs): activity_entry.save() def activity_stream_associate(sender, instance, **kwargs): + if not activity_stream_enabled: + return if 'pre_add' in kwargs['action'] or 'pre_remove' in kwargs['action']: if kwargs['action'] == 'pre_add': action = 'associate' diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 8cf4444f84..fc3d4f3c50 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -335,6 +335,10 @@ EC2_REGIONS_BLACKLIST = [ 'cn-north-1', ] +# Defaults for enabling/disabling activity stream. +ACTIVITY_STREAM_ENABLED = True +ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = True + # Internal API URL for use by inventory scripts and callback plugin. if 'devserver' in INSTALLED_APPS: INTERNAL_API_URL = 'http://127.0.0.1:%s' % DEVSERVER_DEFAULT_PORT diff --git a/awx/settings/license.json b/awx/settings/license.json new file mode 100644 index 0000000000..e3261ec5cd --- /dev/null +++ b/awx/settings/license.json @@ -0,0 +1 @@ +{"instance_count": "1000000", "contact_email": "cchurch@ansibleworks.com", "company_name": "TEST", "contact_name": "Chris Church", "license_date": "1422137308", "license_key": "6ccbecf61a5d9ab7606519037b82b21985fcfade8218a50d3476fc83551be64b"}
\ No newline at end of file diff --git a/config/deb/settings.py b/config/deb/settings.py index 8ef3fd503e..12657035b4 100644 --- a/config/deb/settings.py +++ b/config/deb/settings.py @@ -43,6 +43,9 @@ ALLOWED_HOSTS = ['*'] AWX_TASK_ENV['HOME'] = '/var/lib/awx' AWX_TASK_ENV['USER'] = 'awx' +ACTIVITY_STREAM_ENABLED = True +ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = True + ############################################################################### # EMAIL SETTINGS ############################################################################### diff --git a/config/rpm/settings.py b/config/rpm/settings.py index 8ef3fd503e..12657035b4 100644 --- a/config/rpm/settings.py +++ b/config/rpm/settings.py @@ -43,6 +43,9 @@ ALLOWED_HOSTS = ['*'] AWX_TASK_ENV['HOME'] = '/var/lib/awx' AWX_TASK_ENV['USER'] = 'awx' +ACTIVITY_STREAM_ENABLED = True +ACTIVITY_STREAM_ENABLED_FOR_INVENTORY_SYNC = True + ############################################################################### # EMAIL SETTINGS ############################################################################### |