From 95929fb79f1ea55986532e463f9eb9b3a8d8a463 Mon Sep 17 00:00:00 2001 From: Michael Scherer Date: Sun, 16 Oct 2016 16:57:57 +0200 Subject: [PATCH] Make postgresql module in extras compile on py3 --- .../extras/database/postgresql/postgresql_ext.py | 10 +++++++--- .../extras/database/postgresql/postgresql_lang.py | 4 +++- .../test/utils/shippable/sanity-skip-python3.txt | 2 -- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/extras/database/postgresql/postgresql_ext.py b/lib/ansible/modules/extras/database/postgresql/postgresql_ext.py index 425d6acc92..340411dc22 100644 --- a/lib/ansible/modules/extras/database/postgresql/postgresql_ext.py +++ b/lib/ansible/modules/extras/database/postgresql/postgresql_ext.py @@ -159,7 +159,8 @@ def main(): .ISOLATION_LEVEL_AUTOCOMMIT) cursor = db_connection.cursor( cursor_factory=psycopg2.extras.DictCursor) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="unable to connect to database: %s" % e) try: @@ -174,14 +175,17 @@ def main(): elif state == "present": changed = ext_create(cursor, ext) - except NotSupportedError, e: + except NotSupportedError: + e = get_exception() module.fail_json(msg=str(e)) - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="Database query failed: %s" % e) module.exit_json(changed=changed, db=db, ext=ext) # import module snippets from ansible.module_utils.basic import * +from ansible.module_utils.pycompat24 import get_exception main() diff --git a/lib/ansible/modules/extras/database/postgresql/postgresql_lang.py b/lib/ansible/modules/extras/database/postgresql/postgresql_lang.py index 52cfc0c50a..f80d5b522b 100644 --- a/lib/ansible/modules/extras/database/postgresql/postgresql_lang.py +++ b/lib/ansible/modules/extras/database/postgresql/postgresql_lang.py @@ -222,7 +222,8 @@ def main(): try: db_connection = psycopg2.connect(**kw) cursor = db_connection.cursor() - except Exception, e: + except Exception: + e = get_exception() module.fail_json(msg="unable to connect to database: %s" % e) changed = False lang_dropped = False @@ -267,4 +268,5 @@ def main(): # import module snippets from ansible.module_utils.basic import * +from ansible.module_utils.pycompat24 import get_exception main() diff --git a/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt b/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt index 768b8de61d..0738f1e5f8 100644 --- a/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt +++ b/lib/ansible/modules/extras/test/utils/shippable/sanity-skip-python3.txt @@ -40,8 +40,6 @@ /clustering/consul_kv.py /clustering/consul_session.py /database/mysql/mysql_replication.py -/database/postgresql/postgresql_ext.py -/database/postgresql/postgresql_lang.py /database/vertica/vertica_configuration.py /database/vertica/vertica_facts.py /database/vertica/vertica_role.py