Coverage for /Users/buh/.pyenv/versions/3.12.2/envs/es-testbed/lib/python3.12/site-packages/es_testbed/classes/entitymgrs/templatemgr.py: 95%

32 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-25 19:21 -0600

1"""Index Template Entity Manager Class""" 

2import typing as t 

3from dotmap import DotMap 

4from elasticsearch8 import Elasticsearch 

5from es_testbed.exceptions import ResultNotExpected 

6from es_testbed.helpers import es_api 

7from es_testbed.helpers.utils import getlogger 

8from .entitymgr import EntityMgr 

9 

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

11 

12class TemplateMgr(EntityMgr): 

13 kind = 'template' 

14 listname = 'index_templates' 

15 def __init__( 

16 self, 

17 client: Elasticsearch = None, 

18 plan: DotMap = None, 

19 autobuild: t.Optional[bool] = True, 

20 ): 

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

22 self.logger = getlogger('es_testbed.TemplateMgr') 

23 

24 @property 

25 def logdisplay(self) -> str: 

26 return 'index template' 

27 

28 @property 

29 def patterns(self) -> t.Sequence[str]: 

30 _ = [] 

31 _.append(f"{self.get_pattern('index')}*") 

32 _.append(f"{self.get_pattern('data_stream')}*") 

33 return _ 

34 

35 def get_pattern(self, kind: str) -> str: 

36 return f'{self.plan.prefix}-{self.ident(dkey=kind)}-{self.plan.uniq}' 

37 

38 def setup(self): 

39 ds = {} if self.plan.type == 'data_stream' else None 

40 es_api.put_idx_tmpl( 

41 self.client, 

42 self.name, 

43 self.patterns, 

44 components=self.plan.component_templates, 

45 data_stream=ds 

46 ) 

47 if not es_api.exists(self.client, self.kind, self.name): 47 ↛ 48line 47 didn't jump to line 48, because the condition on line 47 was never true

48 raise ResultNotExpected( 

49 f'Unable to verify creation of index template {self.name}') 

50 self.appender(self.name) 

51 self.logger.debug('Successfully created index template: %s', self.last) 

52 self.success = True