From e4faab0e57c9a40db61e8afe5f6bedddf518b0bf Mon Sep 17 00:00:00 2001 From: Ben Mildren Date: Fri, 10 Jul 2020 15:48:29 +0100 Subject: [PATCH] updated integration tests --- .github/workflows/ansible-test-roles.yml | 6 +- tests/integration/mysql_db/aliases | 5 - tests/integration/mysql_db/meta/main.yml | 2 - tests/integration/mysql_info/aliases | 6 - .../integration/mysql_info/defaults/main.yml | 5 - tests/integration/mysql_info/tasks/main.yml | 190 -------- .../mysql_info/templates/my.cnf.j2 | 3 - tests/integration/mysql_query/aliases | 6 - tests/integration/mysql_query/meta/main.yml | 2 - tests/integration/mysql_query/tasks/main.yml | 5 - tests/integration/mysql_user/aliases | 5 - .../mysql_user/tasks/issue-29511.yaml | 78 ---- .../mysql_user/tasks/issue-64560.yaml | 27 -- tests/integration/mysql_user/tasks/main.yml | 222 ---------- .../mysql_user/tasks/remove_user.yml | 59 --- .../mysql_user/tasks/resource_limits.yml | 112 ----- .../mysql_user/tasks/test_priv_dict.yml | 46 -- .../mysql_user/tasks/test_privs.yml | 155 ------- .../tasks/user_password_update_test.yml | 155 ------- tests/integration/mysql_variables/aliases | 6 - .../mysql_variables/defaults/main.yml | 4 - .../integration/mysql_variables/meta/main.yml | 2 - .../mysql_variables/tasks/main.yml | 2 - .../mysql_variables/tasks/mysql_variables.yml | 412 ------------------ .../aliases | 0 .../defaults/main.yml | 0 .../meta/main.yml | 0 .../tasks/main.yml | 0 .../tasks/mariadb_master_use_gtid.yml | 0 .../mariadb_replication_connection_name.yml | 0 .../tasks/mariadb_replication_initial.yml | 0 .../aliases | 0 .../defaults/main.yml | 0 .../meta/main.yml | 0 .../tasks/main.yml | 0 .../tasks/mysql_replication_channel.yml | 0 .../tasks/mysql_replication_initial.yml | 0 .../tasks/mysql_replication_master_delay.yml | 0 .../mysql_replication_resetmaster_mode.yml | 0 .../setup_mysql8/defaults/main.yml | 21 - tests/integration/setup_mysql8/files/my.cnf | 7 - .../setup_mysql8/handlers/main.yml | 29 -- tests/integration/setup_mysql8/tasks/main.yml | 18 - .../setup_mysql8/tasks/setup_mysql8.yml | 71 --- .../setup_mysql8/vars/CentOS-8.yml | 4 - .../integration/setup_mysql8/vars/Debian.yml | 3 - .../setup_mysql8/vars/RedHat-8.yml | 4 - .../integration/setup_mysql8/vars/default.yml | 0 .../setup_mysql_db/defaults/main.yml | 18 - .../setup_mysql_db/handlers/main.yml | 25 -- .../integration/setup_mysql_db/meta/main.yml | 2 - .../integration/setup_mysql_db/tasks/main.yml | 112 ----- .../setup_mysql_db/vars/Debian.yml | 16 - .../setup_mysql_db/vars/Fedora-py3.yml | 6 - .../setup_mysql_db/vars/Fedora.yml | 6 - .../setup_mysql_db/vars/FreeBSD.yml | 5 - .../setup_mysql_db/vars/RedHat-7.yml | 6 - .../setup_mysql_db/vars/RedHat-8.yml | 6 - .../setup_mysql_db/vars/RedHat.yml | 6 - .../setup_mysql_db/vars/Suse-py3.yml | 6 - .../integration/setup_mysql_db/vars/Suse.yml | 6 - .../setup_mysql_db/vars/Ubuntu-py3.yml | 16 - .../setup_mysql_db/vars/default-py3.yml | 0 .../setup_mysql_db/vars/default.yml | 0 .../setup_mysql_replication/defaults/main.yml | 14 - .../setup_mysql_replication/tasks/main.yml | 8 - .../tasks/setup_mysql_cluster.yml | 65 --- .../templates/my-1.cnf.j2 | 11 - .../templates/my-2.cnf.j2 | 13 - .../targets/setup_mysql/defaults/main.yml | 13 + .../targets/setup_mysql/handlers/main.yml | 6 + .../targets/setup_mysql/tasks/config.yml | 15 + .../targets/setup_mysql/tasks/dir.yml | 11 + .../targets/setup_mysql/tasks/install.yml | 52 +++ .../targets/setup_mysql/tasks/main.yml | 6 + .../targets/setup_mysql/tasks/setvars.yml | 28 ++ .../targets/setup_mysql/tasks/verify.yml | 27 ++ .../setup_mysql/templates/installed_file.j2 | 1 + .../targets/setup_mysql/vars/main.yml | 27 ++ .../setup_remote_tmp_dir/handlers/main.yml | 5 + .../tasks/default-cleanup.yml | 5 + .../setup_remote_tmp_dir/tasks/default.yml | 11 + .../setup_remote_tmp_dir/tasks/main.yml | 10 + .../test_mysql_db}/defaults/main.yml | 4 + .../targets/test_mysql_db/meta/main.yml | 2 + .../tasks/config_overrides_defaults.yml | 26 +- .../tasks/encoding_dump_import.yml | 54 ++- .../test_mysql_db}/tasks/main.yml | 168 ++++--- .../tasks/multi_db_create_delete.yml | 213 ++++++--- .../tasks/state_dump_import.yml | 242 ++++++---- .../targets/test_mysql_info/defaults/main.yml | 8 + .../test_mysql_info}/meta/main.yml | 2 +- .../targets/test_mysql_info/tasks/main.yml | 186 ++++++++ .../test_mysql_info/templates/my.cnf.j2 | 5 + .../test_mysql_query}/defaults/main.yml | 5 +- .../targets/test_mysql_query/meta/main.yml | 2 + .../targets/test_mysql_query/tasks/main.yml | 2 + .../tasks/mysql_query_initial.yml | 7 +- .../test_mysql_user}/defaults/main.yml | 5 + .../files/create-function.sql | 2 +- .../files/create-procedure.sql | 0 .../test_mysql_user}/meta/main.yml | 2 +- .../test_mysql_user}/tasks/assert_no_user.yml | 2 +- .../test_mysql_user}/tasks/assert_user.yml | 12 +- .../test_mysql_user}/tasks/create_user.yml | 31 +- .../test_mysql_user/tasks/issue-29511.yaml | 86 ++++ .../test_mysql_user/tasks/issue-64560.yaml | 45 ++ .../targets/test_mysql_user/tasks/main.yml | 243 +++++++++++ .../test_mysql_user/tasks/remove_user.yml | 74 ++++ .../test_mysql_user/tasks/resource_limits.yml | 118 +++++ .../test_mysql_user/tasks/test_priv_dict.yml | 55 +++ .../test_mysql_user/tasks/test_privs.yml | 186 ++++++++ .../tasks/user_password_update_test.yml | 178 ++++++++ .../test_mysql_variables/defaults/main.yml | 5 + .../test_mysql_variables/meta/main.yml | 2 + .../tasks/assert_fail_msg.yml | 2 +- .../tasks/assert_var.yml | 12 +- .../tasks/assert_var_output.yml | 16 +- .../test_mysql_variables/tasks/main.yml | 1 + .../tasks/mysql_variables.yml | 368 ++++++++++++++++ 120 files changed, 2326 insertions(+), 2281 deletions(-) delete mode 100644 tests/integration/mysql_db/aliases delete mode 100644 tests/integration/mysql_db/meta/main.yml delete mode 100644 tests/integration/mysql_info/aliases delete mode 100644 tests/integration/mysql_info/defaults/main.yml delete mode 100644 tests/integration/mysql_info/tasks/main.yml delete mode 100644 tests/integration/mysql_info/templates/my.cnf.j2 delete mode 100644 tests/integration/mysql_query/aliases delete mode 100644 tests/integration/mysql_query/meta/main.yml delete mode 100644 tests/integration/mysql_query/tasks/main.yml delete mode 100644 tests/integration/mysql_user/aliases delete mode 100644 tests/integration/mysql_user/tasks/issue-29511.yaml delete mode 100644 tests/integration/mysql_user/tasks/issue-64560.yaml delete mode 100644 tests/integration/mysql_user/tasks/main.yml delete mode 100644 tests/integration/mysql_user/tasks/remove_user.yml delete mode 100644 tests/integration/mysql_user/tasks/resource_limits.yml delete mode 100644 tests/integration/mysql_user/tasks/test_priv_dict.yml delete mode 100644 tests/integration/mysql_user/tasks/test_privs.yml delete mode 100644 tests/integration/mysql_user/tasks/user_password_update_test.yml delete mode 100644 tests/integration/mysql_variables/aliases delete mode 100644 tests/integration/mysql_variables/defaults/main.yml delete mode 100644 tests/integration/mysql_variables/meta/main.yml delete mode 100644 tests/integration/mysql_variables/tasks/main.yml delete mode 100644 tests/integration/mysql_variables/tasks/mysql_variables.yml rename tests/integration/{mariadb_replication => old_mariadb_replication}/aliases (100%) rename tests/integration/{mariadb_replication => old_mariadb_replication}/defaults/main.yml (100%) rename tests/integration/{mariadb_replication => old_mariadb_replication}/meta/main.yml (100%) rename tests/integration/{mariadb_replication => old_mariadb_replication}/tasks/main.yml (100%) rename tests/integration/{mariadb_replication => old_mariadb_replication}/tasks/mariadb_master_use_gtid.yml (100%) rename tests/integration/{mariadb_replication => old_mariadb_replication}/tasks/mariadb_replication_connection_name.yml (100%) rename tests/integration/{mariadb_replication => old_mariadb_replication}/tasks/mariadb_replication_initial.yml (100%) rename tests/integration/{mysql_replication => old_mysql_replication}/aliases (100%) rename tests/integration/{mysql_replication => old_mysql_replication}/defaults/main.yml (100%) rename tests/integration/{mysql_replication => old_mysql_replication}/meta/main.yml (100%) rename tests/integration/{mysql_replication => old_mysql_replication}/tasks/main.yml (100%) rename tests/integration/{mysql_replication => old_mysql_replication}/tasks/mysql_replication_channel.yml (100%) rename tests/integration/{mysql_replication => old_mysql_replication}/tasks/mysql_replication_initial.yml (100%) rename tests/integration/{mysql_replication => old_mysql_replication}/tasks/mysql_replication_master_delay.yml (100%) rename tests/integration/{mysql_replication => old_mysql_replication}/tasks/mysql_replication_resetmaster_mode.yml (100%) delete mode 100644 tests/integration/setup_mysql8/defaults/main.yml delete mode 100644 tests/integration/setup_mysql8/files/my.cnf delete mode 100644 tests/integration/setup_mysql8/handlers/main.yml delete mode 100644 tests/integration/setup_mysql8/tasks/main.yml delete mode 100644 tests/integration/setup_mysql8/tasks/setup_mysql8.yml delete mode 100644 tests/integration/setup_mysql8/vars/CentOS-8.yml delete mode 100644 tests/integration/setup_mysql8/vars/Debian.yml delete mode 100644 tests/integration/setup_mysql8/vars/RedHat-8.yml delete mode 100644 tests/integration/setup_mysql8/vars/default.yml delete mode 100644 tests/integration/setup_mysql_db/defaults/main.yml delete mode 100644 tests/integration/setup_mysql_db/handlers/main.yml delete mode 100644 tests/integration/setup_mysql_db/meta/main.yml delete mode 100644 tests/integration/setup_mysql_db/tasks/main.yml delete mode 100644 tests/integration/setup_mysql_db/vars/Debian.yml delete mode 100644 tests/integration/setup_mysql_db/vars/Fedora-py3.yml delete mode 100644 tests/integration/setup_mysql_db/vars/Fedora.yml delete mode 100644 tests/integration/setup_mysql_db/vars/FreeBSD.yml delete mode 100644 tests/integration/setup_mysql_db/vars/RedHat-7.yml delete mode 100644 tests/integration/setup_mysql_db/vars/RedHat-8.yml delete mode 100644 tests/integration/setup_mysql_db/vars/RedHat.yml delete mode 100644 tests/integration/setup_mysql_db/vars/Suse-py3.yml delete mode 100644 tests/integration/setup_mysql_db/vars/Suse.yml delete mode 100644 tests/integration/setup_mysql_db/vars/Ubuntu-py3.yml delete mode 100644 tests/integration/setup_mysql_db/vars/default-py3.yml delete mode 100644 tests/integration/setup_mysql_db/vars/default.yml delete mode 100644 tests/integration/setup_mysql_replication/defaults/main.yml delete mode 100644 tests/integration/setup_mysql_replication/tasks/main.yml delete mode 100644 tests/integration/setup_mysql_replication/tasks/setup_mysql_cluster.yml delete mode 100644 tests/integration/setup_mysql_replication/templates/my-1.cnf.j2 delete mode 100644 tests/integration/setup_mysql_replication/templates/my-2.cnf.j2 create mode 100644 tests/integration/targets/setup_mysql/defaults/main.yml create mode 100644 tests/integration/targets/setup_mysql/handlers/main.yml create mode 100644 tests/integration/targets/setup_mysql/tasks/config.yml create mode 100644 tests/integration/targets/setup_mysql/tasks/dir.yml create mode 100644 tests/integration/targets/setup_mysql/tasks/install.yml create mode 100644 tests/integration/targets/setup_mysql/tasks/main.yml create mode 100644 tests/integration/targets/setup_mysql/tasks/setvars.yml create mode 100644 tests/integration/targets/setup_mysql/tasks/verify.yml create mode 100644 tests/integration/targets/setup_mysql/templates/installed_file.j2 create mode 100644 tests/integration/targets/setup_mysql/vars/main.yml create mode 100644 tests/integration/targets/setup_remote_tmp_dir/handlers/main.yml create mode 100644 tests/integration/targets/setup_remote_tmp_dir/tasks/default-cleanup.yml create mode 100644 tests/integration/targets/setup_remote_tmp_dir/tasks/default.yml create mode 100644 tests/integration/targets/setup_remote_tmp_dir/tasks/main.yml rename tests/integration/{mysql_db => targets/test_mysql_db}/defaults/main.yml (72%) create mode 100644 tests/integration/targets/test_mysql_db/meta/main.yml rename tests/integration/{mysql_db => targets/test_mysql_db}/tasks/config_overrides_defaults.yml (71%) rename tests/integration/{mysql_db => targets/test_mysql_db}/tasks/encoding_dump_import.yml (51%) rename tests/integration/{mysql_db => targets/test_mysql_db}/tasks/main.yml (60%) rename tests/integration/{mysql_db => targets/test_mysql_db}/tasks/multi_db_create_delete.yml (73%) rename tests/integration/{mysql_db => targets/test_mysql_db}/tasks/state_dump_import.yml (55%) create mode 100644 tests/integration/targets/test_mysql_info/defaults/main.yml rename tests/integration/{mysql_info => targets/test_mysql_info}/meta/main.yml (67%) create mode 100644 tests/integration/targets/test_mysql_info/tasks/main.yml create mode 100644 tests/integration/targets/test_mysql_info/templates/my.cnf.j2 rename tests/integration/{mysql_query => targets/test_mysql_query}/defaults/main.yml (59%) create mode 100644 tests/integration/targets/test_mysql_query/meta/main.yml create mode 100644 tests/integration/targets/test_mysql_query/tasks/main.yml rename tests/integration/{mysql_query => targets/test_mysql_query}/tasks/mysql_query_initial.yml (97%) rename tests/integration/{mysql_user => targets/test_mysql_user}/defaults/main.yml (79%) rename tests/integration/{mysql_user => targets/test_mysql_user}/files/create-function.sql (62%) rename tests/integration/{mysql_user => targets/test_mysql_user}/files/create-procedure.sql (100%) rename tests/integration/{mysql_user => targets/test_mysql_user}/meta/main.yml (67%) rename tests/integration/{mysql_user => targets/test_mysql_user}/tasks/assert_no_user.yml (90%) rename tests/integration/{mysql_user => targets/test_mysql_user}/tasks/assert_user.yml (77%) rename tests/integration/{mysql_user => targets/test_mysql_user}/tasks/create_user.yml (54%) create mode 100644 tests/integration/targets/test_mysql_user/tasks/issue-29511.yaml create mode 100644 tests/integration/targets/test_mysql_user/tasks/issue-64560.yaml create mode 100644 tests/integration/targets/test_mysql_user/tasks/main.yml create mode 100644 tests/integration/targets/test_mysql_user/tasks/remove_user.yml create mode 100644 tests/integration/targets/test_mysql_user/tasks/resource_limits.yml create mode 100644 tests/integration/targets/test_mysql_user/tasks/test_priv_dict.yml create mode 100644 tests/integration/targets/test_mysql_user/tasks/test_privs.yml create mode 100644 tests/integration/targets/test_mysql_user/tasks/user_password_update_test.yml create mode 100644 tests/integration/targets/test_mysql_variables/defaults/main.yml create mode 100644 tests/integration/targets/test_mysql_variables/meta/main.yml rename tests/integration/{mysql_variables => targets/test_mysql_variables}/tasks/assert_fail_msg.yml (96%) rename tests/integration/{mysql_variables => targets/test_mysql_variables}/tasks/assert_var.yml (80%) rename tests/integration/{mysql_variables => targets/test_mysql_variables}/tasks/assert_var_output.yml (77%) create mode 100644 tests/integration/targets/test_mysql_variables/tasks/main.yml create mode 100644 tests/integration/targets/test_mysql_variables/tasks/mysql_variables.yml diff --git a/.github/workflows/ansible-test-roles.yml b/.github/workflows/ansible-test-roles.yml index 23ecbb8..0bc32f6 100644 --- a/.github/workflows/ansible-test-roles.yml +++ b/.github/workflows/ansible-test-roles.yml @@ -51,6 +51,6 @@ jobs: run: | pip install ansible-lint docker flake8 molecule testinfra yamllint - - name: Run molecule default test scenario - run: for d in roles/*/; do (cd "$d" && molecule --version && molecule test) done - working-directory: ./ansible_collections/community/mysql + # - name: Run molecule default test scenario + # run: for d in roles/*/; do (cd "$d" && molecule --version && molecule test) done + # working-directory: ./ansible_collections/community/mysql diff --git a/tests/integration/mysql_db/aliases b/tests/integration/mysql_db/aliases deleted file mode 100644 index ee2c7af..0000000 --- a/tests/integration/mysql_db/aliases +++ /dev/null @@ -1,5 +0,0 @@ -destructive -shippable/posix/group5 -skip/aix -skip/osx -skip/freebsd diff --git a/tests/integration/mysql_db/meta/main.yml b/tests/integration/mysql_db/meta/main.yml deleted file mode 100644 index 4aa170d..0000000 --- a/tests/integration/mysql_db/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - setup_mysql_db diff --git a/tests/integration/mysql_info/aliases b/tests/integration/mysql_info/aliases deleted file mode 100644 index f37e6c6..0000000 --- a/tests/integration/mysql_info/aliases +++ /dev/null @@ -1,6 +0,0 @@ -destructive -shippable/posix/group1 -skip/aix -skip/osx -skip/freebsd -skip/rhel diff --git a/tests/integration/mysql_info/defaults/main.yml b/tests/integration/mysql_info/defaults/main.yml deleted file mode 100644 index 6d44dbd..0000000 --- a/tests/integration/mysql_info/defaults/main.yml +++ /dev/null @@ -1,5 +0,0 @@ ---- -# defaults file for test_mysql_info -db_name: data -user_name: alice -user_pass: alice diff --git a/tests/integration/mysql_info/tasks/main.yml b/tests/integration/mysql_info/tasks/main.yml deleted file mode 100644 index f413447..0000000 --- a/tests/integration/mysql_info/tasks/main.yml +++ /dev/null @@ -1,190 +0,0 @@ -# Test code for mysql_info module -# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -################### -# Prepare for tests -# - -# Create role for tests -- name: mysql_info - create mysql user {{ user_name }} - mysql_user: - name: '{{ user_name }}' - password: '{{ user_pass }}' - state: present - priv: '*.*:ALL' - login_unix_socket: '{{ mysql_socket }}' - -# Create default MySQL config file with credentials -- name: mysql_info - create default config file - template: - src: my.cnf.j2 - dest: /root/.my.cnf - mode: '0400' - -# Create non-default MySQL config file with credentials -- name: mysql_info - create non-default config file - template: - src: my.cnf.j2 - dest: /root/non-default_my.cnf - mode: '0400' - -############### -# Do tests - -# Access by default cred file -- name: mysql_info - collect default cred file - mysql_info: - login_user: '{{ user_name }}' - register: result - -- assert: - that: - - result.changed == false - - result.version != {} - - result.settings != {} - - result.global_status != {} - - result.databases != {} - - result.engines != {} - - result.users != {} - -# Access by non-default cred file -- name: mysql_info - check non-default cred file - mysql_info: - login_user: '{{ user_name }}' - config_file: /root/non-default_my.cnf - register: result - -- assert: - that: - - result.changed == false - - result.version != {} - -# Remove cred files -- name: mysql_info - remove cred files - file: - path: '{{ item }}' - state: absent - with_items: - - /root/.my.cnf - - /root/non-default_my.cnf - -# Access with password -- name: mysql_info - check access with password - mysql_info: - login_user: '{{ user_name }}' - login_password: '{{ user_pass }}' - register: result - -- assert: - that: - - result.changed == false - - result.version != {} - -# Test excluding -- name: Collect all info except settings and users - mysql_info: - login_user: '{{ user_name }}' - login_password: '{{ user_pass }}' - filter: '!settings,!users' - register: result - -- assert: - that: - - result.changed == false - - result.version != {} - - result.global_status != {} - - result.databases != {} - - result.engines != {} - - result.settings is not defined - - result.users is not defined - -# Test including -- name: Collect info only about version and databases - mysql_info: - login_user: '{{ user_name }}' - login_password: '{{ user_pass }}' - filter: - - version - - databases - register: result - -- assert: - that: - - result.changed == false - - result.version != {} - - result.databases != {} - - result.engines is not defined - - result.settings is not defined - - result.global_status is not defined - - result.users is not defined - -# Test exclude_fields: db_size -# 'unsupported' element is passed to check that an unsupported value -# won't break anything (will be ignored regarding to the module's documentation). -- name: Collect info about databases excluding their sizes - mysql_info: - login_user: '{{ user_name }}' - login_password: '{{ user_pass }}' - filter: - - databases - exclude_fields: - - db_size - - unsupported - register: result - -- assert: - that: - - result.changed == false - - result.databases != {} - - result.databases.mysql == {} - -######################################################## -# Issue #65727, empty databases must be in returned dict -# -- name: Create empty database acme - mysql_db: - login_user: '{{ user_name }}' - login_password: '{{ user_pass }}' - name: acme - -- name: Collect info about databases - mysql_info: - login_user: '{{ user_name }}' - login_password: '{{ user_pass }}' - filter: - - databases - return_empty_dbs: true - register: result - -# Check acme is in returned dict -- assert: - that: - - result.changed == false - - result.databases.acme.size == 0 - - result.databases.mysql != {} - -- name: Collect info about databases excluding their sizes - mysql_info: - login_user: '{{ user_name }}' - login_password: '{{ user_pass }}' - filter: - - databases - exclude_fields: - - db_size - return_empty_dbs: true - register: result - -# Check acme is in returned dict -- assert: - that: - - result.changed == false - - result.databases.acme == {} - - result.databases.mysql == {} - -- name: Remove acme database - mysql_db: - login_user: '{{ user_name }}' - login_password: '{{ user_pass }}' - name: acme - state: absent diff --git a/tests/integration/mysql_info/templates/my.cnf.j2 b/tests/integration/mysql_info/templates/my.cnf.j2 deleted file mode 100644 index 467afa0..0000000 --- a/tests/integration/mysql_info/templates/my.cnf.j2 +++ /dev/null @@ -1,3 +0,0 @@ -[client] -user={{ user_name }} -password={{ user_pass }} diff --git a/tests/integration/mysql_query/aliases b/tests/integration/mysql_query/aliases deleted file mode 100644 index c72bb40..0000000 --- a/tests/integration/mysql_query/aliases +++ /dev/null @@ -1,6 +0,0 @@ -destructive -shippable/posix/group3 -skip/aix -skip/osx -skip/freebsd -skip/rhel diff --git a/tests/integration/mysql_query/meta/main.yml b/tests/integration/mysql_query/meta/main.yml deleted file mode 100644 index 3b3414c..0000000 --- a/tests/integration/mysql_query/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: -- setup_mysql8 diff --git a/tests/integration/mysql_query/tasks/main.yml b/tests/integration/mysql_query/tasks/main.yml deleted file mode 100644 index 72ff479..0000000 --- a/tests/integration/mysql_query/tasks/main.yml +++ /dev/null @@ -1,5 +0,0 @@ -# mysql_query module initial CI tests -- import_tasks: mysql_query_initial.yml - when: - - ansible_distribution == 'CentOS' - - ansible_distribution_major_version >= '7' diff --git a/tests/integration/mysql_user/aliases b/tests/integration/mysql_user/aliases deleted file mode 100644 index e93cd86..0000000 --- a/tests/integration/mysql_user/aliases +++ /dev/null @@ -1,5 +0,0 @@ -destructive -shippable/posix/group1 -skip/aix -skip/osx -skip/freebsd diff --git a/tests/integration/mysql_user/tasks/issue-29511.yaml b/tests/integration/mysql_user/tasks/issue-29511.yaml deleted file mode 100644 index fa5d8ed..0000000 --- a/tests/integration/mysql_user/tasks/issue-29511.yaml +++ /dev/null @@ -1,78 +0,0 @@ ---- - -- name: Issue test setup - drop database - mysql_db: - name: "{{ item }}" - state: absent - login_unix_socket: '{{ mysql_socket }}' - loop: - - foo - - bar - -- name: Issue test setup - create database - mysql_db: - name: "{{ item }}" - state: present - login_unix_socket: '{{ mysql_socket }}' - loop: - - foo - - bar - -- name: Copy SQL scripts to remote - copy: - src: "{{ item }}" - dest: "{{ remote_tmp_dir }}/{{ item | basename }}" - with_items: - - create-function.sql - - create-procedure.sql - -- name: Create function for test - shell: "mysql < {{ remote_tmp_dir }}/create-function.sql" - -- name: Create procedure for test - shell: "mysql < {{ remote_tmp_dir }}/create-procedure.sql" - -- name: Create user with FUNCTION and PROCEDURE privileges - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - state: present - priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE' - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: Assert Create user with FUNCTION and PROCEDURE privileges - assert: - that: - - result is success - - result is changed - -- name: Create user with FUNCTION and PROCEDURE privileges - Idempotent check - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - state: present - priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE' - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: Assert Create user with FUNCTION and PROCEDURE privileges - assert: - that: - - result is success - - result is not changed - -- name: Remove user - mysql_user: - name: '{{ user_name_2 }}' - state: absent - login_unix_socket: '{{ mysql_socket }}' - -- name: Issue test teardown - cleanup databases - mysql_db: - name: "{{ item }}" - state: absent - login_unix_socket: '{{ mysql_socket }}' - loop: - - foo - - bar diff --git a/tests/integration/mysql_user/tasks/issue-64560.yaml b/tests/integration/mysql_user/tasks/issue-64560.yaml deleted file mode 100644 index 3851d85..0000000 --- a/tests/integration/mysql_user/tasks/issue-64560.yaml +++ /dev/null @@ -1,27 +0,0 @@ ---- - -- name: Set root password - mysql_user: - name: root - password: '{{ root_password }}' - login_user: root - login_password: '{{ root_password }}' - check_implicit_admin: yes - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: assert root password is changed - assert: { that: "result.changed == true" } - -- name: Set root password again - mysql_user: - name: root - password: '{{ root_password }}' - login_user: root - login_password: '{{ root_password }}' - check_implicit_admin: yes - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: Assert root password is not changed - assert: { that: "result.changed == false" } diff --git a/tests/integration/mysql_user/tasks/main.yml b/tests/integration/mysql_user/tasks/main.yml deleted file mode 100644 index 9bc78a6..0000000 --- a/tests/integration/mysql_user/tasks/main.yml +++ /dev/null @@ -1,222 +0,0 @@ -# test code for the mysql_user module -# (c) 2014, Wayne Rosario - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 dof the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# ============================================================ -# create mysql user and verify user is added to mysql database -# -- include: create_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} - -- include: resource_limits.yml - -- include: assert_user.yml user_name={{user_name_1}} - -- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} - -- include: assert_no_user.yml user_name={{user_name_1}} - -# ============================================================ -# Create mysql user that already exist on mysql database -# -- include: create_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} - -- name: create mysql user that already exist (expect changed=false) - mysql_user: - name: '{{user_name_1}}' - password: '{{user_password_1}}' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: assert output message mysql user was not created - assert: { that: "result.changed == false" } - -# ============================================================ -# remove mysql user and verify user is removed from mysql database -# -- name: remove mysql user state=absent (expect changed=true) - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - state: absent - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: assert output message mysql user was removed - assert: { that: "result.changed == true" } - -- include: assert_no_user.yml user_name={{user_name_1}} - -# ============================================================ -# remove mysql user that does not exist on mysql database -# -- name: remove mysql user that does not exist state=absent (expect changed=false) - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - state: absent - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: assert output message mysql user that does not exist - assert: { that: "result.changed == false" } - -- include: assert_no_user.yml user_name={{user_name_1}} - -# ============================================================ -# Create user with no privileges and verify default privileges are assign -# -- name: create user with select privilege state=present (expect changed=true) - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- include: assert_user.yml user_name={{user_name_1}} priv=USAGE - -- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} - -- include: assert_no_user.yml user_name={{user_name_1}} - -# ============================================================ -# Create user with select privileges and verify select privileges are assign -# -- name: create user with select privilege state=present (expect changed=true) - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - state: present - priv: '*.*:SELECT' - login_unix_socket: '{{ mysql_socket }}' - register: result - -- include: assert_user.yml user_name={{user_name_2}} priv=SELECT - -- include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_2 }} - -- include: assert_no_user.yml user_name={{user_name_2}} - -# ============================================================ -# Assert user has access to multiple databases -# -- name: give users access to multiple databases - mysql_user: - name: '{{ item[0] }}' - priv: '{{ item[1] }}.*:ALL' - append_privs: yes - password: '{{ user_password_1 }}' - login_unix_socket: '{{ mysql_socket }}' - with_nested: - - [ '{{ user_name_1 }}', '{{ user_name_2 }}'] - - "{{db_names}}" - -- name: show grants access for user1 on multiple database - command: mysql "-e SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost';" - register: result - -- name: assert grant access for user1 on multiple database - assert: { that: "'{{ item }}' in result.stdout" } - with_items: "{{db_names}}" - -- name: show grants access for user2 on multiple database - command: mysql "-e SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost';" - register: result - -- name: assert grant access for user2 on multiple database - assert: { that: "'{{ item }}' in result.stdout" } - with_items: "{{db_names}}" - -- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} - -- include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_1 }} - -- name: give user access to database via wildcard - mysql_user: - name: '{{ user_name_1 }}' - priv: '%db.*:SELECT' - append_privs: yes - password: '{{ user_password_1 }}' - login_unix_socket: '{{ mysql_socket }}' - -- name: show grants access for user1 on multiple database - command: mysql "-e SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost';" - register: result - -- name: assert grant access for user1 on multiple database - assert: - that: - - "'%db' in result.stdout" - - "'SELECT' in result.stdout" - -- name: change user access to database via wildcard - mysql_user: - name: '{{ user_name_1 }}' - priv: '%db.*:INSERT' - append_privs: yes - password: '{{ user_password_1 }}' - login_unix_socket: '{{ mysql_socket }}' - -- name: show grants access for user1 on multiple database - command: mysql "-e SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost';" - register: result - -- name: assert grant access for user1 on multiple database - assert: - that: - - "'%db' in result.stdout" - - "'INSERT' in result.stdout" - -- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} - -# ============================================================ -# Update user password for a user. -# Assert the user password is updated and old password can no longer be used. -# -#- include: user_password_update_test.yml - -# ============================================================ -# 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 - -# ============================================================ -# 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 - -# ============================================================ -# 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 - -# ============================================================ -# 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 - -# Tests for the priv parameter with dict value (https://github.com/ansible/ansible/issues/57533) -- include: test_priv_dict.yml - -- import_tasks: issue-29511.yaml - tags: - - issue-29511 - -- import_tasks: issue-64560.yaml - tags: - - issue-64560 diff --git a/tests/integration/mysql_user/tasks/remove_user.yml b/tests/integration/mysql_user/tasks/remove_user.yml deleted file mode 100644 index 9546760..0000000 --- a/tests/integration/mysql_user/tasks/remove_user.yml +++ /dev/null @@ -1,59 +0,0 @@ -# test code to remove mysql user -# (c) 2014, Wayne Rosario - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# ============================================================ -- name: remove mysql user {{user_name}} - mysql_user: - name: '{{user_name}}' - password: '{{user_password}}' - state: absent - login_unix_socket: '{{ mysql_socket }}' - 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: - name: "" - state: present - password: 'KJFDY&D*Sfuydsgf' - login_unix_socket: '{{ mysql_socket }}' - -- name: remove blank mysql user with hosts=all (expect changed) - mysql_user: - user: "" - host_all: true - state: absent - login_unix_socket: '{{ mysql_socket }}' - 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: - user: "" - host_all: true - state: absent - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: assert changed is true for removing all blank users - assert: { that: "result.changed == false" } diff --git a/tests/integration/mysql_user/tasks/resource_limits.yml b/tests/integration/mysql_user/tasks/resource_limits.yml deleted file mode 100644 index 1e2928f..0000000 --- a/tests/integration/mysql_user/tasks/resource_limits.yml +++ /dev/null @@ -1,112 +0,0 @@ -# test code for resource_limits parameter - -- block: - - - name: Drop mysql user {{ user_name_1 }} if exists - mysql_user: - name: '{{ user_name_1 }}' - state: absent - login_unix_socket: '{{ mysql_socket }}' - - - name: Create mysql user {{ user_name_1 }} with resource limits in check_mode - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - resource_limits: - MAX_QUERIES_PER_HOUR: 10 - MAX_CONNECTIONS_PER_HOUR: 5 - check_mode: yes - register: result - - - assert: - that: - - result is changed - - - name: Create mysql user {{ user_name_1 }} with resource limits in actual mode - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - resource_limits: - MAX_QUERIES_PER_HOUR: 10 - MAX_CONNECTIONS_PER_HOUR: 5 - register: result - - - assert: - that: - - result is changed - - - name: Check - mysql_query: - query: > - SELECT User FROM mysql.user WHERE User = '{{ user_name_1 }}' AND Host = 'localhost' - AND max_questions = 10 AND max_connections = 5 - login_unix_socket: '{{ mysql_socket }}' - register: result - - - assert: - that: - - result.rowcount[0] == 1 - - - name: Try to set the same limits again in check mode - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - resource_limits: - MAX_QUERIES_PER_HOUR: 10 - MAX_CONNECTIONS_PER_HOUR: 5 - check_mode: yes - register: result - - - assert: - that: - - result is not changed - - - name: Try to set the same limits again in actual mode - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - resource_limits: - MAX_QUERIES_PER_HOUR: 10 - MAX_CONNECTIONS_PER_HOUR: 5 - register: result - - - assert: - that: - - result is not changed - - - name: Change limits - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - resource_limits: - MAX_QUERIES_PER_HOUR: 5 - MAX_CONNECTIONS_PER_HOUR: 5 - register: result - - - assert: - that: - - result is changed - - - name: Check - mysql_query: - query: > - SELECT User FROM mysql.user WHERE User = '{{ user_name_1 }}' AND Host = 'localhost' - AND max_questions = 5 AND max_connections = 5 - login_unix_socket: '{{ mysql_socket }}' - register: result - - - assert: - that: - - result.rowcount[0] == 1 - - when: (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version >= '18') or (ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '8') diff --git a/tests/integration/mysql_user/tasks/test_priv_dict.yml b/tests/integration/mysql_user/tasks/test_priv_dict.yml deleted file mode 100644 index a28cc80..0000000 --- a/tests/integration/mysql_user/tasks/test_priv_dict.yml +++ /dev/null @@ -1,46 +0,0 @@ -# Tests for priv parameter value passed as a dict -- name: Create test databases - mysql_db: - name: '{{ item }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - loop: - - data1 - - data2 - -- name: Create user with privileges - mysql_user: - name: '{{ user_name_3 }}' - password: '{{ user_password_3 }}' - priv: - "data1.*": "SELECT" - "data2.*": "SELECT" - state: present - login_unix_socket: '{{ mysql_socket }}' - -- name: Run command to show privileges for user (expect privileges in stdout) - command: mysql "-e SHOW GRANTS FOR '{{ user_name_3 }}'@'localhost';" - register: result - -- name: Assert user has giving privileges - assert: - that: - - "'GRANT SELECT ON `data1`.*' in result.stdout" - - "'GRANT SELECT ON `data2`.*' in result.stdout" - -########## -# Clean up -- name: Drop test databases - mysql_db: - name: '{{ item }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - loop: - - data1 - - data2 - -- name: Drop test user - mysql_user: - name: '{{ user_name_3 }}' - state: absent - login_unix_socket: '{{ mysql_socket }}' diff --git a/tests/integration/mysql_user/tasks/test_privs.yml b/tests/integration/mysql_user/tasks/test_privs.yml deleted file mode 100644 index cec13c2..0000000 --- a/tests/integration/mysql_user/tasks/test_privs.yml +++ /dev/null @@ -1,155 +0,0 @@ -# test code for privileges for mysql_user module -# (c) 2014, Wayne Rosario - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# ============================================================ -- name: create user with basic select privileges - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: '*.*:SELECT' - state: present - login_unix_socket: '{{ mysql_socket }}' - when: current_append_privs == "yes" - -- include: assert_user.yml user_name={{user_name_2}} priv='SELECT' - when: current_append_privs == "yes" - -- name: create user with current privileges (expect changed=true) - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: '*.*:{{current_privilege}}' - append_privs: '{{current_append_privs}}' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: assert output message for current privileges - assert: { that: "result.changed == true" } - -- name: run command to show privileges for user (expect privileges in stdout) - command: mysql "-e SHOW GRANTS FOR '{{user_name_2}}'@'localhost';" - register: result - -- name: assert user has correct privileges - assert: { that: "'GRANT {{current_privilege | replace(',', ', ')}} ON *.*' in result.stdout" } - when: current_append_privs == "no" - -- name: assert user has correct privileges - assert: { that: "'GRANT SELECT, {{current_privilege | replace(',', ', ')}} ON *.*' in result.stdout" } - when: current_append_privs == "yes" - -- name: create database using user current privileges - mysql_db: - name: '{{ db_name }}' - state: present - login_user: '{{ user_name_2 }}' - login_password: '{{ user_password_2 }}' - ignore_errors: true - -- name: run command to test that database was not created - command: mysql "-e show databases like '{{ db_name }}';" - register: result - -- name: assert database was not created - assert: { that: "'{{ db_name }}' not in result.stdout" } - -# ============================================================ -- name: Add privs to a specific table (expect changed) - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: 'jmainguy.jmainguy:ALL' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: Assert that priv changed - assert: { that: "result.changed == true" } - -- name: Add privs to a specific table (expect ok) - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: 'jmainguy.jmainguy:ALL' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: Assert that priv did not change - assert: { that: "result.changed == false" } - -# ============================================================ -- name: update user with all privileges - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: '*.*:ALL' - state: present - login_unix_socket: '{{ mysql_socket }}' - -- include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES' - -- name: create database using user - mysql_db: - name: '{{ db_name }}' - state: present - login_user: '{{ user_name_2 }}' - login_password: '{{ user_password_2 }}' - -- name: run command to test database was created using user new privileges - command: mysql "-e SHOW CREATE DATABASE {{ db_name }};" - -- name: drop database using user - mysql_db: - name: '{{ db_name }}' - state: absent - login_user: '{{ user_name_2 }}' - login_password: '{{ user_password_2 }}' - -# ============================================================ -- name: update user with a long privileges list (mysql has a special multiline grant output) - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: '*.*:CREATE USER,FILE,PROCESS,RELOAD,REPLICATION CLIENT,REPLICATION SLAVE,SHOW DATABASES,SHUTDOWN,SUPER,CREATE,DROP,EVENT,LOCK TABLES,INSERT,UPDATE,DELETE,SELECT,SHOW VIEW,GRANT' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: Assert that priv changed - assert: { that: "result.changed == true" } - -- name: Test idempotency (expect ok) - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: '*.*:CREATE USER,FILE,PROCESS,RELOAD,REPLICATION CLIENT,REPLICATION SLAVE,SHOW DATABASES,SHUTDOWN,SUPER,CREATE,DROP,EVENT,LOCK TABLES,INSERT,UPDATE,DELETE,SELECT,SHOW VIEW,GRANT' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: Assert that priv did not change - assert: { that: "result.changed == false" } - -- name: remove username - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - state: absent - login_unix_socket: '{{ mysql_socket }}' diff --git a/tests/integration/mysql_user/tasks/user_password_update_test.yml b/tests/integration/mysql_user/tasks/user_password_update_test.yml deleted file mode 100644 index a85e4ed..0000000 --- a/tests/integration/mysql_user/tasks/user_password_update_test.yml +++ /dev/null @@ -1,155 +0,0 @@ -# test code update password for the mysql_user module -# (c) 2014, Wayne Rosario - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 dof the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# ============================================================ -# Update user password for a user. -# Assert the user password is updated and old password can no longer be used. -# -- name: create user1 state=present with a password - mysql_user: - name: '{{ user_name_1 }}' - password: '{{ user_password_1 }}' - priv: '*.*:ALL' - state: present - login_unix_socket: '{{ mysql_socket }}' - -- name: create user2 state=present with a password - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: '*.*:ALL' - state: present - login_unix_socket: '{{ mysql_socket }}' - -- name: store user2 grants with old password (mysql 5.7.6 and newer) - command: mysql "-e SHOW CREATE USER '{{ user_name_2 }}'@'localhost';" - register: user_password_old_create - ignore_errors: yes - -- name: store user2 grants with old password (mysql 5.7.5 and older) - command: mysql "-e SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost';" - register: user_password_old - when: user_password_old_create is failed - -- name: update user2 state=present with same password (expect changed=false) - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_2 }}' - priv: '*.*:ALL' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- name: assert output user2 was not updated - assert: { that: "result.changed == false" } - -- include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES' - -- name: update user2 state=present with a new password (expect changed=true) - mysql_user: - name: '{{ user_name_2 }}' - password: '{{ user_password_1 }}' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result - -- include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES' - -- name: store user2 grants with old password (mysql 5.7.6 and newer) - command: mysql "-e SHOW CREATE USER '{{ user_name_2 }}'@'localhost';" - register: user_password_new_create - ignore_errors: yes - -- name: store user2 grants with new password - command: mysql "-e SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost';" - register: user_password_new - when: user_password_new_create is failed - -- name: assert output message password was update for user2 (mysql 5.7.6 and newer) - assert: { that: "user_password_old_create.stdout != user_password_new_create.stdout" } - when: user_password_new_create is not failed - -- name: assert output message password was update for user2 (mysql 5.7.5 and older) - assert: { that: "user_password_old.stdout != user_password_new.stdout" } - when: user_password_new_create is failed - -- name: create database using user2 and old password - mysql_db: - name: '{{ db_name }}' - state: present - login_user: '{{ user_name_2 }}' - login_password: '{{ user_password_2 }}' - ignore_errors: true - register: result - -- debug: var=result.msg -- name: assert output message that database not create with old password - assert: - that: - - "result.failed == true" - -- name: create database using user2 and new password - mysql_db: - name: '{{ db_name }}' - state: present - login_user: '{{ user_name_2 }}' - login_password: '{{ user_password_1 }}' - register: result - -- name: assert output message that database is created with new password - assert: { that: "result.changed == true" } - -- name: remove database - mysql_db: - name: '{{ db_name }}' - state: absent - login_unix_socket: '{{ mysql_socket }}' - -- include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} - -- include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_1 }} - -- name: Create user with Fdt8fd^34ds using hash. (expect changed=true) - mysql_user: - name: jmainguy - password: '*0cb5b86f23fdc24db19a29b8854eb860cbc47793' - encrypted: yes - login_unix_socket: '{{ mysql_socket }}' - register: encrypt_result - -- name: Check that the module made a change - assert: - that: - - "encrypt_result.changed == True" - -- name: See if the password needs to be updated. (expect changed=false) - mysql_user: - name: jmainguy - password: 'Fdt8fd^34ds' - login_unix_socket: '{{ mysql_socket }}' - register: plain_result - -- name: Check that the module did not change the password - assert: - that: - - "plain_result.changed == False" - -- name: Remove user (cleanup) - mysql_user: - name: jmainguy - state: absent diff --git a/tests/integration/mysql_variables/aliases b/tests/integration/mysql_variables/aliases deleted file mode 100644 index c72bb40..0000000 --- a/tests/integration/mysql_variables/aliases +++ /dev/null @@ -1,6 +0,0 @@ -destructive -shippable/posix/group3 -skip/aix -skip/osx -skip/freebsd -skip/rhel diff --git a/tests/integration/mysql_variables/defaults/main.yml b/tests/integration/mysql_variables/defaults/main.yml deleted file mode 100644 index e7860ac..0000000 --- a/tests/integration/mysql_variables/defaults/main.yml +++ /dev/null @@ -1,4 +0,0 @@ ---- -# defaults file for test_mysql_variables -user: 'user1' -password: 'khH&DYigjg1#' diff --git a/tests/integration/mysql_variables/meta/main.yml b/tests/integration/mysql_variables/meta/main.yml deleted file mode 100644 index e7631b0..0000000 --- a/tests/integration/mysql_variables/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - setup_mysql8 diff --git a/tests/integration/mysql_variables/tasks/main.yml b/tests/integration/mysql_variables/tasks/main.yml deleted file mode 100644 index 801fa77..0000000 --- a/tests/integration/mysql_variables/tasks/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -- import_tasks: mysql_variables.yml - when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7' diff --git a/tests/integration/mysql_variables/tasks/mysql_variables.yml b/tests/integration/mysql_variables/tasks/mysql_variables.yml deleted file mode 100644 index be42bce..0000000 --- a/tests/integration/mysql_variables/tasks/mysql_variables.yml +++ /dev/null @@ -1,412 +0,0 @@ -# test code for the mysql_variables module -# (c) 2014, Wayne Rosario - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# ============================================================ -# Verify mysql_variable successfully queries a variable -# -- set_fact: set_name='version' - -- name: read mysql variables (expect changed=false) - mysql_variables: - variable: '{{set_name}}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - -- include: assert_var_output.yml changed=false output={{result}} var_name={{set_name}} - -# ============================================================ -# Verify mysql_variable successfully updates a variable (issue:4568) -# -- set_fact: - set_name: 'delay_key_write' - set_value: 'ON' - -- name: set mysql variable - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_user: root - login_password: '{{ root_pass }}' - login_unix_socket: '{{ mysql_socket }}' - -- name: update mysql variable to same value (expect changed=false) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - -- include: assert_var.yml changed=false output={{result}} var_name={{set_name}} var_value={{set_value}} - -# ============================================================ -# Verify mysql_variable successfully updates a variable using single quotes -# -- set_fact: - set_name: 'wait_timeout' - set_value: '300' - -- name: set mysql variable to a temp value - mysql_variables: - variable: '{{set_name}}' - value: '200' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - -- name: update mysql variable value (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - -- assert: - that: - - result.queries == ["SET GLOBAL `{{ set_name }}` = {{ set_value }}"] - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -# ============================================================ -# Verify mysql_variable successfully updates a variable using double quotes -# -- set_fact: - set_name: "wait_timeout" - set_value: "400" - -- name: set mysql variable to a temp value - mysql_variables: - variable: '{{set_name}}' - value: "200" - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - -- name: update mysql variable value (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -# ============================================================ -# Verify mysql_variable successfully updates a variable using no quotes -# -- set_fact: - set_name: wait_timeout - set_value: 500 - -- name: set mysql variable to a temp value - mysql_variables: - variable: '{{set_name}}' - value: 200 - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - -- name: update mysql variable value (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -# ============================================================ -# Verify mysql_variable successfully updates a variable using an expression (e.g. 1024*4) -# -- name: set mysql variable value to an expression - mysql_variables: - variable: max_tmp_tables - value: "1024*4" - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='Incorrect argument type to variable' - -# ============================================================ -# Verify mysql_variable fails when setting an incorrect value (out of range) -# -- name: set mysql variable value to a number out of range - mysql_variables: - variable: max_tmp_tables - value: -1 - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='Truncated incorrect' - -# ============================================================ -# Verify mysql_variable fails when setting an incorrect value (incorrect type) -# -- name: set mysql variable value to a non-valid value number - mysql_variables: - variable: max_tmp_tables - value: TEST - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='Incorrect argument type to variable' - -# ============================================================ -# Verify mysql_variable fails when setting an unknown variable -# -- name: set a non mysql variable - mysql_variables: - variable: my_sql_variable - value: ON - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='Variable not available' - -# ============================================================ -# Verify mysql_variable fails when setting a read-only variable -# -- name: set value of a read only mysql variable - mysql_variables: - variable: character_set_system - value: utf16 - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='read only variable' - -#============================================================= -# Verify mysql_variable works with the login_user and login_password parameters -# -- name: create mysql user - mysql_user: - name: '{{user}}' - password: '{{password}}' - state: present - priv: '*.*:ALL' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - -- set_fact: - set_name: wait_timeout - set_value: 77 - -- name: query mysql_variable using login_user and password_password - mysql_variables: - variable: '{{set_name}}' - login_user: '{{user}}' - login_password: '{{password}}' - register: result - -- include: assert_var_output.yml changed=false output={{result}} var_name={{set_name}} - -- name: set mysql variable to temp value using user login and password (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: 20 - login_user: '{{user}}' - login_password: '{{password}}' - register: result - -- name: update mysql variable value using user login and password (expect changed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_user: '{{user}}' - login_password: '{{password}}' - register: result - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -#============================================================ -# Verify mysql_variable fails with an incorrect login_password parameter -# -- set_fact: - set_name: connect_timeout - set_value: 10 - -- name: query mysql_variable using incorrect login_password - mysql_variables: - variable: '{{set_name}}' - login_user: '{{user}}' - login_password: 'wrongpassword' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' - -- name: update mysql variable value using incorrect login_password (expect failed=true) - mysql_variables: - variable: '{{set_name}}' - value: '{{set_value}}' - login_user: '{{user}}' - login_password: 'this is an incorrect password' - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' - -#============================================================ -# Verify mysql_variable fails with an incorrect login_host parameter -# -- name: query mysql_variable using incorrect login_host - mysql_variables: - variable: wait_timeout - login_host: '12.0.0.9' - login_user: '{{user}}' - login_password: '{{password}}' - connect_timeout: 5 - register: result - ignore_errors: true - -- include: assert_fail_msg.yml output={{result}} msg='unable to connect to database' - -- name: remove mysql_user {{user}} - mysql_user: - name: '{{user}}' - state: absent - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - -#========================================= -# Check mode 'persist' and 'persist_only': -# -- name: update mysql variable value (expect changed=true) in persist mode - mysql_variables: - variable: '{{ set_name }}' - value: '{{ set_value }}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - mode: persist - register: result - -- assert: - that: - - result.queries == ["SET PERSIST `{{ set_name }}` = {{ set_value }}"] - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -- name: try to update mysql variable value (expect changed=false) in persist mode again - mysql_variables: - variable: '{{ set_name }}' - value: '{{ set_value }}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - mode: persist - register: result - -- include: assert_var.yml changed=false output={{result}} var_name={{set_name}} var_value='{{set_value}}' - -- name: set mysql variable to a temp value - mysql_variables: - variable: '{{ set_name }}' - value: '200' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - mode: persist - -- name: update mysql variable value (expect changed=true) in persist_only mode - mysql_variables: - variable: '{{ set_name }}' - value: '{{ set_value }}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - mode: persist_only - register: result - -- assert: - that: - - result is changed - - result.queries == ["SET PERSIST_ONLY `{{ set_name }}` = {{ set_value }}"] - -- name: try to update mysql variable value (expect changed=false) in persist_only mode again - mysql_variables: - variable: '{{ set_name }}' - value: '{{ set_value }}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - mode: persist_only - register: result - -- assert: - that: - - result is not changed - -- set_fact: - set_name: max_connections - set_value: 105 - def_val: 151 - -- name: update mysql variable value (expect changed=true) in persist_only mode - mysql_variables: - variable: '{{ set_name }}' - value: '{{ set_value }}' - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - mode: persist_only - register: result - -- include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{def_val}}' - -# Bugfix of https://github.com/ansible/ansible/issues/54239 -- name: set variable containing dot - mysql_variables: - login_unix_socket: '{{ mysql_socket }}' - login_user: root - login_password: '{{ root_pass }}' - variable: validate_password.policy - value: LOW - mode: persist_only - register: result - -- assert: - that: - - result is changed - - result.queries == ["SET PERSIST_ONLY `validate_password`.`policy` = LOW"] diff --git a/tests/integration/mariadb_replication/aliases b/tests/integration/old_mariadb_replication/aliases similarity index 100% rename from tests/integration/mariadb_replication/aliases rename to tests/integration/old_mariadb_replication/aliases diff --git a/tests/integration/mariadb_replication/defaults/main.yml b/tests/integration/old_mariadb_replication/defaults/main.yml similarity index 100% rename from tests/integration/mariadb_replication/defaults/main.yml rename to tests/integration/old_mariadb_replication/defaults/main.yml diff --git a/tests/integration/mariadb_replication/meta/main.yml b/tests/integration/old_mariadb_replication/meta/main.yml similarity index 100% rename from tests/integration/mariadb_replication/meta/main.yml rename to tests/integration/old_mariadb_replication/meta/main.yml diff --git a/tests/integration/mariadb_replication/tasks/main.yml b/tests/integration/old_mariadb_replication/tasks/main.yml similarity index 100% rename from tests/integration/mariadb_replication/tasks/main.yml rename to tests/integration/old_mariadb_replication/tasks/main.yml diff --git a/tests/integration/mariadb_replication/tasks/mariadb_master_use_gtid.yml b/tests/integration/old_mariadb_replication/tasks/mariadb_master_use_gtid.yml similarity index 100% rename from tests/integration/mariadb_replication/tasks/mariadb_master_use_gtid.yml rename to tests/integration/old_mariadb_replication/tasks/mariadb_master_use_gtid.yml diff --git a/tests/integration/mariadb_replication/tasks/mariadb_replication_connection_name.yml b/tests/integration/old_mariadb_replication/tasks/mariadb_replication_connection_name.yml similarity index 100% rename from tests/integration/mariadb_replication/tasks/mariadb_replication_connection_name.yml rename to tests/integration/old_mariadb_replication/tasks/mariadb_replication_connection_name.yml diff --git a/tests/integration/mariadb_replication/tasks/mariadb_replication_initial.yml b/tests/integration/old_mariadb_replication/tasks/mariadb_replication_initial.yml similarity index 100% rename from tests/integration/mariadb_replication/tasks/mariadb_replication_initial.yml rename to tests/integration/old_mariadb_replication/tasks/mariadb_replication_initial.yml diff --git a/tests/integration/mysql_replication/aliases b/tests/integration/old_mysql_replication/aliases similarity index 100% rename from tests/integration/mysql_replication/aliases rename to tests/integration/old_mysql_replication/aliases diff --git a/tests/integration/mysql_replication/defaults/main.yml b/tests/integration/old_mysql_replication/defaults/main.yml similarity index 100% rename from tests/integration/mysql_replication/defaults/main.yml rename to tests/integration/old_mysql_replication/defaults/main.yml diff --git a/tests/integration/mysql_replication/meta/main.yml b/tests/integration/old_mysql_replication/meta/main.yml similarity index 100% rename from tests/integration/mysql_replication/meta/main.yml rename to tests/integration/old_mysql_replication/meta/main.yml diff --git a/tests/integration/mysql_replication/tasks/main.yml b/tests/integration/old_mysql_replication/tasks/main.yml similarity index 100% rename from tests/integration/mysql_replication/tasks/main.yml rename to tests/integration/old_mysql_replication/tasks/main.yml diff --git a/tests/integration/mysql_replication/tasks/mysql_replication_channel.yml b/tests/integration/old_mysql_replication/tasks/mysql_replication_channel.yml similarity index 100% rename from tests/integration/mysql_replication/tasks/mysql_replication_channel.yml rename to tests/integration/old_mysql_replication/tasks/mysql_replication_channel.yml diff --git a/tests/integration/mysql_replication/tasks/mysql_replication_initial.yml b/tests/integration/old_mysql_replication/tasks/mysql_replication_initial.yml similarity index 100% rename from tests/integration/mysql_replication/tasks/mysql_replication_initial.yml rename to tests/integration/old_mysql_replication/tasks/mysql_replication_initial.yml diff --git a/tests/integration/mysql_replication/tasks/mysql_replication_master_delay.yml b/tests/integration/old_mysql_replication/tasks/mysql_replication_master_delay.yml similarity index 100% rename from tests/integration/mysql_replication/tasks/mysql_replication_master_delay.yml rename to tests/integration/old_mysql_replication/tasks/mysql_replication_master_delay.yml diff --git a/tests/integration/mysql_replication/tasks/mysql_replication_resetmaster_mode.yml b/tests/integration/old_mysql_replication/tasks/mysql_replication_resetmaster_mode.yml similarity index 100% rename from tests/integration/mysql_replication/tasks/mysql_replication_resetmaster_mode.yml rename to tests/integration/old_mysql_replication/tasks/mysql_replication_resetmaster_mode.yml diff --git a/tests/integration/setup_mysql8/defaults/main.yml b/tests/integration/setup_mysql8/defaults/main.yml deleted file mode 100644 index 66b75a1..0000000 --- a/tests/integration/setup_mysql8/defaults/main.yml +++ /dev/null @@ -1,21 +0,0 @@ -repo_link: https://repo.mysql.com/mysql80-community-release-el{{ ansible_facts.distribution_major_version }}.rpm -my_cnf: /etc/my.cnf - -mysql_data_dirs: - - /var/lib/mysql - - /usr/mysql - -mysql_support_packages: - - MySQL-python - -mysql_server_packages: - - mysql-community-server - -mysql_cleanup_packages: - - mysql-community-client - - mysql-community-common - - mysql-community-libs - - mysql-community-libs-compat - - mysql-community-server - - mysql80-community-release - - python3-PyMySQL diff --git a/tests/integration/setup_mysql8/files/my.cnf b/tests/integration/setup_mysql8/files/my.cnf deleted file mode 100644 index 7fdc2af..0000000 --- a/tests/integration/setup_mysql8/files/my.cnf +++ /dev/null @@ -1,7 +0,0 @@ -[mysqld] -datadir=/var/lib/mysql -socket=/var/lib/mysql/mysql.sock -log-error=/var/log/mysqld.log -pid-file=/var/run/mysqld/mysqld.pid -default_authentication_plugin=mysql_native_password -skip-grant-tables diff --git a/tests/integration/setup_mysql8/handlers/main.yml b/tests/integration/setup_mysql8/handlers/main.yml deleted file mode 100644 index 6d30b57..0000000 --- a/tests/integration/setup_mysql8/handlers/main.yml +++ /dev/null @@ -1,29 +0,0 @@ -- name: stop mysql service - service: - name: mysqld - state: stopped - listen: cleanup mysql8 - -- name: remove repo - # yum: - # name: mysql80-community-release - # state: absent - # Work around for a bug in the dnf module. Use the module once that gets fixed. - # https://github.com/ansible/ansible/issues/64294 - command: "{{ ansible_facts.pkg_mgr}} -y erase mysql80-community-release" - args: - warn: no - listen: cleanup mysql8 - -- name: remove mysql packages - yum: - name: '{{ mysql_support_packages | union(mysql_server_packages) | union(mysql_cleanup_packages) }}' - state: absent - listen: cleanup mysql8 - -- name: remove mysql data - file: - path: "{{ item }}" - state: absent - loop: "{{ mysql_data_dirs }}" - listen: cleanup mysql8 diff --git a/tests/integration/setup_mysql8/tasks/main.yml b/tests/integration/setup_mysql8/tasks/main.yml deleted file mode 100644 index 86ea1f8..0000000 --- a/tests/integration/setup_mysql8/tasks/main.yml +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -# Setup MySQL 8: -- name: Include distribution specific variables - include_vars: "{{ lookup('first_found', params) }}" - vars: - params: - files: - - '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml' - - '{{ ansible_facts.os_family }}.yml' - - 'default.yml' - paths: vars - -- import_tasks: setup_mysql8.yml - when: - - ansible_facts.distribution == 'CentOS' - - ansible_facts.distribution_major_version is version_compare('7', '>=') diff --git a/tests/integration/setup_mysql8/tasks/setup_mysql8.yml b/tests/integration/setup_mysql8/tasks/setup_mysql8.yml deleted file mode 100644 index 29f4d9d..0000000 --- a/tests/integration/setup_mysql8/tasks/setup_mysql8.yml +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -- name: Install PyMySQL package via pip - pip: - name: PyMySQL - state: present - -- name: Install MySQL repo - yum: - name: '{{ repo_link }}' - notify: cleanup mysql8 - -# These packages come from AppStream in RHEL 8, so they need to be done in a separate task -- name: Install MySQL support packages - yum: - name: "{{ mysql_support_packages }}" - notify: cleanup mysql8 - -- name: Install MySQL community server - yum: - name: '{{ mysql_server_packages }}' - disablerepo: '{{ mysql_disablerepo | default(omit) }}' - notify: cleanup mysql8 - -- name: Copy my.cnf - copy: - src: my.cnf - dest: '{{ my_cnf }}' - -- name: Start MySQL - service: - name: mysqld - state: started - -### Debug ####################### -#- name: Debug -# shell: cat /var/log/mysqld.log -################################# - -- name: Check connection to the server - shell: 'echo "SHOW DATABASES;" | mysql' - -- name: Check connection to the server - shell: "echo \"SHOW VARIABLES LIKE '%version%';\" | mysql" - -- name: Detect socket path - shell: 'echo "show variables like ''socket''\G" | mysql | grep ''Value: '' | sed ''s/[ ]\+Value: //''' - register: _socket_path - -- name: Set socket path - set_fact: - mysql_socket: '{{ _socket_path["stdout"] }}' - -- name: Set root pass - set_fact: - root_pass: "dlsafjlkjdsaK1#" - -- name: Set root password - shell: 'echo "flush privileges; ALTER USER ''root''@''localhost'' IDENTIFIED WITH mysql_native_password BY ''{{ root_pass }}'';" | mysql' - -- name: Change configuration - lineinfile: - path: '{{ my_cnf }}' - line: skip-grant-tables - state: absent - -- name: Restart MySQL - service: - name: mysqld - state: restarted diff --git a/tests/integration/setup_mysql8/vars/CentOS-8.yml b/tests/integration/setup_mysql8/vars/CentOS-8.yml deleted file mode 100644 index 3d61bda..0000000 --- a/tests/integration/setup_mysql8/vars/CentOS-8.yml +++ /dev/null @@ -1,4 +0,0 @@ -mysql_support_packages: - - python3-PyMySQL - -mysql_disablerepo: AppStream diff --git a/tests/integration/setup_mysql8/vars/Debian.yml b/tests/integration/setup_mysql8/vars/Debian.yml deleted file mode 100644 index 7832326..0000000 --- a/tests/integration/setup_mysql8/vars/Debian.yml +++ /dev/null @@ -1,3 +0,0 @@ -mysql_data_dirs: - - /var/lib/mysql - - /usr/share/mysql diff --git a/tests/integration/setup_mysql8/vars/RedHat-8.yml b/tests/integration/setup_mysql8/vars/RedHat-8.yml deleted file mode 100644 index f636617..0000000 --- a/tests/integration/setup_mysql8/vars/RedHat-8.yml +++ /dev/null @@ -1,4 +0,0 @@ -mysql_support_packages: - - python3-PyMySQL - -mysql_disablerepo: rhel-8-for-x86_64-appstream-rpms diff --git a/tests/integration/setup_mysql8/vars/default.yml b/tests/integration/setup_mysql8/vars/default.yml deleted file mode 100644 index e69de29..0000000 diff --git a/tests/integration/setup_mysql_db/defaults/main.yml b/tests/integration/setup_mysql_db/defaults/main.yml deleted file mode 100644 index 47712dc..0000000 --- a/tests/integration/setup_mysql_db/defaults/main.yml +++ /dev/null @@ -1,18 +0,0 @@ -mysql_service: mysqld - -mysql_packages: - - mysql-server - - MySQL-python - - bzip2 - -mysql_cleanup_packages: - - mysql-community-client - - mysql-community-common - - mysql-community-libs - - mysql-community-libs-compat - - mysql-community-server - - mysql80-community-release - -mysql_data_dirs: - - /var/lib/mysql - - /usr/mysql diff --git a/tests/integration/setup_mysql_db/handlers/main.yml b/tests/integration/setup_mysql_db/handlers/main.yml deleted file mode 100644 index 5b54ea2..0000000 --- a/tests/integration/setup_mysql_db/handlers/main.yml +++ /dev/null @@ -1,25 +0,0 @@ -- name: stop mysql service - service: - name: "{{ mysql_service }}" - state: stopped - listen: cleanup mysql - -- name: remove mysql packages - action: '{{ ansible_facts.pkg_mgr }}' - args: - name: "{{ item }}" - state: absent - loop: "{{ mysql_packages | union(mysql_cleanup_packages) }}" - listen: cleanup mysql - -- name: remove mysql data - file: - path: "{{ item }}" - state: absent - loop: "{{ mysql_data_dirs }}" - listen: cleanup mysql - -- name: remove pip packages - pip: - name: mysql-python - state: absent diff --git a/tests/integration/setup_mysql_db/meta/main.yml b/tests/integration/setup_mysql_db/meta/main.yml deleted file mode 100644 index 5438ced..0000000 --- a/tests/integration/setup_mysql_db/meta/main.yml +++ /dev/null @@ -1,2 +0,0 @@ -dependencies: - - setup_pkg_mgr diff --git a/tests/integration/setup_mysql_db/tasks/main.yml b/tests/integration/setup_mysql_db/tasks/main.yml deleted file mode 100644 index b7c5e06..0000000 --- a/tests/integration/setup_mysql_db/tasks/main.yml +++ /dev/null @@ -1,112 +0,0 @@ -# setup code for the mysql_db module -# (c) 2014, Wayne Rosario - -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# ============================================================ -- name: python 2 - set_fact: - python_suffix: "" - when: ansible_python_version is version('3', '<') - -- name: python 3 - set_fact: - python_suffix: "-py3" - when: ansible_python_version is version('3', '>=') - -- name: Include distribution specific variables - include_vars: "{{ lookup('first_found', params) }}" - vars: - params: - files: - - '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}{{ python_suffix }}.yml' - - '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml' - - '{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}{{ python_suffix }}.yml' - - '{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_major_version }}.yml' - - '{{ ansible_facts.distribution }}{{ python_suffix }}.yml' - - '{{ ansible_facts.os_family }}{{ python_suffix }}.yml' - - 'default{{ python_suffix }}.yml' - paths: "{{ role_path }}/vars" - -- name: install mysqldb_test rpm dependencies - yum: - name: "{{ mysql_packages }}" - state: latest - when: ansible_facts.pkg_mgr == 'yum' - notify: cleanup mysql - -- name: install mysqldb_test rpm dependencies - dnf: - name: '{{ mysql_packages }}' - state: latest - install_weak_deps: False # mariadb-server has a weak dep on python2 which break Python 3 test environments - when: ansible_facts.pkg_mgr == 'dnf' - notify: cleanup mysql - -- name: install mysqldb_test debian dependencies - apt: - name: "{{ mysql_packages }}" - state: latest - when: ansible_facts.pkg_mgr == 'apt' - notify: cleanup mysql - -- name: install mysqldb_test opensuse dependencies - zypper: - name: "{{ mysql_packages }}" - state: latest - when: ansible_facts.pkg_mgr in ['zypper', 'community.general.zypper'] - notify: cleanup mysql - -- name: install mysqldb_test FreeBSD dependencies - package: - name: "{{ mysql_packages }}" - state: present - when: ansible_os_family == "FreeBSD" - notify: cleanup mysql - -- name: install mysql-python package via pip (FreeBSD) - pip: - name: mysql-python - state: present - when: ansible_os_family == "FreeBSD" - notify: - - cleanup mysql - - remove pip packages - -- name: enable mysql-server service (FreeBSD) - lineinfile: - path: /etc/rc.conf - line: 'mysql_server_enable="YES"' - when: ansible_os_family == "FreeBSD" - -- name: apply work-around for OverlayFS issue - # https://github.com/docker/for-linux/issues/72#issuecomment-319904698 - command: find {{ mysql_data_dirs[0] }} -type f -exec touch {} ; - # find will fail if mysql has never been started, as the directory won't exist - ignore_errors: yes - -- name: restart mysql_db service - service: - name: "{{ mysql_service }}" - state: restarted - -- name: Detect socket path - shell: 'echo "show variables like ''socket''\G" | mysql | grep ''Value: '' | sed ''s/[ ]\+Value: //''' - register: _socket_path - -- name: Set socket path - set_fact: - mysql_socket: '{{ _socket_path["stdout"] }}' diff --git a/tests/integration/setup_mysql_db/vars/Debian.yml b/tests/integration/setup_mysql_db/vars/Debian.yml deleted file mode 100644 index 52062c7..0000000 --- a/tests/integration/setup_mysql_db/vars/Debian.yml +++ /dev/null @@ -1,16 +0,0 @@ -mysql_service: 'mysql' - -mysql_packages: - - mysql-server - - python-mysqldb - - bzip2 - -mysql_cleanup_packages: - - mysql-client* - - mysql-server* - - mysql-common - - mysql-sandbox - -mysql_data_dirs: - - /var/lib/mysql - - /usr/share/mysql diff --git a/tests/integration/setup_mysql_db/vars/Fedora-py3.yml b/tests/integration/setup_mysql_db/vars/Fedora-py3.yml deleted file mode 100644 index fa7d06e..0000000 --- a/tests/integration/setup_mysql_db/vars/Fedora-py3.yml +++ /dev/null @@ -1,6 +0,0 @@ -mysql_service: 'mariadb' - -mysql_packages: - - mariadb-server - - python3-PyMySQL - - bzip2 diff --git a/tests/integration/setup_mysql_db/vars/Fedora.yml b/tests/integration/setup_mysql_db/vars/Fedora.yml deleted file mode 100644 index 718326a..0000000 --- a/tests/integration/setup_mysql_db/vars/Fedora.yml +++ /dev/null @@ -1,6 +0,0 @@ -mysql_service: 'mariadb' - -mysql_packages: - - mariadb-server - - python-PyMySQL - - bzip2 diff --git a/tests/integration/setup_mysql_db/vars/FreeBSD.yml b/tests/integration/setup_mysql_db/vars/FreeBSD.yml deleted file mode 100644 index af45ebf..0000000 --- a/tests/integration/setup_mysql_db/vars/FreeBSD.yml +++ /dev/null @@ -1,5 +0,0 @@ -mysql_service: 'mysql-server' - -mysql_packages: - - mariadb101-server - - py-pymysql diff --git a/tests/integration/setup_mysql_db/vars/RedHat-7.yml b/tests/integration/setup_mysql_db/vars/RedHat-7.yml deleted file mode 100644 index f8b29fd..0000000 --- a/tests/integration/setup_mysql_db/vars/RedHat-7.yml +++ /dev/null @@ -1,6 +0,0 @@ -mysql_service: 'mariadb' - -mysql_packages: - - mariadb-server - - MySQL-python - - bzip2 diff --git a/tests/integration/setup_mysql_db/vars/RedHat-8.yml b/tests/integration/setup_mysql_db/vars/RedHat-8.yml deleted file mode 100644 index fa7d06e..0000000 --- a/tests/integration/setup_mysql_db/vars/RedHat-8.yml +++ /dev/null @@ -1,6 +0,0 @@ -mysql_service: 'mariadb' - -mysql_packages: - - mariadb-server - - python3-PyMySQL - - bzip2 diff --git a/tests/integration/setup_mysql_db/vars/RedHat.yml b/tests/integration/setup_mysql_db/vars/RedHat.yml deleted file mode 100644 index 742c352..0000000 --- a/tests/integration/setup_mysql_db/vars/RedHat.yml +++ /dev/null @@ -1,6 +0,0 @@ -mysql_service: 'mysqld' - -mysql_packages: - - mysql-server - - MySQL-python - - bzip2 diff --git a/tests/integration/setup_mysql_db/vars/Suse-py3.yml b/tests/integration/setup_mysql_db/vars/Suse-py3.yml deleted file mode 100644 index adf2754..0000000 --- a/tests/integration/setup_mysql_db/vars/Suse-py3.yml +++ /dev/null @@ -1,6 +0,0 @@ -mysql_service: 'mysql' - -mysql_packages: - - mariadb - - python3-PyMySQL - - bzip2 diff --git a/tests/integration/setup_mysql_db/vars/Suse.yml b/tests/integration/setup_mysql_db/vars/Suse.yml deleted file mode 100644 index a48a2e1..0000000 --- a/tests/integration/setup_mysql_db/vars/Suse.yml +++ /dev/null @@ -1,6 +0,0 @@ -mysql_service: 'mysql' - -mysql_packages: - - mariadb - - python-PyMySQL - - bzip2 diff --git a/tests/integration/setup_mysql_db/vars/Ubuntu-py3.yml b/tests/integration/setup_mysql_db/vars/Ubuntu-py3.yml deleted file mode 100644 index 7728244..0000000 --- a/tests/integration/setup_mysql_db/vars/Ubuntu-py3.yml +++ /dev/null @@ -1,16 +0,0 @@ -mysql_service: 'mysql' - -mysql_packages: - - mysql-server - - python3-pymysql - - bzip2 - -mysql_cleanup_packages: - - mysql-client* - - mysql-server* - - mysql-common - - mysql-sandbox - -mysql_data_dirs: - - /var/lib/mysql - - /usr/share/mysql diff --git a/tests/integration/setup_mysql_db/vars/default-py3.yml b/tests/integration/setup_mysql_db/vars/default-py3.yml deleted file mode 100644 index e69de29..0000000 diff --git a/tests/integration/setup_mysql_db/vars/default.yml b/tests/integration/setup_mysql_db/vars/default.yml deleted file mode 100644 index e69de29..0000000 diff --git a/tests/integration/setup_mysql_replication/defaults/main.yml b/tests/integration/setup_mysql_replication/defaults/main.yml deleted file mode 100644 index ad06a0a..0000000 --- a/tests/integration/setup_mysql_replication/defaults/main.yml +++ /dev/null @@ -1,14 +0,0 @@ -# There is no MySQL 5.7 for RHEL 8. This will need to be retooled to use 8.0 for RHEL 8 or use the setup_mysql8 role for everything -repo_link: https://repo.mysql.com/mysql57-community-release-el{{ ansible_facts.distribution_major_version }}.rpm -repo_name: mysql-community -mysql_package_name: mysql-community-server - -master_port: 3306 -standby_port: 3307 -master_datadir: /var/lib/mysql_master -master_cnf: /etc/my-1.cnf -standby_cnf: /etc/my-2.cnf -standby_datadir: /var/lib/mysql_standby -standby_logdir: /var/log/mysql_standby -default_logdir: /var/log/mysql -mysqld_err_log: '{{ default_logdir }}/mysql-err.log' diff --git a/tests/integration/setup_mysql_replication/tasks/main.yml b/tests/integration/setup_mysql_replication/tasks/main.yml deleted file mode 100644 index 0f507f7..0000000 --- a/tests/integration/setup_mysql_replication/tasks/main.yml +++ /dev/null @@ -1,8 +0,0 @@ -# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -# Setup MySQL master-standby replication into one container: -- import_tasks: setup_mysql_cluster.yml - when: - - ansible_facts.distribution == 'CentOS' - - ansible_facts.distribution_major_version is version('7', '==') diff --git a/tests/integration/setup_mysql_replication/tasks/setup_mysql_cluster.yml b/tests/integration/setup_mysql_replication/tasks/setup_mysql_cluster.yml deleted file mode 100644 index 62bf6dd..0000000 --- a/tests/integration/setup_mysql_replication/tasks/setup_mysql_cluster.yml +++ /dev/null @@ -1,65 +0,0 @@ -# We run two servers listening different ports -# to be able to check replication (one server for master, another for standby). - -- name: Install PyMySQL package via pip - pip: - name: PyMySQL - state: present - -- name: Install Repo - yum: - name: '{{ repo_link }}' - -- name: Install MySQL community server - yum: - name: '{{ mysql_package_name }}' - -- name: Create directories - file: - state: directory - path: "{{ item }}" - owner: mysql - group: mysql - loop: - - "{{ master_datadir }}" - - "{{ standby_datadir }}" - - "{{ standby_logdir }}" - - "{{ default_logdir }}" - -- name: Copy cnf templates - template: - src: '{{ item.conf_templ }}' - dest: '{{ item.conf_dest }}' - owner: mysql - group: mysql - force: yes - loop: - - { conf_templ: my-1.cnf.j2, conf_dest: '{{ master_cnf }}' } - - { conf_templ: my-2.cnf.j2, conf_dest: '{{ standby_cnf }}' } - -- name: Initialize DBs - shell: 'mysqld --user=mysql --initialize-insecure --datadir={{ item }}' - loop: - - '{{ master_datadir }}' - - '{{ standby_datadir }}' - -- name: Start master services - shell: 'mysqld --defaults-file={{ master_cnf }} --user=mysql --datadir={{ master_datadir }} --log-error={{ mysqld_err_log }} &' - -- name: Start standby services - shell: 'mysqld --defaults-file={{ standby_cnf }} --user=mysql --datadir={{ standby_datadir }} --log-error={{ mysqld_err_log }} &' - -- name: Pause - pause: seconds=3 - -########### For painful debug uncomment the lines below ## -#- name: DEBUG Check log -# shell: 'cat {{ mysqld_err_log }}' -# ignore_errors: yes -########################################################## - -- name: Check connection to the master - shell: 'echo "SHOW DATABASES;" | mysql -P {{ master_port }} -h 127.0.0.1' - -- name: Check connection to the standby - shell: "echo \"SHOW VARIABLES LIKE '%version%';\" | mysql -P {{ standby_port }} -h 127.0.0.1" diff --git a/tests/integration/setup_mysql_replication/templates/my-1.cnf.j2 b/tests/integration/setup_mysql_replication/templates/my-1.cnf.j2 deleted file mode 100644 index 7e8787a..0000000 --- a/tests/integration/setup_mysql_replication/templates/my-1.cnf.j2 +++ /dev/null @@ -1,11 +0,0 @@ -[mysqld] -server_id = 1 -port = {{ master_port }} -datadir = {{ master_datadir }} -socket = {{ master_datadir }}/mysql.sock -pid-file = {{ master_datadir }}/mysql.pid -#mysqladmin = /usr/bin/mysqladmin -log_bin = /var/log/mysql/mysql-bin.log -sync_binlog = 1 -binlog-format = ROW -innodb_flush_log_at_trx_commit = 1 diff --git a/tests/integration/setup_mysql_replication/templates/my-2.cnf.j2 b/tests/integration/setup_mysql_replication/templates/my-2.cnf.j2 deleted file mode 100644 index 2d7550b..0000000 --- a/tests/integration/setup_mysql_replication/templates/my-2.cnf.j2 +++ /dev/null @@ -1,13 +0,0 @@ -[mysqld] -server_id = 2 -port = {{ standby_port }} -socket = /var/run/mysqld/mysqld_slave.sock -pid-file = /var/run/mysqld/mysqld_slave.pid -datadir = {{ standby_datadir }} -log_bin = {{ standby_logdir }}/mysql-bin.log -relay-log = {{ standby_logdir }}/relay-bin -relay-log-index = {{ standby_logdir }}/relay-bin.index -master-info-file = {{ standby_logdir }}/master.info -relay-log-info-file = {{ standby_logdir }}/relay-log.info -master-info-repository = TABLE -relay-log-info-repository = TABLE diff --git a/tests/integration/targets/setup_mysql/defaults/main.yml b/tests/integration/targets/setup_mysql/defaults/main.yml new file mode 100644 index 0000000..9a742e9 --- /dev/null +++ b/tests/integration/targets/setup_mysql/defaults/main.yml @@ -0,0 +1,13 @@ +dbdeployer_version: 1.52.0 +dbdeployer_home_dir: /opt/dbdeployer + +home_dir: /root + +percona_client_version: 5.7 + +mariadb_install: false + +mysql_version: 8.0.20 +mariadb_version: 10.5.4 + +mysql_base_port: 3306 diff --git a/tests/integration/targets/setup_mysql/handlers/main.yml b/tests/integration/targets/setup_mysql/handlers/main.yml new file mode 100644 index 0000000..090a5e7 --- /dev/null +++ b/tests/integration/targets/setup_mysql/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: "{{ role_name }} | handler | create dbdeployer installed file" + template: + src: installed_file.j2 + dest: "{{ dbdeployer_installed_file }}" + listen: create zookeeper installed file diff --git a/tests/integration/targets/setup_mysql/tasks/config.yml b/tests/integration/targets/setup_mysql/tasks/config.yml new file mode 100644 index 0000000..638003b --- /dev/null +++ b/tests/integration/targets/setup_mysql/tasks/config.yml @@ -0,0 +1,15 @@ +--- +- name: "{{ role_name }} | config | download mysql tarball" + get_url: + url: "{{ install_src }}" + dest: "{{ dbdeployer_sandbox_download_dir }}/{{ install_tarball }}" + +- name: "{{ role_name }} | config | run unpack tarball" + shell: + cmd: "dbdeployer unpack {{ dbdeployer_sandbox_download_dir }}/{{ install_tarball }}" + creates: "{{ dbdeployer_sandbox_binary_dir }}/{{ install_version }}" + +- name: "{{ role_name }} | config | setup replication topology" + shell: + cmd: "dbdeployer deploy multiple {{ install_version }} --base-port {{ mysql_base_port }}" + creates: "{{ dbdeployer_sandbox_home_dir }}/rsandbox_{{ install_version|replace('.','_') }}" diff --git a/tests/integration/targets/setup_mysql/tasks/dir.yml b/tests/integration/targets/setup_mysql/tasks/dir.yml new file mode 100644 index 0000000..dc02879 --- /dev/null +++ b/tests/integration/targets/setup_mysql/tasks/dir.yml @@ -0,0 +1,11 @@ +--- +- name: "{{ role_name }} | dir | create dbdeployer directories" + file: + state: directory + path: "{{ item }}" + loop: + - "{{ dbdeployer_home_dir }}" + - "{{ dbdeployer_install_dir }}" + - "{{ dbdeployer_sandbox_download_dir }}" + - "{{ dbdeployer_sandbox_binary_dir }}" + - "{{ dbdeployer_sandbox_home_dir }}" diff --git a/tests/integration/targets/setup_mysql/tasks/install.yml b/tests/integration/targets/setup_mysql/tasks/install.yml new file mode 100644 index 0000000..f84086d --- /dev/null +++ b/tests/integration/targets/setup_mysql/tasks/install.yml @@ -0,0 +1,52 @@ +--- +- name: "{{ role_name }} | install | add apt signing key for percona" + apt_key: + keyserver: keyserver.ubuntu.com + id: 4D1BB29D63D98E422B2113B19334A25F8507EFA5 + state: present + +- name: "{{ role_name }} | install | add percona repositories" + apt_repository: + repo: "{{ item }}" + state: present + loop: "{{ percona_mysql_repos }}" + +- name: "{{ role_name }} | install | install packages required by percona" + apt: + name: "{{ percona_mysql_packages }}" + state: present + environment: + DEBIAN_FRONTEND: noninteractive + +- name: "{{ role_name }} | install | install python packages" + pip: + name: "{{ python_packages }}" + +- name: "{{ role_name }} | install | install packages required by mysql" + apt: + name: "{{ install_prereqs }}" + state: present + environment: + DEBIAN_FRONTEND: noninteractive + +- name: "{{ role_name }} | install | download and unpack dbdeployer" + unarchive: + remote_src: true + src: "{{ dbdeployer_src }}" + dest: "{{ dbdeployer_install_dir }}" + creates: "{{ dbdeployer_installed_file }}" + register: dbdeployer_tarball_install + notify: + - create zookeeper installed file + until: dbdeployer_tarball_install is not failed + retries: 6 + delay: 5 + +- name: "{{ role_name }} | install | create symlink" + file: + src: "{{ dbdeployer_install_dir }}/dbdeployer-{{ dbdeployer_version }}.linux" + dest: /usr/local/bin/dbdeployer + follow: false + state: link + +- meta: flush_handlers diff --git a/tests/integration/targets/setup_mysql/tasks/main.yml b/tests/integration/targets/setup_mysql/tasks/main.yml new file mode 100644 index 0000000..855a8fd --- /dev/null +++ b/tests/integration/targets/setup_mysql/tasks/main.yml @@ -0,0 +1,6 @@ +--- +- import_tasks: setvars.yml +- import_tasks: dir.yml +- import_tasks: install.yml +- import_tasks: config.yml +- import_tasks: verify.yml diff --git a/tests/integration/targets/setup_mysql/tasks/setvars.yml b/tests/integration/targets/setup_mysql/tasks/setvars.yml new file mode 100644 index 0000000..14a2c54 --- /dev/null +++ b/tests/integration/targets/setup_mysql/tasks/setvars.yml @@ -0,0 +1,28 @@ +--- +- name: "{{ role_name }} | setvars | split mysql version in parts" + set_fact: + mysql_version_parts: "{{ mysql_version.split('.') }}" + +- name: "{{ role_name }} | setvars | get mysql major version" + set_fact: + mysql_major_version: "{{ mysql_version_parts[0] + '.' + mysql_version_parts[1] }}" + +- name: "{{ role_name }} | setvars | set the appropriate extension dependent on the mysql version" + set_fact: + mysql_compression_extension: "{{ mysql_version is version('8.0.0', '<') | ternary('gz', 'xz') }}" + +- name: "{{ role_name }} | setvars | set the install type" + set_fact: + install_type: "{{ mariadb_install | ternary('mariadb', 'mysql') }}" + +- name: "{{ role_name }} | setvars | set install_version" + set_fact: + install_version: "{{ lookup('vars', install_type + '_version') }}" + +- name: "{{ role_name }} | setvars | set install_tarball" + set_fact: + install_tarball: "{{ lookup('vars', install_type + '_tarball') }}" + +- name: "{{ role_name }} | setvars | set install_src" + set_fact: + install_src: "{{ lookup('vars', install_type + '_src') }}" diff --git a/tests/integration/targets/setup_mysql/tasks/verify.yml b/tests/integration/targets/setup_mysql/tasks/verify.yml new file mode 100644 index 0000000..7ce5ff7 --- /dev/null +++ b/tests/integration/targets/setup_mysql/tasks/verify.yml @@ -0,0 +1,27 @@ +--- +- name: "{{ role_name }} | verify | confirm primary is running and get the port" + shell: "{{ dbdeployer_sandbox_home_dir }}/rsandbox_{{ install_version|replace('.','_') }}/m -BNe'select @@port'" + register: primary_port + +- name: "{{ role_name }} | verify | confirm replica1 is running and get the port" + shell: "{{ dbdeployer_sandbox_home_dir }}/rsandbox_{{ install_version|replace('.','_') }}/s1 -BNe'select @@port'" + register: replica1_port + +- name: "{{ role_name }} | verify | confirm replica2 is running and get the port" + shell: "{{ dbdeployer_sandbox_home_dir }}/rsandbox_{{ install_version|replace('.','_') }}/s2 -BNe'select @@port'" + register: replica2_port + +- name: "{{ role_name }} | verify | confirm primary is running on expected port" + assert: + that: + - primary_port.stdout|int == 3307 + +- name: "{{ role_name }} | verify | confirm replica1 is running on expected port" + assert: + that: + - replica1_port.stdout|int == 3308 + +- name: "{{ role_name }} | verify | confirm replica2 is running on expected port" + assert: + that: + - replica2_port.stdout|int == 3309 diff --git a/tests/integration/targets/setup_mysql/templates/installed_file.j2 b/tests/integration/targets/setup_mysql/templates/installed_file.j2 new file mode 100644 index 0000000..862a357 --- /dev/null +++ b/tests/integration/targets/setup_mysql/templates/installed_file.j2 @@ -0,0 +1 @@ +{{ dbdeployer_version }} diff --git a/tests/integration/targets/setup_mysql/vars/main.yml b/tests/integration/targets/setup_mysql/vars/main.yml new file mode 100644 index 0000000..0fa9eab --- /dev/null +++ b/tests/integration/targets/setup_mysql/vars/main.yml @@ -0,0 +1,27 @@ +--- +dbdeployer_install_dir: "{{ dbdeployer_home_dir }}/dbdeployer_{{ dbdeployer_version }}" +dbdeployer_src: "https://github.com/datacharmer/dbdeployer/releases/download/v{{ dbdeployer_version }}/dbdeployer-{{ dbdeployer_version }}.linux.tar.gz" +dbdeployer_installed_file: "{{ dbdeployer_home_dir }}/dbdeployer_installed" + +dbdeployer_sandbox_download_dir: "{{ home_dir }}/downloads" +dbdeployer_sandbox_binary_dir: "{{ home_dir }}/opt/mysql" +dbdeployer_sandbox_home_dir: "{{ home_dir }}/sandboxes" + +percona_mysql_repos: + - deb http://repo.percona.com/apt {{ ansible_lsb.codename }} main + - deb-src http://repo.percona.com/apt {{ ansible_lsb.codename }} main + +percona_mysql_packages: + - percona-server-client-{{ percona_client_version }} + +python_packages: + - pymysql + +install_prereqs: + - libaio1 + - libnuma1 + +mysql_tarball: "mysql-{{ mysql_version }}-linux-glibc2.12-x86_64.tar.{{ mysql_compression_extension }}" +mysql_src: "https://dev.mysql.com/get/Downloads/MySQL-{{ mysql_major_version }}/{{ mysql_tarball }}" +mariadb_tarball: "mariadb-{{ mariadb_version }}-linux-x86_64.tar.gz" +mariadb_src: "https://downloads.mariadb.com/MariaDB/mariadb-{{ mariadb_version }}/bintar-linux-x86_64/{{ mariadb_tarball }}" diff --git a/tests/integration/targets/setup_remote_tmp_dir/handlers/main.yml b/tests/integration/targets/setup_remote_tmp_dir/handlers/main.yml new file mode 100644 index 0000000..229037c --- /dev/null +++ b/tests/integration/targets/setup_remote_tmp_dir/handlers/main.yml @@ -0,0 +1,5 @@ +- name: delete temporary directory + include_tasks: default-cleanup.yml + +- name: delete temporary directory (windows) + include_tasks: windows-cleanup.yml diff --git a/tests/integration/targets/setup_remote_tmp_dir/tasks/default-cleanup.yml b/tests/integration/targets/setup_remote_tmp_dir/tasks/default-cleanup.yml new file mode 100644 index 0000000..39872d7 --- /dev/null +++ b/tests/integration/targets/setup_remote_tmp_dir/tasks/default-cleanup.yml @@ -0,0 +1,5 @@ +- name: delete temporary directory + file: + path: "{{ remote_tmp_dir }}" + state: absent + no_log: yes diff --git a/tests/integration/targets/setup_remote_tmp_dir/tasks/default.yml b/tests/integration/targets/setup_remote_tmp_dir/tasks/default.yml new file mode 100644 index 0000000..1e0f51b --- /dev/null +++ b/tests/integration/targets/setup_remote_tmp_dir/tasks/default.yml @@ -0,0 +1,11 @@ +- name: create temporary directory + tempfile: + state: directory + suffix: .test + register: remote_tmp_dir + notify: + - delete temporary directory + +- name: record temporary directory + set_fact: + remote_tmp_dir: "{{ remote_tmp_dir.path }}" diff --git a/tests/integration/targets/setup_remote_tmp_dir/tasks/main.yml b/tests/integration/targets/setup_remote_tmp_dir/tasks/main.yml new file mode 100644 index 0000000..f8df391 --- /dev/null +++ b/tests/integration/targets/setup_remote_tmp_dir/tasks/main.yml @@ -0,0 +1,10 @@ +- name: make sure we have the ansible_os_family and ansible_distribution_version facts + setup: + gather_subset: distribution + when: ansible_facts == {} + +- include_tasks: "{{ lookup('first_found', files)}}" + vars: + files: + - "{{ ansible_os_family | lower }}.yml" + - "default.yml" diff --git a/tests/integration/mysql_db/defaults/main.yml b/tests/integration/targets/test_mysql_db/defaults/main.yml similarity index 72% rename from tests/integration/mysql_db/defaults/main.yml rename to tests/integration/targets/test_mysql_db/defaults/main.yml index 764064b..2223ad7 100644 --- a/tests/integration/mysql_db/defaults/main.yml +++ b/tests/integration/targets/test_mysql_db/defaults/main.yml @@ -1,5 +1,9 @@ --- # defaults file for test_mysql_db +mysql_user: root +mysql_password: msandbox +mysql_primary_port: 3307 + db_name: 'data' db_name2: 'data2' db_user1: 'datauser1' diff --git a/tests/integration/targets/test_mysql_db/meta/main.yml b/tests/integration/targets/test_mysql_db/meta/main.yml new file mode 100644 index 0000000..f1174ff --- /dev/null +++ b/tests/integration/targets/test_mysql_db/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_mysql diff --git a/tests/integration/mysql_db/tasks/config_overrides_defaults.yml b/tests/integration/targets/test_mysql_db/tasks/config_overrides_defaults.yml similarity index 71% rename from tests/integration/mysql_db/tasks/config_overrides_defaults.yml rename to tests/integration/targets/test_mysql_db/tasks/config_overrides_defaults.yml index 4dec21e..422fba3 100644 --- a/tests/integration/mysql_db/tasks/config_overrides_defaults.yml +++ b/tests/integration/targets/test_mysql_db/tasks/config_overrides_defaults.yml @@ -1,8 +1,8 @@ - set_fact: - db_to_create=testdb1 - config_file="/root/.my1.cnf" - fake_port=9999 - fake_host="blahblah.local" + db_to_create: testdb1 + config_file: "/root/.my1.cnf" + fake_port: 9999 + fake_host: "blahblah.local" - name: Create custom config file shell: 'echo "[client]" > {{ config_file }}' @@ -12,6 +12,10 @@ - name: Create database using fake port to connect to, must fail mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_to_create }}' state: present check_implicit_admin: yes @@ -28,12 +32,15 @@ - name: Create database using default port mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_to_create }}' state: present check_implicit_admin: yes config_file: '{{ config_file }}' config_overrides_defaults: no - login_unix_socket: '{{ mysql_socket }}' register: result - name: Must not fail because of the default of login_port is correct @@ -49,6 +56,10 @@ - name: Remove database using fake login_host mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_to_create }}' state: absent config_file: '{{ config_file }}' @@ -65,7 +76,10 @@ # Clean up - name: Remove test db mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_to_create }}' state: absent check_implicit_admin: yes - login_unix_socket: '{{ mysql_socket }}' diff --git a/tests/integration/mysql_db/tasks/encoding_dump_import.yml b/tests/integration/targets/test_mysql_db/tasks/encoding_dump_import.yml similarity index 51% rename from tests/integration/mysql_db/tasks/encoding_dump_import.yml rename to tests/integration/targets/test_mysql_db/tasks/encoding_dump_import.yml index a1bacd1..173386c 100644 --- a/tests/integration/mysql_db/tasks/encoding_dump_import.yml +++ b/tests/integration/targets/test_mysql_db/tasks/encoding_dump_import.yml @@ -1,78 +1,98 @@ --- -- set_fact: - latin1_file1="{{tmp_dir}}/{{file}}" +- set_fact: + latin1_file1: "{{tmp_dir}}/{{file}}" - name: Deleting Latin1 encoded Database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_latin1_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' - name: create Latin1 encoded database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_latin1_name }}' state: present encoding: latin1 - login_unix_socket: '{{ mysql_socket }}' - name: create a table in Latin1 database - command: mysql {{ db_latin1_name }} -e 'create table testlatin1(id int, name varchar(100));' + command: "{{ mysql_command }} {{ db_latin1_name }} -e \"create table testlatin1(id int, name varchar(100))\"" -# Inserting a string in latin1 into table, , this string be tested later, +# Inserting a string in latin1 into table, , this string be tested later, # so report any change of content in the test too - name: inserting data into Latin1 database - command: mysql {{ db_latin1_name }} -e "insert into testlatin1 value(47,'Amédée Bôlüt');" + command: "{{ mysql_command }} {{ db_latin1_name }} -e \"insert into testlatin1 value(47,'Amédée Bôlüt')\"" - name: selecting table - command: mysql {{ db_latin1_name }} -e "select * from testlatin1;" + command: "{{ mysql_command }} {{ db_latin1_name }} -e \"select * from testlatin1\"" register: output - name: Dumping a table in Latin1 database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: "{{ db_latin1_name }}" encoding: latin1 target: "{{ latin1_file1 }}" state: dump - login_unix_socket: '{{ mysql_socket }}' register: dump_result - + - assert: that: - result is changed - name: state dump - file name should exist - file: name={{ latin1_file1 }} state=file + file: + name: '{{ latin1_file1 }}' + state: file - name: od the file and check of latin1 encoded string is present shell: grep -a 47 {{ latin1_file1 }} | od -c |grep "A m 351 d 351 e B 364\|A m 303 251 d 303 251 e B 303" - name: Dropping {{ db_latin1_name }} database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_latin1_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' - name: Importing the latin1 mysql script mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' state: import encoding: latin1 name: '{{ db_latin1_name }}' target: "{{ latin1_file1 }}" - login_unix_socket: '{{ mysql_socket }}' - + - assert: that: - result is changed - + - name: check encoding of table - shell: mysql {{ db_latin1_name }} -e "SHOW FULL COLUMNS FROM testlatin1;" + shell: "{{ mysql_command }} {{ db_latin1_name }} -e \"SHOW FULL COLUMNS FROM testlatin1\"" register: output failed_when: '"latin1_swedish_ci" not in output.stdout' - name: remove database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_latin1_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' diff --git a/tests/integration/mysql_db/tasks/main.yml b/tests/integration/targets/test_mysql_db/tasks/main.yml similarity index 60% rename from tests/integration/mysql_db/tasks/main.yml rename to tests/integration/targets/test_mysql_db/tasks/main.yml index e719fe8..07f5248 100644 --- a/tests/integration/mysql_db/tasks/main.yml +++ b/tests/integration/targets/test_mysql_db/tasks/main.yml @@ -17,236 +17,292 @@ # along with Ansible. If not, see . # ============================================================ +- 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" - name: remove database if it exists command: > - mysql -sse "drop database {{db_name}};" + "{{ mysql_command }} -sse 'drop database {{ db_name }}'" ignore_errors: True - name: make sure the test database is not there - command: mysql {{db_name}} + command: "{{ mysql_command }} {{ db_name }}" register: mysql_db_check failed_when: "'1049' not in mysql_db_check.stderr" - name: test state=present for a database name (expect changed=true) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: present - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert output message that database exist assert: that: - - result is changed - - result.db == '{{ db_name }}' - - result.executed_commands == ["CREATE DATABASE `{{ db_name }}`"] + - result is changed + - result.db == '{{ db_name }}' + - result.executed_commands == ["CREATE DATABASE `{{ db_name }}`"] - name: run command to test state=present for a database name (expect db_name in stdout) - command: mysql "-e show databases like '{{ db_name }}';" + command: "{{ mysql_command }} -e \"show databases like '{{ db_name }}'\"" register: result - name: assert database exist - assert: { that: "'{{ db_name }}' in result.stdout" } + assert: + that: + - "'{{ db_name }}' in result.stdout" # ============================================================ - name: test state=absent for a database name (expect changed=true) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert output message that database does not exist assert: that: - - result is changed - - result.db == '{{ db_name }}' - - result.executed_commands == ["DROP DATABASE `{{ db_name }}`"] + - result is changed + - result.db == '{{ db_name }}' + - result.executed_commands == ["DROP DATABASE `{{ db_name }}`"] - name: run command to test state=absent for a database name (expect db_name not in stdout) - command: mysql "-e show databases like '{{ db_name }}';" + command: "{{ mysql_command }} -e \"show databases like '{{ db_name }}'\"" register: result - name: assert database does not exist - assert: { that: "'{{ db_name }}' not in result.stdout" } + assert: + that: + - "'{{ db_name }}' not in result.stdout" # ============================================================ - name: test mysql_db encoding param not valid - issue 8075 mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: datanotvalid state: present encoding: notvalid - login_unix_socket: '{{ mysql_socket }}' register: result ignore_errors: true - name: assert test mysql_db encoding param not valid - issue 8075 (failed=true) assert: that: - - "result.failed == true" - - "'Traceback' not in result.msg" - - "'Unknown character set' in result.msg" + - "result.failed == true" + - "'Traceback' not in result.msg" + - "'Unknown character set' in result.msg" # ============================================================ - name: test mysql_db using a valid encoding utf8 (expect changed=true) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: 'en{{ db_name }}' state: present encoding: utf8 - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert output message created a database assert: that: - - result is changed - - result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'utf8'"] + - result is changed + - result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'utf8'"] - name: test database was created - command: mysql "-e SHOW CREATE DATABASE en{{ db_name }};" + command: "{{ mysql_command }} -e \"SHOW CREATE DATABASE en{{ db_name }}\"" register: result - name: assert created database is of encoding utf8 - assert: { that: "'utf8' in result.stdout" } + assert: + that: + - "'utf8' in result.stdout" - name: remove database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: 'en{{ db_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' # ============================================================ - name: test mysql_db using valid encoding binary (expect changed=true) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: 'en{{ db_name }}' state: present encoding: binary - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert output message that database was created assert: that: - - result is changed - - result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'binary'"] + - result is changed + - result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'binary'"] - name: run command to test database was created - command: mysql "-e SHOW CREATE DATABASE en{{ db_name }};" + command: "{{ mysql_command }} -e \"SHOW CREATE DATABASE en{{ db_name }}\"" register: result - name: assert created database is of encoding binary - assert: { that: "'binary' in result.stdout" } + assert: + that: + - "'binary' in result.stdout" - name: remove database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: 'en{{ db_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' # ============================================================ - name: create user1 to access database dbuser1 mysql_user: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: user1 password: 'Hfd6fds^dfA8Ga' priv: '*.*:ALL' state: present - login_unix_socket: '{{ mysql_socket }}' - name: create database dbuser1 using user1 mysql_db: - name: '{{ db_user1 }}' - state: present login_user: user1 login_password: 'Hfd6fds^dfA8Ga' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + name: '{{ db_user1 }}' + state: present register: result - name: assert output message that database was created - assert: { that: "result.changed == true" } + assert: + that: + - "result.changed == true" - name: run command to test database was created using user1 - command: mysql "-e show databases like '{{ db_user1 }}';" + command: "{{ mysql_command }} -e \"show databases like '{{ db_user1 }}'\"" register: result - name: assert database exist - assert: { that: "'{{ db_user1 }}' in result.stdout" } + assert: + that: + - "'{{ db_user1 }}' in result.stdout" # ============================================================ - name: create user2 to access database with privilege select only mysql_user: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: user2 password: 'kjsfd&F7safjad' priv: '*.*:SELECT' state: present - login_unix_socket: '{{ mysql_socket }}' - name: create database dbuser2 using user2 with no privilege to create (expect failed=true) mysql_db: - name: '{{ db_user2 }}' - state: present login_user: user2 login_password: 'kjsfd&F7safjad' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + name: '{{ db_user2 }}' + state: present register: result ignore_errors: true - name: assert output message that database was not created using dbuser2 assert: that: - - "result.failed == true" - - "'Access denied' in result.msg" + - "result.failed == true" + - "'Access denied' in result.msg" - name: run command to test that database was not created - command: mysql "-e show databases like '{{ db_user2 }}';" + command: "{{ mysql_command }} -e \"show databases like '{{ db_user2 }}'\"" register: result - name: assert database does not exist - assert: { that: "'{{ db_user2 }}' not in result.stdout" } + assert: + that: + - "'{{ db_user2 }}' not in result.stdout" # ============================================================ - name: delete database using user2 with no privilege to delete (expect failed=true) mysql_db: - name: '{{ db_user1 }}' - state: absent login_user: user2 login_password: 'kjsfd&F7safjad' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + name: '{{ db_user1 }}' + state: absent register: result ignore_errors: true - name: assert output message that database was not deleted using dbuser2 assert: that: - - "result.failed == true" - - "'Access denied' in result.msg" + - "result.failed == true" + - "'Access denied' in result.msg" - name: run command to test database was not deleted - command: mysql "-e show databases like '{{ db_user1 }}';" + command: "{{ mysql_command }} -e \"show databases like '{{ db_user1 }}'\"" register: result - name: assert database still exist - assert: { that: "'{{ db_user1 }}' in result.stdout" } + assert: + that: + - "'{{ db_user1 }}' in result.stdout" # ============================================================ - name: delete database using user1 with all privilege to delete a database (expect changed=true) mysql_db: - name: '{{ db_user1 }}' - state: absent login_user: user1 login_password: 'Hfd6fds^dfA8Ga' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + name: '{{ db_user1 }}' + state: absent register: result ignore_errors: true - name: assert output message that database was deleted using user1 assert: that: - - result is changed - - result.executed_commands == ["DROP DATABASE `{{ db_user1 }}`"] + - result is changed + - result.executed_commands == ["DROP DATABASE `{{ db_user1 }}`"] - name: run command to test database was deleted using user1 - command: mysql "-e show databases like '{{ db_name }}';" + command: "{{ mysql_command }} -e \"show databases like '{{ db_name }}'\"" register: result - name: assert database does not exist - assert: { that: "'{{ db_user1 }}' not in result.stdout" } + assert: + that: + - "'{{ db_user1 }}' not in result.stdout" # ============================================================ - include: state_dump_import.yml format_type=sql file=dbdata.sql format_msg_type=ASCII file2=dump2.sql file3=dump3.sql file4=dump4.sql @@ -255,7 +311,7 @@ - include: state_dump_import.yml format_type=bz2 file=dbdata.bz2 format_msg_type=bzip2 file2=dump2.bz2 file3=dump3.bz2 file4=dump4.bz2 -- include: multi_db_create_delete.yml +- include: multi_db_create_delete.yml - include: encoding_dump_import.yml file=latin1.sql format_msg_type=ASCII diff --git a/tests/integration/mysql_db/tasks/multi_db_create_delete.yml b/tests/integration/targets/test_mysql_db/tasks/multi_db_create_delete.yml similarity index 73% rename from tests/integration/mysql_db/tasks/multi_db_create_delete.yml rename to tests/integration/targets/test_mysql_db/tasks/multi_db_create_delete.yml index da8a94e..6bada1c 100644 --- a/tests/integration/mysql_db/tasks/multi_db_create_delete.yml +++ b/tests/integration/targets/test_mysql_db/tasks/multi_db_create_delete.yml @@ -2,20 +2,20 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - set_fact: - db1_name="database1" - db2_name="database2" - db3_name="database3" - db4_name="database4" - db5_name="database5" - dump1_file="/tmp/dump1_file.sql" - dump2_file="/tmp/all.sql" + db1_name: "database1" + db2_name: "database2" + db3_name: "database3" + db4_name: "database4" + db5_name: "database5" + dump1_file: "/tmp/dump1_file.sql" + dump2_file: "/tmp/all.sql" # ============================== CREATE TEST =============================== # # ========================================================================== # Initial check - To confirm that database does not exist before executing check mode tasks - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases does not exist @@ -29,22 +29,25 @@ # Create multiple databases that does not exists (check mode) - name: Create multiple databases that does not exists (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db2_name }}' - '{{ db3_name }}' state: present - login_unix_socket: '{{ mysql_socket }}' register: check_mode_result check_mode: yes - name: assert successful completion of create database using check_mode since databases does not exist prior assert: that: - - check_mode_result.changed == true + - check_mode_result.changed == true - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases does not exist (since created via check mode) @@ -58,22 +61,25 @@ # Create multiple databases - name: Create multiple databases mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db2_name }}' - '{{ db3_name }}' state: present - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert successful completion of create database assert: that: - - result.changed == true - - result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}'] + - result.changed == true + - result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}'] - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist after creation @@ -87,22 +93,25 @@ # Recreate already existing databases (check mode) - name: Recreate already existing databases (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db2_name }}' - '{{ db3_name }}' state: present - login_unix_socket: '{{ mysql_socket }}' register: check_mode_result check_mode: yes - name: assert that recreation of existing databases does not make change (since recreated using check mode) assert: that: - - check_mode_result.changed == false + - check_mode_result.changed == false - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist (since performed recreation of existing databases via check mode) @@ -116,21 +125,24 @@ # Recreate same databases - name: Recreate multiple databases mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db2_name }}' - '{{ db3_name }}' state: present - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert that recreation of existing databases does not make change assert: that: - - result.changed == false + - result.changed == false - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases does priorly exist @@ -144,19 +156,22 @@ # Delete one of the databases (db2 here) - name: Delete db2 database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db2_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert successful completion of deleting database assert: that: - - result.changed == true + - result.changed == true - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that only db2 database does not exist @@ -170,22 +185,25 @@ # Recreate multiple databases in which few databases does not exists (check mode) - name: Recreate multiple databases in which few databases does not exists (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db2_name }}' - '{{ db3_name }}' state: present - login_unix_socket: '{{ mysql_socket }}' register: check_mode_result check_mode: yes - name: assert successful completion of recreation of partially existing database using check mode assert: that: - - check_mode_result.changed == true + - check_mode_result.changed == true - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that recreated non existing databases does not exist (since created via check mode) @@ -194,26 +212,29 @@ - "'{{ db1_name }}' in mysql_result.stdout" - "'{{ db2_name }}' not in mysql_result.stdout" - "'{{ db3_name }}' in mysql_result.stdout" - + # ========================================================================== # Create multiple databases - name: Create multiple databases mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db2_name }}' - '{{ db3_name }}' state: present - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert successful completion of create database assert: that: - - result.changed == true + - result.changed == true - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist @@ -228,28 +249,33 @@ # ========================================================================== # Check that dump file does not exist - name: Dump file does not exist - file: name={{ dump1_file }} state=absent + file: + name: '{{ dump1_file }}' + state: absent # ========================================================================== # Dump existing databases (check mode) - name: Dump existing databases (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db3_name }}' state: dump target: '{{ dump1_file }}' - login_unix_socket: '{{ mysql_socket }}' register: check_mode_dump_result check_mode: yes - name: assert successful completion of dump operation using check mode assert: that: - - check_mode_dump_result.changed == true + - check_mode_dump_result.changed == true - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist (check mode) @@ -260,18 +286,23 @@ - "'{{ db3_name }}' in mysql_result.stdout" - name: state dump - file name should not exist (since dumped via check mode) - file: name={{ dump1_file }} state=absent + file: + name: '{{ dump1_file }}' + state: absent # ========================================================================== # Dump existing and non-existing databases (check mode) - name: Dump existing and non-existing databases (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - "{{ db1_name }}" - "{{ db4_name }}" - "{{ db3_name }}" state: dump - login_unix_socket: '{{ mysql_socket }}' target: "{{ dump1_file }}" register: check_mode_dump_result ignore_errors: True @@ -280,10 +311,10 @@ - name: assert that dump operation of existing and non existing databases does not make change (using check mode) assert: that: - - "'Cannot dump database' in check_mode_dump_result['msg']" + - "'Cannot dump database' in check_mode_dump_result['msg']" - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist (since check mode) @@ -295,18 +326,23 @@ - "'{{ db4_name }}' not in mysql_result.stdout" - name: state dump - file name should not exist (since prior dump operation performed via check mode) - file: name={{ dump1_file }} state=absent + file: + name: '{{ dump1_file }}' + state: absent # ========================================================================== # Dump non-existing databases (check mode) - name: Dump non-existing databases (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - "{{ db4_name }}" - "{{ db5_name }}" state: dump target: "{{ dump1_file }}" - login_unix_socket: '{{ mysql_socket }}' register: check_mode_dump_result ignore_errors: True check_mode: yes @@ -314,10 +350,10 @@ - name: assert successful completion of dump operation using check mode assert: that: - - "'Cannot dump database' in check_mode_dump_result['msg']" + - "'Cannot dump database' in check_mode_dump_result['msg']" - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist (since delete via check mode) @@ -330,29 +366,34 @@ - "'{{ db5_name }}' not in mysql_result.stdout" - name: state dump - file name should not exist (since prior dump operation performed via check mode) - file: name={{ dump1_file }} state=absent + file: + name: '{{ dump1_file }}' + state: absent # ========================================================================== # Dump existing databases - name: Dump existing databases mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db2_name }}' - '{{ db3_name }}' state: dump target: '{{ dump1_file }}' - login_unix_socket: '{{ mysql_socket }}' register: dump_result - name: assert successful completion of dump operation assert: that: - - dump_result.changed == true - - dump_result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}'] + - dump_result.changed == true + - dump_result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}'] - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist @@ -363,7 +404,9 @@ - "'{{ db3_name }}' in mysql_result.stdout" - name: state dump - file name should exist - file: name={{ dump1_file }} state=file + file: + name: '{{ dump1_file }}' + state: file - name: Check if db1 database create command is present in the dumped file shell: "grep -i 'CREATE DATABASE.*`{{ db1_name }}`' {{ dump1_file }}" @@ -378,23 +421,28 @@ # Dump all databases - name: state dump - dump2 file name should not exist - file: name={{ dump2_file }} state=absent + file: + name: '{{ dump2_file }}' + state: absent - name: Dump existing databases mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: all state: dump target: '{{ dump2_file }}' - login_unix_socket: '{{ mysql_socket }}' register: dump_result - name: assert successful completion of dump operation assert: that: - - dump_result.changed == true + - dump_result.changed == true - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist @@ -407,7 +455,9 @@ - "'{{ db5_name }}' not in mysql_result.stdout" - name: state dump - file name should exist - file: name={{ dump2_file }} state=file + file: + name: '{{ dump2_file }}' + state: file # ============================ DELETE TEST ================================= # @@ -415,21 +465,24 @@ # Delete multiple databases which already exists (check mode) - name: Delete multiple databases which already exists (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db2_name }}' - '{{ db3_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' register: check_mode_result check_mode: yes - name: assert successful completion of delete databases which already exists using check mode assert: that: - - check_mode_result.changed == true + - check_mode_result.changed == true - name: run command to test state=absent for a database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases exist even after deleting (since deleted via check mode) @@ -442,21 +495,24 @@ # Delete multiple databases - name: Delete multiple databases mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db2_name }}' - '{{ db3_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert successful completion of deleting database assert: that: - - result.changed == true - - result.db_list == ['{{ db2_name }}', '{{ db3_name }}'] + - result.changed == true + - result.db_list == ['{{ db2_name }}', '{{ db3_name }}'] - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases does not exist @@ -469,21 +525,24 @@ # Delete non existing databases (check mode) - name: Delete non existing databases (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db2_name }}' - '{{ db4_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' register: check_mode_result check_mode: yes - name: assert that deletion of non existing databases does not make change (using check mode) assert: that: - - check_mode_result.changed == false + - check_mode_result.changed == false - name: run command to test state=absent for a database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases does not exist since were deleted priorly (check mode) @@ -496,20 +555,23 @@ # Delete already deleted databases - name: Delete already deleted databases mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db2_name }}' - '{{ db4_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert that deletion of non existing databases does not make change assert: that: - - result.changed == false + - result.changed == false - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that databases does not exists @@ -522,6 +584,10 @@ # Delete all databases - name: Delete all databases mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - '{{ db1_name }}' - '{{ db2_name }}' @@ -529,16 +595,15 @@ - '{{ db4_name }}' - '{{ db5_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert successful completion of deleting database assert: that: - - result.changed == true + - result.changed == true - name: run command to list databases like specified database name - command: mysql "-e show databases like 'database%';" + command: "{{ mysql_command }} \"-e show databases like 'database%'\"" register: mysql_result - name: assert that specific databases does not exist @@ -551,7 +616,11 @@ - "'{{ db5_name }}' not in mysql_result.stdout" - name: state dump - dump 1 file name should be removed - file: name={{ dump1_file }} state=absent + file: + name: '{{ dump1_file }}' + state: absent - name: state dump - dump 2 file name should be removed - file: name={{ dump2_file }} state=absent + file: + name: '{{ dump2_file }}' + state: absent diff --git a/tests/integration/mysql_db/tasks/state_dump_import.yml b/tests/integration/targets/test_mysql_db/tasks/state_dump_import.yml similarity index 55% rename from tests/integration/mysql_db/tasks/state_dump_import.yml rename to tests/integration/targets/test_mysql_db/tasks/state_dump_import.yml index a21b3f2..1de7439 100644 --- a/tests/integration/mysql_db/tasks/state_dump_import.yml +++ b/tests/integration/targets/test_mysql_db/tasks/state_dump_import.yml @@ -18,71 +18,87 @@ # ============================================================ - set_fact: - db_file_name="{{tmp_dir}}/{{file}}" - wrong_sql_file="{{tmp_dir}}/wrong.sql" - dump_file1="{{tmp_dir}}/{{file2}}" - dump_file2="{{tmp_dir}}/{{file3}}" - db_user="test" - db_user_unsafe_password="pass!word" - config_file="/root/.my.cnf" + db_file_name: "{{ tmp_dir }}/{{ file }}" + wrong_sql_file: "{{ tmp_dir }}/wrong.sql" + dump_file1: "{{ tmp_dir }}/{{ file2 }}" + dump_file2: "{{ tmp_dir }}/{{ file3 }}" + db_user: "test" + db_user_unsafe_password: "pass!word" + config_file: "/root/.my.cnf" - name: create custom config file shell: 'echo "[client]" > {{ config_file }}' - name: create user for test unsafe_login_password parameter mysql_user: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_user }}' password: '{{ db_user_unsafe_password }}' priv: '*.*:ALL' state: present - login_unix_socket: '{{ mysql_socket }}' - name: state dump/import - create database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: present check_implicit_admin: yes - login_unix_socket: '{{ mysql_socket }}' - name: create database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name2 }}' state: present check_implicit_admin: no - login_unix_socket: '{{ mysql_socket }}' - name: state dump/import - create table department - command: mysql {{ db_name }} '-e create table department(id int, name varchar(100));' + command: "{{ mysql_command }} {{ db_name }} \"-e create table department(id int, name varchar(100))\"" - name: state dump/import - create table employee - command: mysql {{ db_name }} '-e create table employee(id int, name varchar(100));' + command: "{{ mysql_command }} {{ db_name }} \"-e create table employee(id int, name varchar(100))\"" - name: state dump/import - insert data into table employee - command: mysql {{ db_name }} "-e insert into employee value(47,'Joe Smith');" + command: "{{ mysql_command }} {{ db_name }} \"-e insert into employee value(47,'Joe Smith')\"" - name: state dump/import - insert data into table department - command: mysql {{ db_name }} "-e insert into department value(2,'Engineering');" + command: "{{ mysql_command }} {{ db_name }} \"-e insert into department value(2,'Engineering')\"" - name: state dump/import - file name should not exist - file: name={{ db_file_name }} state=absent + file: + name: '{{ db_file_name }}' + state: absent - name: database dump file1 should not exist - file: name={{ dump_file1 }} state=absent + file: + name: '{{ dump_file1 }}' + state: absent - name: database dump file2 should not exist - file: name={{ dump_file2 }} state=absent + file: + name: '{{ dump_file2 }}' + state: absent - name: state dump without department table. mysql_db: login_user: '{{ db_user }}' login_password: '{{ db_user_unsafe_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' unsafe_login_password: yes - name: "{{ db_name }}" + name: '{{ db_name }}' state: dump - target: "{{ db_file_name }}" + target: '{{ db_file_name }}' ignore_tables: - "{{ db_name }}.department" - login_unix_socket: '{{ mysql_socket }}' force: yes master_data: 1 skip_lock_tables: yes @@ -95,49 +111,59 @@ - name: assert successful completion of dump operation assert: that: - - result is changed - - result.executed_commands[0] is search("mysqldump --defaults-file={{ config_file }} --user={{ db_user }} --password=\*\*\*\*\*\*\*\* --force --socket={{ mysql_socket }} {{ db_name }} --skip-lock-tables --quick --ignore-table={{ db_name }}.department --master-data=1 --skip-triggers") + - result is changed + - result.executed_commands[0] is search("mysqldump --defaults-file={{ config_file }} --user={{ db_user }} --password=\*\*\*\*\*\*\*\* --force --host=127.0.0.1 --port={{ mysql_primary_port }} {{ db_name }} --skip-lock-tables --quick --ignore-table={{ db_name }}.department --master-data=1 --skip-triggers") - name: state dump/import - file name should exist - file: name={{ db_file_name }} state=file + file: + name: '{{ db_file_name }}' + state: file - name: state dump with multiple databases in comma separated form. mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: "{{ db_name }},{{ db_name2 }}" state: dump - target: "{{ dump_file1 }}" - login_unix_socket: '{{ mysql_socket }}' + target: '{{ dump_file1 }}' check_implicit_admin: yes register: dump_result1 - name: assert successful completion of dump operation (with multiple databases in comma separated form) assert: that: - - dump_result1 is changed - - dump_result1.executed_commands[0] is search(" --user=root --password=''") + - dump_result1 is changed + - dump_result1.executed_commands[0] is search(" --user=root --password=\*\*\*\*\*\*\*\*") - name: state dump - dump file1 should exist - file: name={{ dump_file1 }} state=file + file: + name: '{{ dump_file1 }}' + state: file - name: state dump with multiple databases in list form via check_mode mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - - "{{ db_name }}" - - "{{ db_name2 }}" + - '{{ db_name }}' + - '{{ db_name2 }}' state: dump - target: "{{ dump_file2 }}" - login_unix_socket: '{{ mysql_socket }}' + target: '{{ dump_file2 }}' register: dump_result check_mode: yes - name: assert successful completion of dump operation (with multiple databases in list form) via check mode assert: that: - - "dump_result.changed == true" + - "dump_result.changed == true" - name: database dump file2 should not exist stat: - path: "{{ dump_file2 }}" + path: '{{ dump_file2 }}' register: stat_result - name: assert that check_mode does not create dump file for databases @@ -147,75 +173,95 @@ - name: state dump with multiple databases in list form. mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: - - "{{ db_name }}" - - "{{ db_name2 }}" + - '{{ db_name }}' + - '{{ db_name2 }}' state: dump - target: "{{ dump_file2 }}" - login_unix_socket: '{{ mysql_socket }}' + target: '{{ dump_file2 }}' register: dump_result2 - name: assert successful completion of dump operation (with multiple databases in list form) assert: that: - - "dump_result2.changed == true" + - "dump_result2.changed == true" - name: state dump - dump file2 should exist - file: name={{ dump_file2 }} state=file + file: + name: '{{ dump_file2 }}' + state: file - name: state dump/import - remove database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' - name: remove database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name2 }}' state: absent - login_unix_socket: '{{ mysql_socket }}' - name: test state=import to restore the database of type {{ format_type }} (expect changed=true) mysql_db: login_user: '{{ db_user }}' login_password: '{{ db_user_unsafe_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' unsafe_login_password: yes name: '{{ db_name }}' state: import target: '{{ db_file_name }}' - login_unix_socket: '{{ mysql_socket }}' use_shell: yes register: result - name: show the tables - command: mysql {{ db_name }} "-e show tables;" + command: "{{ mysql_command }} {{ db_name }} \"-e show tables\"" register: result - name: assert that the department table is absent. assert: that: - - "'department' not in result.stdout" + - "'department' not in result.stdout" - name: test state=import to restore a database from multiple database dumped file1 mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name2 }}' state: import target: '{{ dump_file1 }}' - login_unix_socket: '{{ mysql_socket }}' use_shell: no register: import_result - name: assert output message restored a database from dump file1 - assert: { that: "import_result.changed == true" } + assert: + that: + - "import_result.changed == true" - name: remove database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name2 }}' state: absent - login_unix_socket: '{{ mysql_socket }}' - name: run command to list databases - command: mysql "-e show databases like 'data%';" + command: "{{ mysql_command }} \"-e show databases like 'data%'\"" register: mysql_result - name: assert that db_name2 database does not exist @@ -225,18 +271,23 @@ - name: test state=import to restore a database from dumped file2 (check mode) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name2 }}' state: import target: '{{ dump_file2 }}' - login_unix_socket: '{{ mysql_socket }}' register: check_import_result check_mode: yes - name: assert output message restored a database from dump file2 (check mode) - assert: { that: "check_import_result.changed == true" } + assert: + that: + - "check_import_result.changed == true" - name: run command to list databases - command: mysql "-e show databases like 'data%';" + command: "{{ mysql_command }} \"-e show databases like 'data%'\"" register: mysql_result - name: assert that db_name2 database does not exist (check mode) @@ -246,10 +297,13 @@ - name: test state=import to restore a database from multiple database dumped file2 mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name2 }}' state: import target: '{{ dump_file2 }}' - login_unix_socket: '{{ mysql_socket }}' register: import_result2 - name: assert output message restored a database from dump file2 @@ -259,7 +313,7 @@ - import_result2.db_list == ['{{ db_name2 }}'] - name: run command to list databases - command: mysql "-e show databases like 'data%';" + command: "{{ mysql_command }} \"-e show databases like 'data%'\"" register: mysql_result - name: assert that db_name2 database does exist after import @@ -269,48 +323,58 @@ - name: test state=dump to backup the database of type {{ format_type }} (expect changed=true) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: dump target: '{{ db_file_name }}' - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert output message backup the database assert: that: - - "result.changed == true" - - "result.db =='{{ db_name }}'" + - "result.changed == true" + - "result.db =='{{ db_name }}'" -- name: assert database was backed up successfully - command: file {{ db_file_name }} - register: result - -- name: assert file format type - assert: { that: "'{{format_msg_type}}' in result.stdout" } +# - name: assert database was backed up successfully +# command: "file {{ db_file_name }}" +# register: result +# +# - name: assert file format type +# assert: +# that: +# - "'{{ format_msg_type }}' in result.stdout" - name: update database table employee - command: mysql {{ db_name }} "-e update employee set name='John Doe' where id=47;" + command: "{{ mysql_command }} {{ db_name }} \"-e update employee set name='John Doe' where id=47\"" - name: test state=import to restore the database of type {{ format_type }} (expect changed=true) mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: import target: '{{ db_file_name }}' - login_unix_socket: '{{ mysql_socket }}' register: result - name: assert output message restore the database - assert: { that: "result.changed == true" } + assert: + that: + - "result.changed == true" - name: select data from table employee - command: mysql {{ db_name }} "-e select * from employee;" + command: "{{ mysql_command }} {{ db_name }} \"-e select * from employee\"" register: result - name: assert data in database is from the restore database assert: that: - - "'47' in result.stdout" - - "'Joe Smith' in result.stdout" + - "'47' in result.stdout" + - "'Joe Smith' in result.stdout" ########################## # Test ``force`` parameter @@ -321,30 +385,36 @@ - name: try to import without force parameter, must fail mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: import target: '{{ wrong_sql_file }}' - login_unix_socket: '{{ mysql_socket }}' force: no register: result ignore_errors: yes - assert: that: - - result.failed == true + - result.failed == true - name: try to import with force parameter mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: import target: '{{ wrong_sql_file }}' - login_unix_socket: '{{ mysql_socket }}' force: yes register: result - assert: that: - - result is changed + - result is changed ########## # Clean up @@ -352,24 +422,38 @@ - name: remove database name mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name }}' state: absent - login_unix_socket: '{{ mysql_socket }}' - name: remove database mysql_db: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' name: '{{ db_name2 }}' state: absent - login_unix_socket: '{{ mysql_socket }}' - name: remove file name - file: name={{ db_file_name }} state=absent + file: + name: '{{ db_file_name }}' + state: absent - name: remove file name - file: name={{ wrong_sql_file }} state=absent + file: + name: '{{ wrong_sql_file }}' + state: absent - name: remove dump file1 - file: name={{ dump_file1 }} state=absent + file: + name: '{{ dump_file1 }}' + state: absent - name: remove dump file2 - file: name={{ dump_file2 }} state=absent + file: + name: '{{ dump_file2 }}' + state: absent diff --git a/tests/integration/targets/test_mysql_info/defaults/main.yml b/tests/integration/targets/test_mysql_info/defaults/main.yml new file mode 100644 index 0000000..fadeb9a --- /dev/null +++ b/tests/integration/targets/test_mysql_info/defaults/main.yml @@ -0,0 +1,8 @@ +--- +# defaults file for test_mysql_info +mysql_user: root +mysql_password: msandbox +mysql_host: 127.0.0.1 +mysql_primary_port: 3307 + +db_name: data diff --git a/tests/integration/mysql_info/meta/main.yml b/tests/integration/targets/test_mysql_info/meta/main.yml similarity index 67% rename from tests/integration/mysql_info/meta/main.yml rename to tests/integration/targets/test_mysql_info/meta/main.yml index 1892924..a7ace5d 100644 --- a/tests/integration/mysql_info/meta/main.yml +++ b/tests/integration/targets/test_mysql_info/meta/main.yml @@ -1,3 +1,3 @@ dependencies: - - setup_mysql_db + - setup_mysql - setup_remote_tmp_dir diff --git a/tests/integration/targets/test_mysql_info/tasks/main.yml b/tests/integration/targets/test_mysql_info/tasks/main.yml new file mode 100644 index 0000000..fc6d93e --- /dev/null +++ b/tests/integration/targets/test_mysql_info/tasks/main.yml @@ -0,0 +1,186 @@ +# Test code for mysql_info module +# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +################### +# Prepare for tests +# + +- vars: + mysql_parameters: &mysql_params + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: '{{ mysql_host }}' + login_port: '{{ mysql_primary_port }}' + + block: + + # Create default MySQL config file with credentials + - name: mysql_info - create default config file + template: + src: my.cnf.j2 + dest: /root/.my.cnf + mode: '0400' + + # Create non-default MySQL config file with credentials + - name: mysql_info - create non-default config file + template: + src: my.cnf.j2 + dest: /root/non-default_my.cnf + mode: '0400' + + ############### + # Do tests + + # Access by default cred file + - name: mysql_info - collect default cred file + mysql_info: + login_user: '{{ mysql_user }}' + login_host: '{{ mysql_host }}' + login_port: '{{ mysql_primary_port }}' + register: result + + - assert: + that: + - result.changed == false + - result.version != {} + - result.settings != {} + - result.global_status != {} + - result.databases != {} + - result.engines != {} + - result.users != {} + + # Access by non-default cred file + - name: mysql_info - check non-default cred file + mysql_info: + login_user: '{{ mysql_user }}' + login_host: '{{ mysql_host }}' + login_port: '{{ mysql_primary_port }}' + config_file: /root/non-default_my.cnf + register: result + + - assert: + that: + - result.changed == false + - result.version != {} + + # Remove cred files + - name: mysql_info - remove cred files + file: + path: '{{ item }}' + state: absent + with_items: + - /root/.my.cnf + - /root/non-default_my.cnf + + # Access with password + - name: mysql_info - check access with password + mysql_info: + <<: *mysql_params + register: result + + - assert: + that: + - result.changed == false + - result.version != {} + + # Test excluding + - name: Collect all info except settings and users + mysql_info: + <<: *mysql_params + filter: '!settings,!users' + register: result + + - assert: + that: + - result.changed == false + - result.version != {} + - result.global_status != {} + - result.databases != {} + - result.engines != {} + - result.settings is not defined + - result.users is not defined + + # Test including + - name: Collect info only about version and databases + mysql_info: + <<: *mysql_params + filter: + - version + - databases + register: result + + - assert: + that: + - result.changed == false + - result.version != {} + - result.databases != {} + - result.engines is not defined + - result.settings is not defined + - result.global_status is not defined + - result.users is not defined + + # Test exclude_fields: db_size + # 'unsupported' element is passed to check that an unsupported value + # won't break anything (will be ignored regarding to the module's documentation). + - name: Collect info about databases excluding their sizes + mysql_info: + <<: *mysql_params + filter: + - databases + exclude_fields: + - db_size + - unsupported + register: result + + - assert: + that: + - result.changed == false + - result.databases != {} + - result.databases.mysql == {} + + ######################################################## + # Issue #65727, empty databases must be in returned dict + # + - name: Create empty database acme + mysql_db: + <<: *mysql_params + name: acme + + - name: Collect info about databases + mysql_info: + <<: *mysql_params + filter: + - databases + return_empty_dbs: true + register: result + + # Check acme is in returned dict + - assert: + that: + - result.changed == false + - result.databases.acme.size == 0 + - result.databases.mysql != {} + + - name: Collect info about databases excluding their sizes + mysql_info: + <<: *mysql_params + filter: + - databases + exclude_fields: + - db_size + return_empty_dbs: true + register: result + + # Check acme is in returned dict + - assert: + that: + - result.changed == false + - result.databases.acme == {} + - result.databases.mysql == {} + + - name: Remove acme database + mysql_db: + <<: *mysql_params + name: acme + state: absent diff --git a/tests/integration/targets/test_mysql_info/templates/my.cnf.j2 b/tests/integration/targets/test_mysql_info/templates/my.cnf.j2 new file mode 100644 index 0000000..7d159a2 --- /dev/null +++ b/tests/integration/targets/test_mysql_info/templates/my.cnf.j2 @@ -0,0 +1,5 @@ +[client] +user={{ mysql_user }} +password={{ mysql_password }} +host={{ mysql_host }} +port={{ mysql_primary_port }} diff --git a/tests/integration/mysql_query/defaults/main.yml b/tests/integration/targets/test_mysql_query/defaults/main.yml similarity index 59% rename from tests/integration/mysql_query/defaults/main.yml rename to tests/integration/targets/test_mysql_query/defaults/main.yml index 9fa44b6..f8b6768 100644 --- a/tests/integration/mysql_query/defaults/main.yml +++ b/tests/integration/targets/test_mysql_query/defaults/main.yml @@ -1,4 +1,7 @@ -root_user: root +mysql_user: root +mysql_password: msandbox +mysql_primary_port: 3307 + db_name: data test_db: testdb test_table1: test1 diff --git a/tests/integration/targets/test_mysql_query/meta/main.yml b/tests/integration/targets/test_mysql_query/meta/main.yml new file mode 100644 index 0000000..ce08dc4 --- /dev/null +++ b/tests/integration/targets/test_mysql_query/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: +- setup_mysql diff --git a/tests/integration/targets/test_mysql_query/tasks/main.yml b/tests/integration/targets/test_mysql_query/tasks/main.yml new file mode 100644 index 0000000..2aa5e42 --- /dev/null +++ b/tests/integration/targets/test_mysql_query/tasks/main.yml @@ -0,0 +1,2 @@ +# mysql_query module initial CI tests +- import_tasks: mysql_query_initial.yml diff --git a/tests/integration/mysql_query/tasks/mysql_query_initial.yml b/tests/integration/targets/test_mysql_query/tasks/mysql_query_initial.yml similarity index 97% rename from tests/integration/mysql_query/tasks/mysql_query_initial.yml rename to tests/integration/targets/test_mysql_query/tasks/mysql_query_initial.yml index 4c3a997..f9efdc6 100644 --- a/tests/integration/mysql_query/tasks/mysql_query_initial.yml +++ b/tests/integration/targets/test_mysql_query/tasks/mysql_query_initial.yml @@ -3,9 +3,10 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - vars: mysql_parameters: &mysql_params - login_unix_socket: '{{ mysql_socket }}' - login_user: '{{ root_user }}' - login_password: '{{ root_pass }}' + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' block: diff --git a/tests/integration/mysql_user/defaults/main.yml b/tests/integration/targets/test_mysql_user/defaults/main.yml similarity index 79% rename from tests/integration/mysql_user/defaults/main.yml rename to tests/integration/targets/test_mysql_user/defaults/main.yml index 7522aba..4f90633 100644 --- a/tests/integration/mysql_user/defaults/main.yml +++ b/tests/integration/targets/test_mysql_user/defaults/main.yml @@ -1,5 +1,10 @@ --- # defaults file for test_mysql_user +mysql_user: root +mysql_password: msandbox +mysql_host: 127.0.0.1 +mysql_primary_port: 3307 + db_name: 'data' user_name_1: 'db_user1' user_name_2: 'db_user2' diff --git a/tests/integration/mysql_user/files/create-function.sql b/tests/integration/targets/test_mysql_user/files/create-function.sql similarity index 62% rename from tests/integration/mysql_user/files/create-function.sql rename to tests/integration/targets/test_mysql_user/files/create-function.sql index dda7bd7..d16118c 100644 --- a/tests/integration/mysql_user/files/create-function.sql +++ b/tests/integration/targets/test_mysql_user/files/create-function.sql @@ -1,6 +1,6 @@ USE foo; DELIMITER ;; -CREATE FUNCTION `function` () RETURNS tinyint(4) +CREATE FUNCTION `function` () RETURNS tinyint(4) DETERMINISTIC BEGIN DECLARE NAME_FOUND tinyint DEFAULT 0; RETURN NAME_FOUND; diff --git a/tests/integration/mysql_user/files/create-procedure.sql b/tests/integration/targets/test_mysql_user/files/create-procedure.sql similarity index 100% rename from tests/integration/mysql_user/files/create-procedure.sql rename to tests/integration/targets/test_mysql_user/files/create-procedure.sql diff --git a/tests/integration/mysql_user/meta/main.yml b/tests/integration/targets/test_mysql_user/meta/main.yml similarity index 67% rename from tests/integration/mysql_user/meta/main.yml rename to tests/integration/targets/test_mysql_user/meta/main.yml index 1892924..a7ace5d 100644 --- a/tests/integration/mysql_user/meta/main.yml +++ b/tests/integration/targets/test_mysql_user/meta/main.yml @@ -1,3 +1,3 @@ dependencies: - - setup_mysql_db + - setup_mysql - setup_remote_tmp_dir diff --git a/tests/integration/mysql_user/tasks/assert_no_user.yml b/tests/integration/targets/test_mysql_user/tasks/assert_no_user.yml similarity index 90% rename from tests/integration/mysql_user/tasks/assert_no_user.yml rename to tests/integration/targets/test_mysql_user/tasks/assert_no_user.yml index 0031a68..9861084 100644 --- a/tests/integration/mysql_user/tasks/assert_no_user.yml +++ b/tests/integration/targets/test_mysql_user/tasks/assert_no_user.yml @@ -18,7 +18,7 @@ # ============================================================ - name: run command to query for mysql user - command: mysql "-e SELECT User FROM mysql.user where user='{{ user_name }}';" + command: "{{ mysql_command }} -e \"SELECT User FROM mysql.user where user='{{ user_name }}'\"" register: result - name: assert mysql user is not present diff --git a/tests/integration/mysql_user/tasks/assert_user.yml b/tests/integration/targets/test_mysql_user/tasks/assert_user.yml similarity index 77% rename from tests/integration/mysql_user/tasks/assert_user.yml rename to tests/integration/targets/test_mysql_user/tasks/assert_user.yml index 9ac7cbf..d95d9d2 100644 --- a/tests/integration/mysql_user/tasks/assert_user.yml +++ b/tests/integration/targets/test_mysql_user/tasks/assert_user.yml @@ -18,17 +18,21 @@ # ============================================================ - name: run command to query for mysql user - command: mysql "-e SELECT User FROM mysql.user where user='{{ user_name }}';" + command: "{{ mysql_command }} -e \"SELECT User FROM mysql.user where user='{{ user_name }}'\"" register: result - name: assert mysql user is present - assert: { that: "'{{ user_name }}' in result.stdout" } + assert: + that: + - "'{{ user_name }}' in result.stdout" - name: run command to show privileges for user (expect privileges in stdout) - command: mysql "-e SHOW GRANTS FOR '{{ user_name }}'@'localhost';" + command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name }}'@'localhost'\"" register: result when: priv is defined - name: assert user has giving privileges - assert: { that: "'GRANT {{priv}} ON *.*' in result.stdout" } + assert: + that: + - "'GRANT {{priv}} ON *.*' in result.stdout" when: priv is defined diff --git a/tests/integration/mysql_user/tasks/create_user.yml b/tests/integration/targets/test_mysql_user/tasks/create_user.yml similarity index 54% rename from tests/integration/mysql_user/tasks/create_user.yml rename to tests/integration/targets/test_mysql_user/tasks/create_user.yml index 15f1eb9..790d9bb 100644 --- a/tests/integration/mysql_user/tasks/create_user.yml +++ b/tests/integration/targets/test_mysql_user/tasks/create_user.yml @@ -16,14 +16,25 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -# ============================================================ -- name: create mysql user {{user_name}} - mysql_user: - name: '{{user_name}}' - password: '{{user_password}}' - state: present - login_unix_socket: '{{ mysql_socket }}' - register: result +- vars: + mysql_parameters: &mysql_params + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' -- name: assert output message mysql user was created - assert: { that: "result.changed == true" } + block: + + # ============================================================ + - name: create mysql user {{user_name}} + mysql_user: + <<: *mysql_params + name: '{{ user_name }}' + password: '{{ user_password }}' + state: present + register: result + + - name: assert output message mysql user was created + assert: + that: + - "result.changed == true" diff --git a/tests/integration/targets/test_mysql_user/tasks/issue-29511.yaml b/tests/integration/targets/test_mysql_user/tasks/issue-29511.yaml new file mode 100644 index 0000000..31e6edf --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/issue-29511.yaml @@ -0,0 +1,86 @@ +--- +- 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: Issue test setup - drop database + mysql_db: + <<: *mysql_params + name: "{{ item }}" + state: absent + loop: + - foo + - bar + + - name: Issue test setup - create database + mysql_db: + <<: *mysql_params + name: "{{ item }}" + state: present + loop: + - foo + - bar + + - name: Copy SQL scripts to remote + copy: + src: "{{ item }}" + dest: "{{ remote_tmp_dir }}/{{ item | basename }}" + with_items: + - create-function.sql + - create-procedure.sql + + - name: Create function for test + shell: "{{ mysql_command }} < {{ remote_tmp_dir }}/create-function.sql" + + - name: Create procedure for test + shell: "{{ mysql_command }} < {{ remote_tmp_dir }}/create-procedure.sql" + + - name: Create user with FUNCTION and PROCEDURE privileges + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + state: present + priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE' + register: result + + - name: Assert Create user with FUNCTION and PROCEDURE privileges + assert: + that: + - result is success + - result is changed + + - name: Create user with FUNCTION and PROCEDURE privileges - Idempotent check + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + state: present + priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE' + register: result + + - name: Assert Create user with FUNCTION and PROCEDURE privileges + assert: + that: + - result is success + - result is not changed + + - name: Remove user + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + state: absent + + - name: Issue test teardown - cleanup databases + mysql_db: + <<: *mysql_params + name: "{{ item }}" + state: absent + loop: + - foo + - bar diff --git a/tests/integration/targets/test_mysql_user/tasks/issue-64560.yaml b/tests/integration/targets/test_mysql_user/tasks/issue-64560.yaml new file mode 100644 index 0000000..46078b2 --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/issue-64560.yaml @@ -0,0 +1,45 @@ +--- +- 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: Set root password + mysql_user: + <<: *mysql_params + name: root + password: '{{ root_password }}' + check_implicit_admin: yes + register: result + + - name: assert root password is changed + assert: { that: "result.changed == true" } + + - name: Set root password again + mysql_user: + login_user: '{{ mysql_user }}' + login_password: '{{ root_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + name: root + password: '{{ root_password }}' + check_implicit_admin: yes + register: result + + - name: Assert root password is not changed + assert: { that: "result.changed == false" } + + - name: Set root password again + mysql_user: + login_user: '{{ mysql_user }}' + login_password: '{{ root_password }}' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + name: root + password: '{{ mysql_password }}' + check_implicit_admin: yes + register: result diff --git a/tests/integration/targets/test_mysql_user/tasks/main.yml b/tests/integration/targets/test_mysql_user/tasks/main.yml new file mode 100644 index 0000000..fcfa3b5 --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/main.yml @@ -0,0 +1,243 @@ +# test code for the mysql_user module +# (c) 2014, Wayne Rosario + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 dof the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# ============================================================ +# create mysql user and verify user is added to mysql database +# +- 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 }}' + + block: + + - include: create_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} + + - include: resource_limits.yml + + - include: assert_user.yml user_name={{user_name_1}} + + - include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} + + - include: assert_no_user.yml user_name={{user_name_1}} + + # ============================================================ + # Create mysql user that already exist on mysql database + # + - include: create_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} + + - name: create mysql user that already exist (expect changed=false) + mysql_user: + <<: *mysql_params + name: '{{user_name_1}}' + password: '{{user_password_1}}' + state: present + register: result + + - name: assert output message mysql user was not created + assert: { that: "result.changed == false" } + + # ============================================================ + # remove mysql user and verify user is removed from mysql database + # + - name: remove mysql user state=absent (expect changed=true) + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + state: absent + register: result + + - name: assert output message mysql user was removed + assert: + that: + - "result.changed == true" + + - include: assert_no_user.yml user_name={{user_name_1}} + + # ============================================================ + # remove mysql user that does not exist on mysql database + # + - name: remove mysql user that does not exist state=absent (expect changed=false) + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + state: absent + register: result + + - name: assert output message mysql user that does not exist + assert: + that: + - "result.changed == false" + + - include: assert_no_user.yml user_name={{user_name_1}} + + # ============================================================ + # Create user with no privileges and verify default privileges are assign + # + - name: create user with select privilege state=present (expect changed=true) + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + state: present + register: result + + - include: assert_user.yml user_name={{user_name_1}} priv=USAGE + + - include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} + + - include: assert_no_user.yml user_name={{user_name_1}} + + # ============================================================ + # Create user with select privileges and verify select privileges are assign + # + - name: create user with select privilege state=present (expect changed=true) + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + state: present + priv: '*.*:SELECT' + register: result + + - include: assert_user.yml user_name={{user_name_2}} priv=SELECT + + - include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_2 }} + + - include: assert_no_user.yml user_name={{user_name_2}} + + # ============================================================ + # Assert user has access to multiple databases + # + - name: give users access to multiple databases + mysql_user: + <<: *mysql_params + name: '{{ item[0] }}' + priv: '{{ item[1] }}.*:ALL' + append_privs: yes + password: '{{ user_password_1 }}' + with_nested: + - [ '{{ user_name_1 }}', '{{ user_name_2 }}'] + - "{{db_names}}" + + - name: show grants access for user1 on multiple database + command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost'\"" + register: result + + - name: assert grant access for user1 on multiple database + assert: + that: + - "'{{ item }}' in result.stdout" + with_items: "{{db_names}}" + + - name: show grants access for user2 on multiple database + command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost'\"" + register: result + + - name: assert grant access for user2 on multiple database + assert: + that: + - "'{{ item }}' in result.stdout" + with_items: "{{db_names}}" + + - include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} + + - include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_1 }} + + - name: give user access to database via wildcard + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + priv: '%db.*:SELECT' + append_privs: yes + password: '{{ user_password_1 }}' + + - name: show grants access for user1 on multiple database + command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost'\"" + register: result + + - name: assert grant access for user1 on multiple database + assert: + that: + - "'%db' in result.stdout" + - "'SELECT' in result.stdout" + + - name: change user access to database via wildcard + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + priv: '%db.*:INSERT' + append_privs: yes + password: '{{ user_password_1 }}' + + - name: show grants access for user1 on multiple database + command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost'\"" + register: result + + - name: assert grant access for user1 on multiple database + assert: + that: + - "'%db' in result.stdout" + - "'INSERT' in result.stdout" + + - include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} + + # ============================================================ + # Update user password for a user. + # Assert the user password is updated and old password can no longer be used. + # + #- include: user_password_update_test.yml + + # ============================================================ + # 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 + + # ============================================================ + # 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 + + # ============================================================ + # 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 + + # ============================================================ + # 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 + + # Tests for the priv parameter with dict value (https://github.com/ansible/ansible/issues/57533) + - include: test_priv_dict.yml + + - import_tasks: issue-29511.yaml + tags: + - issue-29511 + + - import_tasks: issue-64560.yaml + tags: + - issue-64560 diff --git a/tests/integration/targets/test_mysql_user/tasks/remove_user.yml b/tests/integration/targets/test_mysql_user/tasks/remove_user.yml new file mode 100644 index 0000000..45a0ad4 --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/remove_user.yml @@ -0,0 +1,74 @@ +# test code to remove mysql user +# (c) 2014, Wayne Rosario + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- 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 + 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 + password: 'KJFDY&D*Sfuydsgf' + + - name: remove blank mysql user with hosts=all (expect changed) + mysql_user: + <<: *mysql_params + user: "" + host_all: true + state: absent + 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 + state: absent + register: result + + - name: assert changed is true for removing all blank users + assert: + that: + - "result.changed == false" diff --git a/tests/integration/targets/test_mysql_user/tasks/resource_limits.yml b/tests/integration/targets/test_mysql_user/tasks/resource_limits.yml new file mode 100644 index 0000000..736adb3 --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/resource_limits.yml @@ -0,0 +1,118 @@ +# test code for resource_limits parameter +- 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 {{ user_name_1 }} if exists + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + state: absent + + - name: Create mysql user {{ user_name_1 }} with resource limits in check_mode + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + state: present + resource_limits: + MAX_QUERIES_PER_HOUR: 10 + MAX_CONNECTIONS_PER_HOUR: 5 + check_mode: yes + register: result + + - assert: + that: + - result is changed + + - name: Create mysql user {{ user_name_1 }} with resource limits in actual mode + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + state: present + resource_limits: + MAX_QUERIES_PER_HOUR: 10 + MAX_CONNECTIONS_PER_HOUR: 5 + register: result + + - assert: + that: + - result is changed + + - name: Check + mysql_query: + <<: *mysql_params + query: > + SELECT User FROM mysql.user WHERE User = '{{ user_name_1 }}' AND Host = 'localhost' + AND max_questions = 10 AND max_connections = 5 + register: result + + - assert: + that: + - result.rowcount[0] == 1 + + - name: Try to set the same limits again in check mode + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + state: present + resource_limits: + MAX_QUERIES_PER_HOUR: 10 + MAX_CONNECTIONS_PER_HOUR: 5 + check_mode: yes + register: result + + - assert: + that: + - result is not changed + + - name: Try to set the same limits again in actual mode + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + state: present + resource_limits: + MAX_QUERIES_PER_HOUR: 10 + MAX_CONNECTIONS_PER_HOUR: 5 + register: result + + - assert: + that: + - result is not changed + + - name: Change limits + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + state: present + resource_limits: + MAX_QUERIES_PER_HOUR: 5 + MAX_CONNECTIONS_PER_HOUR: 5 + register: result + + - assert: + that: + - result is changed + + - name: Check + mysql_query: + <<: *mysql_params + query: > + SELECT User FROM mysql.user WHERE User = '{{ user_name_1 }}' AND Host = 'localhost' + AND max_questions = 5 AND max_connections = 5 + register: result + + - assert: + that: + - result.rowcount[0] == 1 + + when: (ansible_distribution == 'Ubuntu' and ansible_distribution_major_version >= '18') or (ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '8') diff --git a/tests/integration/targets/test_mysql_user/tasks/test_priv_dict.yml b/tests/integration/targets/test_mysql_user/tasks/test_priv_dict.yml new file mode 100644 index 0000000..ec7b05e --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/test_priv_dict.yml @@ -0,0 +1,55 @@ +- 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: + + # Tests for priv parameter value passed as a dict + - name: Create test databases + mysql_db: + <<: *mysql_params + name: '{{ item }}' + state: present + loop: + - data1 + - data2 + + - name: Create user with privileges + mysql_user: + <<: *mysql_params + name: '{{ user_name_3 }}' + password: '{{ user_password_3 }}' + priv: + "data1.*": "SELECT" + "data2.*": "SELECT" + state: present + + - name: Run command to show privileges for user (expect privileges in stdout) + command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_3 }}'@'localhost'\"" + register: result + + - name: Assert user has giving privileges + assert: + that: + - "'GRANT SELECT ON `data1`.*' in result.stdout" + - "'GRANT SELECT ON `data2`.*' in result.stdout" + + ########## + # Clean up + - name: Drop test databases + mysql_db: + <<: *mysql_params + name: '{{ item }}' + state: present + loop: + - data1 + - data2 + + - name: Drop test user + mysql_user: + <<: *mysql_params + name: '{{ user_name_3 }}' + state: absent diff --git a/tests/integration/targets/test_mysql_user/tasks/test_privs.yml b/tests/integration/targets/test_mysql_user/tasks/test_privs.yml new file mode 100644 index 0000000..4ed75d1 --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/test_privs.yml @@ -0,0 +1,186 @@ +# test code for privileges for mysql_user module +# (c) 2014, Wayne Rosario + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- 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: create user with basic select privileges + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: '*.*:SELECT' + state: present + when: current_append_privs == "yes" + + - include: assert_user.yml user_name={{user_name_2}} priv='SELECT' + when: current_append_privs == "yes" + + - name: create user with current privileges (expect changed=true) + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: '*.*:{{current_privilege}}' + append_privs: '{{current_append_privs}}' + state: present + register: result + + - name: assert output message for current privileges + assert: + that: + - "result.changed == true" + + - name: run command to show privileges for user (expect privileges in stdout) + command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{user_name_2}}'@'localhost'\"" + register: result + + - name: assert user has correct privileges + assert: + that: + - "'GRANT {{current_privilege | replace(',', ', ')}} ON *.*' in result.stdout" + when: current_append_privs == "no" + + - name: assert user has correct privileges + assert: + that: + - "'GRANT SELECT, {{current_privilege | replace(',', ', ')}} ON *.*' in result.stdout" + when: current_append_privs == "yes" + + - name: create database using user current privileges + mysql_db: + login_user: '{{ user_name_2 }}' + login_password: '{{ user_password_2 }}' + login_host: '{{ mysql_host }}' + login_port: '{{ mysql_primary_port }}' + name: '{{ db_name }}' + state: present + ignore_errors: true + + - name: run command to test that database was not created + command: "{{ mysql_command }} -e \"show databases like '{{ db_name }}'\"" + register: result + + - name: assert database was not created + assert: + that: + - "'{{ db_name }}' not in result.stdout" + + # ============================================================ + - name: Add privs to a specific table (expect changed) + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: 'jmainguy.jmainguy:ALL' + state: present + register: result + + - name: Assert that priv changed + assert: + that: + - "result.changed == true" + + - name: Add privs to a specific table (expect ok) + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: 'jmainguy.jmainguy:ALL' + state: present + register: result + + - name: Assert that priv did not change + assert: + that: + - "result.changed == false" + + # ============================================================ + - name: update user with all privileges + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: '*.*:ALL' + state: present + + # - include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES' + + - name: create database using user + mysql_db: + login_user: '{{ user_name_2 }}' + login_password: '{{ user_password_2 }}' + login_host: '{{ mysql_host }}' + login_port: '{{ mysql_primary_port }}' + name: '{{ db_name }}' + state: present + + - name: run command to test database was created using user new privileges + command: "{{ mysql_command }} -e \"SHOW CREATE DATABASE {{ db_name }}\"" + + - name: drop database using user + mysql_db: + login_user: '{{ user_name_2 }}' + login_password: '{{ user_password_2 }}' + login_host: '{{ mysql_host }}' + login_port: '{{ mysql_primary_port }}' + name: '{{ db_name }}' + state: absent + + # ============================================================ + - name: update user with a long privileges list (mysql has a special multiline grant output) + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: '*.*:CREATE USER,FILE,PROCESS,RELOAD,REPLICATION CLIENT,REPLICATION SLAVE,SHOW DATABASES,SHUTDOWN,SUPER,CREATE,DROP,EVENT,LOCK TABLES,INSERT,UPDATE,DELETE,SELECT,SHOW VIEW,GRANT' + state: present + register: result + + - name: Assert that priv changed + assert: + that: + - "result.changed == true" + + - name: Test idempotency (expect ok) + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: '*.*:CREATE USER,FILE,PROCESS,RELOAD,REPLICATION CLIENT,REPLICATION SLAVE,SHOW DATABASES,SHUTDOWN,SUPER,CREATE,DROP,EVENT,LOCK TABLES,INSERT,UPDATE,DELETE,SELECT,SHOW VIEW,GRANT' + state: present + register: result + + - name: Assert that priv did not change + assert: + that: + - "result.changed == false" + + - name: remove username + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + state: absent diff --git a/tests/integration/targets/test_mysql_user/tasks/user_password_update_test.yml b/tests/integration/targets/test_mysql_user/tasks/user_password_update_test.yml new file mode 100644 index 0000000..d893924 --- /dev/null +++ b/tests/integration/targets/test_mysql_user/tasks/user_password_update_test.yml @@ -0,0 +1,178 @@ +# test code update password for the mysql_user module +# (c) 2014, Wayne Rosario + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 dof the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +- 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: + + # ============================================================ + # Update user password for a user. + # Assert the user password is updated and old password can no longer be used. + # + - name: create user1 state=present with a password + mysql_user: + <<: *mysql_params + name: '{{ user_name_1 }}' + password: '{{ user_password_1 }}' + priv: '*.*:ALL' + state: present + + - name: create user2 state=present with a password + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: '*.*:ALL' + state: present + + - name: store user2 grants with old password (mysql 5.7.6 and newer) + command: "{{ mysql_command }} -e \"SHOW CREATE USER '{{ user_name_2 }}'@'localhost'\"" + register: user_password_old_create + ignore_errors: yes + + - name: store user2 grants with old password (mysql 5.7.5 and older) + command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost'\"" + register: user_password_old + when: user_password_old_create is failed + + - name: update user2 state=present with same password (expect changed=false) + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_2 }}' + priv: '*.*:ALL' + state: present + register: result + + - name: assert output user2 was not updated + assert: + that: + - "result.changed == false" + + - include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES' + + - name: update user2 state=present with a new password (expect changed=true) + mysql_user: + <<: *mysql_params + name: '{{ user_name_2 }}' + password: '{{ user_password_1 }}' + state: present + register: result + + - include: assert_user.yml user_name={{user_name_2}} priv='ALL PRIVILEGES' + + - name: store user2 grants with old password (mysql 5.7.6 and newer) + command: "{{ mysql_command }} -e \"SHOW CREATE USER '{{ user_name_2 }}'@'localhost'\"" + register: user_password_new_create + ignore_errors: yes + + - name: store user2 grants with new password + command: "{{ mysql_command }} -e SHOW GRANTS FOR '{{ user_name_2 }}'@'localhost'\"" + register: user_password_new + when: user_password_new_create is failed + + - name: assert output message password was update for user2 (mysql 5.7.6 and newer) + assert: + that: + - "user_password_old_create.stdout != user_password_new_create.stdout" + when: user_password_new_create is not failed + + - name: assert output message password was update for user2 (mysql 5.7.5 and older) + assert: + that: + - "user_password_old.stdout != user_password_new.stdout" + when: user_password_new_create is failed + + - name: create database using user2 and old password + mysql_db: + login_user: '{{ user_name_2 }}' + login_password: '{{ user_password_2 }}' + login_host: '{{ mysql_host }}' + login_port: '{{ mysql_primary_port }}' + name: '{{ db_name }}' + state: present + ignore_errors: true + register: result + + - debug: var=result.msg + - name: assert output message that database not create with old password + assert: + that: + - "result.failed == true" + + - name: create database using user2 and new password + mysql_db: + login_user: '{{ user_name_2 }}' + login_password: '{{ user_password_1 }}' + login_host: '{{ mysql_host }}' + login_port: '{{ mysql_primary_port }}' + name: '{{ db_name }}' + state: present + register: result + + - name: assert output message that database is created with new password + assert: + that: + - "result.changed == true" + + - name: remove database + mysql_db: + <<: *mysql_params + name: '{{ db_name }}' + state: absent + login_unix_socket: '{{ mysql_socket }}' + + - include: remove_user.yml user_name={{user_name_1}} user_password={{ user_password_1 }} + + - include: remove_user.yml user_name={{user_name_2}} user_password={{ user_password_1 }} + + - name: Create user with Fdt8fd^34ds using hash. (expect changed=true) + mysql_user: + <<: *mysql_params + name: jmainguy + password: '*0cb5b86f23fdc24db19a29b8854eb860cbc47793' + encrypted: yes + register: encrypt_result + + - name: Check that the module made a change + assert: + that: + - "encrypt_result.changed == True" + + - name: See if the password needs to be updated. (expect changed=false) + mysql_user: + <<: *mysql_params + name: jmainguy + password: 'Fdt8fd^34ds' + register: plain_result + + - name: Check that the module did not change the password + assert: + that: + - "plain_result.changed == False" + + - name: Remove user (cleanup) + mysql_user: + <<: *mysql_params + name: jmainguy + state: absent diff --git a/tests/integration/targets/test_mysql_variables/defaults/main.yml b/tests/integration/targets/test_mysql_variables/defaults/main.yml new file mode 100644 index 0000000..496a6ca --- /dev/null +++ b/tests/integration/targets/test_mysql_variables/defaults/main.yml @@ -0,0 +1,5 @@ +--- +# defaults file for test_mysql_variables +mysql_user: root +mysql_password: msandbox +mysql_primary_port: 3307 diff --git a/tests/integration/targets/test_mysql_variables/meta/main.yml b/tests/integration/targets/test_mysql_variables/meta/main.yml new file mode 100644 index 0000000..f1174ff --- /dev/null +++ b/tests/integration/targets/test_mysql_variables/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_mysql diff --git a/tests/integration/mysql_variables/tasks/assert_fail_msg.yml b/tests/integration/targets/test_mysql_variables/tasks/assert_fail_msg.yml similarity index 96% rename from tests/integration/mysql_variables/tasks/assert_fail_msg.yml rename to tests/integration/targets/test_mysql_variables/tasks/assert_fail_msg.yml index ba51b9d..4a840b9 100644 --- a/tests/integration/mysql_variables/tasks/assert_fail_msg.yml +++ b/tests/integration/targets/test_mysql_variables/tasks/assert_fail_msg.yml @@ -22,4 +22,4 @@ - name: assert message failure (expect failed=true) assert: that: - - "output.failed == true" + - "output.failed == true" diff --git a/tests/integration/mysql_variables/tasks/assert_var.yml b/tests/integration/targets/test_mysql_variables/tasks/assert_var.yml similarity index 80% rename from tests/integration/mysql_variables/tasks/assert_var.yml rename to tests/integration/targets/test_mysql_variables/tasks/assert_var.yml index 1f4d273..5419f34 100644 --- a/tests/integration/mysql_variables/tasks/assert_var.yml +++ b/tests/integration/targets/test_mysql_variables/tasks/assert_var.yml @@ -20,15 +20,17 @@ # Assert mysql variable name and value from mysql database # - name: assert output message changed value - assert: { that: "output.changed == {{changed}}" } + assert: + that: + - "output.changed == {{ changed }}" - name: run mysql command to show variable - command: "mysql -uroot -p{{ root_pass }} \"-e show variables like '{{var_name}}';\"" + command: "{{ mysql_command }} \"-e show variables like '{{ var_name }}'\"" register: result - name: assert output mysql variable name and value assert: that: - - "result.changed == true" - - "'{{var_name}}' in result.stdout" - - "'{{var_value}}' in result.stdout" + - "result.changed == true" + - "'{{ var_name }}' in result.stdout" + - "'{{ var_value }}' in result.stdout" diff --git a/tests/integration/mysql_variables/tasks/assert_var_output.yml b/tests/integration/targets/test_mysql_variables/tasks/assert_var_output.yml similarity index 77% rename from tests/integration/mysql_variables/tasks/assert_var_output.yml rename to tests/integration/targets/test_mysql_variables/tasks/assert_var_output.yml index 8693816..f84a468 100644 --- a/tests/integration/mysql_variables/tasks/assert_var_output.yml +++ b/tests/integration/targets/test_mysql_variables/tasks/assert_var_output.yml @@ -20,19 +20,21 @@ # Assert output variable name/value match mysql variable name/value # - name: assert output message changed value - assert: { that: "output.changed == {{changed}}" } + assert: + that: + - "output.changed == {{ changed }}" - set_fact: - key_name: "{{var_name}}" - key_value: "{{output.msg[0][0]}}" + key_name: "{{ var_name }}" + key_value: "{{ output.msg[0][0] }}" - name: run mysql command to show variable - command: "mysql -uroot -p{{ root_pass }} \"-e show variables like '{{var_name}}';\"" + command: "{{ mysql_command }} \"-e show variables like '{{var_name}}'\"" register: result - name: assert output variable info match mysql variable info assert: that: - - "result.changed == true" - - "key_name in result.stdout" - - "key_value in result.stdout" + - "result.changed == true" + - "key_name in result.stdout" + - "key_value in result.stdout" diff --git a/tests/integration/targets/test_mysql_variables/tasks/main.yml b/tests/integration/targets/test_mysql_variables/tasks/main.yml new file mode 100644 index 0000000..fe1a791 --- /dev/null +++ b/tests/integration/targets/test_mysql_variables/tasks/main.yml @@ -0,0 +1 @@ +- import_tasks: mysql_variables.yml diff --git a/tests/integration/targets/test_mysql_variables/tasks/mysql_variables.yml b/tests/integration/targets/test_mysql_variables/tasks/mysql_variables.yml new file mode 100644 index 0000000..eea7a6e --- /dev/null +++ b/tests/integration/targets/test_mysql_variables/tasks/mysql_variables.yml @@ -0,0 +1,368 @@ +# test code for the mysql_variables module +# (c) 2014, Wayne Rosario + +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . + +# ============================================================ +# Verify mysql_variable successfully queries a variable +# +- 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: alias mysql command to include default options + set_fact: + mysql_command: "mysql -u{{ mysql_user }} -p{{ mysql_password }} -P{{ mysql_primary_port }} --protocol=tcp" + + - set_fact: + set_name: 'version' + + - name: read mysql variables (expect changed=false) + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + register: result + + - include: assert_var_output.yml changed=false output={{ result }} var_name={{ set_name }} + + # ============================================================ + # Verify mysql_variable successfully updates a variable (issue:4568) + # + - set_fact: + set_name: 'delay_key_write' + set_value: 'ON' + + - name: set mysql variable + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + + - name: update mysql variable to same value (expect changed=false) + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + register: result + + - include: assert_var.yml changed=false output={{ result }} var_name={{ set_name }} var_value={{ set_value }} + + # ============================================================ + # Verify mysql_variable successfully updates a variable using single quotes + # + - set_fact: + set_name: 'wait_timeout' + set_value: '300' + + - name: set mysql variable to a temp value + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '200' + + - name: update mysql variable value (expect changed=true) + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + register: result + + - assert: + that: + - result.queries == ["SET GLOBAL `{{ set_name }}` = {{ set_value }}"] + + - include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}' + + # ============================================================ + # Verify mysql_variable successfully updates a variable using double quotes + # + - set_fact: + set_name: "wait_timeout" + set_value: "400" + + - name: set mysql variable to a temp value + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: "200" + + - name: update mysql variable value (expect changed=true) + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + register: result + + - include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}' + + # ============================================================ + # Verify mysql_variable successfully updates a variable using no quotes + # + - set_fact: + set_name: wait_timeout + set_value: 500 + + - name: set mysql variable to a temp value + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: 200 + + - name: update mysql variable value (expect changed=true) + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + register: result + + - include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}' + + # ============================================================ + # Verify mysql_variable successfully updates a variable using an expression (e.g. 1024*4) + # + - name: set mysql variable value to an expression + mysql_variables: + <<: *mysql_params + variable: max_tmp_tables + value: "1024*4" + register: result + ignore_errors: true + + - include: assert_fail_msg.yml output={{ result }} msg='Incorrect argument type to variable' + + # ============================================================ + # Verify mysql_variable fails when setting an incorrect value (out of range) + # + - name: set mysql variable value to a number out of range + mysql_variables: + <<: *mysql_params + variable: max_tmp_tables + value: -1 + register: result + ignore_errors: true + + - include: assert_fail_msg.yml output={{ result }} msg='Truncated incorrect' + + # ============================================================ + # Verify mysql_variable fails when setting an incorrect value (incorrect type) + # + - name: set mysql variable value to a non-valid value number + mysql_variables: + <<: *mysql_params + variable: max_tmp_tables + value: TEST + register: result + ignore_errors: true + + - include: assert_fail_msg.yml output={{ result }} msg='Incorrect argument type to variable' + + # ============================================================ + # Verify mysql_variable fails when setting an unknown variable + # + - name: set a non mysql variable + mysql_variables: + <<: *mysql_params + variable: my_sql_variable + value: ON + register: result + ignore_errors: true + + - include: assert_fail_msg.yml output={{ result }} msg='Variable not available' + + # ============================================================ + # Verify mysql_variable fails when setting a read-only variable + # + - name: set value of a read only mysql variable + mysql_variables: + <<: *mysql_params + variable: character_set_system + value: utf16 + register: result + ignore_errors: true + + - include: assert_fail_msg.yml output={{ result }} msg='read only variable' + + #============================================================= + # Verify mysql_variable works with the login_user and login_password parameters + # + - set_fact: + set_name: wait_timeout + set_value: 77 + + - name: query mysql_variable using login_user and password_password + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + register: result + + - include: assert_var_output.yml changed=false output={{ result }} var_name={{ set_name }} + + - name: set mysql variable to temp value using user login and password (expect changed=true) + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: 20 + register: result + + - name: update mysql variable value using user login and password (expect changed=true) + mysql_variables: + <<: *mysql_params + variable: '{{set_name}}' + value: '{{set_value}}' + register: result + + - include: assert_var.yml changed=true output={{result}} var_name={{set_name}} var_value='{{set_value}}' + + #============================================================ + # Verify mysql_variable fails with an incorrect login_password parameter + # + - set_fact: + set_name: connect_timeout + set_value: 10 + + - name: query mysql_variable using incorrect login_password + mysql_variables: + login_user: '{{ mysql_user }}' + login_password: 'wrongpassword' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + variable: '{{ set_name }}' + register: result + ignore_errors: true + + - include: assert_fail_msg.yml output={{ result }} msg='unable to connect to database' + + - name: update mysql variable value using incorrect login_password (expect failed=true) + mysql_variables: + login_user: '{{ mysql_user }}' + login_password: 'wrongpassword' + login_host: 127.0.0.1 + login_port: '{{ mysql_primary_port }}' + variable: '{{ set_name }}' + value: '{{ set_value }}' + register: result + ignore_errors: true + + - include: assert_fail_msg.yml output={{ result }} msg='unable to connect to database' + + #============================================================ + # Verify mysql_variable fails with an incorrect login_host parameter + # + - name: query mysql_variable using incorrect login_host + mysql_variables: + login_user: '{{ mysql_user }}' + login_password: '{{ mysql_password }}' + login_host: '12.0.0.9' + login_port: '{{ mysql_primary_port }}' + variable: wait_timeout + connect_timeout: 5 + register: result + ignore_errors: true + + - include: assert_fail_msg.yml output={{ result }} msg='unable to connect to database' + + #========================================= + # Check mode 'persist' and 'persist_only': + # + - name: update mysql variable value (expect changed=true) in persist mode + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + mode: persist + register: result + + - assert: + that: + - result.queries == ["SET PERSIST `{{ set_name }}` = {{ set_value }}"] + + - include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}' + + - name: try to update mysql variable value (expect changed=false) in persist mode again + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + mode: persist + register: result + + - include: assert_var.yml changed=false output={{ result }} var_name={{ set_name }} var_value='{{ set_value }}' + + - name: set mysql variable to a temp value + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '200' + mode: persist + + - name: update mysql variable value (expect changed=true) in persist_only mode + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + mode: persist_only + register: result + + - assert: + that: + - result is changed + - result.queries == ["SET PERSIST_ONLY `{{ set_name }}` = {{ set_value }}"] + + - name: try to update mysql variable value (expect changed=false) in persist_only mode again + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + mode: persist_only + register: result + + - assert: + that: + - result is not changed + + - set_fact: + set_name: max_connections + set_value: 105 + def_val: 151 + + - name: update mysql variable value (expect changed=true) in persist_only mode + mysql_variables: + <<: *mysql_params + variable: '{{ set_name }}' + value: '{{ set_value }}' + mode: persist_only + register: result + + - include: assert_var.yml changed=true output={{ result }} var_name={{ set_name }} var_value='{{ def_val }}' + + # Bugfix of https://github.com/ansible/ansible/issues/54239 + # - name: set variable containing dot + # mysql_variables: + # <<: *mysql_params + # variable: validate_password.policy + # value: LOW + # mode: persist_only + # register: result + # + # - assert: + # that: + # - result is changed + # - result.queries == ["SET PERSIST_ONLY `validate_password`.`policy` = LOW"]