File 0001-Robust-detection-for-postgresql-connection-errors.patch of Package openstack-nova-doc

From d9bbb042f6287061e89c1e2f96b9f70c176c871a Mon Sep 17 00:00:00 2001
From: Dirk Mueller <dirk@dmllr.de>
Date: Fri, 11 Apr 2014 17:06:53 +0200
Subject: [PATCH] Robust detection for postgresql connection errors

In most cases, when the database is failing over to a new node,
engine.dialect.is_disconnected() returns True. However in some
cases it returns False and the exception string is "unknown error".
In those cases we can however query the closed attribute on the
db_connection that is set to True at that point.

Change-Id: I64ef17f451780c622e1cfd257acf74e2e11e8b62
Closes-Bug: #1306668
---
 openstack/common/db/sqlalchemy/session.py   |  4 ++-
 tests/unit/db/sqlalchemy/test_sqlalchemy.py | 44 +++++++++++++++++++++++++++--
 2 files changed, 45 insertions(+), 3 deletions(-)

Index: nova-2014.1.3.dev100.gc04b6ea/nova/openstack/common/db/sqlalchemy/session.py
===================================================================
--- nova-2014.1.3.dev100.gc04b6ea.orig/nova/openstack/common/db/sqlalchemy/session.py
+++ nova-2014.1.3.dev100.gc04b6ea/nova/openstack/common/db/sqlalchemy/session.py
@@ -505,7 +505,10 @@ def _ping_listener(engine, dbapi_conn, c
             ping_sql = 'select 1 from (values (1)) AS t1'
         cursor.execute(ping_sql)
     except Exception as ex:
-        if engine.dialect.is_disconnect(ex, dbapi_conn, cursor):
+        if (engine.dialect.is_disconnect(ex, dbapi_conn, cursor) or
+            ('unknown error' in str(ex).partition('\n')[0] and
+             getattr(dbapi_conn, 'closed', False))):
+
             msg = _LW('Database server has gone away: %s') % ex
             LOG.warning(msg)
 
openSUSE Build Service is sponsored by