From 610d015f2db8170d28bb1c215e0998f813890937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 22 Nov 2018 19:59:10 +0100 Subject: [PATCH] hobo-deploy: don't call convert-to-sql to create tables (#28263) --- tests/test_hobo.py | 24 +++++++++++------------- wcs/ctl/check_hobos.py | 15 ++------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/tests/test_hobo.py b/tests/test_hobo.py index 8646e4cc4..b284478d0 100644 --- a/tests/test_hobo.py +++ b/tests/test_hobo.py @@ -425,14 +425,12 @@ def test_configure_postgresql(): pub.set_config(skip_sql=True) service['base_url'] = service['base_url'].strip('/') + pub.initialize_sql = mock.Mock() with mock.patch('psycopg2.connect') as connect: - with mock.patch('subprocess.call') as call: - hobo_cmd.configure_sql(service, pub) - assert connect.call_args_list[0][1] == {'user': 'test', 'database': 'postgres'} - assert connect.call_args_list[1][1] == {'user': 'fred', 'database': 'tests_wcs_wcs_example_net'} - assert call.call_args[0][0][1:] == ['convert-to-sql', - '--dbname', 'tests_wcs_wcs_example_net', - '--user', 'fred', 'wcs.example.net'] + hobo_cmd.configure_sql(service, pub) + assert connect.call_args_list[0][1] == {'user': 'test', 'database': 'postgres'} + assert connect.call_args_list[1][1] == {'user': 'fred', 'database': 'tests_wcs_wcs_example_net'} + assert pub.initialize_sql.call_count == 1 pub.reload_cfg() assert 'createdb-connection-params' in pub.cfg['postgresql'] @@ -442,9 +440,9 @@ def test_configure_postgresql(): pub.cfg['postgresql']['database-template-name'] = 'very_long_'*10 + '%s' with mock.patch('psycopg2.connect') as connect: - with mock.patch('subprocess.call') as call: - hobo_cmd.configure_sql(service, pub) - assert connect.call_args_list[0][1] == {'user': 'test', 'database': 'postgres'} - assert connect.call_args_list[1][1] == {'user': 'fred', - 'database': 'very_long_very_long_very_long_c426_ng_very_long_wcs_example_net'} - assert len(connect.call_args_list[1][1]['database']) == 63 + hobo_cmd.configure_sql(service, pub) + assert connect.call_args_list[0][1] == {'user': 'test', 'database': 'postgres'} + assert connect.call_args_list[1][1] == {'user': 'fred', + 'database': 'very_long_very_long_very_long_c426_ng_very_long_wcs_example_net'} + assert len(connect.call_args_list[1][1]['database']) == 63 + assert pub.initialize_sql.call_count == 2 diff --git a/wcs/ctl/check_hobos.py b/wcs/ctl/check_hobos.py index 1bc914cdb..a8df5c7eb 100644 --- a/wcs/ctl/check_hobos.py +++ b/wcs/ctl/check_hobos.py @@ -528,19 +528,8 @@ class CmdCheckHobos(Command): if not new_database: return - cmd = [sys.argv[0]] - if self.base_options.configfile: - cmd.extend(['-f', self.base_options.configfile]) - cmd.append('convert-to-sql') - for param in ('database', 'user', 'password', 'host', 'port'): - if pub.cfg['postgresql'].get(param): - if param == 'database': - cmd.append('--dbname') - else: - cmd.append('--' + param) - cmd.append(str(pub.cfg['postgresql'].get(param))) - cmd.append(str(self.get_instance_path(service))) - subprocess.call(cmd) + # create tables etc. + pub.initialize_sql() @classmethod def shared_secret(cls, secret1, secret2): -- 2.19.1