Skip to content

Commit

Permalink
Merge pull request #1303 from untergeek/fix/1297
Browse files Browse the repository at this point in the history
Reindex action must respect ignore_empty_list
  • Loading branch information
untergeek committed Oct 30, 2018
2 parents 3384530 + 3c32f08 commit f2c6ca8
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 6 deletions.
11 changes: 6 additions & 5 deletions curator/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1308,11 +1308,8 @@ def sources(self):
dest = self.body['dest']['index']
source_list = utils.ensure_list(self.body['source']['index'])
self.loggit.debug('source_list: {0}'.format(source_list))
if source_list == []: # Empty list
raise exceptions.ConfigurationError(
'Source index must be list of actual indices. '
'It must not be an empty list.'
)
if source_list == [] or source_list == ['REINDEX_SELECTED']: # Empty list
raise exceptions.NoIndices
if not self.migration:
yield self.body['source']['index'], dest

Expand Down Expand Up @@ -1383,6 +1380,10 @@ def do_action(self):
'to check task_id "{1}" for successful completion '
'manually.'.format(self.wfc, response['task'])
)
except exceptions.NoIndices as e:
raise exceptions.NoIndices(
'Source index must be list of actual indices. '
'It must not be an empty list.')
except Exception as e:
utils.report_failure(e)

Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Changelog
command line. Reported in #1237 (untergeek)
* Pin ``click`` version for compatibility. (Andrewsville) #1280
* Allow much older epoch timestamps (rsteneteg) #1296
* Reindex action respects ``ignore_empty_list`` flag (untergeek) #1297

**Documentation**

Expand Down
64 changes: 64 additions & 0 deletions test/integration/test_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,70 @@ def test_reindex_selected_many_to_one(self):
],
)
self.assertEqual(expected, self.client.count(index=dest)['count'])
def test_reindex_selected_empty_list_fail(self):
wait_interval = 1
max_wait = 3
source1 = 'my_source1'
source2 = 'my_source2'
dest = 'my_dest'
expected = 6

self.create_index(source1)
self.add_docs(source1)
self.create_index(source2)
for i in ["4", "5", "6"]:
self.client.create(
index=source2, doc_type='log', id=i,
body={"doc" + i :'TEST DOCUMENT'},
)
# Decorators make this pylint exception necessary
# pylint: disable=E1123
self.client.indices.flush(index=source2, force=True)
self.write_config(
self.args['configfile'], testvars.client_config.format(host, port))
self.write_config(self.args['actionfile'],
testvars.reindex_empty_list.format('false', wait_interval, max_wait, dest))
test = clicktest.CliRunner()
_ = test.invoke(
curator.cli,
[
'--config', self.args['configfile'],
self.args['actionfile']
],
)
self.assertEqual(_.exit_code, 1)
def test_reindex_selected_empty_list_pass(self):
wait_interval = 1
max_wait = 3
source1 = 'my_source1'
source2 = 'my_source2'
dest = 'my_dest'
expected = 6

self.create_index(source1)
self.add_docs(source1)
self.create_index(source2)
for i in ["4", "5", "6"]:
self.client.create(
index=source2, doc_type='log', id=i,
body={"doc" + i :'TEST DOCUMENT'},
)
# Decorators make this pylint exception necessary
# pylint: disable=E1123
self.client.indices.flush(index=source2, force=True)
self.write_config(
self.args['configfile'], testvars.client_config.format(host, port))
self.write_config(self.args['actionfile'],
testvars.reindex_empty_list.format('true', wait_interval, max_wait, dest))
test = clicktest.CliRunner()
_ = test.invoke(
curator.cli,
[
'--config', self.args['configfile'],
self.args['actionfile']
],
)
self.assertEqual(_.exit_code, 0)
def test_reindex_from_remote(self):
wait_interval = 1
max_wait = 3
Expand Down
20 changes: 20 additions & 0 deletions test/integration/testvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,26 @@
' index: {3}\n'
' filters:\n'
' - filtertype: none\n')

reindex_empty_list = ('---\n'
'actions:\n'
' 1:\n'
' description: "Reindex"\n'
' action: reindex\n'
' options:\n'
' ignore_empty_list: {0}\n'
' wait_interval: {1}\n'
' max_wait: {2}\n'
' request_body:\n'
' source:\n'
' index: REINDEX_SELECTED\n'
' dest:\n'
' index: {3}\n'
' filters:\n'
' - filtertype: pattern\n'
' kind: prefix\n'
' value: notfound\n')

remote_reindex = ('---\n'
'actions:\n'
' 1:\n'
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_action_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ def test_init_raise_empty_source_list(self):
'dest': { 'index': 'other_index' }
}
ro = curator.Reindex(ilo, badval)
self.assertRaises(curator.FailedExecution, ro.do_action)
self.assertRaises(curator.NoIndices, ro.do_action)

0 comments on commit f2c6ca8

Please sign in to comment.