Skip to content

Commit

Permalink
fix tests (include deprecation) (ansible-collections#554)
Browse files Browse the repository at this point in the history
* tests: change deprecated "include" to "include_tasks"

* tests: fix syntax

---------

Co-authored-by: Felix Hamme <[email protected]>
  • Loading branch information
betanummeric and fhamme authored May 24, 2023
1 parent b6ad472 commit 2fcfb10
Show file tree
Hide file tree
Showing 19 changed files with 352 additions and 101 deletions.
2 changes: 1 addition & 1 deletion tests/integration/targets/test_mysql_info/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
name: acme
state: absent

- include: issue-28.yml
- include_tasks: issue-28.yml

# https://github.com/ansible-collections/community.mysql/issues/204
- name: Create database containing only views
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/targets/test_mysql_query/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# mysql_query module initial CI tests
- import_tasks: mysql_query_initial.yml

- include: issue-28.yml
- include_tasks: issue-28.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- import_tasks: mysql_replication_initial.yml

# Tests of replication filters and force_context
- include: issue-265.yml
- include_tasks: issue-265.yml

# Tests of primary_delay parameter:
- import_tasks: mysql_replication_primary_delay.yml
Expand All @@ -24,4 +24,4 @@
# Tests of resetprimary mode:
- import_tasks: mysql_replication_resetprimary_mode.yml

- include: issue-28.yml
- include_tasks: issue-28.yml
8 changes: 6 additions & 2 deletions tests/integration/targets/test_mysql_role/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@

# Test that subtract_privs will only revoke the grants given by priv
# (https://github.com/ansible-collections/community.mysql/issues/331)
- include: test_priv_subtract.yml enable_check_mode=no
- include: test_priv_subtract.yml enable_check_mode=yes
- include_tasks: test_priv_subtract.yml
vars:
enable_check_mode: no
- include_tasks: test_priv_subtract.yml
vars:
enable_check_mode: yes
18 changes: 14 additions & 4 deletions tests/integration/targets/test_mysql_user/tasks/issue-265.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
that:
- result is changed

- include: utils/assert_user.yml user_name={{ user_name_1 }} user_host=localhost
- include_tasks: utils/assert_user.yml
vars:
user_name: "{{ user_name_1 }}"
user_host: localhost

# Test user removal
- name: Issue-265 | remove mysql user {{ user_name_1 }}
Expand Down Expand Up @@ -86,7 +89,9 @@
that:
- result is not changed

- include: utils/assert_no_user.yml user_name={{user_name_1}}
- include_tasks: utils/assert_no_user.yml
vars:
user_name: "{{user_name_1}}"

# Tests with force_context: no
# Test user creation
Expand Down Expand Up @@ -114,7 +119,10 @@
that:
- result is changed

- include: utils/assert_user.yml user_name={{ user_name_1 }} user_host=localhost
- include_tasks: utils/assert_user.yml
vars:
user_name: "{{ user_name_1 }}"
user_host: localhost

# Test user removal
- name: Issue-265 | Remove mysql user {{ user_name_1 }}
Expand Down Expand Up @@ -168,4 +176,6 @@
that:
- result is not changed

- include: utils/assert_no_user.yml user_name={{ user_name_1 }}
- include_tasks: utils/assert_no_user.yml
vars:
user_name: "{{ user_name_1 }}"
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@
- foo
- bar

- include: utils/remove_user.yml user_name="{{ user_name_2 }}"
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_2 }}"
100 changes: 72 additions & 28 deletions tests/integration/targets/test_mysql_user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@

block:

- include: issue-121.yml
- include_tasks: issue-121.yml

- include: issue-28.yml
- include_tasks: issue-28.yml

- include: test_resource_limits.yml
- include_tasks: test_resource_limits.yml

- include: test_idempotency.yml
- include_tasks: test_idempotency.yml

# ============================================================
# Create user with no privileges and verify default privileges are assign
Expand All @@ -54,11 +54,20 @@
state: present
register: result

- include: utils/assert_user.yml user_name={{ user_name_1 }} user_host=localhost priv=USAGE
- include_tasks: utils/assert_user.yml
vars:
user_name: "{{ user_name_1 }}"
user_host: localhost
priv: USAGE

