Exemple #1
0
 def test_deletesnapshot(self):
     ### Create snapshots to delete and verify them
     self.create_repository()
     timestamps = []
     for i in range(1, 4):
         self.add_docs('my_index{0}'.format(i))
         ilo = curator.IndexList(self.client)
         snap = curator.Snapshot(ilo,
                                 repository=self.args['repository'],
                                 name='curator-%Y%m%d%H%M%S',
                                 wait_interval=0.5)
         snap.do_action()
         snapshot = curator.get_snapshot(self.client,
                                         self.args['repository'], '_all')
         self.assertEqual(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, port))
     self.write_config(
         self.args['actionfile'],
         testvars.delete_snap_proto.format(self.args['repository'], 'age',
                                           'creation_date', 'older', ' ',
                                           'seconds', '0', timestamps[0]))
     test = clicktest.CliRunner()
     _ = test.invoke(
         curator.cli,
         ['--config', self.args['configfile'], self.args['actionfile']],
     )
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(2, len(snapshot['snapshots']))
Exemple #2
0
 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_deletesnapshot(self):
     ### Create snapshots to delete and verify them
     self.create_repository()
     timestamps = []
     for i in range(1, 4):
         self.add_docs("my_index{0}".format(i))
         ilo = curator.IndexList(self.client)
         snap = curator.Snapshot(ilo, repository=self.args["repository"], name="curator-%Y%m%d%H%M%S")
         snap.do_action()
         snapshot = curator.get_snapshot(self.client, self.args["repository"], "_all")
         self.assertEqual(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, port))
     self.write_config(
         self.args["actionfile"],
         testvars.delete_snap_proto.format(
             self.args["repository"], "age", "creation_date", "older", " ", "seconds", "0", timestamps[0]
         ),
     )
     test = clicktest.CliRunner()
     result = test.invoke(curator.cli, ["--config", self.args["configfile"], self.args["actionfile"]])
     snapshot = curator.get_snapshot(self.client, self.args["repository"], "_all")
     self.assertEqual(2, len(snapshot["snapshots"]))
 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_deletesnapshot(self):
     ### Create snapshots to delete and verify them
     self.create_repository()
     timestamps = []
     for i in range(1,4):
         self.add_docs('my_index{0}'.format(i))
         ilo = curator.IndexList(self.client)
         snap = curator.Snapshot(ilo, repository=self.args['repository'], name='curator-%Y%m%d%H%M%S', wait_interval=0.5)
         snap.do_action()
         snapshot = curator.get_snapshot(self.client, self.args['repository'], '_all')
         self.assertEqual(i, len(snapshot['snapshots']))
         time.sleep(1.0)
         timestamps.append(int(time.time()))
         time.sleep(1.0)
     ### Setup the actual delete
     args = self.get_runner_args()
     args += [
         '--config', self.args['configfile'],
         'delete_snapshots',
         '--repository', self.args['repository'],
         '--filter_list', '{"filtertype":"age","source":"creation_date","direction":"older","unit":"seconds","unit_count":0,"epoch":' + str(timestamps[0]) + '}',
     ]
     self.assertEqual(0, self.run_subprocess(args, logname='TestCLIDeleteSnapshots.test_deletesnapshot'))
     snapshot = curator.get_snapshot(self.client, self.args['repository'], '_all')
     self.assertEqual(2, len(snapshot['snapshots']))
