~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/canonical/librarian/storage.py

[r=wgrant][bug=840068] Support database aliases with Librarian file
 uploads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
from zope.component import getUtility
13
13
 
 
14
from canonical.config import dbconfig
 
15
from canonical.database.postgresql import ConnectionString
14
16
from canonical.launchpad.webapp.interfaces import (
15
17
        IStoreSelector, MAIN_STORE, DEFAULT_FLAVOR)
16
18
from lp.services.database import write_transaction
123
125
            # If the client told us the name of the database it's using,
124
126
            # check that it matches.
125
127
            if self.databaseName is not None:
 
128
                # Per Bug #840068, there are two methods of getting the
 
129
                # database name (connection string and db
 
130
                # introspection), and they can give different results
 
131
                # due to pgbouncer database aliases. Lets check both,
 
132
                # and succeed if either matches.
 
133
                config_dbname = ConnectionString(
 
134
                    dbconfig.rw_main_master).dbname
 
135
 
126
136
                store = getUtility(IStoreSelector).get(
127
137
                        MAIN_STORE, DEFAULT_FLAVOR)
128
138
                result = store.execute("SELECT current_database()")
129
 
                databaseName = result.get_one()[0]
130
 
                if self.databaseName != databaseName:
131
 
                    raise WrongDatabaseError(self.databaseName, databaseName)
 
139
                real_dbname = result.get_one()[0]
 
140
                if self.databaseName not in (config_dbname, real_dbname):
 
141
                    raise WrongDatabaseError(
 
142
                        self.databaseName, (config_dbname, real_dbname))
132
143
 
133
144
            self.debugLog.append(
134
145
                'database name %r ok' % (self.databaseName, ))