示例#1
0
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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
 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.")
示例#5
0
    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())
示例#6
0
    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)
示例#8
0
    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)
示例#9
0
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)