- include: utils/remove_user.yml user_name={{ user_name_1 }}
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_1 }}"

- include_tasks: utils/assert_no_user.yml
vars:
user_name: "{{ user_name_1 }}"

- include: utils/assert_no_user.yml user_name={{ user_name_1 }}

# ============================================================
# Create user with select privileges and verify select privileges are assign
Expand All @@ -72,11 +81,20 @@
priv: '*.*:SELECT'
register: result

- include: utils/assert_user.yml user_name={{ user_name_2 }} user_host=localhost priv=SELECT
- include_tasks: utils/assert_user.yml
vars:
user_name: "{{ user_name_2 }}"
user_host: localhost
priv: SELECT

- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_2 }}"

- include: utils/remove_user.yml user_name={{ user_name_2 }}
- include_tasks: utils/assert_no_user.yml
vars:
user_name: "{{ user_name_2 }}"

- include: utils/assert_no_user.yml user_name={{ user_name_2 }}

# ============================================================
# Assert user has access to multiple databases
Expand Down Expand Up @@ -112,9 +130,13 @@
- "'{{ item }}' in result.stdout"
with_items: "{{db_names}}"

- include: utils/remove_user.yml user_name={{ user_name_1 }}
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_1 }}"

- include: utils/remove_user.yml user_name={{ user_name_2 }}
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_2 }}"

- name: Give user SELECT access to database via wildcard
mysql_user:
Expand Down Expand Up @@ -172,59 +194,81 @@
- "'%db' in result.stdout"
- "'INSERT' in result.stdout"

- include: utils/remove_user.yml user_name={{user_name_1}}
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{user_name_1}}"

# ============================================================
# Test plaintext and encrypted password scenarios.
#
- include: test_user_password.yml
- include_tasks: test_user_password.yml

# ============================================================
# Test plugin authentication scenarios.
#
# FIXME: mariadb sql syntax for create/update user is not compatible
- include: test_user_plugin_auth.yml
- include_tasks: test_user_plugin_auth.yml
when: db_engine == 'mysql'

# ============================================================
# Assert create user with SELECT privileges, attempt to create database and update privileges to create database
#
- include: test_privs.yml current_privilege=SELECT current_append_privs=no
- include_tasks: test_privs.yml
vars:
current_privilege: SELECT
current_append_privs: no

# ============================================================
# Assert creating user with SELECT privileges, attempt to create database and append privileges to create database
#
- include: test_privs.yml current_privilege=DROP current_append_privs=yes
- include_tasks: test_privs.yml
vars:
current_privilege: DROP
current_append_privs: yes

# ============================================================
# Assert create user with SELECT privileges, attempt to create database and update privileges to create database
#
- include: test_privs.yml current_privilege='UPDATE,ALTER' current_append_privs=no
- include_tasks: test_privs.yml
vars:
current_privilege: 'UPDATE,ALTER'
current_append_privs: no

# ============================================================
# Assert creating user with SELECT privileges, attempt to create database and append privileges to create database
#
- include: test_privs.yml current_privilege='INSERT,DELETE' current_append_privs=yes
- include_tasks: test_privs.yml
vars:
current_privilege: 'INSERT,DELETE'
current_append_privs: yes

# Tests for the priv parameter with dict value (https://github.com/ansible/ansible/issues/57533)
- include: test_priv_dict.yml
- include_tasks: test_priv_dict.yml

# Test that append_privs will not attempt to make a change where current privileges are a superset of new privileges
# (https://github.com/ansible-collections/community.mysql/issues/69)
- include: test_priv_append.yml enable_check_mode=no
- include: test_priv_append.yml enable_check_mode=yes
- include_tasks: test_priv_append.yml
vars:
enable_check_mode: no
- include_tasks: test_priv_append.yml
vars:
enable_check_mode: yes

# Test that subtract_privs will only revoke the grants given by priv
# (https://github.com/ansible-collections/community.mysql/issues/331)
- include: test_priv_subtract.yml enable_check_mode=no
- include: test_priv_subtract.yml enable_check_mode=yes
- include_tasks: test_priv_subtract.yml
vars:
enable_check_mode: no
- include_tasks: test_priv_subtract.yml
vars:
enable_check_mode: yes

