sql: keep createdb-connection-params available after deployment (#16794)
This commit is contained in:
parent
135382bb30
commit
9629a27027
|
@ -18,6 +18,7 @@ from quixote import cleanup
|
|||
from wcs.ctl.check_hobos import CmdCheckHobos
|
||||
from wcs.publisher import WcsPublisher
|
||||
from wcs import fields
|
||||
from wcs import sql
|
||||
|
||||
HOBO_JSON = {
|
||||
'services': [
|
||||
|
@ -408,3 +409,9 @@ def test_configure_postgresql():
|
|||
assert call.call_args[0][0][1:] == ['convert-to-sql',
|
||||
'--dbname', 'tests_wcs_wcs_example_net',
|
||||
'--user', 'fred', 'wcs.example.net']
|
||||
|
||||
pub.reload_cfg()
|
||||
assert 'createdb-connection-params' in pub.cfg['postgresql']
|
||||
with mock.patch('psycopg2.connect') as connect:
|
||||
sql.get_connection(new=True)
|
||||
assert connect.call_args_list[0][1] == {'user': 'fred', 'database': 'tests_wcs_wcs_example_net'}
|
||||
|
|
|
@ -399,14 +399,12 @@ class CmdCheckHobos(Command):
|
|||
if not domain_table_name in database_name:
|
||||
database_name = '%s_%s' % (database_name.split('_')[0], domain_table_name)
|
||||
|
||||
postgresql_cfg = {}
|
||||
for k, v in pub.cfg['postgresql'].items():
|
||||
if v and isinstance(v, basestring):
|
||||
postgresql_cfg[k] = v
|
||||
|
||||
createdb_cfg = pub.cfg['postgresql'].get('createdb-connection-params')
|
||||
if not createdb_cfg:
|
||||
createdb_cfg = postgresql_cfg
|
||||
createdb_cfg = {}
|
||||
for k, v in pub.cfg['postgresql'].items():
|
||||
if v and isinstance(v, basestring):
|
||||
createdb_cfg[k] = v
|
||||
|
||||
try:
|
||||
pgconn = psycopg2.connect(**createdb_cfg)
|
||||
|
@ -430,8 +428,7 @@ class CmdCheckHobos(Command):
|
|||
else:
|
||||
cur.close()
|
||||
|
||||
postgresql_cfg['database'] = database_name
|
||||
pub.cfg['postgresql'] = postgresql_cfg
|
||||
pub.cfg['postgresql']['database'] = database_name
|
||||
pub.write_cfg()
|
||||
pub.set_config(skip_sql=False)
|
||||
|
||||
|
@ -443,12 +440,12 @@ class CmdCheckHobos(Command):
|
|||
cmd.extend(['-f', self.base_options.configfile])
|
||||
cmd.append('convert-to-sql')
|
||||
for param in ('database', 'user', 'password', 'host', 'port'):
|
||||
if postgresql_cfg.get(param):
|
||||
if pub.cfg['postgresql'].get(param):
|
||||
if param == 'database':
|
||||
cmd.append('--dbname')
|
||||
else:
|
||||
cmd.append('--' + param)
|
||||
cmd.append(str(postgresql_cfg.get(param)))
|
||||
cmd.append(str(pub.cfg['postgresql'].get(param)))
|
||||
cmd.append(str(self.get_instance_path(service)))
|
||||
subprocess.call(cmd)
|
||||
|
||||
|
|
|
@ -241,7 +241,7 @@ def get_connection(new=False):
|
|||
if not hasattr(get_publisher(), 'pgconn') or get_publisher().pgconn is None:
|
||||
postgresql_cfg = {}
|
||||
for k, v in get_cfg('postgresql', {}).items():
|
||||
if v:
|
||||
if v and isinstance(v, basestring):
|
||||
postgresql_cfg[k] = v
|
||||
try:
|
||||
get_publisher().pgconn = psycopg2.connect(**postgresql_cfg)
|
||||
|
|
Loading…
Reference in New Issue