mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-02 15:21:25 -07:00
postgresql_ext: Update param handling, fix doc formatting, added: CI tests, examples, a return value (#54027)
* postgresql_ext: instead_of_3196, initial * postgresql_ext: fixes * postgresql_ext: fixes
This commit is contained in:
parent
ab47142fa0
commit
76f1f96163
3 changed files with 352 additions and 71 deletions
|
@ -784,13 +784,23 @@
|
|||
# Test postgresql_privs
|
||||
- include: postgresql_privs.yml
|
||||
|
||||
# Test postgresql_facts module:
|
||||
# Test postgresql_facts module
|
||||
- include: postgresql_facts.yml
|
||||
|
||||
# Test default_privs with target_role
|
||||
- include: test_target_role.yml
|
||||
when: postgres_version_resp.stdout is version('9.1', '>=')
|
||||
|
||||
# Test postgresql_ext.
|
||||
# pg_extension system view is available from PG 9.1.
|
||||
# The tests are restricted by Fedora because there will be errors related with
|
||||
# attempts to change the environment during postgis installation or
|
||||
# missing postgis package in repositories.
|
||||
# Anyway, these tests completely depend on Postgres version,
|
||||
# not specific distributions.
|
||||
- include: postgresql_ext.yml
|
||||
when: postgres_version_resp.stdout is version('9.1', '>=') and ansible_distribution == 'Fedora'
|
||||
|
||||
# dump/restore tests per format
|
||||
# ============================================================
|
||||
- include: state_dump_restore.yml test_fixture=user file=dbdata.sql
|
||||
|
|
227
test/integration/targets/postgresql/tasks/postgresql_ext.yml
Normal file
227
test/integration/targets/postgresql/tasks/postgresql_ext.yml
Normal file
|
@ -0,0 +1,227 @@
|
|||
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Create test schema:
|
||||
- name: postgresql_ext - install postgis
|
||||
package: name=postgis state=present
|
||||
when: ansible_os_family != "Windows"
|
||||
|
||||
- name: postgresql_ext - install postgis RedHat
|
||||
win_package: name=postgis state=present
|
||||
when: ansible_os_family == "Windows"
|
||||
|
||||
- name: postgresql_ext - create schema schema1
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_schema:
|
||||
database: postgres
|
||||
name: schema1
|
||||
state: present
|
||||
|
||||
- name: postgresql_ext - drop extension if exists
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_query:
|
||||
db: postgres
|
||||
query: "DROP EXTENSION IF EXISTS postgis"
|
||||
ignore_errors: yes
|
||||
|
||||
##############
|
||||
# Start tests:
|
||||
|
||||
# Create extension in check_mode, also check aliases for db and port params:
|
||||
- name: postgresql_ext - create extension postgis in check_mode
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_ext:
|
||||
login_db: postgres
|
||||
login_port: 5432
|
||||
name: postgis
|
||||
check_mode: yes
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.queries == []
|
||||
|
||||
# Check that extension doesn't exist after the previous step, rowcount must be 0
|
||||
- name: postgresql_ext - check that extension doesn't exist after the previous step
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_query:
|
||||
db: postgres
|
||||
query: "SELECT extname FROM pg_extension WHERE extname='postgis'"
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount == 0
|
||||
|
||||
# Create extension postgis, also check aliases for db and port params
|
||||
- name: postgresql_ext - create extension postgis
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_ext:
|
||||
login_db: postgres
|
||||
login_port: 5432
|
||||
name: postgis
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.queries == ['CREATE EXTENSION "postgis"']
|
||||
|
||||
# Check that extension exists after the previous step, rowcount must be 1
|
||||
- name: postgresql_ext - check that extension exists after the previous step
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_query:
|
||||
db: postgres
|
||||
query: "SELECT extname FROM pg_extension WHERE extname='postgis'"
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount == 1
|
||||
|
||||
# Drop extension postgis:
|
||||
- name: postgresql_ext - drop extension postgis
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_ext:
|
||||
db: postgres
|
||||
name: postgis
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.queries == ['DROP EXTENSION "postgis"']
|
||||
|
||||
# Check that extension doesn't exist after the previous step, rowcount must be 0
|
||||
- name: postgresql_ext - check that extension doesn't exist after the previous step
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_query:
|
||||
db: postgres
|
||||
query: "SELECT extname FROM pg_extension WHERE extname='postgis'"
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount == 0
|
||||
|
||||
# Create extension postgis in particular schema
|
||||
- name: postgresql_ext - create extension postgis
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_ext:
|
||||
db: postgres
|
||||
name: postgis
|
||||
schema: schema1
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.queries == ['CREATE EXTENSION "postgis" WITH SCHEMA "schema1"']
|
||||
|
||||
# Check that extension exists after the previous step, rowcount must be 1
|
||||
- name: postgresql_ext - check that extension exists after the previous step
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_query:
|
||||
db: postgres
|
||||
query: |
|
||||
SELECT extname FROM pg_extension AS e LEFT JOIN pg_catalog.pg_namespace AS n
|
||||
ON n.oid = e.extnamespace WHERE e.extname='postgis' AND n.nspname='schema1'
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount == 1
|
||||
|
||||
#
|
||||
# Check cascade option. For creation it's available from PG 9.6.
|
||||
# I couldn't check it for two or more extension in one time
|
||||
# because most of the common extensions are available in postgresql-contrib package
|
||||
# that tries to change the default python interpreter and fails during tests respectively.
|
||||
# Anyway, that's enough to be sure that the proper SQL was exequted.
|
||||
#
|
||||
|
||||
# Drop extension cascade
|
||||
- name: postgresql_ext - drop extension postgis cascade
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_ext:
|
||||
db: postgres
|
||||
name: postgis
|
||||
state: absent
|
||||
cascade: yes
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.queries == ['DROP EXTENSION "postgis" CASCADE']
|
||||
|
||||
# Check that extension doesn't exist after the previous step, rowcount must be 0
|
||||
- name: postgresql_ext - check that extension doesn't exist after the previous step
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_query:
|
||||
db: postgres
|
||||
query: "SELECT extname FROM pg_extension WHERE extname='postgis'"
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount == 0
|
||||
|
||||
# Create extension postgis cascade.
|
||||
# CASCADE for CREATE command is available from PG 9.6
|
||||
- name: postgresql_ext - create extension postgis cascade
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_ext:
|
||||
db: postgres
|
||||
name: postgis
|
||||
cascade: yes
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
when: postgres_version_resp.stdout is version('9.6', '<=')
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.changed == true
|
||||
- result.queries == ['CREATE EXTENSION "postgis" CASCADE"']
|
||||
when: postgres_version_resp.stdout is version('9.6', '<=')
|
||||
|
||||
# Check that extension exists after the previous step, rowcount must be 1
|
||||
- name: postgresql_ext - check that extension exists after the previous step
|
||||
become_user: "{{ pg_user }}"
|
||||
become: yes
|
||||
postgresql_query:
|
||||
db: postgres
|
||||
query: "SELECT extname FROM pg_extension WHERE extname='postgis'"
|
||||
ignore_errors: yes
|
||||
register: result
|
||||
when: postgres_version_resp.stdout is version('9.6', '<=')
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.rowcount == 1
|
||||
when: postgres_version_resp.stdout is version('9.6', '<=')
|
Loading…
Add table
Add a link
Reference in a new issue