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

32 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-24 22:41 -0600

1"""Tracker Class Definition""" 

2import typing as t 

3from dotmap import DotMap 

4from elasticsearch8 import Elasticsearch 

5from es_testbed.helpers.utils import getlogger 

6from .entitymgrs import ( 

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

8 

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

10 

11TYPEMAP = {'indices': IndexMgr, 'data_stream': DataStreamMgr} 

12 

13class Tracker: 

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

15 def __init__( 

16 self, 

17 client: Elasticsearch = None, 

18 plan: DotMap = None, 

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

20 ): 

21 """Initialize""" 

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

23 self.client = client 

24 self.plan = plan 

25 self.ilm_policies = None 

26 self.components = None 

27 self.templates = None 

28 self.entities = None 

29 self.snapshots = None 

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

31 self.setup() 

32 

33 def setup(self): 

34 kw = {'client': self.client, 'plan': self.plan} 

35 self.ilm_policies = IlmMgr(**kw) 

36 self.components = ComponentMgr(**kw) 

37 self.templates = TemplateMgr(**kw) 

38 self.snapshots = SnapshotMgr(**kw) 

39 etype = TYPEMAP[self.plan.type] 

40 self.entities = etype(**kw, snapmgr=self.snapshots) 

41 

42 def teardown(self): 

43 # These are ordered this way on purpose 

44 self.entities.teardown() 

45 self.snapshots.teardown() 

46 self.templates.teardown() 

47 self.components.teardown() 

48 self.ilm_policies.teardown()