Merge "Error deleting index in initial syncing"

This commit is contained in:
Jenkins 2016-04-21 17:00:10 +00:00 committed by Gerrit Code Review
commit e7829f19f4
2 changed files with 17 additions and 0 deletions

View File

@ -317,6 +317,8 @@ def alias_search_update(alias_search, index_name):
def delete_index(index_name):
"""Delete the specified index. """
if index_name is None:
return
# Alias will be cleaned up automatically by ES when the index is deleted.
es_engine = searchlight.elasticsearch.get_api()
es_engine.indices.delete(index=index_name, ignore=404)

View File

@ -219,6 +219,21 @@ class TestReindexingUtils(test_utils.BaseTestCase):
index=old_ndx)
mock_api.assert_called_with()
def test_delete_non_exist_index(self):
old_ndx = None
# Set up the ES mock.
mock_engine = mock.Mock()
with mock.patch('searchlight.elasticsearch.get_api') as mock_api:
# Plug in the ES mock.
mock_api.return_value = mock_engine
# Delete the existing index.
plugin_utils.delete_index(old_ndx)
mock_engine.indices.delete.assert_not_called()
mock_api.assert_not_called()
def test_alias_error_cleanup(self):
single = {'g': 'ndx'}
multiple = {'g1': 'ndx1', 'g2': 'ndx2', 'g3': 'ndx3'}