From eb8456037416e91a0ca5133880a02ebd1c19e312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 9 Jun 2017 16:06:41 +0200 Subject: [PATCH] sql: keep createdb-connection-params available after deployment (#16794) --- tests/test_hobo.py | 7 +++++++ wcs/ctl/check_hobos.py | 7 +++---- wcs/sql.py | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/test_hobo.py b/tests/test_hobo.py index a1925f4c..26931637 100644 --- a/tests/test_hobo.py +++ b/tests/test_hobo.py @@ -19,6 +19,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': [ @@ -411,3 +412,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'} diff --git a/wcs/ctl/check_hobos.py b/wcs/ctl/check_hobos.py index 9ea3c897..38a7c53b 100644 --- a/wcs/ctl/check_hobos.py +++ b/wcs/ctl/check_hobos.py @@ -447,8 +447,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) @@ -460,12 +459,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) diff --git a/wcs/sql.py b/wcs/sql.py index edbaa512..cb7324e9 100644 --- a/wcs/sql.py +++ b/wcs/sql.py @@ -254,7 +254,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 isinstance(v, basestring): postgresql_cfg[k] = v try: get_publisher().pgconn = psycopg2.connect(**postgresql_cfg) -- 2.11.0