1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
"""Test delete snapshot functionality"""
# pylint: disable=C0115, C0116, invalid-name
import os
import time
from curator import IndexList
from curator.actions.snapshot import Snapshot
from curator.helpers.getters import get_snapshot
from . import CuratorTestCase
from . import testvars
HOST = os.environ.get('TEST_ES_SERVER', 'http://127.0.0.1:9200')
# ' repository: {0}\n'
# ' - filtertype: {1}\n'
# ' source: {2}\n'
# ' direction: {3}\n'
# ' timestring: {4}\n'
# ' unit: {5}\n'
# ' unit_count: {6}\n'
# ' epoch: {7}\n')
class TestActionFileDeleteSnapshots(CuratorTestCase):
def test_deletesnapshot(self):
# Create snapshots to delete and verify them
self.create_repository()
timestamps = []
for i in range(1, 4):
self.add_docs(f'my_index{i}')
ilo = IndexList(self.client)
snap = Snapshot(
ilo,
repository=self.args['repository'],
name='curator-%Y%m%d%H%M%S',
wait_interval=0.5,
)
snap.do_action()
snapshot = get_snapshot(self.client, self.args['repository'], '*')
assert i == len(snapshot['snapshots'])
time.sleep(1.0)
timestamps.append(int(time.time()))
time.sleep(1.0)
# Setup the actual delete
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(
self.args['actionfile'],
testvars.delete_snap_proto.format(
self.args['repository'],
'age',
'creation_date',
'older',
' ',
'seconds',
'0',
timestamps[0],
),
)
self.invoke_runner()
snapshot = get_snapshot(self.client, self.args['repository'], '*')
assert 2 == len(snapshot['snapshots'])
def test_no_repository(self):
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(
self.args['actionfile'],
testvars.delete_snap_proto.format(
' ', 'age', 'creation_date', 'older', ' ', 'seconds', '0', ' '
),
)
self.invoke_runner()
assert 1 == self.result.exit_code
def test_extra_options(self):
self.write_config(self.args['configfile'], testvars.client_config.format(HOST))
self.write_config(
self.args['actionfile'],
testvars.bad_option_proto_test.format('delete_snapshots'),
)
self.invoke_runner()
assert 1 == self.result.exit_code
class TestCLIDeleteSnapshots(CuratorTestCase):
def test_deletesnapshot(self):
# Create snapshots to delete and verify them
self.create_repository()
timestamps = []
for i in range(1, 4):
self.add_docs(f'my_index{i}')
ilo = IndexList(self.client)
snap = Snapshot(
ilo,
repository=self.args['repository'],
name='curator-%Y%m%d%H%M%S',
wait_interval=0.5,
)
snap.do_action()
snapshot = get_snapshot(self.client, self.args['repository'], '*')
assert i == len(snapshot['snapshots'])
time.sleep(1.0)
timestamps.append(int(time.time()))
time.sleep(1.0)
filter_list = (
'{"filtertype":"age","source":"creation_date","direction":"older",'
'"unit":"seconds","unit_count":0,"epoch":' + str(timestamps[0]) + '}'
)
# Setup the actual delete
args = self.get_runner_args()
args += [
'--config',
self.args['configfile'],
'delete-snapshots',
'--repository',
self.args['repository'],
'--filter_list',
filter_list,
]
assert 0 == self.run_subprocess(
args, logname='TestCLIDeleteSnapshots.test_deletesnapshot'
)
snapshot = get_snapshot(self.client, self.args['repository'], '*')
assert 2 == len(snapshot['snapshots'])
def test_count_by_age(self):
self.create_repository()
timestamps = []
def add_snap(num, name):
self.add_docs(f'my_index{num}')
ilo = IndexList(self.client)
snap = Snapshot(
ilo, repository=self.args['repository'], name=name, wait_interval=0.5
)
snap.do_action()
snapshot = get_snapshot(self.client, self.args['repository'], '*')
assert num == len(snapshot['snapshots'])
time.sleep(1.0)
timestamps.append(int(time.time()))
time.sleep(1.0)
name = 'curator-%Y%m%d%H%M%S'
for i in range(1, 4):
add_snap(i, name)
add_snap(4, 'kibana-index')
# Setup the actual delete
filter_list = (
'{"filtertype":"count","count":2,"use_age":true,"source":"name",'
'"timestring":"%Y%m%d%H%M%S"}'
)
args = self.get_runner_args()
args += [
'--config',
self.args['configfile'],
'delete-snapshots',
'--repository',
self.args['repository'],
'--filter_list',
filter_list,
]
assert 0 == self.run_subprocess(
args, logname='TestCLIDeleteSnapshots.test_deletesnapshot'
)
snapshot = get_snapshot(self.client, self.args['repository'], '*')
assert 3 == len(snapshot['snapshots'])
|