generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mysql_info - add table count to the databases returned values (#691)
* Add tables count per database * Add integrations tests * Deduplicate tests between main and new task file
- Loading branch information
1 parent
d613fa1
commit 9057637
Showing
4 changed files
with
207 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
minor_changes: | ||
- mysql_info - adds the count of tables for each database to the returned values. It is possible to exclude this new field using the ``db_table_count`` exclusion filter. (https://github.com/ansible-collections/community.mysql/pull/691) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
tests/integration/targets/test_mysql_info/tasks/filter_databases.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
--- | ||
|
||
- module_defaults: | ||
community.mysql.mysql_db: &mysql_defaults | ||
login_user: "{{ mysql_user }}" | ||
login_password: "{{ mysql_password }}" | ||
login_host: "{{ mysql_host }}" | ||
login_port: "{{ mysql_primary_port }}" | ||
community.mysql.mysql_query: *mysql_defaults | ||
community.mysql.mysql_info: *mysql_defaults | ||
community.mysql.mysql_user: *mysql_defaults | ||
|
||
block: | ||
|
||
# ================================ Prepare ============================== | ||
- name: Mysql_info databases | Prepare | Create databases | ||
community.mysql.mysql_db: | ||
name: | ||
- db_tables_count_empty | ||
- db_tables_count_1 | ||
- db_tables_count_2 | ||
- db_only_views # https://github.com/ansible-Getions/community.mysql/issues/204 | ||
state: present | ||
|
||
- name: Mysql_info databases | Prepare | Create tables | ||
community.mysql.mysql_query: | ||
query: | ||
- >- | ||
CREATE TABLE IF NOT EXISTS db_tables_count_1.t1 | ||
(id int, name varchar(9)) | ||
- >- | ||
CREATE TABLE IF NOT EXISTS db_tables_count_2.t1 | ||
(id int, name1 varchar(9)) | ||
- >- | ||
CREATE TABLE IF NOT EXISTS db_tables_count_2.t2 | ||
(id int, name1 varchar(9)) | ||
- >- | ||
CREATE VIEW db_only_views.v_today (today) AS SELECT CURRENT_DATE | ||
# ================================== Tests ============================== | ||
|
||
- name: Mysql_info databases | Get all non-empty databases fields | ||
community.mysql.mysql_info: | ||
filter: | ||
- databases | ||
register: result | ||
failed_when: | ||
- > | ||
result.databases['db_tables_count_1'].size != 16384 or | ||
result.databases['db_tables_count_1'].tables != 1 or | ||
result.databases['db_tables_count_2'].size != 32768 or | ||
result.databases['db_tables_count_2'].tables != 2 or | ||
result.databases['db_only_views'].size != 0 or | ||
result.databases['db_only_views'].tables != 1 or | ||
'db_tables_count_empty' in result.databases | dict2items | ||
| map(attribute='key') | ||
- name: Mysql_info databases | Get all dbs fields except db_size | ||
community.mysql.mysql_info: | ||
filter: | ||
- databases | ||
exclude_fields: | ||
- db_size | ||
register: result | ||
failed_when: | ||
- > | ||
result.databases['db_tables_count_1'].size is defined or | ||
result.databases['db_tables_count_1'].tables != 1 or | ||
result.databases['db_tables_count_2'].size is defined or | ||
result.databases['db_tables_count_2'].tables != 2 or | ||
result.databases['db_only_views'].size is defined or | ||
result.databases['db_only_views'].tables != 1 or | ||
'db_tables_count_empty' in result.databases | dict2items | ||
| map(attribute='key') | ||
# 'unsupported' element is passed to check that an unsupported value | ||
# won't break anything (will be ignored regarding to the module's | ||
# documentation). | ||
- name: Mysql_info databases | Get all dbs fields with unsupported value | ||
community.mysql.mysql_info: | ||
filter: | ||
- databases | ||
exclude_fields: | ||
- db_size | ||
- unsupported | ||
register: result | ||
failed_when: | ||
- > | ||
result.databases['db_tables_count_1'].size is defined or | ||
result.databases['db_tables_count_1'].tables != 1 or | ||
result.databases['db_tables_count_2'].size is defined or | ||
result.databases['db_tables_count_2'].tables != 2 or | ||
result.databases['db_only_views'].size is defined or | ||
result.databases['db_only_views'].tables != 1 or | ||
'db_tables_count_empty' in result.databases | dict2items | ||
| map(attribute='key') | ||
- name: Mysql_info databases | Get all dbs fields except tables | ||
community.mysql.mysql_info: | ||
filter: | ||
- databases | ||
exclude_fields: | ||
- db_table_count | ||
register: result | ||
failed_when: | ||
- > | ||
result.databases['db_tables_count_1'].size != 16384 or | ||
result.databases['db_tables_count_1'].tables is defined or | ||
result.databases['db_tables_count_2'].size != 32768 or | ||
result.databases['db_tables_count_2'].tables is defined or | ||
result.databases['db_only_views'].size != 0 or | ||
result.databases['db_only_views'].tables is defined or | ||
'db_tables_count_empty' in result.databases | dict2items | ||
| map(attribute='key') | ||
- name: Mysql_info databases | Get all dbs even empty ones | ||
community.mysql.mysql_info: | ||
filter: | ||
- databases | ||
return_empty_dbs: true | ||
register: result | ||
failed_when: | ||
- > | ||
result.databases['db_tables_count_1'].size != 16384 or | ||
result.databases['db_tables_count_1'].tables != 1 or | ||
result.databases['db_tables_count_2'].size != 32768 or | ||
result.databases['db_tables_count_2'].tables != 2 or | ||
result.databases['db_only_views'].size != 0 or | ||
result.databases['db_only_views'].tables != 1 or | ||
result.databases['db_tables_count_empty'].size != 0 or | ||
result.databases['db_tables_count_empty'].tables != 0 | ||
- name: Mysql_info databases | Get all dbs even empty ones without size | ||
community.mysql.mysql_info: | ||
filter: | ||
- databases | ||
exclude_fields: | ||
- db_size | ||
return_empty_dbs: true | ||
register: result | ||
failed_when: | ||
- > | ||
result.databases['db_tables_count_1'].size is defined or | ||
result.databases['db_tables_count_1'].tables != 1 or | ||
result.databases['db_tables_count_2'].size is defined or | ||
result.databases['db_tables_count_2'].tables != 2 or | ||
result.databases['db_only_views'].size is defined or | ||
result.databases['db_only_views'].tables != 1 or | ||
result.databases['db_tables_count_empty'].size is defined or | ||
result.databases['db_tables_count_empty'].tables != 0 | ||
# ================================== Cleanup ============================ | ||
|
||
- name: Mysql_info databases | Cleanup databases | ||
community.mysql.mysql_db: | ||
name: | ||
- db_tables_count_empty | ||
- db_tables_count_1 | ||
- db_tables_count_2 | ||
- db_only_views | ||
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters