diff --git a/example/apps/test_security/tests/commands.py b/example/apps/test_security/tests/commands.py index a3f0f681..1580a502 100644 --- a/example/apps/test_security/tests/commands.py +++ b/example/apps/test_security/tests/commands.py @@ -120,3 +120,10 @@ def test_elasticsearch_purge_logs_should_remove_logged_data(self): ).count(), 0) assert_equal(len(os.listdir(log_directory)), 1) shutil.rmtree(settings.BACKUP_STORAGE_PATH) + + @override_settings( + SECURITY_COMMAND_LOG_EXCLUDED_COMMANDS={'init_elasticsearch_log'}, + SECURITY_BACKUP_STORAGE_PATH=os.path.join(django_settings.PROJECT_DIR, 'var', 'backup_elastic') + ) + def test_init_elasticsearch_logs(self): + test_call_command('init_elasticsearch_log', interactive=False) diff --git a/security/backends/elasticsearch/management/commands/init_elasticsearch_log.py b/security/backends/elasticsearch/management/commands/init_elasticsearch_log.py index 2969305b..22d1d950 100644 --- a/security/backends/elasticsearch/management/commands/init_elasticsearch_log.py +++ b/security/backends/elasticsearch/management/commands/init_elasticsearch_log.py @@ -2,7 +2,7 @@ from security.backends.elasticsearch.connection import set_connection from security.backends.elasticsearch.models import ( - InputRequestLog, OutputRequestLog, CommandLog, CeleryTaskRunLog, CeleryTaskInvocationLog + InputRequestLog, OutputRequestLog, CommandLog, CeleryTaskRunLog, CeleryTaskInvocationLog, PartitionedLog, ) @@ -28,5 +28,9 @@ def handle(self, **options): self.stdout.write('Init elasticsearch logs') set_connection(init_documents=False) for document in InputRequestLog, OutputRequestLog, CommandLog, CeleryTaskRunLog, CeleryTaskInvocationLog: - document._index.delete(ignore=404) - document.init() + if issubclass(document, PartitionedLog): + template = document.get_template() + template.save() + else: + document._index.delete(ignore=404) + document.init()