Coverage for src/es_testbed/classes/entitymgrs/snapshotmgr.py: 53%
32 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-23 13:14 -0600
« prev ^ index » next coverage.py v7.5.0, created at 2024-04-23 13:14 -0600
1"""Snapshot Entity Manager Class"""
2import typing as t
3from elasticsearch8 import Elasticsearch
4from es_testbed.helpers import es_api
5from es_testbed.helpers.utils import getlogger
6from .entitymgr import EntityMgr
7from ..testplan import TestPlan
9# pylint: disable=missing-docstring
11class SnapshotMgr(EntityMgr):
12 def __init__(
13 self,
14 client: Elasticsearch = None,
15 plan: TestPlan = None,
16 autobuild: t.Optional[bool] = False,
17 ):
18 super().__init__(client=client, plan=plan, autobuild=autobuild)
19 self.kind = 'snapshot'
20 self.logger = getlogger('es_testbed.SnapshotMgr')
21 # We do not autobuild in this class
23 def add(self, index: str, tier: str) -> None:
24 msg = f'Creating snapshot of index {index} and mounting in the {tier} tier...'
25 self.logger.info(msg)
26 es_api.do_snap(
27 self.client,
28 self.plan.ilm.repository,
29 self.name,
30 index,
31 tier=tier
32 )
33 self.entity_list.append(self.name)
34 self.logger.info('Successfully created snapshot "%s"', self.last)
35 self.success = True
37 def add_existing(self, name: str) -> None:
38 """Add a snapshot that's already been created, e.g. by ILM promotion"""
39 self.logger.info('Adding snapshot %s to list...', name)
40 self.entity_list.append(name)
41 self.success = True
43 def setup(self):
44 pass
46 def teardown(self):
47 if not self.success: 47 ↛ 50line 47 didn't jump to line 50, because the condition on line 47 was never false
48 self.logger.info('No snapshots to clean up.')
49 return
50 self.logger.info('Cleaning up any existing snapshots...')
51 for snapshot in self.entity_list:
52 es_api.delete(self.client, 'snapshot', snapshot, repository=self.plan.ilm.repository)
53 self.logger.info('Cleanup of snapshots completed.')