def get_es_conn(): """Return an Elasticsearch ConnectionContext.""" cm = ConfigurationManager( ConnectionContext.get_required_config(), values_source_list=[environment] ) config = cm.get_config() return ConnectionContext(config)
def get_conn(): # Create a configuration manager that will only check the environment for # configuration and not command line parameters cm = ConfigurationManager(ConnectionContext.get_required_config(), values_source_list=[environment]) config = cm.get_config() return ConnectionContext(config)
def es_conn(): """Create an Elasticsearch ConnectionContext and clean up indices afterwards.""" cm = ConfigurationManager(ConnectionContext.get_required_config(), values_source_list=[environment]) config = cm.get_config() conn = ConnectionContext(config) yield conn for index in conn.get_indices(): conn.delete_index(index)
def handle(self, **options): config = config_from_configman()["elasticsearch"] conn = ConnectionContext(config) indices = conn.delete_expired_indices() if indices: self.stdout.write("Deleting expired crash report indices.") for index in indices: self.stdout.write("Deleting %s" % index) else: self.stdout.write("No expired indices to delete.")
def setup_method(self, method): super().setup_method(method) self.config = self.get_base_config() self.es_context = ConnectionContext(self.config) self.index_client = self.es_context.indices_client() with self.es_context() as conn: self.connection = conn self.es_context.create_index(self.es_context.get_index_template())
def test_connection_context(self): """Instantiate the context and ensure that it quacks like a duck. """ # The context is effectively a connection factory. es_context = ConnectionContext(config=self.config.elasticsearch) # The connection context *must* have specific elements. assert es_context.config assert es_context.connection # There is one operational exception. assert elasticsearch.exceptions.ConnectionError in es_context.operational_exceptions # Currently there are no conditional exceptions. assert len(es_context.conditional_exceptions) == 0
def test_connection_context_client(self): """Instantiate the client and ensure that it quacks like a duck. """ es_context = ConnectionContext(config=self.config.elasticsearch) client = es_context.connection() # The client *must* have specific elements. ok_(client._connection) ok_(client.close) ok_(client.commit) ok_(client.config) ok_(client.rollback) # The underlying ES interface is exposed by _connection. This API is # exhaustive and well outside of the scope of this test suite; in the # interest of safety however, we'll check one here. ok_(client._connection.index)
def setup_method(self): super().setup_method() self.config = self.get_base_config() self.es_context = ConnectionContext(self.config) self.crashstorage = ESCrashStorage( config=self.get_tuned_config(ESCrashStorage)) self.index_client = self.es_context.indices_client() self.conn = self.es_context.connection() # Delete everything there first for index_name in self.es_context.get_indices(): print(f"setup: delete test index: {index_name}") self.es_context.delete_index(index_name) to_create = [ self.es_context.get_index_for_date(utc_now()), self.es_context.get_index_for_date(utc_now() - timedelta(days=7)), ] for index_name in to_create: print(f"setup: creating index: {index_name}") self.es_context.create_index(index_name)
def es_conn(): """Create an Elasticsearch ConnectionContext and clean up indices afterwards.""" conn = ConnectionContext(config_from_configman()["elasticsearch"]) yield conn for index in conn.get_indices(): conn.delete_index(index)