Exemple #6
0
 def test_restore(self):
     indices = []
     for i in range(1, 4):
         self.add_docs('my_index{0}'.format(i))
         indices.append('my_index{0}'.format(i))
     snap_name = 'snapshot1'
     self.create_snapshot(snap_name, ','.join(indices))
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(1, len(snapshot['snapshots']))
     self.client.indices.delete(','.join(indices))
     self.assertEqual([], curator.get_indices(self.client))
     self.write_config(self.args['configfile'],
                       testvars.client_config.format(host, port))
     self.write_config(
         self.args['actionfile'],
         testvars.restore_snapshot_proto.format(self.args['repository'],
                                                snap_name, indices, False,
                                                False, True, False, ' ',
                                                ' ', ' ', True, False, 301,
                                                1, 3))
     test = clicktest.CliRunner()
     result = test.invoke(
         curator.cli,
         ['--config', self.args['configfile'], self.args['actionfile']],
     )
     restored_indices = sorted(curator.get_indices(self.client))
     self.assertEqual(indices, restored_indices)
     # The test runs so fast that it tries to execute the cleanup step
     # and delete the repository before Elasticsearch is actually ready
     time.sleep(0.5)
 def test_cli_snapshot_indices(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = 'snapshot1'
     indices = curator.get_indices(self.client)
     expected = sorted(indices, reverse=True)[:4]
     test = clicktest.CliRunner()
     result = test.invoke(
                 curator.cli,
                 [
                     '--logfile', os.devnull,
                     '--host', host,
                     '--port', str(port),
                     'snapshot',
                     '--repository', self.args['repository'],
                     '--name', snap_name,
                     'indices',
                     '--all-indices',
                 ],
                 obj={"filters":[]})
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name, snapshot['snapshots'][0]['snapshot'])
Exemple #8
0
 def test_restore(self):
     indices = []
     for i in range(1,4):
         self.add_docs('my_index{0}'.format(i))
         indices.append('my_index{0}'.format(i))
     snap_name = 'snapshot1'
     self.create_snapshot(snap_name, ','.join(indices))
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(1, len(snapshot['snapshots']))
     self.client.indices.delete(','.join(indices))
     self.assertEqual([], curator.get_indices(self.client))
     args = self.get_runner_args()
     args += [
         '--config', self.args['configfile'],
         'restore',
         '--repository', self.args['repository'],
         '--name', snap_name,
         '--index', indices[0],
         '--index', indices[1],
         '--index', indices[2],
         '--wait_interval', '1',
         '--max_wait', '3',
         '--filter_list', '{"filtertype":"none"}',
     ]
     self.assertEqual(0, self.run_subprocess(args, logname='TestCLIRestore.test_restore'))
     restored_indices = sorted(curator.get_indices(self.client))
     self.assertEqual(indices, restored_indices)
     # The test runs so fast that it tries to execute the cleanup step
     # and delete the repository before Elasticsearch is actually ready
     time.sleep(0.5)
 def test_cli_snapshot_huge_list(self):
     self.create_indices(200)
     self.create_repository()
     snap_name = 'snapshot1'
     test = clicktest.CliRunner()
     result = test.invoke(
                 curator.cli,
                 [
                     '--logfile', os.devnull,
                     '--host', host,
                     '--port', str(port),
                     '--timeout', 600,
                     'snapshot',
                     '--repository', self.args['repository'],
                     '--name', snap_name,
                     'indices',
                     '--all-indices',
                 ],
                 obj={"filters":[]})
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name, snapshot['snapshots'][0]['snapshot'])
     self.assertEqual(200, len(snapshot['snapshots'][0]['indices']))
Exemple #10
0
 def test_cli_snapshot_indices(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = 'snapshot1'
     indices = curator.get_indices(self.client)
     expected = sorted(indices, reverse=True)[:4]
     test = clicktest.CliRunner()
     result = test.invoke(curator.cli, [
         '--logfile',
         os.devnull,
         '--host',
         host,
         '--port',
         str(port),
         'snapshot',
         '--repository',
         self.args['repository'],
         '--name',
         snap_name,
         'indices',
         '--all-indices',
     ],
                          obj={"filters": []})
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name, snapshot['snapshots'][0]['snapshot'])
Exemple #11
0
 def test_cli_snapshot_huge_list(self):
     self.create_indices(200)
     self.create_repository()
     snap_name = 'snapshot1'
     test = clicktest.CliRunner()
     result = test.invoke(curator.cli, [
         '--logfile',
         os.devnull,
         '--host',
         host,
         '--port',
         str(port),
         '--timeout',
         600,
         'snapshot',
         '--repository',
         self.args['repository'],
         '--name',
         snap_name,
         'indices',
         '--all-indices',
     ],
                          obj={"filters": []})
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name, snapshot['snapshots'][0]['snapshot'])
     self.assertEqual(200, len(snapshot['snapshots'][0]['indices']))
