def test_snapshot_selection_all_filtered_fail(self): self.create_repository() for i in ["1", "2", "3"]: self.create_index("index" + i) self.client.create( index="index" + i, doc_type='log', body={'message': 'TEST DOCUMENT'}, ) curator.create_snapshot(self.client, name="snapshot" + i, indices="index" + i, repository=self.args['repository']) test = clicktest.CliRunner() result = test.invoke(curator.cli, [ '--logfile', os.devnull, '--host', host, '--port', str(port), 'show', 'snapshots', '--repository', self.args['repository'], '--prefix', 'no_match', ], obj={"filters": []}) self.assertEqual(0, result.exit_code)
def test_snapshot_selection_show_all_snapshots_with_exclude(self): self.create_repository() for i in ["1", "2"]: self.create_index("index" + i) self.client.create( index="index" + i, doc_type='log', body={'message': 'TEST DOCUMENT'}, ) curator.create_snapshot(self.client, name="snapshot" + i, indices="index" + i, repository=self.args['repository']) test = clicktest.CliRunner() result = test.invoke(curator.cli, [ '--logfile', os.devnull, '--host', host, '--port', str(port), 'show', 'snapshots', '--repository', self.args['repository'], '--all-snapshots', '--exclude', '2', ], obj={"filters": []}) self.assertEqual(['snapshot1'], result.output.splitlines()[:1])
def test_snapshot_selection_delete_all_snapshots_with_dry_run(self): self.create_repository() for i in ["1", "2"]: self.create_index("index" + i) self.client.create( index="index" + i, doc_type='log', body={'message': 'TEST DOCUMENT'}, ) curator.create_snapshot(self.client, name="snapshot" + i, indices="index" + i, repository=self.args['repository']) test = clicktest.CliRunner() result = test.invoke(curator.cli, [ '--dry-run', '--host', host, '--port', str(port), 'delete', 'snapshots', '--repository', self.args['repository'], '--all-snapshots', '--exclude', '2', ], obj={"filters": []}) output = sorted(result.output.splitlines(), reverse=True)[:4] # I tried doing a nested, double list comprehension here. # It works in the interpreter, but not here for some reason. output = [x.split(' ')[-1:] for x in output] output = [x[0] for x in output if x[0].startswith('snapshot1')] self.assertEqual(['snapshot1'], output)
def test_snapshot_selection_all_filtered_fail(self): self.create_repository() for i in ["1", "2", "3"]: self.create_index("index" + i) self.client.create( index="index" + i, doc_type='log', body={'message':'TEST DOCUMENT'}, ) curator.create_snapshot( self.client, name="snapshot" + i, indices="index" + i, repository=self.args['repository'] ) test = clicktest.CliRunner() result = test.invoke( curator.cli, [ '--logfile', os.devnull, '--host', host, '--port', str(port), 'show', 'snapshots', '--repository', self.args['repository'], '--prefix', 'no_match', ], obj={"filters":[]}) self.assertEqual(99, result.exit_code)
def test_snapshot_selection_show_all_snapshots(self): index_name = 'index1' snap_name = 'snapshot1' self.create_index(index_name) self.create_repository() self.client.create(index=index_name, doc_type='log', body={'message': 'TEST DOCUMENT'}) curator.create_snapshot(self.client, name=snap_name, indices=index_name, repository=self.args['repository']) test = clicktest.CliRunner() result = test.invoke(curator.cli, [ '--logfile', os.devnull, '--host', host, '--port', str(port), 'show', 'snapshots', '--repository', self.args['repository'], '--all-snapshots', ], obj={"filters": []}) self.assertEqual([snap_name], result.output.splitlines()[:1])
def test_snapshot_selection_delete_all_snapshots_with_dry_run(self): self.create_repository() for i in ["1", "2"]: self.create_index("index" + i) self.client.create( index="index" + i, doc_type='log', body={'message':'TEST DOCUMENT'}, ) curator.create_snapshot( self.client, name="snapshot" + i, indices="index" + i, repository=self.args['repository'] ) test = clicktest.CliRunner() result = test.invoke( curator.cli, [ '--dry-run', '--host', host, '--port', str(port), 'delete', 'snapshots', '--repository', self.args['repository'], '--all-snapshots', '--exclude', '2', ], obj={"filters":[]}) output = sorted(result.output.splitlines(), reverse=True)[:4] # I tried doing a nested, double list comprehension here. # It works in the interpreter, but not here for some reason. output = [ x.split(' ')[-1:] for x in output ] output = [ x[0] for x in output if x[0].startswith('snapshot1') ] self.assertEqual(['snapshot1'], output)
def test_snapshot_selection_delete_snapshot(self): self.create_repository() for i in ["1", "2"]: self.create_index("index" + i) self.client.create( index="index" + i, doc_type='log', body={'message':'TEST DOCUMENT'}, ) curator.create_snapshot( self.client, name="snapshot" + i, indices="index" + i, repository=self.args['repository'] ) result = curator.get_snapshot(self.client, self.args['repository'], '_all') self.assertEqual(2, len(result['snapshots'])) test = clicktest.CliRunner() result = test.invoke( curator.cli, [ '--logfile', os.devnull, '--host', host, '--port', str(port), 'delete', 'snapshots', '--repository', self.args['repository'], '--exclude', '2', ], obj={"filters":[]}) result = curator.get_snapshot(self.client, self.args['repository'], '_all') self.assertEqual(1, len(result['snapshots'])) self.assertEqual('snapshot2', result['snapshots'][0]['snapshot'])
def test_snapshot_selection_show_all_snapshots_with_exclude_and_other(self): self.create_repository() for i in ["1", "2"]: self.create_index("index" + i) self.client.create( index="index" + i, doc_type='log', body={'message':'TEST DOCUMENT'}, ) curator.create_snapshot( self.client, name="snapshot" + i, indices="index" + i, repository=self.args['repository'] ) test = clicktest.CliRunner() result = test.invoke( curator.cli, [ '--logfile', os.devnull, '--host', host, '--port', str(port), 'show', 'snapshots', '--repository', self.args['repository'], '--all-snapshots', '--exclude', '2', '--prefix', 'missing', '--suffix', 'also_missing', ], obj={"filters":[]}) self.assertEqual(['snapshot1'], result.output.splitlines()[:1])
def test_snapshot_selection_show_all_snapshots(self): index_name = 'index1' snap_name = 'snapshot1' self.create_index(index_name) self.create_repository() self.client.create( index=index_name, doc_type='log', body={'message':'TEST DOCUMENT'} ) curator.create_snapshot( self.client, name=snap_name, indices=index_name, repository=self.args['repository'] ) test = clicktest.CliRunner() result = test.invoke( curator.cli, [ '--logfile', os.devnull, '--host', host, '--port', str(port), 'show', 'snapshots', '--repository', self.args['repository'], '--all-snapshots', ], obj={"filters":[]}) self.assertEqual([snap_name], result.output.splitlines()[:1])
def main(argv): parser = OptionParser() parser.add_option("-p", "--prefix", dest="prefix", action="store", help="prefix to indices filter ") parser.add_option("-r", "--repository", dest="repository", action="store", help="repository name") (opts, args) = parser.parse_args() if not opts.repository: # if repository is not given print 'repository not given' usage() sys.exit() if not opts.prefix: # if repository is not given print 'prefix not given' usage() sys.exit() client = elasticsearch.Elasticsearch([ {'host': 'localhost', 'port': 9200} ]) indices_list = curator.get_indices(client) _filter = curator.build_filter(kindOf='prefix', value=opts.prefix) working_list = curator.apply_filter(indices_list, **_filter) res = curator.create_snapshot(client, indices=working_list, name=None, prefix='curator-', repository=opts.repository, ignore_unavailable=True, include_global_state=False, partial=False, wait_for_completion=True, request_timeout=21600, skip_repo_validation=False) print res
def main(argv): parser = OptionParser() parser.add_option("-p", "--prefix", dest="prefix", action="store", help="prefix to indices filter ") parser.add_option("-r", "--repository", dest="repository", action="store", help="repository name") (opts, args) = parser.parse_args() if not opts.repository: # if repository is not given print 'repository not given' usage() sys.exit() if not opts.prefix: # if repository is not given print 'prefix not given' usage() sys.exit() client = elasticsearch.Elasticsearch([{'host': 'localhost', 'port': 9200}]) indices_list = curator.get_indices(client) _filter = curator.build_filter(kindOf='prefix', value=opts.prefix) working_list = curator.apply_filter(indices_list, **_filter) res = curator.create_snapshot(client, indices=working_list, name=None, prefix='curator-', repository=opts.repository, ignore_unavailable=True, include_global_state=False, partial=False, wait_for_completion=True, request_timeout=21600, skip_repo_validation=False) print res