Skip to content

Commit

Permalink
Merge pull request #852 from untergeek/fix/848
Browse files Browse the repository at this point in the history
Catch empty list during filter iteration
  • Loading branch information
untergeek committed Dec 22, 2016
2 parents 4ce8389 + 681dc8c commit 5e946f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
35 changes: 13 additions & 22 deletions curator/singletons.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ def _actionator(action, action_obj, dry_run=True):
sys.exit(1)
logger.info('Singleton "{0}" action completed.'.format(action))

def _check_empty_list(list_object, ignore=False):
def _do_filters(list_object, filters, ignore=False):
logger = logging.getLogger(__name__)
logger.debug('Testing for empty list object')
logger.debug('Running filters and testing for empty list object')
try:
list_object.iterate_filters(filters)
list_object.empty_list_check()
except (NoIndices, NoSnapshots) as e:
if str(type(e)) == "<class 'curator.exceptions.NoIndices'>":
Expand Down Expand Up @@ -192,8 +193,7 @@ def allocation_singleton(
'filters': filter_schema_check(action, filter_list)
}
ilo = IndexList(client)
ilo.iterate_filters(clean_filters)
_check_empty_list(ilo, ignore_empty_list)
_do_filters(ilo, clean_filters, ignore_empty_list)
action_obj = action_class(ilo, **mykwargs)
### Do the action
_actionator(action, action_obj, dry_run=ctx.parent.params['dry_run'])
Expand Down Expand Up @@ -231,8 +231,7 @@ def close_singleton(
'filters': filter_schema_check(action, filter_list)
}
ilo = IndexList(client)
ilo.iterate_filters(clean_filters)
_check_empty_list(ilo, ignore_empty_list)
_do_filters(ilo, clean_filters, ignore_empty_list)
action_obj = action_class(ilo, **mykwargs)
### Do the action
_actionator(action, action_obj, dry_run=ctx.parent.params['dry_run'])
Expand Down Expand Up @@ -265,8 +264,7 @@ def delete_indices_singleton(ctx, ignore_empty_list, filter_list):
'filters': filter_schema_check(action, filter_list)
}
ilo = IndexList(client)
ilo.iterate_filters(clean_filters)
_check_empty_list(ilo, ignore_empty_list)
_do_filters(ilo, clean_filters, ignore_empty_list)
action_obj = action_class(ilo, **mykwargs)
### Do the action
_actionator(action, action_obj, dry_run=ctx.parent.params['dry_run'])
Expand Down Expand Up @@ -315,8 +313,7 @@ def delete_snapshots_singleton(
'filters': filter_schema_check(action, filter_list)
}
slo = SnapshotList(client, repository=repository)
slo.iterate_filters(clean_filters)
_check_empty_list(slo, ignore_empty_list)
_do_filters(slo, clean_filters, ignore_empty_list)
action_obj = action_class(slo, **mykwargs)
### Do the action
_actionator(action, action_obj, dry_run=ctx.parent.params['dry_run'])
Expand Down Expand Up @@ -347,8 +344,7 @@ def open_singleton(
'filters': filter_schema_check(action, filter_list)
}
ilo = IndexList(client)
ilo.iterate_filters(clean_filters)
_check_empty_list(ilo, ignore_empty_list)
_do_filters(ilo, clean_filters, ignore_empty_list)
action_obj = action_class(ilo)
### Do the action
_actionator(action, action_obj, dry_run=ctx.parent.params['dry_run'])
Expand Down Expand Up @@ -393,8 +389,7 @@ def forcemerge_singleton(
'filters': filter_schema_check(action, filter_list)
}
ilo = IndexList(client)
ilo.iterate_filters(clean_filters)
_check_empty_list(ilo, ignore_empty_list)
_do_filters(ilo, clean_filters, ignore_empty_list)
action_obj = action_class(ilo, **mykwargs)
### Do the action
_actionator(action, action_obj, dry_run=ctx.parent.params['dry_run'])
Expand Down Expand Up @@ -437,8 +432,7 @@ def replicas_singleton(
'filters': filter_schema_check(action, filter_list)
}
ilo = IndexList(client)
ilo.iterate_filters(clean_filters)
_check_empty_list(ilo, ignore_empty_list)
_do_filters(ilo, clean_filters, ignore_empty_list)
action_obj = action_class(ilo, **mykwargs)
### Do the action
_actionator(action, action_obj, dry_run=ctx.parent.params['dry_run'])
Expand Down Expand Up @@ -509,8 +503,7 @@ def snapshot_singleton(
'filters': filter_schema_check(action, filter_list)
}
ilo = IndexList(client)
ilo.iterate_filters(clean_filters)
_check_empty_list(ilo, ignore_empty_list)
_do_filters(ilo, clean_filters, ignore_empty_list)
action_obj = action_class(ilo, **mykwargs)
### Do the action
_actionator(action, action_obj, dry_run=ctx.parent.params['dry_run'])
Expand Down Expand Up @@ -547,8 +540,7 @@ def show_indices_singleton(
'filters': filter_schema_check(action, filter_list)
}
ilo = IndexList(client)
ilo.iterate_filters(clean_filters)
_check_empty_list(ilo, ignore_empty_list)
_do_filters(ilo, clean_filters, ignore_empty_list)
indices = sorted(ilo.indices)
# Do some calculations to figure out the proper column sizes
allbytes = []
Expand Down Expand Up @@ -624,8 +616,7 @@ def show_snapshots_singleton(
'filters': filter_schema_check(action, filter_list)
}
slo = SnapshotList(client, repository=repository)
slo.iterate_filters(clean_filters)
_check_empty_list(slo, ignore_empty_list)
_do_filters(slo, clean_filters, ignore_empty_list)
snapshots = sorted(slo.snapshots)
for idx in snapshots:
click.secho('{0}'.format(idx))
Expand Down
6 changes: 6 additions & 0 deletions docs/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Changelog

* Fix cli integration test when different host/port are specified. Reported
in #843 (untergeek)
* Catch empty list condition during filter iteration in singleton actions.
Reported in #848 (untergeek)

**Documentation**

* Fix typo in Click version in docs. #850 (breml)

4.2.4 (7 December 2016)
-----------------------
Expand Down

0 comments on commit 5e946f4

Please sign in to comment.