Exemple #12
0
 def test_restore_with_rename(self):
     indices = []
     for i in range(1, 4):
         self.add_docs('my_index{0}'.format(i))
         indices.append('my_index{0}'.format(i))
     snap_name = 'snapshot1'
     self.create_snapshot(snap_name, ','.join(indices))
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(1, len(snapshot['snapshots']))
     self.client.indices.delete(','.join(indices))
     self.assertEqual([], curator.get_indices(self.client))
     self.write_config(self.args['configfile'],
                       testvars.client_config.format(host, port))
     self.write_config(
         self.args['actionfile'],
         testvars.restore_snapshot_proto.format(self.args['repository'],
                                                snap_name, indices, False,
                                                False, True, False,
                                                'my_index(.+)',
                                                'new_index$1', ' ', True,
                                                False, 301))
     test = clicktest.CliRunner()
     result = test.invoke(
         curator.cli,
         ['--config', self.args['configfile'], self.args['actionfile']],
     )
     restored_indices = sorted(curator.get_indices(self.client))
     self.assertEqual(['new_index1', 'new_index2', 'new_index3'],
                      restored_indices)
Exemple #13
0
 def test_snapshot(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = 'snapshot1'
     args = self.get_runner_args()
     args += [
         '--config',
         self.args['configfile'],
         'snapshot',
         '--repository',
         self.args['repository'],
         '--name',
         snap_name,
         '--wait_interval',
         '1',
         '--max_wait',
         '30',
         '--filter_list',
         '{"filtertype":"none"}',
     ]
     self.assertEqual(
         0,
         self.run_subprocess(args, logname='TestCLISnapshot.test_snapshot'))
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name, snapshot['snapshots'][0]['snapshot'])
 def test_deletesnapshot(self):
     def add_docs(idx):
         for i in ["1", "2", "3"]:
             self.client.create(
                 index=idx, doc_type='log',
                 body={"doc" + i :'TEST DOCUMENT'},
             )
             # This should force each doc to be in its own segment.
             self.client.indices.flush(index=idx, force=True)
     ### Create snapshots to delete and verify them
     self.create_repository()
     timestamps = []
     for i in range(1,4):
         add_docs('my_index{0}'.format(i))
         ilo = curator.IndexList(self.client)
         snap = curator.Snapshot(ilo, repository=self.args['repository'],
             name='curator-%Y%m%d%H%M%S'
         )
         snap.do_action()
         snapshot = curator.get_snapshot(
                     self.client, self.args['repository'], '_all'
                    )
         self.assertEqual(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, port))
     self.write_config(self.args['actionfile'],
         testvars.delete_snap_proto.format(
             self.args['repository'], 'age', 'creation_date', 'older', ' ',
             'seconds', '0', timestamps[0]
         )
     )
     test = clicktest.CliRunner()
     result = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(2, len(snapshot['snapshots']))
Exemple #15
0
 def test_get_snapshot_positive(self):
     client = Mock()
     client.snapshot.get.return_value = testvars.snapshot
     self.assertEqual(
         testvars.snapshot,
         curator.get_snapshot(client,
                              repository=testvars.repo_name,
                              snapshot=testvars.snap_name))
Exemple #16
0
 def test_restore_wildcard(self):
     indices = []
     my_indices = []
     wildcard = ['my_*']
     for i in range(1,4):
         for prefix in ['my_', 'not_my_']:
             self.add_docs('{0}index{1}'.format(prefix, i))
             indices.append('{0}index{1}'.format(prefix, i))
             if prefix == 'my_':
                 my_indices.append('{0}index{1}'.format(prefix, i))
     snap_name = 'snapshot1'
     self.create_snapshot(snap_name, ','.join(indices))
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(1, len(snapshot['snapshots']))
     self.client.indices.delete(','.join(indices))
     self.assertEqual([], curator.get_indices(self.client))
     self.write_config(
         self.args['configfile'], testvars.client_config.format(host, port))
     self.write_config(self.args['actionfile'],
         testvars.restore_snapshot_proto.format(
             self.args['repository'],
             snap_name,
             wildcard,
             False,
             False,
             True,
             False,
             ' ',
             ' ',
             ' ',
             True,
             False,
             301,
             1,
             3
         )
     )
     test = clicktest.CliRunner()
     result = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     restored_indices = sorted(curator.get_indices(self.client))
     self.assertEqual(my_indices, restored_indices)
     # The test runs so fast that it tries to execute the cleanup step
     # and delete the repository before Elasticsearch is actually ready
     time.sleep(0.5)
