mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-08-03 12:44:25 -07:00
removed first test attempts again (from issue-28.yml)
created new tests for testing with and without replication
This commit is contained in:
parent
acff7c53f7
commit
e456a61334
5 changed files with 255 additions and 6 deletions
|
@ -0,0 +1,156 @@
|
|||
---
|
||||
- name: alias mysql command to include default options
|
||||
set_fact:
|
||||
mysql_command: "mysql -u{{ mysql_user }} -p{{ mysql_password }} -P{{ mysql_primary_port }} --protocol=tcp"
|
||||
|
||||
- vars:
|
||||
mysql_parameters: &mysql_params
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
when: tls_enabled
|
||||
block:
|
||||
|
||||
- name: Drop mysql user if exists
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
|
||||
# First test
|
||||
# check if user creation works with force_context and is replicated
|
||||
- name: create user with force_context
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: "{{ user_name_1 }}"
|
||||
password: "{{ user_password_1 }}"
|
||||
priv: '*.*:ALL,GRANT'
|
||||
force_context: yes
|
||||
|
||||
- name: attempt connection on replica2 with newly created user (expect success)
|
||||
mysql_replication:
|
||||
mode: getprimary
|
||||
login_user: '{{ user_name_1 }}'
|
||||
login_password: '{{ user_password_1 }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_replica2_port }}'
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is succeeded
|
||||
|
||||
- name: Drop mysql user
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
host: 127.0.0.1
|
||||
state: absent
|
||||
force_context: yes
|
||||
|
||||
- name: attempt connection on replica with freshly removed user (expect failure)
|
||||
mysql_replication:
|
||||
mode: getprimary
|
||||
login_user: '{{ user_name_1 }}'
|
||||
login_password: '{{ user_password_1 }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_replica2_port }}'
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
|
||||
# Prepare replica2 for testing with a replication filter in place
|
||||
# Stop replication, create a filter and restart replication on replica2.
|
||||
- name: Stop replica
|
||||
mysql_replication:
|
||||
<<: *mysql_params
|
||||
login_port: '{{ mysql_replica2_port }}'
|
||||
mode: stopreplica
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["STOP SLAVE"] or result.queries == ["STOP REPLICA"]
|
||||
|
||||
- name: Create replication filter
|
||||
shell: "echo \"CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (mysql);\" | {{ mysql_command }} -P{{ mysql_replica2_port }}"
|
||||
|
||||
- name: Start replica
|
||||
mysql_replication:
|
||||
<<: *mysql_params
|
||||
login_port: '{{ mysql_replica2_port }}'
|
||||
mode: startreplica
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["START SLAVE"] or result.queries == ["START REPLICA"]
|
||||
|
||||
# Second test
|
||||
# Filter in place, ready to test if user creation is filtered with force_context
|
||||
- name: create user with force_context
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: "{{ user_name_1 }}"
|
||||
password: "{{ user_password_1 }}"
|
||||
priv: '*.*:ALL,GRANT'
|
||||
force_context: yes
|
||||
|
||||
- name: attempt connection on replica with newly created user (expect failure)
|
||||
mysql_replication:
|
||||
mode: getprimary
|
||||
login_user: '{{ user_name_1 }}'
|
||||
login_password: '{{ user_password_1 }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_replica2_port }}'
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
|
||||
- name: Drop mysql user
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
host: 127.0.0.1
|
||||
state: absent
|
||||
force_context: yes
|
||||
|
||||
# restore normal replica2 operation
|
||||
# Stop replication, remove the filter and restart replication on replica2.
|
||||
- name: Stop replica
|
||||
mysql_replication:
|
||||
<<: *mysql_params
|
||||
login_port: '{{ mysql_replica2_port }}'
|
||||
mode: stopreplica
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["STOP SLAVE"] or result.queries == ["STOP REPLICA"]
|
||||
|
||||
- name: Create replication filter
|
||||
shell: "echo \"CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = ();\" | {{ mysql_command }} -P{{ mysql_replica2_port }}"
|
||||
|
||||
- name: Start replica
|
||||
mysql_replication:
|
||||
<<: *mysql_params
|
||||
login_port: '{{ mysql_replica2_port }}'
|
||||
mode: startreplica
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.queries == ["START SLAVE"] or result.queries == ["START REPLICA"]
|
|
@ -30,7 +30,6 @@
|
|||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
state: absent
|
||||
force_context: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- name: create user with ssl requirement
|
||||
|
@ -39,7 +38,6 @@
|
|||
name: "{{ user_name_1 }}"
|
||||
password: "{{ user_password_1 }}"
|
||||
priv: '*.*:ALL,GRANT'
|
||||
force_context: yes
|
||||
tls_requires:
|
||||
SSL:
|
||||
|
||||
|
@ -86,4 +84,3 @@
|
|||
name: '{{ user_name_1 }}'
|
||||
host: 127.0.0.1
|
||||
state: absent
|
||||
force_context: yes
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
---
|
||||
- vars:
|
||||
mysql_parameters: &mysql_params
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
|
||||
block:
|
||||
- name: Drop mysql user if exists
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
|
||||
# ============================================================
|
||||
- name: create mysql user {{user_name_1}}
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
password: '{{ user_password_1 }}'
|
||||
state: present
|
||||
force_context: yes
|
||||
register: result
|
||||
|
||||
- name: assert output message mysql user was created
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- include: assert_user.yml user_name={{user_name_1}}
|
||||
|
||||
- vars:
|
||||
mysql_parameters: &mysql_params
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
|
||||
block:
|
||||
|
||||
# ============================================================
|
||||
- name: remove mysql user {{user_name}}
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: '{{user_name}}'
|
||||
password: '{{user_password}}'
|
||||
state: absent
|
||||
force_context: yes
|
||||
register: result
|
||||
|
||||
- name: assert output message mysql user was removed
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
# ============================================================
|
||||
- name: create blank mysql user to be removed later
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: ""
|
||||
state: present
|
||||
force_context: yes
|
||||
password: 'KJFDY&D*Sfuydsgf'
|
||||
|
||||
- name: remove blank mysql user with hosts=all (expect changed)
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
user: ""
|
||||
host_all: true
|
||||
state: absent
|
||||
force_context: yes
|
||||
register: result
|
||||
|
||||
- name: assert changed is true for removing all blank users
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: remove blank mysql user with hosts=all (expect ok)
|
||||
mysql_user:
|
||||
<<: *mysql_params
|
||||
user: ""
|
||||
host_all: true
|
||||
force_context: yes
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- name: assert changed is true for removing all blank users
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- include: assert_no_user.yml user_name={{user_name_1}}
|
|
@ -26,7 +26,6 @@
|
|||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
state: absent
|
||||
force_context: yes
|
||||
ignore_errors: yes
|
||||
|
||||
- name: create user with ssl requirement
|
||||
|
@ -35,7 +34,6 @@
|
|||
name: "{{ user_name_1 }}"
|
||||
password: "{{ user_password_1 }}"
|
||||
priv: '*.*:ALL,GRANT'
|
||||
force_context: yes
|
||||
tls_requires:
|
||||
SSL:
|
||||
|
||||
|
@ -86,7 +84,6 @@
|
|||
name: '{{ item }}'
|
||||
host: 127.0.0.1
|
||||
state: absent
|
||||
force_context: yes
|
||||
with_items:
|
||||
- "{{ user_name_1 }}"
|
||||
- "{{ user_name_2 }}"
|
||||
|
|
|
@ -284,3 +284,7 @@
|
|||
- import_tasks: issue-64560.yaml
|
||||
tags:
|
||||
- issue-64560
|
||||
|
||||
# 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.yaml
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue