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

22 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-02 13:33 -0600

1"""Snapshot Entity Manager Class""" 

2 

3import typing as t 

4from .entitymgr import EntityMgr 

5from ..helpers.es_api import do_snap 

6from ..helpers.utils import getlogger 

7 

8if t.TYPE_CHECKING: 

9 from elasticsearch8 import Elasticsearch 

10 from dotmap import DotMap 

11 

12# pylint: disable=missing-docstring 

13 

14 

15class SnapshotMgr(EntityMgr): 

16 kind = 'snapshot' 

17 listname = 'snapshots' 

18 

19 def __init__( 

20 self, 

21 client: t.Union['Elasticsearch', None] = None, 

22 plan: t.Union['DotMap', None] = None, 

23 ): 

24 self.logger = getlogger('es_testbed.SnapshotMgr') 

25 super().__init__(client=client, plan=plan) 

26 

27 def add(self, index: str, tier: str) -> None: 

28 """Perform a snapshot and add it to the entity_list""" 

29 msg = f'Creating snapshot of index {index} and mounting in the {tier} tier...' 

30 self.logger.info(msg) 

31 do_snap(self.client, self.plan.repository, self.name, index, tier=tier) 

32 self.appender(self.name) 

33 self.logger.info('Successfully created snapshot "%s"', self.last) 

34 self.success = True 

35 

36 def add_existing(self, name: str) -> None: 

37 """Add a snapshot that's already been created, e.g. by ILM promotion""" 

38 self.logger.info('Adding snapshot %s to list...', name) 

39 self.appender(name) 

40 self.success = True