예제 #1
0
 def test_curator_will_create_and_delete_multiple_snapshots(self):
     self.create_indices(10)
     self.create_repository()
     curator.command_loop(self.client, command='snapshot', older_than=3, delete_older_than=None, most_recent=None, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     self.assertEqual(7, len(result['snapshots']))
     curator.command_loop(self.client, command='snapshot', delete_older_than=6, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     self.assertEqual(3, len(result['snapshots']))
예제 #2
0
 def test_curator_will_manage_hourly_snapshots(self):
     self.create_indices(10, 'hours')
     self.create_repository()
     curator.command_loop(self.client, time_unit='hours', command='snapshot', older_than=3, delete_older_than=None, most_recent=None, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     self.assertEqual(7, len(result['snapshots']))
     curator.command_loop(self.client, time_unit='hours', command='snapshot', delete_older_than=6, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     self.assertEqual(3, len(result['snapshots']))
예제 #3
0
 def test_curator_will_snap_latest_n_indices(self):
     self.create_indices(10)
     self.create_repository()
     curator.snapshot(self.client, most_recent=3, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     snapped_indices = result['snapshots'][0]['indices']
     indices = curator.get_indices(self.client)
     self.assertEqual(snapped_indices, indices[-3:])
예제 #4
0
 def test_curator_will_ignore_wrong_timestamp(self):
     self.create_indices(10)
     self.create_indices(10, 'hours')
     self.create_repository()
     curator.snapshot(self.client, older_than=1, timestring='%Y.%m.%d', repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     snapped_indices = result['snapshots'][0]['indices']
     self.assertEqual(9, len(snapped_indices))
예제 #5
0
 def test_curator_will_create_multiple_snapshots(self):
     self.create_indices(10)
     self.create_repository()
     for i in range(3,0,-1):
         curator.snapshot(self.client, older_than=i, timestring='%Y.%m.%d', repository=self.args['repository'])
         time.sleep(1)
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     self.assertEqual(3, len(result['snapshots']))
예제 #6
0
 def test_curator_will_snap_latest_n_indices(self):
     self.create_indices(10)
     self.create_repository()
     curator.command_loop(self.client, command='snapshot', delete_older_than=None, most_recent=3, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     self.assertEqual(3, len(result['snapshots']))
     snapshots = [x['indices'][0] for x in result['snapshots']]
     indices = curator.get_indices(self.client)
     self.assertEqual(snapshots, indices[-3:])
예제 #7
0
 def test_curator_will_create_and_delete_multiple_snapshots(self):
     self.create_indices(10)
     self.create_repository()
     curator.command_loop(self.client,
                          command='snapshot',
                          older_than=3,
                          delete_older_than=None,
                          most_recent=None,
                          repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     self.assertEqual(7, len(result['snapshots']))
     curator.command_loop(self.client,
                          command='snapshot',
                          delete_older_than=6,
                          repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     self.assertEqual(3, len(result['snapshots']))
예제 #8
0
 def test_curator_will_snap_all_indices(self):
     self.create_indices(10)
     self.create_repository()
     curator.snapshot(self.client, all_indices=True, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     snapped_indices = result['snapshots'][0]['indices']
     snapped_indices.sort()
     indices = curator.get_indices(self.client)
     indices.sort()
     self.assertEqual(snapped_indices, indices)
예제 #9
0
 def test_curator_will_snap_latest_n_indices(self):
     self.create_indices(10)
     self.create_repository()
     curator.snapshot(self.client,
                      most_recent=3,
                      repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     snapped_indices = result['snapshots'][0]['indices']
     indices = curator.get_indices(self.client)
     self.assertEqual(snapped_indices, indices[-3:])
예제 #10
0
 def test_snapshot_will_not_be_created_twice(self):
     name = 'l-2014.05.22'
     self.create_repository()
     self.create_index(name)
     self.client.create(index=name, doc_type='log', body={'message':'TEST DOCUMENT'})
     curator.create_snapshot(self.client, snapshot_name=name, indices=name, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], name)
     self.assertEqual(name, result['snapshots'][0]['snapshot'])
     self.assertEqual('SUCCESS', result['snapshots'][0]['state'])
     self.client.create(index=name, doc_type='log', body={'message':'TEST DOCUMENT TWO'})
     # create_snapshot will return True if it skipped the creation...
     self.assertTrue(curator.create_snapshot(self.client, snapshot_name=name, indices=name, repository=self.args['repository']))
예제 #11
0
 def test_curator_will_manage_hourly_snapshots(self):
     self.create_indices(10, 'hours')
     self.create_repository()
     curator.command_loop(self.client,
                          time_unit='hours',
                          command='snapshot',
                          older_than=3,
                          delete_older_than=None,
                          most_recent=None,
                          repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     self.assertEqual(7, len(result['snapshots']))
     curator.command_loop(self.client,
                          time_unit='hours',
                          command='snapshot',
                          delete_older_than=6,
                          repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     self.assertEqual(3, len(result['snapshots']))
예제 #12
0
 def test_snapshot_will_be_created_and_deleted(self):
     name = 'l-2014.05.22'
     self.create_repository()
     self.create_index(name)
     self.client.create(index=name, doc_type='log', body={'message':'TEST DOCUMENT'})
     curator.create_snapshot(self.client, snapshot_name=name, indices=name, repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], name)
     self.assertEqual(name, result['snapshots'][0]['snapshot'])
     self.assertEqual('SUCCESS', result['snapshots'][0]['state'])
     curator.delete_snapshot(self.client, name, repository=self.args['repository'])
     snaps = self.client.snapshot.get(repository=self.args['repository'], snapshot='_all')
     self.assertEqual({"snapshots":[]}, snaps)
예제 #13
0
 def test_curator_will_ignore_wrong_timestamp(self):
     self.create_indices(10)
     self.create_indices(10, 'hours')
     self.create_repository()
     curator.snapshot(self.client,
                      older_than=1,
                      timestring='%Y.%m.%d',
                      repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     snapped_indices = result['snapshots'][0]['indices']
     self.assertEqual(9, len(snapped_indices))
예제 #14
0
 def test_curator_will_match_snapshot_prefix(self):
     self.create_indices(10)
     self.create_repository()
     curator.snapshot(self.client, most_recent=3, snapshot_prefix='foo-', repository=self.args['repository'])
     curator.snapshot(self.client, most_recent=6, snapshot_prefix='bar-', repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'], '_all')
     for snap in result['snapshots']:
         if snap['snapshot'].startswith("foo-"):
             foo_indices = snap['indices']
         elif snap['snapshot'].startswith("bar-"):
             bar_indices = snap['indices']
     self.assertEqual(3, len(foo_indices))
     self.assertEqual(6, len(bar_indices))
예제 #15
0
 def test_curator_will_snap_all_indices(self):
     self.create_indices(10)
     self.create_repository()
     curator.snapshot(self.client,
                      all_indices=True,
                      repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     snapped_indices = result['snapshots'][0]['indices']
     snapped_indices.sort()
     indices = curator.get_indices(self.client)
     indices.sort()
     self.assertEqual(snapped_indices, indices)
예제 #16
0
 def test_curator_will_snap_latest_n_indices(self):
     self.create_indices(10)
     self.create_repository()
     curator.command_loop(self.client,
                          command='snapshot',
                          delete_older_than=None,
                          most_recent=3,
                          repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     self.assertEqual(3, len(result['snapshots']))
     snapshots = [x['indices'][0] for x in result['snapshots']]
     indices = curator.get_indices(self.client)
     self.assertEqual(snapshots, indices[-3:])
예제 #17
0
 def test_curator_will_create_multiple_snapshots(self):
     self.create_indices(10)
     self.create_repository()
     for i in range(3, 0, -1):
         curator.snapshot(self.client,
                          older_than=i,
                          timestring='%Y.%m.%d',
                          repository=self.args['repository'])
         time.sleep(1)
     # Test two ways of getting results to ensure both return properly
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     result2 = curator.get_object_list(self.client,
                                       data_type='snapshot',
                                       repository=self.args['repository'])
     self.assertEqual(3, len(result['snapshots']))
     self.assertEqual(3, len(result2))
예제 #18
0
 def test_curator_will_match_snapshot_prefix(self):
     self.create_indices(10)
     self.create_repository()
     curator.snapshot(self.client,
                      most_recent=3,
                      snapshot_prefix='foo-',
                      repository=self.args['repository'])
     curator.snapshot(self.client,
                      most_recent=6,
                      snapshot_prefix='bar-',
                      repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   '_all')
     for snap in result['snapshots']:
         if snap['snapshot'].startswith("foo-"):
             foo_indices = snap['indices']
         elif snap['snapshot'].startswith("bar-"):
             bar_indices = snap['indices']
     self.assertEqual(3, len(foo_indices))
     self.assertEqual(6, len(bar_indices))
예제 #19
0
 def test_snapshot_will_be_created_and_deleted(self):
     name = 'l-2014.05.22'
     self.create_repository()
     self.create_index(name)
     self.client.create(index=name,
                        doc_type='log',
                        body={'message': 'TEST DOCUMENT'})
     curator._create_snapshot(self.client,
                              name,
                              prefix='l-',
                              repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   name)
     self.assertEqual(name, result['snapshots'][0]['snapshot'])
     self.assertEqual('SUCCESS', result['snapshots'][0]['state'])
     curator._delete_snapshot(self.client,
                              name,
                              repository=self.args['repository'])
     snaps = self.client.snapshot.get(repository=self.args['repository'],
                                      snapshot='_all')
     self.assertEqual({"snapshots": []}, snaps)
예제 #20
0
 def test_snapshot_will_not_be_created_twice(self):
     name = 'l-2014.05.22'
     self.create_repository()
     self.create_index(name)
     self.client.create(index=name,
                        doc_type='log',
                        body={'message': 'TEST DOCUMENT'})
     curator._create_snapshot(self.client,
                              name,
                              prefix='l-',
                              repository=self.args['repository'])
     result = curator.get_snapshot(self.client, self.args['repository'],
                                   name)
     self.assertEqual(name, result['snapshots'][0]['snapshot'])
     self.assertEqual('SUCCESS', result['snapshots'][0]['state'])
     self.client.create(index=name,
                        doc_type='log',
                        body={'message': 'TEST DOCUMENT TWO'})
     # _create_snapshot will return True if it skipped the creation...
     self.assertTrue(
         curator._create_snapshot(self.client,
                                  name,
                                  prefix='l-',
                                  repository=self.args['repository']))