Coverage for src/es_testbed/classes/entitymgrs/ilmmgr.py: 90%
37 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-23 13:32 -0600
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-23 13:32 -0600
1"""ILM Policy Entity Manager Class"""
2import typing as t
3from elasticsearch8 import Elasticsearch
4from es_testbed.exceptions import ResultNotExpected
5from es_testbed.helpers import es_api
6from es_testbed.helpers.utils import getlogger
7from .entitymgr import EntityMgr
8from ..ilm import IlmBuilder
9from ..testplan import TestPlan
10# pylint: disable=missing-docstring
12class IlmMgr(EntityMgr):
13 def __init__(
14 self,
15 client: Elasticsearch = None,
16 plan: TestPlan = None,
17 autobuild: t.Optional[bool] = True,
18 ):
19 super().__init__(client=client, plan=plan, autobuild=autobuild)
20 self.logger = getlogger('es_testbed.IlmMgr')
21 self.kind = 'ilm'
22 self.ilm = False
23 # If ILM was configured in the plan settings, plan.ilm should be an IlmBuilder instance
24 # If not, we won't end up using ILM
25 if isinstance(self.plan, TestPlan): 25 ↛ 33line 25 didn't jump to line 33, because the condition on line 25 was never false
26 self.logger.debug('We have a plan object')
27 self.logger.debug('Our plan object contains: %s', self.plan.asdict)
28 if isinstance(self.plan.ilm, IlmBuilder):
29 self.logger.debug('Our plan object is an IlmBuilder class instance')
30 self.ilm = self.plan.ilm
31 self.logger.debug('Our plan is: %s', self.ilm.asdict)
32 else:
33 self.logger.debug('We have no plan object')
34 if self.autobuild: 34 ↛ exitline 34 didn't return from function '__init__', because the condition on line 34 was never false
35 self.setup()
37 @property
38 def logdisplay(self) -> str:
39 return 'ILM policy'
41 def setup(self):
42 if isinstance(self.ilm, IlmBuilder):
43 es_api.put_ilm(self.client, self.name, policy=self.ilm.policy)
44 # Verify existence
45 if not es_api.exists(self.client, 'ilm', self.name): 45 ↛ 46line 45 didn't jump to line 46, because the condition on line 45 was never true
46 raise ResultNotExpected(
47 f'Unable to verify creation of ilm policy {self.name}')
48 self.entity_list.append(self.name)
49 self.logger.info('Successfully created ILM policy: %s', self.last)
50 else:
51 self.entity_list.append(None)
52 self.logger.info('No ILM policy created.')
53 self.success = True