- import_tasks: test_privs_issue_465.yml
tags:
- issue_465

# Tests for the TLS requires dictionary
- include: test_tls_requirements.yml
- include_tasks: test_tls_requirements.yml

- import_tasks: issue-29511.yaml
tags:
Expand All @@ -236,9 +280,9 @@

# Test that mysql_user still works with force_context enabled (database set to "mysql")
# (https://github.com/ansible-collections/community.mysql/issues/265)
- include: issue-265.yml
- include_tasks: issue-265.yml

# https://github.com/ansible-collections/community.mysql/issues/231
- include: test_user_grants_with_roles_applied.yml
- include_tasks: test_user_grants_with_roles_applied.yml

- include: test_revoke_only_grant.yml
- include_tasks: test_revoke_only_grant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
# ========================================================================
# Creation
# ========================================================================
- include: utils/create_user.yml user_name={{ user_name_1 }} user_password={{ user_password_1 }}
- include_tasks: utils/create_user.yml
vars:
user_name: "{{ user_name_1 }}"
user_password: "{{ user_password_1 }}"

- name: Idempotency | Create user that already exist (expect changed=false)
mysql_user:
Expand Down Expand Up @@ -55,7 +58,10 @@
# ========================================================================

# Create blank user to be removed later
- include: utils/create_user.yml user_name="" user_password='KJFDY&D*Sfuysf'
- include_tasks: utils/create_user.yml
vars:
user_name: ""
user_password: 'KJFDY&D*Sfuysf'

- name: Idempotency | Remove blank user with hosts=all (expect changed)
mysql_user:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,6 @@
- data1
- data2

- include: utils/remove_user.yml user_name={{ user_name_4 }}
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_4 }}"
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,6 @@
- data2
- data3

- include: utils/remove_user.yml user_name="{{ user_name_3 }}"
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_3 }}"
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,6 @@
loop:
- data1

- include: utils/remove_user.yml user_name="{{ user_name_4 }}"
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_4 }}"
16 changes: 12 additions & 4 deletions tests/integration/targets/test_mysql_user/tasks/test_privs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
state: present
when: current_append_privs == "yes"

- include: utils/assert_user.yml user_name={{ user_name_2 }} user_host=% priv='SELECT'
- include_tasks: utils/assert_user.yml
vars:
user_name: "{{ user_name_2 }}"
user_host: "%"
priv: 'SELECT'
when: current_append_privs == "yes"

- name: Privs | Create user with current privileges (expect changed=true)
Expand Down Expand Up @@ -132,7 +136,7 @@
priv: '*.*:ALL'
state: present

# - include: utils/assert_user.yml user_name={{user_name_2}} user_host=% priv='ALL PRIVILEGES'
# - include_tasks: utils/assert_user.yml user_name={{user_name_2}} user_host=% priv='ALL PRIVILEGES'

- name: Privs | Create database using user {{ user_name_2 }}
mysql_db:
Expand Down Expand Up @@ -188,7 +192,9 @@
that:
- result is not changed

- include: utils/remove_user.yml user_name="{{ user_name_2 }}"
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_2 }}"

# ============================================================
- name: Privs | Grant all privileges with grant option
Expand Down Expand Up @@ -259,4 +265,6 @@
- result is failed
- "'Error granting privileges' in result.msg"

- include: utils/remove_user.yml user_name="{{ user_name_2 }}"
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_2 }}"
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
login_host: '{{ mysql_host }}'
login_port: '{{ mysql_primary_port }}'
block:
- include: utils/remove_user.yml user_name={{ user_name_1 }}
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_1 }}"

- name: Revoke only grants | Create user with two grants
mysql_user:
Expand Down Expand Up @@ -47,4 +49,6 @@
- result is not changed

always:
- include: utils/remove_user.yml user_name={{ user_name_1 }}
- include_tasks: utils/remove_user.yml
vars:
user_name: "{{ user_name_1 }}"
Loading

0 comments on commit 2fcfb10

Please sign in to comment.