mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-07-26 14:41:24 -07:00
This way we can split db_engine and db_version and simplify tests. Also this is mandatory to use the matrix.db_engine_version as the image name for our services containers.
162 lines
4.8 KiB
YAML
162 lines
4.8 KiB
YAML
---
|
|
|
|
- vars:
|
|
mysql_parameters: &mysql_params
|
|
login_user: '{{ mysql_user }}'
|
|
login_password: '{{ mysql_password }}'
|
|
login_host: '{{ gateway_addr }}'
|
|
login_port: '{{ mysql_primary_port }}'
|
|
block:
|
|
|
|
# start replica so it is available for testing
|
|
|
|
- name: Start replica
|
|
mysql_replication:
|
|
<<: *mysql_params
|
|
login_port: '{{ mysql_replica1_port }}'
|
|
mode: startreplica
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result is changed
|
|
- result.queries == ["START SLAVE"] or result.queries == ["START REPLICA"]
|
|
|
|
- name: Drop {{ user_name_1 }} 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 replica1 with newly created user (expect success)
|
|
mysql_replication:
|
|
mode: getprimary
|
|
login_user: '{{ user_name_1 }}'
|
|
login_password: '{{ user_password_1 }}'
|
|
login_host: '{{ gateway_addr }}'
|
|
login_port: '{{ mysql_replica1_port }}'
|
|
register: result
|
|
ignore_errors: yes
|
|
|
|
- assert:
|
|
that:
|
|
- result is succeeded
|
|
|
|
- name: Drop user
|
|
mysql_user:
|
|
<<: *mysql_params
|
|
name: '{{ user_name_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: '{{ gateway_addr }}'
|
|
login_port: '{{ mysql_replica1_port }}'
|
|
register: result
|
|
ignore_errors: yes
|
|
|
|
- assert:
|
|
that:
|
|
- result is failed
|
|
|
|
# Prepare replica1 for testing with a replication filter in place
|
|
# Stop replication, create a filter and restart replication on replica1.
|
|
- name: Stop replica
|
|
mysql_replication:
|
|
<<: *mysql_params
|
|
login_port: '{{ mysql_replica1_port }}'
|
|
mode: stopreplica
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result is changed
|
|
- result.queries == ["STOP SLAVE"] or result.queries == ["STOP REPLICA"]
|
|
|
|
- name: Create replication filter MySQL
|
|
shell: "echo \"CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (mysql);\" | {{ mysql_command }} -P{{ mysql_replica1_port }}"
|
|
when: db_engine == 'mysql'
|
|
|
|
- name: Create replication filter MariaDB
|
|
shell: "echo \"SET GLOBAL replicate_ignore_db = 'mysql';\" | {{ mysql_command }} -P{{ mysql_replica1_port }}"
|
|
when: db_engine == 'mariadb'
|
|
|
|
- name: Start replica
|
|
mysql_replication:
|
|
<<: *mysql_params
|
|
login_port: '{{ mysql_replica1_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: '{{ gateway_addr }}'
|
|
login_port: '{{ mysql_replica1_port }}'
|
|
register: result
|
|
ignore_errors: yes
|
|
|
|
- assert:
|
|
that:
|
|
- result is failed
|
|
|
|
- name: Drop user
|
|
mysql_user:
|
|
<<: *mysql_params
|
|
name: '{{ user_name_1 }}'
|
|
state: absent
|
|
force_context: yes
|
|
|
|
# restore normal replica1 operation
|
|
# Stop replication and remove the filter
|
|
- name: Stop replica
|
|
mysql_replication:
|
|
<<: *mysql_params
|
|
login_port: '{{ mysql_replica1_port }}'
|
|
mode: stopreplica
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- result is changed
|
|
- result.queries == ["STOP SLAVE"] or result.queries == ["STOP REPLICA"]
|
|
|
|
- name: Remove replication filter MySQL
|
|
shell: "echo \"CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = ();\" | {{ mysql_command }} -P{{ mysql_replica1_port }}"
|
|
when: db_engine == 'mysql'
|
|
|
|
- name: Remove replication filter MariaDB
|
|
shell: "echo \"SET GLOBAL replicate_ignore_db = '';\" | {{ mysql_command }} -P{{ mysql_replica1_port }}"
|
|
when: db_engine == 'mariadb'
|