Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/odbc/tasks/main.yml

raw
1 ---
2 ####################################################################
3 # WARNING: These are designed specifically for Ansible tests #
4 # and should not be used as examples of how to write Ansible roles #
5 ####################################################################
6
7 # Copyright (c) Ansible Project
8 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
9 # SPDX-License-Identifier: GPL-3.0-or-later
10
11 - debug:
12 msg: "{{ ansible_facts.os_family }} / {{ ansible_facts.distribution }} / {{ ansible_facts.distribution_major_version }}"
13
14 - when:
15 - ansible_facts.distribution != 'Debian' or ansible_facts.distribution_major_version != '13' # TODO fix tests for Debian 13 (Trixie)!
16 block:
17
18 #
19 # Test for proper failures without pyodbc
20 #
21 # Some of the docker images already have pyodbc installed on it
22 - include_tasks: no_pyodbc.yml
23 when: ansible_facts.os_family != 'FreeBSD' and ansible_facts.os_family != 'Suse' and ansible_facts.os_family != 'Debian'
24
25 #
26 # Install PostgreSQL ODBC driver from AUR on Arch Linux
27 #
28 - include_tasks: install_arch_odbc.yml
29 when: ansible_facts.os_family == 'Archlinux'
30
31 #
32 # Get pyodbc installed
33 #
34 - include_tasks: install_pyodbc.yml
35
36 #
37 # Test missing parameters & invalid DSN
38 #
39 - include_tasks: negative_tests.yml
40
41 #
42 # Setup DSN per env
43 #
44 - name: Changing DSN for Suse
45 set_fact:
46 dsn: "DRIVER={PSQL};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
47 when: ansible_facts.os_family == 'Suse' or ansible_facts.os_family == 'Alpine'
48
49 - name: Changing DSN for Alpine
50 set_fact:
51 dsn: "DRIVER={/usr/lib/psqlodbcw.so};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
52 when: ansible_facts.os_family == 'Alpine'
53
54 - name: Changing DSN for Debian
55 set_fact:
56 dsn: "DRIVER={PostgreSQL Unicode};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
57 when: ansible_facts.os_family == 'Debian'
58
59 - name: Changing DSN for Arch Linux
60 set_fact:
61 dsn: "DRIVER={/usr/lib/psqlodbcw.so};Server=localhost;Port=5432;Database=postgres;Uid={{ my_user }};Pwd={{ my_pass_decrypted }};UseUnicode=True"
62 when: ansible_facts.os_family == 'Archlinux'
63
64 #
65 # Name setup database
66 #
67 - name: Create a user to run the tests with
68 shell: echo "CREATE USER {{ my_user }} SUPERUSER PASSWORD '{{ my_pass }}'" | psql postgres
69 become_user: "{{ pg_user }}"
70 become: true
71
72 - name: Create a table
73 odbc:
74 dsn: "{{ dsn }}"
75 query: |
76 CREATE TABLE films (
77 code char(5) CONSTRAINT firstkey PRIMARY KEY,
78 title varchar(40) NOT NULL,
79 did integer NOT NULL,
80 date_prod date,
81 kind varchar(10),
82 len interval hour to minute
83 );
84 become_user: "{{ pg_user }}"
85 become: true
86 register: results
87
88 - assert:
89 that:
90 - results is changed
91
92 #
93 # Insert records
94 #
95 - name: Insert a record without params
96 odbc:
97 dsn: "{{ dsn }}"
98 query: "INSERT INTO films (code, title, did, date_prod, kind, len) VALUES ('asdfg', 'My First Movie', 1, '2019-01-12', 'SyFi', '02:00')"
99 become_user: "{{ pg_user }}"
100 become: true
101 register: results
102
103 - assert:
104 that:
105 - results is changed
106
107 - name: Insert a record with params
108 odbc:
109 dsn: "{{ dsn }}"
110 query: "INSERT INTO films (code, title, did, date_prod, kind, len) VALUES (?, ?, ?, ?, ?, ?)"
111 params:
112 - 'qwert'
113 - 'My Second Movie'
114 - 2
115 - '2019-01-12'
116 - 'Comedy'
117 - '01:30'
118 become_user: "{{ pg_user }}"
119 become: true
120 register: results
121
122 - assert:
123 that:
124 - results is changed
125 - results['row_count'] == -1
126 - results['results'] == []
127 - results['description'] == []
128
129 #
130 # Select data
131 #
132 - name: Perform select single row without params (do not coherse changed)
133 odbc:
134 dsn: "{{ dsn }}"
135 query: "SELECT * FROM films WHERE code='asdfg'"
136 register: results
137
138 - assert:
139 that:
140 - results is changed
141 - results is successful
142 - results.row_count == 1
143
144 - name: Perform select multiple rows with params (coherse changed)
145 odbc:
146 dsn: "{{ dsn }}"
147 query: 'SELECT * FROM films WHERE code=? or code=?'
148 params:
149 - 'asdfg'
150 - 'qwert'
151 register: results
152 changed_when: false
153
154 - assert:
155 that:
156 - results is not changed
157 - results is successful
158 - results.row_count == 2
159
160 - name: Drop the table
161 odbc:
162 dsn: "{{ dsn }}"
163 query: "DROP TABLE films"
164 register: results
165
166 - assert:
167 that:
168 - results is successful
169 - results is changed
170 - results['row_count'] == -1
171 - results['results'] == []
172 - results['description'] == []