Exemple #17
0
 def test_restore_with_rename(self):
     indices = []
     for i in range(1,4):
         self.add_docs('my_index{0}'.format(i))
         indices.append('my_index{0}'.format(i))
     snap_name = 'snapshot1'
     self.create_snapshot(snap_name, ','.join(indices))
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     time.sleep(1)
     self.assertEqual(1, len(snapshot['snapshots']))
     self.client.indices.delete(','.join(indices))
     self.assertEqual([], curator.get_indices(self.client))
     self.write_config(
         self.args['configfile'], testvars.client_config.format(host, port))
     self.write_config(self.args['actionfile'],
         testvars.restore_snapshot_proto.format(
             self.args['repository'],
             snap_name,
             indices,
             False,
             False,
             True,
             False,
             'my_index(.+)',
             'new_index$1',
             ' ',
             True,
             False,
             301,
             1,
             3,
         )
     )
     test = clicktest.CliRunner()
     result = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     time.sleep(1)
     restored_indices = sorted(curator.get_indices(self.client))
     self.assertEqual(
         ['new_index1', 'new_index2', 'new_index3'],
         restored_indices
     )
     # The test runs so fast that it tries to execute the cleanup step
     # and delete the repository before Elasticsearch is actually ready
     time.sleep(1)
 def test_deletesnapshot(self):
     ### Create snapshots to delete and verify them
     self.create_repository()
     timestamps = []
     for i in range(1,4):
         self.add_docs('my_index{0}'.format(i))
         ilo = curator.IndexList(self.client)
         snap = curator.Snapshot(ilo, repository=self.args['repository'],
             name='curator-%Y%m%d%H%M%S', wait_interval=0.5
         )
         snap.do_action()
         snapshot = curator.get_snapshot(
                     self.client, self.args['repository'], '_all'
                    )
         self.assertEqual(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, port))
     self.write_config(self.args['actionfile'],
         testvars.delete_snap_proto.format(
             self.args['repository'], 'age', 'creation_date', 'older', ' ',
             'seconds', '0', timestamps[0]
         )
     )
     test = clicktest.CliRunner()
     result = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(2, len(snapshot['snapshots']))
Exemple #19
0
 def add_snap(num, name):
     self.add_docs('my_index{0}'.format(num))
     ilo = curator.IndexList(self.client)
     snap = curator.Snapshot(ilo,
                             repository=self.args['repository'],
                             name=name,
                             wait_interval=0.5)
     snap.do_action()
     snapshot = curator.get_snapshot(self.client,
                                     self.args['repository'], '_all')
     self.assertEqual(num, len(snapshot['snapshots']))
     time.sleep(1.0)
     timestamps.append(int(time.time()))
     time.sleep(1.0)
Exemple #20
0
 def test_restore_with_rename(self):
     indices = []
     for i in range(1,4):
         self.add_docs('my_index{0}'.format(i))
         indices.append('my_index{0}'.format(i))
     snap_name = 'snapshot1'
     self.create_snapshot(snap_name, ','.join(indices))
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(1, len(snapshot['snapshots']))
     self.client.indices.delete(','.join(indices))
     self.assertEqual([], curator.get_indices(self.client))
     self.write_config(
         self.args['configfile'], testvars.client_config.format(host, port))
     self.write_config(self.args['actionfile'],
         testvars.restore_snapshot_proto.format(
             self.args['repository'],
             snap_name,
             indices,
             False,
             False,
             True,
             False,
             'my_index(.+)',
             'new_index$1',
             ' ',
             True,
             False,
             301
         )
     )
     test = clicktest.CliRunner()
     result = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     restored_indices = sorted(curator.get_indices(self.client))
     self.assertEqual(
         ['new_index1', 'new_index2', 'new_index3'], 
         restored_indices
     )
