Coverage for curator/actions/open.py: 100%

1"""Open index action class"""

2 import logging

3 from curator.helpers.testers import verify_index_list

4 from curator.helpers.utils import chunk_index_list, report_failure, show_dry_run, to_csv

5

6 class Open:

7 """Open Action Class"""

8 def __init__(self, ilo):

9 """

10 :param ilo: An IndexList Object

11

12 :type ilo: :py:class:`~.curator.indexlist.IndexList`

13 """

14 verify_index_list(ilo)

15 #: The :py:class:`~.curator.indexlist.IndexList` object passed from param ``ilo``

16 self.index_list = ilo

17 #: The :py:class:`~.elasticsearch.Elasticsearch` client object derived from

18 #: :py:attr:`index_list`

19 self.client = ilo.client

20 self.loggit = logging.getLogger('curator.actions.open')

21

22 def do_dry_run(self):

23 """Log what the output would be, but take no action."""

24 show_dry_run(self.index_list, 'open')

25

26 def do_action(self):

27 """:py:meth:`~.elasticsearch.client.IndicesClient.open` indices in :py:attr:`index_list`"""

28 self.index_list.empty_list_check()

29 msg = f'Opening {len(self.index_list.indices)} selected indices: {self.index_list.indices}'

30 self.loggit.info(msg)

31 try:

32 index_lists = chunk_index_list(self.index_list.indices)

33 for lst in index_lists:

34 self.client.indices.open(index=to_csv(lst))

35 # pylint: disable=broad-except

36 except Exception as err:

37 report_failure(err)