Ejemplo n.º 1
0
def get_db():
    opts = get_options()
    db_engine = opts.pop('db')
    if db_engine == 'elasticsearch':
        logging.debug(
            _i18n._LI('ElasticSearch config options: %s') % str(opts))
        db = elastic.ElasticSearchEngine(**opts)
    else:
        raise Exception(
            _i18n._('Database Engine %s not supported') % db_engine)
    return db
Ejemplo n.º 2
0
def get_db():
    db_engine = CONF.storage.db
    if db_engine == 'simpledict':
        logging.info('Storage backend: simple dictionary')
        db = simpledict.SimpleDictStorageEngine()
    elif db_engine == 'elasticsearch':
        endpoint = CONF.storage.endpoint
        logging.info('Storage backend: Elasticsearch at {0}'.format(endpoint))
        db = elastic.ElasticSearchEngine(endpoint)
    else:
        raise Exception('Database Engine {0} not supported'.format(db_engine))
    return db
Ejemplo n.º 3
0
def _get_elastic_opts(backend=None):
    """Return Opts for elasticsearch driver"""
    if not backend:
        backend = "elasticsearch"
    es = elastic.ElasticSearchEngine(backend=backend)
    return {backend: es.get_opts()}
Ejemplo n.º 4
0
 def test_index_backup_raise_when_es_search_raises(self, monkeypatch):
     self.patch_logging(monkeypatch)
     monkeypatch.setattr(elasticsearch, 'Elasticsearch', FakeElasticsearch_search_raise)
     engine = elastic.ElasticSearchEngine('host')
     pytest.raises(StorageEngineError, engine.add_backup, fake_data_0_user_id,
                   fake_data_0_user_name, fake_data_0_backup_metadata)
Ejemplo n.º 5
0
 def test_index_backup_raise_when_data_exists(self, monkeypatch):
     self.patch_logging(monkeypatch)
     monkeypatch.setattr(elasticsearch, 'Elasticsearch', FakeElasticsearch_hit)
     engine = elastic.ElasticSearchEngine('host')
     pytest.raises(DocumentExists, engine.add_backup, fake_data_0_user_id,
                   fake_data_0_user_name, fake_data_0_backup_metadata)
Ejemplo n.º 6
0
 def test_index_backup_success(self, monkeypatch):
     self.patch_logging(monkeypatch)
     monkeypatch.setattr(elasticsearch, 'Elasticsearch', FakeElasticsearch_insert_ok)
     engine = elastic.ElasticSearchEngine('host')
     res = engine.add_backup(fake_data_0_user_id, fake_data_0_user_name, fake_data_0_backup_metadata)
     assert (res == fake_data_0_backup_id)
Ejemplo n.º 7
0
 def test_get_backup_list_return_ok(self, monkeypatch):
     self.patch_logging(monkeypatch)
     monkeypatch.setattr(elasticsearch, 'Elasticsearch', FakeElasticsearch_hit)
     engine = elastic.ElasticSearchEngine('host')
     res = engine.get_backup_list(fake_data_0_user_id)
     assert (res == [fake_data_0_backup_metadata, ])
Ejemplo n.º 8
0
 def test_get_backup_raises_when_query_has_no_hits(self, monkeypatch):
     self.patch_logging(monkeypatch)
     monkeypatch.setattr(elasticsearch, 'Elasticsearch', FakeElasticsearch_miss)
     engine = elastic.ElasticSearchEngine('host')
     pytest.raises(ObjectNotFound, engine.get_backup, fake_data_0_user_id, fake_data_0_backup_id)
Ejemplo n.º 9
0
 def test_delete_backup_ok(self, monkeypatch):
     self.patch_logging(monkeypatch)
     monkeypatch.setattr(elasticsearch, 'Elasticsearch', FakeElasticsearch_hit)
     engine = elastic.ElasticSearchEngine('host')
     res = engine.delete_backup(fake_data_0_user_id, fake_data_0_backup_id)
     assert (res == fake_data_0_backup_id)
Ejemplo n.º 10
0
 def test_index_backup_raise_when_data_is_malformed(self, monkeypatch):
     self.patch_logging(monkeypatch)
     monkeypatch.setattr(elasticsearch, 'Elasticsearch', FakeElasticsearch_insert_ok)
     engine = elastic.ElasticSearchEngine('host')
     pytest.raises(BadDataFormat, engine.add_backup, fake_data_0_user_id,
                   fake_data_0_user_name, fake_malformed_data_0_backup_metadata)