예제 #1
0
    def test_report_state_newly_disconnected(self):
        host = 'foo'
        binary = 'bar'
        topic = 'test'
        service_create = {
            'host': host,
            'binary': binary,
            'topic': topic,
            'report_count': 0,
            'availability_zone': 'nova'
        }
        service_ref = {
            'host': host,
            'binary': binary,
            'topic': topic,
            'report_count': 0,
            'availability_zone': 'nova',
            'id': 1
        }

        service.db.service_get_by_args(mox.IgnoreArg(), host,
                                       binary).AndRaise(exception.NotFound())
        service.db.service_create(mox.IgnoreArg(),
                                  service_create).AndReturn(service_ref)
        service.db.service_get(mox.IgnoreArg(), mox.IgnoreArg()).AndRaise(
            db_exc.DBConnectionError())

        self.mox.ReplayAll()
        serv = service.Service(host, binary, topic,
                               'cinder.tests.test_service.FakeManager')
        serv.start()
        serv.report_state()
        self.assertTrue(serv.model_disconnected)
예제 #2
0
def _raise_if_db_connection_lost(error, engine):
    # NOTE(vsergeyev): Function is_disconnect(e, connection, cursor)
    #                  requires connection and cursor in incoming parameters,
    #                  but we have no possibility to create connection if DB
    #                  is not available, so in such case reconnect fails.
    #                  But is_disconnect() ignores these parameters, so it
    #                  makes sense to pass to function None as placeholder
    #                  instead of connection and cursor.
    if engine.dialect.is_disconnect(error, None, None):
        raise exception.DBConnectionError(error)
예제 #3
0
def _raise_for_remaining_DBAPIError(error, match, engine_name, is_disconnect):
    """Filter for remaining DBAPIErrors.

    Filter for remaining DBAPIErrors and wrap if they represent
    a disconnect error.
    """
    if is_disconnect:
        raise exception.DBConnectionError(error)
    else:
        LOG.exception(_LE('DBAPIError exception wrapped from %s') % error)
        raise exception.DBError(error)
예제 #4
0
def _execute_sql(engine, sql, driver):
    """Initialize connection, execute sql query and close it."""
    try:
        with engine.connect() as conn:
            if driver == 'postgresql':
                conn.connection.set_isolation_level(0)
            for s in sql:
                conn.execute(s)
    except sqlalchemy.exc.OperationalError:
        msg = ('%s does not match database admin '
               'credentials or database does not exist.')
        LOG.exception(msg, engine.url)
        raise exc.DBConnectionError(msg % engine.url)
예제 #5
0
파일: test_api.py 프로젝트: ropex/oslo.db
 def api_raise_deadlock_err_two_decorators(self, *args, **kwargs):
     if self.error_counter > 2:
         return False
     if self.error_counter == 2:
         self.error_counter -= 1
         orig = sqla.exc.DBAPIError(False, False, False)
         orig.args = [2006, 'Test raise operational error']
         raise exception.DBConnectionError(orig)
     if self.error_counter == 1:
         self.error_counter -= 1
         raise exception.DBDeadlock()
     else:
         return True
예제 #6
0
def _raise_operational_errors_directly_filter(operational_error, match,
                                              engine_name, is_disconnect):
    """Filter for all remaining OperationalError classes and apply.

    Filter for all remaining OperationalError classes and apply
    special rules.
    """
    if is_disconnect:
        # operational errors that represent disconnect
        # should be wrapped
        raise exception.DBConnectionError(operational_error)
    else:
        # NOTE(comstud): A lot of code is checking for OperationalError
        # so let's not wrap it for now.
        raise operational_error
예제 #7
0
    def _api_raise(self, *args, **kwargs):
        """Simulate raising a database-has-gone-away error

        This method creates a fake OperationalError with an ID matching
        a valid MySQL "database has gone away" situation. It also decrements
        the error_counter so that we can artificially keep track of
        how many times this function is called by the wrapper. When
        error_counter reaches zero, this function returns True, simulating
        the database becoming available again and the query succeeding.
        """

        if self.error_counter > 0:
            self.error_counter -= 1
            orig = sqla.exc.DBAPIError(False, False, False)
            orig.args = [2006, 'Test raise operational error']
            e = exception.DBConnectionError(orig)
            raise e
        else:
            return True
예제 #8
0
def _is_db_connection_error(operational_error, match, engine_name,
                            is_disconnect):
    """Detect the exception as indicating a recoverable error on connect."""
    raise exception.DBConnectionError(operational_error)
예제 #9
0
파일: test_api.py 프로젝트: ropex/oslo.db
 def api_raise_conn_err_enable_retry(self, *args, **kwargs):
     return self._api_raise(exception.DBConnectionError(), *args, **kwargs)
예제 #10
0
파일: test_api.py 프로젝트: ropex/oslo.db
 def api_raise_conn_err_default(self, *args, **kwargs):
     return self._api_raise(exception.DBConnectionError(), *args, **kwargs)