From a25acbbf8301864c8d04d0edc6c6e24cf36fa078 Mon Sep 17 00:00:00 2001 From: Andrey Klychkov Date: Tue, 11 Jun 2019 17:07:03 +0300 Subject: [PATCH] postgresql_idx: self.__exec_sql -> module_utils.postgres.exec_sql (#57684) * postgresql_idx: self.__exec_sql -> module_utils.postgres.exec_sql * postgresql_idx: exec_sql, added a changelog fragment * postgresql_idx: exec_sql, fix the changelog fragment --- ...ql_idx_use_exec_sql_instead_of_methods.yml | 2 ++ .../database/postgresql/postgresql_idx.py | 27 ++++++------------- 2 files changed, 10 insertions(+), 19 deletions(-) create mode 100644 changelogs/fragments/57684-postgresql_idx_use_exec_sql_instead_of_methods.yml diff --git a/changelogs/fragments/57684-postgresql_idx_use_exec_sql_instead_of_methods.yml b/changelogs/fragments/57684-postgresql_idx_use_exec_sql_instead_of_methods.yml new file mode 100644 index 00000000000..6ca9008090b --- /dev/null +++ b/changelogs/fragments/57684-postgresql_idx_use_exec_sql_instead_of_methods.yml @@ -0,0 +1,2 @@ +bugfixes: + - postgresql_idx - remove ``__exec_sql`` method and use ``module_utils.postgres.exec_sql`` instead (https://github.com/ansible/ansible/pull/57684) diff --git a/lib/ansible/modules/database/postgresql/postgresql_idx.py b/lib/ansible/modules/database/postgresql/postgresql_idx.py index 0517761f651..f0100aa5ca1 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_idx.py +++ b/lib/ansible/modules/database/postgresql/postgresql_idx.py @@ -228,7 +228,11 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.database import SQLParseError -from ansible.module_utils.postgres import connect_to_db, postgres_common_argument_spec +from ansible.module_utils.postgres import ( + connect_to_db, + exec_sql, + postgres_common_argument_spec, +) from ansible.module_utils._text import to_native @@ -248,7 +252,6 @@ class Index(object): 2. Add possibility to change tablespace 3. Add list called executed_queries (executed_query should be left too) 4. Use self.module instead of passing arguments to the methods whenever possible - 5. Remove self.__exec_sql and use module_utils.postgres.exec_sql instead Args: module (AnsibleModule) -- object of AnsibleModule class @@ -311,7 +314,7 @@ class Index(object): "ON c.oid = pi.indexrelid " "WHERE i.indexname = '%s'" % self.name) - res = self.__exec_sql(query) + res = exec_sql(self, query, add_to_executed=False) if res: self.exists = True self.info = dict( @@ -377,7 +380,7 @@ class Index(object): self.executed_query = query - if self.__exec_sql(query, ddl=True): + if exec_sql(self, query, ddl=True, add_to_executed=False): return True return False @@ -415,25 +418,11 @@ class Index(object): self.executed_query = query - if self.__exec_sql(query, ddl=True): + if exec_sql(self, query, ddl=True, add_to_executed=False): return True return False - def __exec_sql(self, query, ddl=False): - try: - self.cursor.execute(query) - if not ddl: - res = self.cursor.fetchall() - return res - return True - except SQLParseError as e: - self.module.fail_json(msg=to_native(e)) - except Exception as e: - self.module.fail_json(msg="Cannot execute SQL '%s': %s" % (query, to_native(e))) - - return False - # =========================================== # Module execution.