Exemple #21
0
 def test_snapshot(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = 'snapshot1'
     self.write_config(self.args['configfile'],
                       testvars.client_config.format(host, port))
     self.write_config(
         self.args['actionfile'],
         testvars.snapshot_test.format(self.args['repository'], snap_name))
     test = clicktest.CliRunner()
     result = test.invoke(
         curator.cli,
         ['--config', self.args['configfile'], self.args['actionfile']],
     )
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name, snapshot['snapshots'][0]['snapshot'])
Exemple #22
0
 def test_snapshot(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = 'snapshot1'
     args = self.get_runner_args()
     args += [
         '--config', self.args['configfile'],
         'snapshot',
         '--repository', self.args['repository'],
         '--name', snap_name,
         '--wait_interval', '1',
         '--max_wait', '30',
         '--filter_list', '{"filtertype":"none"}',
     ]
     self.assertEqual(0, self.run_subprocess(args, logname='TestCLISnapshot.test_snapshot'))
     snapshot = curator.get_snapshot(self.client, self.args['repository'], '_all')
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name, snapshot['snapshots'][0]['snapshot'])
Exemple #23
0
 def test_snapshot_do_not_ignore_empty_list(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = 'snapshot1'
     self.write_config(self.args['configfile'],
                       testvars.client_config.format(host, port))
     self.write_config(
         self.args['actionfile'],
         testvars.test_682.format(self.args['repository'], snap_name, False,
                                  1, 30))
     test = clicktest.CliRunner()
     _ = test.invoke(
         curator.cli,
         ['--config', self.args['configfile'], self.args['actionfile']],
     )
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(0, len(snapshot['snapshots']))
     self.assertEquals(5, len(curator.get_indices(self.client)))
Exemple #24
0
    def test_count_by_age(self):
        self.create_repository()
        timestamps = []

        def add_snap(num, name):
            self.add_docs('my_index{0}'.format(num))
            ilo = curator.IndexList(self.client)
            snap = curator.Snapshot(ilo,
                                    repository=self.args['repository'],
                                    name=name,
                                    wait_interval=0.5)
            snap.do_action()
            snapshot = curator.get_snapshot(self.client,
                                            self.args['repository'], '_all')
            self.assertEqual(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
        args = self.get_runner_args()
        args += [
            '--config',
            self.args['configfile'],
            'delete-snapshots',
            '--repository',
            self.args['repository'],
            '--filter_list',
            '{"filtertype":"count","count":2,"use_age":true,"source":"name","timestring":"%Y%m%d%H%M%S"}',
        ]
        self.assertEqual(
            0,
            self.run_subprocess(
                args, logname='TestCLIDeleteSnapshots.test_deletesnapshot'))
        snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                        '_all')
        self.assertEqual(3, len(snapshot['snapshots']))
Exemple #25
0
 def test_snapshot(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = 'snapshot1'
     self.write_config(
         self.args['configfile'], testvars.client_config.format(host, port))
     self.write_config(self.args['actionfile'],
         testvars.snapshot_test.format(self.args['repository'], snap_name, 1, 30))
     test = clicktest.CliRunner()
     _ = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name, snapshot['snapshots'][0]['snapshot'])
Exemple #26
0
 def test_snapshot_do_not_ignore_empty_list(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = 'snapshot1'
     self.write_config(
         self.args['configfile'], testvars.client_config.format(host, port))
     self.write_config(self.args['actionfile'],
         testvars.test_682.format(self.args['repository'], snap_name, False, 1, 30))
     test = clicktest.CliRunner()
     _ = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(0, len(snapshot['snapshots']))
     self.assertEquals(5, len(curator.get_indices(self.client)))
Exemple #27
0
 def test_snapshot_datemath(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = '<snapshot-{now-1d/d}>'
     snap_name_parsed = u'snapshot-{0}'.format(
         (datetime.utcnow() - timedelta(days=1)).strftime('%Y.%m.%d'))
     self.write_config(self.args['configfile'],
                       testvars.client_config.format(host, port))
     self.write_config(
         self.args['actionfile'],
         testvars.snapshot_test.format(self.args['repository'], snap_name,
                                       1, 30))
     test = clicktest.CliRunner()
     _ = test.invoke(
         curator.cli,
         ['--config', self.args['configfile'], self.args['actionfile']],
     )
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name_parsed,
                      snapshot['snapshots'][0]['snapshot'])
Exemple #28
0
 def test_snapshot_datemath(self):
     self.create_indices(5)
     self.create_repository()
     snap_name = '<snapshot-{now-1d/d}>'
     snap_name_parsed = u'snapshot-{0}'.format((datetime.utcnow()-timedelta(days=1)).strftime('%Y.%m.%d'))
     self.write_config(
         self.args['configfile'], testvars.client_config.format(host, port))
     self.write_config(self.args['actionfile'],
         testvars.snapshot_test.format(self.args['repository'], snap_name, 1, 30))
     test = clicktest.CliRunner()
     _ = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEqual(1, len(snapshot['snapshots']))
     self.assertEqual(snap_name_parsed, snapshot['snapshots'][0]['snapshot'])
Exemple #29
0
 def test_get_snapshot_positive(self):
     client = Mock()
     client.snapshot.get.return_value = testvars.snapshot
     self.assertEqual(testvars.snapshot, curator.get_snapshot(client, repository=testvars.repo_name, snapshot=testvars.snap_name))
Exemple #30
0
 def test_fix_for_687(self):
     self.create_repository()
     snap_name = 'test687'
     # 7 june (week 23)
     self.client.indices.create(index='logstash-2016.23',
                                body={
                                    'settings': {
                                        'creation_date': 1465293737000,
                                        'number_of_shards': 1,
                                        'number_of_replicas': 0
                                    }
                                })
     # 14 june (week 24)
     self.client.indices.create(index='logstash-2016.24',
                                body={
                                    'settings': {
                                        'creation_date': 1465898537000,
                                        'number_of_shards': 1,
                                        'number_of_replicas': 0
                                    }
                                })
     # 21 june (week 25)
     self.client.indices.create(index='logstash-2016.25',
                                body={
                                    'settings': {
                                        'creation_date': 1466503337000,
                                        'number_of_shards': 1,
                                        'number_of_replicas': 0
                                    }
                                })
     # 28 july (week 26)
     self.client.indices.create(index='logstash-2016.26',
                                body={
                                    'settings': {
                                        'creation_date': 1467108137000,
                                        'number_of_shards': 1,
                                        'number_of_replicas': 0
                                    }
                                })
     # 5 july (week 27)
     self.client.indices.create(index='logstash-2016.27',
                                body={
                                    'settings': {
                                        'creation_date': 1467712937000,
                                        'number_of_shards': 1,
                                        'number_of_replicas': 0
                                    }
                                })
     # 12 july (week 28)
     self.client.indices.create(index='logstash-2016.28',
                                body={
                                    'settings': {
                                        'creation_date': 1468317737000,
                                        'number_of_shards': 1,
                                        'number_of_replicas': 0
                                    }
                                })
     self.client.cluster.health(wait_for_status='yellow')
     self.write_config(self.args['configfile'],
                       testvars.client_config.format(host, port))
     self.write_config(
         self.args['actionfile'],
         testvars.test_687.format(self.args['repository'], snap_name))
     test = clicktest.CliRunner()
     result = test.invoke(
         curator.cli,
         ['--config', self.args['configfile'], self.args['actionfile']],
     )
     snapshot = curator.get_snapshot(self.client, self.args['repository'],
                                     '_all')
     self.assertEquals(6, len(curator.get_indices(self.client)))
 def test_fix_for_687(self):
     self.create_repository()
     snap_name = 'test687'
     # 7 june (week 23)
     self.client.indices.create(
         index='logstash-2016.23',
         body={
             'settings': {
                 'creation_date': 1465293737000,
                 'number_of_shards': 1, 'number_of_replicas': 0
             }
         }
     )
     # 14 june (week 24)
     self.client.indices.create(
         index='logstash-2016.24',
         body={
             'settings': {
                 'creation_date': 1465898537000,
                 'number_of_shards': 1, 'number_of_replicas': 0
             }
         }
     )
     # 21 june (week 25)
     self.client.indices.create(
         index='logstash-2016.25',
         body={
             'settings': {
                 'creation_date': 1466503337000,
                 'number_of_shards': 1, 'number_of_replicas': 0
             }
         }
     )
     # 28 july (week 26)
     self.client.indices.create(
         index='logstash-2016.26',
         body={
             'settings': {
                 'creation_date': 1467108137000,
                 'number_of_shards': 1, 'number_of_replicas': 0
             }
         }
     )
     # 5 july (week 27)
     self.client.indices.create(
         index='logstash-2016.27',
         body={
             'settings': {
                 'creation_date': 1467712937000,
                 'number_of_shards': 1, 'number_of_replicas': 0
             }
         }
     )
     # 12 july (week 28)
     self.client.indices.create(
         index='logstash-2016.28',
         body={
             'settings': {
                 'creation_date': 1468317737000,
                 'number_of_shards': 1, 'number_of_replicas': 0
             }
         }
     )
     self.client.cluster.health(wait_for_status='yellow')
     self.write_config(
         self.args['configfile'], testvars.client_config.format(host, port))
     self.write_config(self.args['actionfile'],
         testvars.test_687.format(self.args['repository'], snap_name))
     test = clicktest.CliRunner()
     result = test.invoke(
                 curator.cli,
                 [
                     '--config', self.args['configfile'],
                     self.args['actionfile']
                 ],
                 )
     snapshot = curator.get_snapshot(
                 self.client, self.args['repository'], '_all'
                )
     self.assertEquals(6, len(curator.get_indices(self.client)))