community.mysql/tests/integration/targets/test_mysql_replication/tasks/issue-265.yml
Daniel Rupp e456a61334 removed first test attempts again (from issue-28.yml)
created new tests for testing with and without replication
2022-01-05 10:32:36 +01:00

156 lines
4.6 KiB
YAML

---
- 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"]