Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/classes/entitymgrs/ilmmgr.py: 85%
32 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-27 20:59 -0600
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-27 20:59 -0600
1"""ILM Policy Entity Manager Class"""
3import typing as t
4from es_testbed.exceptions import ResultNotExpected
5from es_testbed.helpers import es_api
6from es_testbed.helpers.utils import build_ilm_policy, getlogger
7from .entitymgr import EntityMgr
9if t.TYPE_CHECKING: 9 ↛ 10line 9 didn't jump to line 10, because the condition on line 9 was never true
10 from elasticsearch8 import Elasticsearch
11 from dotmap import DotMap
13# pylint: disable=missing-docstring
16class IlmMgr(EntityMgr):
17 kind = 'ilm'
18 listname = 'ilm_policies'
20 def __init__(
21 self,
22 client: t.Union['Elasticsearch', None] = None,
23 plan: t.Union['DotMap', None] = None,
24 autobuild: t.Optional[bool] = True,
25 ):
26 super().__init__(client=client, plan=plan, autobuild=autobuild)
27 self.logger = getlogger('es_testbed.IlmMgr')
29 @property
30 def logdisplay(self) -> str:
31 """Return a human readable representation of what is managed"""
32 return 'ILM policy'
34 def get_policy(self) -> t.Dict:
35 """Return the configured ILM policy"""
36 d = self.plan.ilm
37 kwargs = {
38 'tiers': d.tiers,
39 'forcemerge': d.forcemerge,
40 'max_num_segments': d.max_num_segments,
41 'repository': self.plan.repository,
42 }
43 return build_ilm_policy(**kwargs)
45 def setup(self) -> None:
46 """Setup the entity manager"""
47 if self.plan.ilm.enabled:
48 self.plan.ilm.policy = self.get_policy()
49 es_api.put_ilm(self.client, self.name, policy=self.plan.ilm.policy)
50 # Verify existence
51 if not es_api.exists(self.client, 'ilm', self.name): 51 ↛ 52line 51 didn't jump to line 52, because the condition on line 51 was never true
52 raise ResultNotExpected(
53 f'Unable to verify creation of ilm policy {self.name}'
54 )
55 # This goes first because the length of entity_list determines the suffix
56 self.appender(self.name)
57 self.logger.info('Successfully created ILM policy: %s', self.last)
58 else:
59 self.appender(None) # This covers self.plan.ilm_policies[-1]
60 self.logger.info('No ILM policy created.')
61 self.success = True