Coverage for src/es_testbed/classes/entitymgrs/templatemgr.py: 92%

31 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-23 13:14 -0600

1"""Index Template 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 ..testplan import TestPlan 

9 

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

11 

12class TemplateMgr(EntityMgr): 

13 def __init__( 

14 self, 

15 client: Elasticsearch = None, 

16 plan: TestPlan = None, 

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

18 is_ds: t.Optional[bool] = False, 

19 components: t.Sequence[str] = None, 

20 ): 

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

22 self.kind = 'template' 

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

24 self.components = components 

25 self.ds = {} if is_ds else None 

26 if self.autobuild: 26 ↛ exitline 26 didn't return from function '__init__', because the condition on line 26 was never false

27 self.setup() 

28 

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

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

31 

32 @property 

33 def logdisplay(self) -> str: 

34 return 'index template' 

35 

36 def setup(self): 

37 patterns = [] 

38 patterns.append(f"{self.get_pattern('index')}*") 

39 patterns.append(f"{self.get_pattern('data_stream')}*") 

40 es_api.put_idx_tmpl( 

41 self.client, 

42 self.name, 

43 patterns, 

44 components=self.components, 

45 data_stream=self.ds 

46 ) 

47 if not es_api.exists(self.client, 'template', 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.entity_list.append(self.name) 

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

52 self.success = True