Coverage for src/es_testbed/classes/tracker.py: 94%

39 statements  

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

1"""Tracker Class Definition""" 

2import typing as t 

3from elasticsearch8 import Elasticsearch 

4from es_testbed.helpers.utils import getlogger 

5from .entitymgrs import ( 

6 ComponentMgr, DataStreamMgr, IlmMgr, IndexMgr, SnapshotMgr, TemplateMgr) 

7from .testplan import TestPlan 

8 

9# pylint: disable=missing-docstring,too-many-instance-attributes 

10 

11class Tracker: 

12 """Object for tracking entities created in TestBed""" 

13 def __init__( 

14 self, 

15 client: Elasticsearch = None, 

16 plan: TestPlan = None, 

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

18 ): 

19 """Initialize""" 

20 self.logger = getlogger('es_testbed.Tracker') 

21 self.client = client 

22 self.plan = plan 

23 self.ilm_policies = None 

24 self.components = None 

25 self.templates = None 

26 self.entities = None 

27 self.snapshots = None 

28 if autobuild: 28 ↛ 29line 28 didn't jump to line 29, because the condition on line 28 was never true

29 self.setup() 

30 

31 def setup(self): 

32 # Build IlmBuilder from self.plan.ilm 

33 self.ilm_policies = IlmMgr(client=self.client, plan=self.plan) 

34 self.logger.debug('ilm_policies = %s', self.ilm_policies.entity_list) 

35 alias = None 

36 if self.plan.rollover_alias: 

37 alias = f'{self.plan.prefix}-idx-{self.plan.uniq}' 

38 self.components = ComponentMgr( 

39 client=self.client, 

40 plan=self.plan, 

41 ilm_policy=self.ilm_policies.last, 

42 rollover_alias=alias 

43 ) 

44 self.templates = TemplateMgr( 

45 client=self.client, 

46 plan=self.plan, 

47 components=self.components.entity_list, 

48 is_ds=self.plan.type == 'data_streams' 

49 ) 

50 self.snapshots = SnapshotMgr( 

51 client=self.client, 

52 plan=self.plan 

53 ) 

54 if self.plan.type == 'indices': 

55 self.logger.debug('Tracker.entities will be IndexMgr') 

56 etype = IndexMgr 

57 elif self.plan.type == 'data_streams': 57 ↛ 60line 57 didn't jump to line 60, because the condition on line 57 was never false

58 self.logger.debug('Tracker.entities will be DataStreamMgr') 

59 etype = DataStreamMgr 

60 self.entities = etype( 

61 client=self.client, 

62 plan=self.plan, 

63 snapmgr=self.snapshots, 

64 policy_name=self.ilm_policies.last 

65 ) 

66 

67 def teardown(self): 

68 # These are ordered this way on purpose 

69 self.entities.teardown() 

70 self.snapshots.teardown() 

71 self.ilm_policies.teardown() 

72 self.templates.teardown() 

73 self.components.teardown()