Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/mgrs/componentmgr.py: 86%

29 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-27 23:17 -0600

1"""Component Template Entity Manager Class""" 

2 

3import typing as t 

4from .entitymgr import EntityMgr 

5from ..exceptions import ResultNotExpected 

6from ..helpers.es_api import exists, put_comp_tmpl 

7from ..helpers.utils import getlogger, mapping_component, setting_component 

8 

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 

12 

13# pylint: disable=missing-docstring,too-many-arguments 

14 

15 

16class ComponentMgr(EntityMgr): 

17 kind = 'component' 

18 listname = 'component_templates' 

19 

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 self.logger = getlogger('es_testbed.ComponentMgr') 

27 super().__init__(client=client, plan=plan, autobuild=autobuild) 

28 

29 @property 

30 def components(self) -> t.Sequence[t.Dict]: 

31 """Return a list of component template dictionaries""" 

32 retval = [] 

33 kw = { 

34 'ilm_policy': self.plan.ilm_policies[-1], 

35 'rollover_alias': self.plan.rollover_alias, 

36 } 

37 retval.append(setting_component(**kw)) 

38 retval.append(mapping_component()) 

39 return retval 

40 

41 def setup(self) -> None: 

42 """Setup the entity manager""" 

43 for component in self.components: 

44 put_comp_tmpl(self.client, self.name, component) 

45 if not exists(self.client, self.kind, 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 component template {self.name}' 

48 ) 

49 self.appender(self.name) 

50 self.logger.info( 

51 'Successfully created all component templates: %s', self.entity_list 

52 ) 

53 self.success = True