Ejemplo n.º 1
1
 def test_create_repository_repo_already_in_results(self):
     client = Mock()
     client.snapshot.get_repository.return_value = {'repo':{'foo':'bar'}}
     with self.assertRaises(SystemExit) as cm:
         curator.create_repository(client, repository="repo", repo_type="fs")
     self.assertEqual(cm.exception.code, 1)
Ejemplo n.º 2
0
 def test_create_repository_repo_already_in_results(self):
     client = Mock()
     client.snapshot.get_repository.return_value = {'repo': {'foo': 'bar'}}
     with self.assertRaises(SystemExit) as cm:
         curator.create_repository(client,
                                   repository="repo",
                                   repo_type="fs")
     self.assertEqual(cm.exception.code, 1)
Ejemplo n.º 3
0
 def test_empty_result_call(self):
     client = Mock()
     client.snapshot.get_repository.return_value = None
     self.assertTrue(
         curator.create_repository(client,
                                   repository="repo",
                                   repo_type="fs"))
Ejemplo n.º 4
0
 def test_create_repository_exception(self):
     client = Mock()
     client.snapshot.get_repository.return_value = {"not_your_repo": {"foo": "bar"}}
     client.snapshot.create_repository.side_effect = elasticsearch.TransportError(
         500, "Error message", {"message": "Error"}
     )
     self.assertRaises(Exception, curator.create_repository(client, repository="repo", repo_type="fs"))
Ejemplo n.º 5
0
def lambda_handler(event, context):

    if not SNAPSHOT_INDEX_FILTERS and not DELETE_INDEX_FILTERS:
        raise ValueError(
            'No value for delete_index_filters or snapshot_index_filters found - aborting'
        )

    if SNAPSHOT_INDEX_FILTERS:
        if not SNAPSHOT_BUCKET or not SNAPSHOT_BUCKET_REGION or not SNAPSHOT_NAME:
            raise ValueError(
                'Some required snapshot parameters have no values - aborting')

    es = elasticsearch_client()

    result = {}

    if SNAPSHOT_INDEX_FILTERS:
        snapshot_name = datetime.now().strftime(SNAPSHOT_NAME)
        indices = filter_indices(es, SNAPSHOT_INDEX_FILTERS)

        if TEST_MODE:
            result['snapshots'] = indices.working_list()
            result['test_mode'] = True
        else:
            if indices.working_list():

                if not curator.repository_exists(es,
                                                 repository=SNAPSHOT_BUCKET):
                    print('Registering snapshot repository in s3://{}'.format(
                        SNAPSHOT_BUCKET))
                    response = curator.create_repository(
                        client=es,
                        repository=SNAPSHOT_BUCKET,
                        repo_type='s3',
                        bucket=SNAPSHOT_BUCKET,
                        region=SNAPSHOT_BUCKET_REGION)
                    print('Response: ' + str(response))

                print('Creating a snapshot of indices')
                snapshot_indices = curator.Snapshot(indices,
                                                    repository=SNAPSHOT_BUCKET,
                                                    name=snapshot_name)
                snapshot_indices.do_action()
                result['snapshot'] = indices.working_list()

    if DELETE_INDEX_FILTERS:
        indices = filter_indices(es, DELETE_INDEX_FILTERS)

        if TEST_MODE:
            result['deleted'] = indices.working_list()
            result['test_mode'] = True
        else:
            if indices.working_list():
                print('Deleting indices')
                delete_indices = curator.DeleteIndices(indices)
                delete_indices.do_action()
                result['deleted'] = indices.working_list()

    return result
Ejemplo n.º 6
0
 def test_repo_not_in_results(self):
     client = Mock()
     client.snapshot.get_repository.return_value = {
         'not_your_repo': {
             'foo': 'bar'
         }
     }
     self.assertTrue(
         curator.create_repository(client,
                                   repository="repo",
                                   repo_type="fs"))
Ejemplo n.º 7
0
 def test_create_repository_exception(self):
     client = Mock()
     client.snapshot.get_repository.return_value = {
         'not_your_repo': {
             'foo': 'bar'
         }
     }
     client.snapshot.create_repository.side_effect = fake_fail
     self.assertRaises(
         Exception,
         curator.create_repository(client,
                                   repository="repo",
                                   repo_type="fs"))
Ejemplo n.º 8
0
 def test_create_repository_exception(self):
     client = Mock()
     client.snapshot.get_repository.return_value = {'not_your_repo':{'foo':'bar'}}
     client.snapshot.create_repository.side_effect = fake_fail
     self.assertRaises(Exception, curator.create_repository(client, repository="repo", repo_type="fs"))
Ejemplo n.º 9
0
 def test_create_repository_repo_not_in_results(self):
     client = Mock()
     client.snapshot.get_repository.return_value = {'not_your_repo':{'foo':'bar'}}
     self.assertTrue(curator.create_repository(client, repository="repo", repo_type="fs"))
Ejemplo n.º 10
0
 def test_create_repository_empty_result_call(self):
     client = Mock()
     client.snapshot.get_repository.return_value = None
     self.assertTrue(curator.create_repository(client, repository="repo", repo_type="fs"))
Ejemplo n.º 11
0
 def test_create_repository_missing_arg(self):
     client = Mock()
     with self.assertRaises(SystemExit) as cm:
         curator.create_repository(client)
     self.assertEqual(cm.exception.code, 1)
Ejemplo n.º 12
0
 def test_create_repository_exception(self):
     client = Mock()
     client.snapshot.get_repository.return_value = {'not_your_repo':{'foo':'bar'}}
     client.snapshot.create_repository.side_effect = elasticsearch.TransportError(500, "Error message", {"message":"Error"})
     self.assertRaises(Exception, curator.create_repository(client, repository="repo", repo_type="fs"))
Ejemplo n.º 13
0
 def test_create_repository_missing_arg(self):
     client = Mock()
     with self.assertRaises(SystemExit) as cm:
         curator.create_repository(client)
     self.assertEqual(cm.exception.code, 1)