mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-08-04 13:14:26 -07:00
Integrations tests : Use containers for more control and verify that versions match expectation (#490)
* Draft: Add a mariadb container
* Add playbook to test connection to the server
* Add healthcheck to MariaDB before starting the tests
This prevent the first test to fail because the db isn't ready yet.
* Add default file for root necessary since using venv instead of docker
* Add % instead of the default 'localhost' since we use remote connection
Previously, everything was on localhost. Now ansible-test is in a
venv and the db is in a container. The db see the IP address from the
podman host (10.88.0.2)
* Add ansible-test integration inventory to .gitignore
* Revert to old workflow to use ansible-test --venv
It seams that that ansible-test-gh-action doesn't handle this option:
https://github.com/ansible-community/ansible-test-gh-action/blob/main/action.yml#L483-L497
* Cut target filtering
* Fix comparison
We are not logged in as 127.0.0.1 anymore, but 10.88... as I couldn't
test this easily, I decided to simplify the test.
* Add path to default-file
/root doesn't exist with --venv
* Fix workflow unknown option container_name
* Attempt GHA communication between container using "docker host network"
https://docs.github.com/en/actions/using-containerized-services/about-service-containers
I re-revert the workflow to use the new custom action. But I'm not sure
it will works because I don't know how the container for ansible-test
is started and if it will have access to the services containers.
* Cut anchors currently unsupported by GHA
* Disable healthcheck
I want to first prove that this setup is possible before adding safety
* Disable sanity, units and matrix to speed up tests in GHA
* Further disable tests to speed up
* Add mysql_client to the controller
* Install mysql_client the correct way
* Fix package name and missing apt cache
* Prepare controller with Podman/Docker Network
We use the Podman/Docker network gateway address to communicate between
container. I haven't tested Docker. I would have preferred to use a pod
but only Podman support it and ansible-test only support the
--docker-network option.
* Swap MariaDB with MySQL
* De-duplicate the mysql_command alias
* Generalize mysql and mariadb version based on container name
This way we can split db_engine and db_version and simplify tests.
Also this is mandatory to use the matrix.db_engine_version as the
image name for our services containers.
* Cut docker healthcheck unsupported by GHA
* Fix replication server_id already in use
* Add static test with replication containers
* Fix database not selected
* Fix replication due to usage of gateway_addr instead of localhost
* Simplify version computation
* Linting
* Refactor setup_mysql into setup_controller
* Fix test_mysql_role
* Fix server_id in GHA
GHA lack a way to pass option to docker's command. Also server_id is
not read as a environment variable. So I'm forced to use a config file.
* Add back a package to connect to MySQL 8+
* Linting
* Refactor test_mysql_user to work with other host than localhost
* Refactor way tests info are passed from sed to file with lookup
The idea is to avoid modifying test targets from the workflow to prevent
ansible-test to think every tests needs to be run.
* Fix missing var
* Refactor test to use the db_version from setup_controller
* Add temporary files to .gitignore
* Fix volume path
* Fix volume path by adding a final /
* Fix volume path using $(pwd)
* Fix volume path using github.workspace var
* Cut files from gitignore because it prevents ansible-test to copy them
* Fix pre-test-cmd missing separators
* Cut the newline added by lookup 'file'
* Fix tailing newline by not created it in the first place
* Disable tests to concentrate on the \n and quote issue with my files
* Fix trailing newline and quote in db_engine_version
* Re-enable integration tests to validate db_engine_version is fixed
* lint
* Cut unused file
* Fix pre-test-cmd paste in wrong context
* Re-enable service containers
* Add back docker healthcheck on services
I saw in the GHA logs that it perform an healtcheck ! So I hope this
will work.
* Add tmate to debug the server_id in replicas
* Attempt to fix "invalid syntax"
* Enclose command in quotes
* Refactor the way server_id is set for replicas
The simple way is to add '--server-id 2' after the name of the image of
the container. But GHA doesn't let us do that. The idea of mount a file
from our repo doesn't work because the repo is check out later in the
workflow and I failed to find a pre-job hook. Then I realized that this
MySQL option is dynamic! So we will set that in the test target!
* Re-activate all tests
* Cut useless task
* Use same variable as other target for consistency
* Linting
* Update version tested
* Add options to the makefile
* Add same variables as other target for consistency
* Add IF NOT EXISTS to prevent misleading error on retry
* Cut python 3.11 not supported by ansible-test yet
* Attempt to set log-bin into docker
* Reformat for readability
* Document that full version is mandatory
* Fix newline
* Github complain it doesn't find python 3.1 !!!
* Add option to run only a single target
* Fix mysqlclient not supporting Python 3.9
* Enhance installation of mysql_client
Initially I wanted to install mysql-client-5.7 to test mysql server 5.7
but this package is not available for Ubuntu 18+.
I keep those changes because it allow us to specify the name of the
package based on the Ubuntu version.
* Linting
* Add unique name to simplify debugging
* Fix mysql_dump for MySQL 5.7 and MariaDB when using mysqldump 8
* Add unique name to simplify debugging
* Deduplicate tasks
* Lining
* Add python script to recreate the test matrix from github workflow file
* Fix dump with mysqldump 8 against mysql 5.7
* Disable test for replication with chanel for mysql 5.7
* Add better task name
* Fix exclusion function
* Disable replication with channel tests entirely for MySQL 5.7
* Activate Mysql 8 and Mariadb into GitHub Action Workflow
* Cut Ansible since we can't change what the user have on his computer
* Add running make command for all tests of the matrix
* Add unique test names
* Document run_all_tests.py
* Add unique test names
* Add tmate to experiment with docker healthcheck
* Fix replication settings
sh don't know 'echo -e', so we use bash instead.
Also, we need to wait for the container to be healthy before trying to
restart it. Otherwise that could corrupt it.
* Add TODO verify that the version of mysql/mariadb is correct
* Add more descriptive tests names
* Use mysql_host var name instead of gateway_addr in tests
* Refactor user@<gateway ip addr> into user@%
* Fix healthcheck in GHA
* Disable tests that fails only on MariaDB
* Refactor to remove useless variables
* Workaround for plugin role that fails with any MariaDB versions
* Fix Python 3.10 beein run as 3.1
* Ensure replicas are healthy before rebooting them
* Enable all tests
* Add a virtualenv for ansible-test used locally
* Simplify connector_name variables
* Add PoC using custom ansible-test containers
* Fix docker_container variable name
* Cut forgotten comment
* Fix error when using local registry by using quay.io
* Change tag of test-containers to latest
* Fix ansible-test unknown option
I copied blindly https://github.com/ansible-collections/community.sops/blob/main/.github/workflows/ansible-test.yml#L195
and forgot what ansible-test was expecting
* Cut column-statistics disabling
Thanks to our test-container, we now use the correspond mysql-client.
So to test mysql 5.7 we use mysql-client-5.7 and to test mysql 8 we
use mysql-client-8.
* Add manual test matrix (MariaDB 10.6, 10.7 and 10.8 missing)
* Fix test matrix
Python version should be quoted, otherwise 3.10 become 3.1
We can skip 2.14 and devel with Python3.8
We can skip devel with Python 3.9
We can skip MariaDB 10.4 with mysql-client-10.6
Add tests for MariaDB 10.6, 10.7 and 10.8
* Reduce number of tests and adapt containers images
* Fix queries for roles
* Add filter for issues resolved in newer version of mysqlclient
* Add names to tests
* Fix assertion for mariadb
* Linting
* Cut tests for incompatible MySQL 8 and pymysql 0.7.11
* Fix assertion for older mysqlclient than 2.0.1 with mysql (mariadb ok)
* Cut playbook that are now handled by the test-containers
* Change timeout from 10 to 30 seconds to let mysql/mariadb restart
* Add connector information to the returned values
I need to know what python library was used. I had a container with
both mysqlclient and pymysql installed and tests used a different
connector that what is advertised by the title of integration tests.
We need to prevent that otherwise our tests are worth nothing.
* Add a verify stage at setup of test to assert all version are correct
* Attempt to build and publish an image on ghcr.io
* Add latest release of actions and with a context
* Add trigger on workflow file edit
* Fix env not recognized in the 'on' clause
* Add latest tag
* Fix insufficient context
* Add missing slash
* Cut addition of tag 'latest' as GHA does it automatically
* Add ghcr.io image for mariadb10.3 python3.8 mysqlclient2.0.1
* Change docker-image workflow to work on all images using matrix
* Fix workflow title
* Add support for version of mysqlclient
* Fix context path
* Workaround failed to push ghcr.io
Error was: failed to copy: io: read/write on closed pipe
* Add back all tests using ghcr.io images
* Cut unused images
* Fix verify database version
Sometimes, version_full contains trailing information (-log). To prevent
issues it's best to concatenate major and minor version.
* Fix verify for mysqlclient second name MySQLdb
* Rename variable for consistency
* Fix container name
* Add tag 'latest' to images
* Cut filter for tests now that the right connector is used
* Fix test of mysql/mariadb version in use
* Fix python version lookup
* Add clean up in "always" phase of the block
Because our tests use --retry-on-error, and the first thing the test
does is to try to create the database. We must cleanup otherwise if
there is a retry, it will throw a misleading "database already exists"
error.
* Document TODO
* Disable tests using pymysql 1.0.2
Many tests are failing but this must be fixed in the plugins in a future
PR.
* Cut test MySQL 8 with incompatible pymysql 0.7.11
It fails to connect with error about cryptography unsupported
* Fix dict key lookup
* Fix indentation
* Cut tests that was excluded in previous matrix
* Enable back sanity and unit tests
* Refactor get_driver_version to display name while passing sanity tests
* Fix variable name
* Fix missing cffi package to connect to MySQL 8 using Python 3.9
* Fix image not found
* Split Docker image workflow to rebuild only changed Dockerfile
My goal is not to save the planet but to make it work. Currently
docker/setup-buildx-action@v2 often fails. You have to rerun the
workflow multiple times until it succeed. When you do that with the
matrix with 15 containers, you never get to the point where they all
built successfully. Having separate workflows makes rerun the failing
build easier.
* Fix verify ansible 'devel' for which the version is unknown
Today 'devel' means 2.15, but in the future it will be something else.
* Fix ansible version extraction for "devel"
* Cut matrix from when build was done in a single workflow
* Document fix container name
* Add bold
* Add option to let containers alive at end of testing
* Enhance error handling and doc of get_driver_name and get_driver_version
* Migrate tests documentations in their own file
* Skip retry-on-error by default and add option to activate it on demand
* Rename folder to better purpose
* Enable back push and schedule workflow
* Rename registry from fork to upstream
* Cut Docker Image workflow's filter for branch from my fork
* Add changelog fragment
* Update supported versions
* Rename file for clarity
* Cut mariadb non long term releases
* Add '-client' to the block title to better explain what it is
* Update readme for tested versions of long term release of MariaDB
* Attempt to add the workflow to the Action tab
* Second attempt to add the workflow to the Action tab
* Cut folder re-created by merge from main
* Cut filter by branch
GHA will build the image using the branch name as tag. So we can safely
remove this filter.
* Cut changelog item done in #497
* Attempt to fix upload of image under c.mysql instead of my fork
* Add debug to buildkitd
* Bump setup-buildy-action to latest
* Cut dot in image name in attempt to fix buildx bad request 400 error
* Sanitize the repository name using metadata-action
https://github.com/docker/build-push-action/blob/master/TROUBLESHOOTING.md#repository-name-must-be-lowercase
* Document why we use optional checkout action
* Cut debugging from setup-buildx-action
* Fix workflow to work both on fork and c.mysql repository
* Use apt-get instead of apt that not have a stable CLI interface
* Use apt-get instead of apt
* update docker image path to my personal repo
I'm unable to publish under community.mysql. Either it's the dot in
the name or I do something wrong with the GITHUB_TOKEN, but we need to
test my PR, so I'll use docker images from my fork for now.
* Fix test after merge of PR497
* Enhance testing documentation header
* Fix installation of ansible venv
ansible-test is included in ansible package. Also, on Fedora 37 with
python 3.11, pip is missing. By using ensurepip we solve that issue.
* Document usage of continue_on_errors
* Fix versions used in examples
* Add support for systems with unsupported python set as default
* Fix cleanup task
* Fix variable assignation to the include task
* Add forgotten variable to handle unsupported python version
* Fix user site-packages not visible in virtualenv
* Fix test connection to the database and tasks names
* Add create podman network for system missing it.
We saw that on a Fedora 33 with Podman 3.3.1, an old system. I didn't
find in which release the default network changed and maybe it's
defined in the Linux distribution. So in doubt I always attempt to
create the network.
* Add full path to image to prevent podman asking which registry to use
* Add options to enforce recreate containers even if already exists
* Reformat command multiline to oneline
* Add deletion of anonymous volumes associated with the container
* Comment unused variable
* Change shebang from python to python3 to avoid confusion with python2
This script is a python3 script.
* Add disk and RAM requirements
* Cut the 3 from python command to follow shebang recommendations
https://docs.ansible.com/ansible-core/devel/dev_guide/testing/sanity/shebang.html
* Reformat spelling
Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <jorge.rodriguez@futurice.com>
* Reformat file path
Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <jorge.rodriguez@futurice.com>
* Fix link URI
Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <jorge.rodriguez@futurice.com>
* Fix link URI
Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <jorge.rodriguez@futurice.com>
* Lint
Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <jorge.rodriguez@futurice.com>
* Lint
Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <jorge.rodriguez@futurice.com>
* Add better task name
Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <jorge.rodriguez@futurice.com>
* Move utility task files in their own folder
* Refactor using reusable GHA workflows
* Fix path to called workflow file
* Fix path to use local workflow
* Fix cannot specify version when calling local workflows
* Attempt to use a fixed repo name in the image name
My last attempts produced duplicates images under my name + repo name:
laurent-indermuehle/community.mysql. Previously I had only my name. And
none of the above are what we want. We want only community.mysql in the
image name...
* Add called workflow file in the GHA hooks
Without this, the containers are not rebuilt when you modify the file
built-docker-image.yml.
* Rollback to github.repository in container image name
This time I think I understood. We publish in the
github.repository_owner's namespace. In my case it's laurent-indermuehle
and in case of upstream it's ansible-collection. A proof of that:
https://github.com/orgs/ansible-collections/packages <- here there is
one attempt I did in february to push my branch to the upstream.
So, our tests containers will be visible to the whole community, not
just community.mysql.
---------
Co-authored-by: Jorge Rodriguez (A.K.A. Tiriel) <jorge.rodriguez@futurice.com>
(cherry picked from commit 6970aef8f6
)
This commit is contained in:
parent
62e2ed5d36
commit
13950b0965
121 changed files with 2926 additions and 1460 deletions
|
@ -1,57 +1,59 @@
|
|||
- set_fact:
|
||||
---
|
||||
- name: Config overrides | Set facts
|
||||
set_fact:
|
||||
db_to_create: testdb1
|
||||
config_file: "/root/.my1.cnf"
|
||||
config_file: "{{ playbook_dir }}/.my1.cnf"
|
||||
fake_port: 9999
|
||||
fake_host: "blahblah.local"
|
||||
include_dir: "/root/mycnf.d"
|
||||
include_dir: "{{ playbook_dir }}/mycnf.d"
|
||||
|
||||
- name: Create custom config file
|
||||
- name: Config overrides | Create custom config file
|
||||
shell: 'echo "[client]" > {{ config_file }}'
|
||||
|
||||
- name: Add fake port to config file
|
||||
- name: Config overrides | Add fake port to config file
|
||||
shell: 'echo "port = {{ fake_port }}" >> {{ config_file }}'
|
||||
|
||||
- name: Add blank line
|
||||
- name: Config overrides | Add blank line
|
||||
shell: 'echo "" >> {{ config_file }}'
|
||||
when:
|
||||
- >
|
||||
connector_name is not search('pymysql')
|
||||
connector_name != 'pymysql'
|
||||
or (
|
||||
connector_name is search('pymysql')
|
||||
and connector_ver is version('0.9.3', '>=')
|
||||
connector_name == 'pymysql'
|
||||
and connector_version is version('0.9.3', '>=')
|
||||
)
|
||||
|
||||
- name: Create include_dir
|
||||
- name: Config overrides | Create include_dir
|
||||
file:
|
||||
path: '{{ include_dir }}'
|
||||
state: directory
|
||||
mode: '0777'
|
||||
when:
|
||||
- >
|
||||
connector_name is not search('pymysql')
|
||||
connector_name != 'pymysql'
|
||||
or (
|
||||
connector_name is search('pymysql')
|
||||
and connector_ver is version('0.9.3', '>=')
|
||||
connector_name == 'pymysql'
|
||||
and connector_version is version('0.9.3', '>=')
|
||||
)
|
||||
|
||||
- name: Add include_dir
|
||||
- name: Config overrides | Add include_dir
|
||||
lineinfile:
|
||||
path: '{{ config_file }}'
|
||||
line: '!includedir {{ include_dir }}'
|
||||
insertafter: EOF
|
||||
when:
|
||||
- >
|
||||
connector_name is not search('pymysql')
|
||||
connector_name != 'pymysql'
|
||||
or (
|
||||
connector_name is search('pymysql')
|
||||
and connector_ver is version('0.9.3', '>=')
|
||||
connector_name == 'pymysql'
|
||||
and connector_version is version('0.9.3', '>=')
|
||||
)
|
||||
|
||||
- name: Create database using fake port to connect to, must fail
|
||||
- name: Config overrides | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_to_create }}'
|
||||
state: present
|
||||
|
@ -61,17 +63,17 @@
|
|||
ignore_errors: yes
|
||||
register: result
|
||||
|
||||
- name: Must fail because login_port default has beed overriden by wrong value from config file
|
||||
- name: Config overrides | Must fail because login_port default has beed overriden by wrong value from config file
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result.msg is search("unable to connect to database")
|
||||
- result is failed
|
||||
- result.msg is search("unable to connect to database")
|
||||
|
||||
- name: Create database using default port
|
||||
- name: Config overrides | Create database using default port
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_to_create }}'
|
||||
state: present
|
||||
|
@ -80,22 +82,22 @@
|
|||
config_overrides_defaults: no
|
||||
register: result
|
||||
|
||||
- name: Must not fail because of the default of login_port is correct
|
||||
- name: Config overrides | Must not fail because of the default of login_port is correct
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result is changed
|
||||
|
||||
- name: Reinit custom config file
|
||||
- name: Config overrides | Reinit custom config file
|
||||
shell: 'echo "[client]" > {{ config_file }}'
|
||||
|
||||
- name: Add fake host to config file
|
||||
- name: Config overrides | Add fake host to config file
|
||||
shell: 'echo "host = {{ fake_host }}" >> {{ config_file }}'
|
||||
|
||||
- name: Remove database using fake login_host
|
||||
- name: Config overrides | Remove database using fake login_host
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_to_create }}'
|
||||
state: absent
|
||||
|
@ -104,18 +106,17 @@
|
|||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Must fail because login_host default has beed overriden by wrong value from config file
|
||||
- name: Config overrides | Must fail because login_host default has beed overriden by wrong value from config file
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- result.msg is search("Can't connect to MySQL server on '{{ fake_host }}'") or result.msg is search("Unknown MySQL server host '{{ fake_host }}'")
|
||||
- result is failed
|
||||
- result.msg is search("Can't connect to MySQL server on '{{ fake_host }}'") or result.msg is search("Unknown MySQL server host '{{ fake_host }}'")
|
||||
|
||||
# Clean up
|
||||
- name: Remove test db
|
||||
- name: Config overrides | Clean up test database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_to_create }}'
|
||||
state: absent
|
||||
|
|
|
@ -1,45 +1,46 @@
|
|||
---
|
||||
|
||||
- set_fact:
|
||||
latin1_file1: "{{tmp_dir}}/{{file}}"
|
||||
- name: Encoding | Set fact
|
||||
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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_latin1_name }}'
|
||||
state: absent
|
||||
|
||||
- name: create Latin1 encoded database
|
||||
- name: Encoding | Create Latin1 encoded database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_latin1_name }}'
|
||||
state: present
|
||||
encoding: latin1
|
||||
|
||||
- name: create a table in Latin1 database
|
||||
- name: Encoding | Create a table in Latin1 database
|
||||
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,
|
||||
# so report any change of content in the test too
|
||||
- name: inserting data into Latin1 database
|
||||
- name: Encoding | Inserting data into Latin1 database
|
||||
command: "{{ mysql_command }} {{ db_latin1_name }} -e \"insert into testlatin1 value(47,'Amédée Bôlüt')\""
|
||||
|
||||
- name: selecting table
|
||||
- name: Encoding | Selecting table
|
||||
command: "{{ mysql_command }} {{ db_latin1_name }} -e \"select * from testlatin1\""
|
||||
register: output
|
||||
|
||||
- name: Dumping a table in Latin1 database
|
||||
- name: Encoding | Dumping a table in Latin1 database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: "{{ db_latin1_name }}"
|
||||
encoding: latin1
|
||||
|
@ -49,30 +50,30 @@
|
|||
|
||||
- assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result is changed
|
||||
|
||||
- name: state dump - file name should exist
|
||||
- name: Encoding | State dump - file name should exist (latin1_file1)
|
||||
file:
|
||||
name: '{{ latin1_file1 }}'
|
||||
state: file
|
||||
|
||||
- name: od the file and check of latin1 encoded string is present
|
||||
- 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
|
||||
- name: Encoding | Dropping {{ db_latin1_name }} database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_latin1_name }}'
|
||||
state: absent
|
||||
|
||||
- name: Importing the latin1 mysql script
|
||||
- name: Encoding | Importing the latin1 mysql script
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
state: import
|
||||
encoding: latin1
|
||||
|
@ -80,20 +81,25 @@
|
|||
target: "{{ latin1_file1 }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
- name: Encoding | Assert that importing latin1 is changed
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result is changed
|
||||
|
||||
- name: check encoding of table
|
||||
shell: "{{ mysql_command }} {{ db_latin1_name }} -e \"SHOW FULL COLUMNS FROM testlatin1\""
|
||||
- name: Encoding | Check encoding of table
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
{{ mysql_command }}
|
||||
{{ db_latin1_name }}
|
||||
-e "SHOW FULL COLUMNS FROM {{ db_latin1_name }}.testlatin1"
|
||||
register: output
|
||||
failed_when: '"latin1_swedish_ci" not in output.stdout'
|
||||
|
||||
- name: remove database
|
||||
- name: Encoding | Clean up database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_latin1_name }}'
|
||||
state: absent
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
mysql_parameters: &mysql_params
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
when: tls_enabled
|
||||
block:
|
||||
|
@ -26,6 +26,7 @@
|
|||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
host_all: true
|
||||
state: absent
|
||||
ignore_errors: yes
|
||||
|
||||
|
@ -33,6 +34,7 @@
|
|||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: "{{ user_name_1 }}"
|
||||
host: "%"
|
||||
password: "{{ user_password_1 }}"
|
||||
priv: '*.*:ALL,GRANT'
|
||||
tls_requires:
|
||||
|
@ -44,7 +46,7 @@
|
|||
state: absent
|
||||
login_user: '{{ user_name_1 }}'
|
||||
login_password: '{{ user_password_1 }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
ca_cert: /tmp/cert.pem
|
||||
register: result
|
||||
|
@ -53,12 +55,14 @@
|
|||
- assert:
|
||||
that:
|
||||
- result is failed
|
||||
when: connector_name is search('pymysql')
|
||||
when:
|
||||
- connector_name == 'pymysql'
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result is succeeded
|
||||
when: connector_name is not search('pymysql')
|
||||
when:
|
||||
- connector_name != 'pymysql'
|
||||
|
||||
- name: attempt connection with newly created user ignoring hostname
|
||||
mysql_db:
|
||||
|
@ -66,7 +70,7 @@
|
|||
state: absent
|
||||
login_user: '{{ user_name_1 }}'
|
||||
login_password: '{{ user_password_1 }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
ca_cert: /tmp/cert.pem
|
||||
check_hostname: no
|
||||
|
@ -81,5 +85,5 @@
|
|||
mysql_user:
|
||||
<<: *mysql_params
|
||||
name: '{{ user_name_1 }}'
|
||||
host: 127.0.0.1
|
||||
host_all: true
|
||||
state: absent
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
|
@ -21,10 +22,6 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
- 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: Check state present/absent
|
||||
include_tasks: state_present_absent.yml
|
||||
vars:
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -43,7 +43,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -75,7 +75,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -107,7 +107,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -139,7 +139,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -170,7 +170,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
|
@ -199,7 +199,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -231,7 +231,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -271,7 +271,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -308,7 +308,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- "{{ db1_name }}"
|
||||
|
@ -348,7 +348,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- "{{ db4_name }}"
|
||||
|
@ -384,11 +384,12 @@
|
|||
|
||||
# ==========================================================================
|
||||
# Dump existing databases
|
||||
|
||||
- name: Dump existing databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
@ -398,13 +399,13 @@
|
|||
target: '{{ dump1_file }}'
|
||||
register: dump_result
|
||||
|
||||
- name: assert successful completion of dump operation
|
||||
- name: Assert successful completion of dump operation (existing database)
|
||||
assert:
|
||||
that:
|
||||
- dump_result is changed
|
||||
- dump_result.db_list == ['{{ db1_name }}', '{{ db2_name }}', '{{ db3_name }}']
|
||||
|
||||
- name: run command to list databases like specified database name
|
||||
- name: Run command to list databases like specified database name
|
||||
command: "{{ mysql_command }} \"-e show databases like 'database%'\""
|
||||
register: mysql_result
|
||||
|
||||
|
@ -415,7 +416,7 @@
|
|||
- "'{{ db2_name }}' in mysql_result.stdout"
|
||||
- "'{{ db3_name }}' in mysql_result.stdout"
|
||||
|
||||
- name: state dump - file name should exist
|
||||
- name: State dump - file name should exist (dump1_file)
|
||||
file:
|
||||
name: '{{ dump1_file }}'
|
||||
state: file
|
||||
|
@ -441,7 +442,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: all
|
||||
state: dump
|
||||
|
@ -466,7 +467,7 @@
|
|||
- "'{{ db4_name }}' not in mysql_result.stdout"
|
||||
- "'{{ db5_name }}' not in mysql_result.stdout"
|
||||
|
||||
- name: state dump - file name should exist
|
||||
- name: state dump - file name should exist (dump2_file)
|
||||
file:
|
||||
name: '{{ dump2_file }}'
|
||||
state: file
|
||||
|
@ -479,7 +480,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
|
@ -509,7 +510,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
|
@ -539,7 +540,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
|
@ -569,7 +570,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db2_name }}'
|
||||
|
@ -598,7 +599,7 @@
|
|||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db1_name }}'
|
||||
|
|
|
@ -17,113 +17,116 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
- set_fact:
|
||||
- name: Dump and Import | Set facts
|
||||
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"
|
||||
config_file: "{{ playbook_dir }}/root/.my.cnf"
|
||||
|
||||
- name: create custom config file
|
||||
- name: Dump and Import | Create custom config file
|
||||
shell: 'echo "[client]" > {{ config_file }}'
|
||||
|
||||
- name: create user for test unsafe_login_password parameter
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_user }}'
|
||||
host: '%'
|
||||
password: '{{ db_user_unsafe_password }}'
|
||||
priv: '*.*:ALL'
|
||||
state: present
|
||||
|
||||
- name: state dump/import - create database
|
||||
- name: Dump and Import | State dump/import - create database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: present
|
||||
check_implicit_admin: yes
|
||||
|
||||
- name: create database
|
||||
- name: Dump and Import | Create database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: present
|
||||
check_implicit_admin: no
|
||||
|
||||
- name: state dump/import - create table department
|
||||
- name: Dump and Import | State dump/import - create table department
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e create table department(id int, name varchar(100))\""
|
||||
|
||||
- name: state dump/import - create table employee
|
||||
- name: Dump and Import | State dump/import - create table employee
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e create table employee(id int, name varchar(100))\""
|
||||
|
||||
- name: state dump/import - insert data into table employee
|
||||
- name: Dump and Import | State dump/import - insert data into table employee
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e insert into employee value(47,'Joe Smith')\""
|
||||
|
||||
- name: state dump/import - insert data into table department
|
||||
- name: Dump and Import | State dump/import - insert data into table department
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e insert into department value(2,'Engineering')\""
|
||||
|
||||
- name: state dump/import - file name should not exist
|
||||
- name: Dump and Import | State dump/import - file name should not exist
|
||||
file:
|
||||
name: '{{ db_file_name }}'
|
||||
state: absent
|
||||
|
||||
- name: database dump file1 should not exist
|
||||
- name: Dump and Import | Database dump file1 should not exist
|
||||
file:
|
||||
name: '{{ dump_file1 }}'
|
||||
state: absent
|
||||
|
||||
- name: database dump file2 should not exist
|
||||
- name: Dump and Import | Database dump file2 should not exist
|
||||
file:
|
||||
name: '{{ dump_file2 }}'
|
||||
state: absent
|
||||
|
||||
- name: state dump without department table.
|
||||
- name: Dump and Import | State dump without department table.
|
||||
mysql_db:
|
||||
login_user: '{{ db_user }}'
|
||||
login_password: '{{ db_user_unsafe_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
unsafe_login_password: yes
|
||||
name: '{{ db_name }}'
|
||||
state: dump
|
||||
target: '{{ db_file_name }}'
|
||||
ignore_tables:
|
||||
- "{{ db_name }}.department"
|
||||
- "{{ db_name }}.department"
|
||||
force: yes
|
||||
master_data: 1
|
||||
skip_lock_tables: yes
|
||||
dump_extra_args: --skip-triggers
|
||||
dump_extra_args: >-
|
||||
--skip-triggers
|
||||
config_file: '{{ config_file }}'
|
||||
restrict_config_file: yes
|
||||
check_implicit_admin: no
|
||||
register: result
|
||||
|
||||
- name: assert successful completion of dump operation
|
||||
- name: Dump and Import | 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 --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")
|
||||
- result.executed_commands[0] is search(".department --master-data=1 --skip-triggers")
|
||||
|
||||
- name: state dump/import - file name should exist
|
||||
- name: Dump and Import | State dump/import - file name should exist (db_file_name)
|
||||
file:
|
||||
name: '{{ db_file_name }}'
|
||||
state: file
|
||||
|
||||
- name: state dump with multiple databases in comma separated form.
|
||||
- name: Dump and Import | State dump with multiple databases in comma separated form for MySQL.
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: "{{ db_name }},{{ db_name2 }}"
|
||||
state: dump
|
||||
|
@ -131,22 +134,22 @@
|
|||
check_implicit_admin: yes
|
||||
register: dump_result1
|
||||
|
||||
- name: assert successful completion of dump operation (with multiple databases in comma separated form)
|
||||
- name: Dump and Import | 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=\*\*\*\*\*\*\*\*")
|
||||
|
||||
- name: state dump - dump file1 should exist
|
||||
- name: Dump and Import | State dump - dump file1 should exist
|
||||
file:
|
||||
name: '{{ dump_file1 }}'
|
||||
state: file
|
||||
|
||||
- name: state dump with multiple databases in list form via check_mode
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db_name }}'
|
||||
|
@ -156,26 +159,26 @@
|
|||
register: dump_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert successful completion of dump operation (with multiple databases in list form) via check mode
|
||||
- name: Dump and Import | Assert successful completion of dump operation (with multiple databases in list form) via check mode
|
||||
assert:
|
||||
that:
|
||||
- dump_result is changed
|
||||
|
||||
- name: database dump file2 should not exist
|
||||
- name: Dump and Import | Database dump file2 should not exist
|
||||
stat:
|
||||
path: '{{ dump_file2 }}'
|
||||
register: stat_result
|
||||
|
||||
- name: assert that check_mode does not create dump file for databases
|
||||
- name: Dump and Import | Assert that check_mode does not create dump file for databases
|
||||
assert:
|
||||
that:
|
||||
- stat_result.stat.exists is defined and not stat_result.stat.exists
|
||||
|
||||
- name: state dump with multiple databases in list form.
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name:
|
||||
- '{{ db_name }}'
|
||||
|
@ -184,39 +187,39 @@
|
|||
target: '{{ dump_file2 }}'
|
||||
register: dump_result2
|
||||
|
||||
- name: assert successful completion of dump operation (with multiple databases in list form)
|
||||
- name: Dump and Import | Assert successful completion of dump operation (with multiple databases in list form)
|
||||
assert:
|
||||
that:
|
||||
- dump_result2 is changed
|
||||
|
||||
- name: state dump - dump file2 should exist
|
||||
- name: Dump and Import | State dump - dump file2 should exist
|
||||
file:
|
||||
name: '{{ dump_file2 }}'
|
||||
state: file
|
||||
|
||||
- name: state dump/import - remove database
|
||||
- name: Dump and Import | State dump/import - remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: absent
|
||||
|
||||
- name: remove database
|
||||
- name: Dump and Import | Remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: absent
|
||||
|
||||
- name: test state=import to restore the database of type {{ format_type }} (expect changed=true)
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
unsafe_login_password: yes
|
||||
name: '{{ db_name }}'
|
||||
|
@ -225,20 +228,20 @@
|
|||
use_shell: yes
|
||||
register: result
|
||||
|
||||
- name: show the tables
|
||||
- name: Dump and Import | Show the tables
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e show tables\""
|
||||
register: result
|
||||
|
||||
- name: assert that the department table is absent.
|
||||
- name: Dump and Import | Assert that the department table is absent.
|
||||
assert:
|
||||
that:
|
||||
- "'department' not in result.stdout"
|
||||
|
||||
- name: test state=import to restore a database from multiple database dumped file1
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: import
|
||||
|
@ -246,34 +249,34 @@
|
|||
use_shell: no
|
||||
register: import_result
|
||||
|
||||
- name: assert output message restored a database from dump file1
|
||||
- name: Dump and Import | Assert output message restored a database from dump file1
|
||||
assert:
|
||||
that:
|
||||
- import_result is changed
|
||||
|
||||
- name: remove database
|
||||
- name: Dump and Import | Remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: absent
|
||||
|
||||
- name: run command to list databases
|
||||
- name: Dump and Import | Run command to list databases
|
||||
command: "{{ mysql_command }} \"-e show databases like 'data%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that db_name2 database does not exist
|
||||
- name: Dump and Import | Assert that db_name2 database does not exist
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_name2 }}' not in mysql_result.stdout"
|
||||
|
||||
- name: test state=import to restore a database from dumped file2 (check mode)
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: import
|
||||
|
@ -281,96 +284,96 @@
|
|||
register: check_import_result
|
||||
check_mode: yes
|
||||
|
||||
- name: assert output message restored a database from dump file2 (check mode)
|
||||
- name: Dump and Import | Assert output message restored a database from dump file2 (check mode)
|
||||
assert:
|
||||
that:
|
||||
- check_import_result is changed
|
||||
|
||||
- name: run command to list databases
|
||||
- name: Dump and Import | Run command to list databases
|
||||
command: "{{ mysql_command }} \"-e show databases like 'data%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that db_name2 database does not exist (check mode)
|
||||
- name: Dump and Import | Assert that db_name2 database does not exist (check mode)
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_name2 }}' not in mysql_result.stdout"
|
||||
|
||||
- name: test state=import to restore a database from multiple database dumped file2
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name2 }}'
|
||||
state: import
|
||||
target: '{{ dump_file2 }}'
|
||||
register: import_result2
|
||||
|
||||
- name: assert output message restored a database from dump file2
|
||||
- name: Dump and Import | Assert output message restored a database from dump file2
|
||||
assert:
|
||||
that:
|
||||
- import_result2 is changed
|
||||
- import_result2.db_list == ['{{ db_name2 }}']
|
||||
|
||||
- name: run command to list databases
|
||||
- name: Dump and Import | Run command to list databases
|
||||
command: "{{ mysql_command }} \"-e show databases like 'data%'\""
|
||||
register: mysql_result
|
||||
|
||||
- name: assert that db_name2 database does exist after import
|
||||
- name: Dump and Import | Assert that db_name2 database does exist after import
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_name2 }}' in mysql_result.stdout"
|
||||
|
||||
- name: test state=dump to backup the database of type {{ format_type }} (expect changed=true)
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: dump
|
||||
target: '{{ db_file_name }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message backup the database
|
||||
- name: Dump and Import | Assert output message backup the database
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- "result.db =='{{ db_name }}'"
|
||||
|
||||
# - name: assert database was backed up successfully
|
||||
# - name: Dump and Import | Assert database was backed up successfully
|
||||
# command: "file {{ db_file_name }}"
|
||||
# register: result
|
||||
#
|
||||
# - name: assert file format type
|
||||
# - name: Dump and Import | Assert file format type
|
||||
# assert:
|
||||
# that:
|
||||
# - "'{{ format_msg_type }}' in result.stdout"
|
||||
|
||||
- name: update database table employee
|
||||
- name: Dump and Import | Update database table employee
|
||||
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)
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: import
|
||||
target: '{{ db_file_name }}'
|
||||
register: result
|
||||
|
||||
- name: assert output message restore the database
|
||||
- name: Dump and Import | Assert output message restore the database
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: select data from table employee
|
||||
- name: Dump and Import | Select data from table employee
|
||||
command: "{{ mysql_command }} {{ db_name }} \"-e select * from employee\""
|
||||
register: result
|
||||
|
||||
- name: assert data in database is from the restore database
|
||||
- name: Dump and Import | Assert data in database is from the restore database
|
||||
assert:
|
||||
that:
|
||||
- "'47' in result.stdout"
|
||||
|
@ -380,14 +383,14 @@
|
|||
# Test ``force`` parameter
|
||||
##########################
|
||||
|
||||
- name: create wrong sql file
|
||||
- name: Dump and Import | Create wrong sql file
|
||||
shell: echo 'CREATE TABLE hello (id int); CREATE ELBAT ehlo (int id);' >> '{{ wrong_sql_file }}'
|
||||
|
||||
- name: try to import without force parameter, must fail
|
||||
- name: Dump and Import | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: import
|
||||
|
@ -400,11 +403,11 @@
|
|||
that:
|
||||
- result is failed
|
||||
|
||||
- name: try to import with force parameter
|
||||
- name: Dump and Import | Try to import with force parameter
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: import
|
||||
|
@ -420,40 +423,24 @@
|
|||
# Clean up
|
||||
##########
|
||||
|
||||
- name: remove database name
|
||||
- name: Dump and Import | Clean up databases
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
name: '{{ item }}'
|
||||
state: absent
|
||||
loop:
|
||||
- '{{ db_name }}'
|
||||
- '{{ db_name2 }}'
|
||||
|
||||
- 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
|
||||
|
||||
- name: remove file name
|
||||
- name: Dump and Import | Clean up files
|
||||
file:
|
||||
name: '{{ db_file_name }}'
|
||||
state: absent
|
||||
|
||||
- name: remove file name
|
||||
file:
|
||||
name: '{{ wrong_sql_file }}'
|
||||
state: absent
|
||||
|
||||
- name: remove dump file1
|
||||
file:
|
||||
name: '{{ dump_file1 }}'
|
||||
state: absent
|
||||
|
||||
- name: remove dump file2
|
||||
file:
|
||||
name: '{{ dump_file2 }}'
|
||||
name: '{{ item }}'
|
||||
state: absent
|
||||
loop:
|
||||
- '{{ db_file_name }}'
|
||||
- '{{ wrong_sql_file }}'
|
||||
- '{{ dump_file1 }}'
|
||||
- '{{ dump_file2 }}'
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
---
|
||||
# test code for mysql_db module with database name containing special chars
|
||||
|
||||
# This file is part of Ansible
|
||||
|
@ -16,75 +17,75 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ============================================================
|
||||
- name: remove database if it exists
|
||||
- name: State Present Absent | Remove database if it exists
|
||||
command: >
|
||||
"{{ mysql_command }} -sse 'DROP DATABASE IF EXISTS {{ db_name }}'"
|
||||
ignore_errors: true
|
||||
|
||||
- name: make sure the test database is not there
|
||||
- name: State Present Absent | Make sure the test database is not there
|
||||
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)
|
||||
- name: State Present Absent | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: present
|
||||
register: result
|
||||
|
||||
- name: assert output message that database exist
|
||||
- name: State Present Absent | Assert output message that database exist
|
||||
assert:
|
||||
that:
|
||||
- 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)
|
||||
- name: State Present Absent | Run command to test state=present for a database name (expect db_name in stdout)
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_name | regex_replace(\"([%_\\\\])\", \"\\\\\\1\") }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database exist
|
||||
- name: State Present Absent | Assert database exist
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_name }}' in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: test state=absent for a database name (expect changed=true)
|
||||
- name: State Present Absent | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_name }}'
|
||||
state: absent
|
||||
register: result
|
||||
|
||||
- name: assert output message that database does not exist
|
||||
- name: State Present Absent | Assert output message that database does not exist
|
||||
assert:
|
||||
that:
|
||||
- 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)
|
||||
- name: State Present Absent | Run command to test state=absent for a database name (expect db_name not in stdout)
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_name | regex_replace(\"([%_\\\\])\", \"\\\\\\1\") }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database does not exist
|
||||
- name: State Present Absent | Assert database does not exist
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_name }}' not in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: test mysql_db encoding param not valid - issue 8075
|
||||
- name: State Present Absent | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: datanotvalid
|
||||
state: present
|
||||
|
@ -92,7 +93,7 @@
|
|||
register: result
|
||||
ignore_errors: true
|
||||
|
||||
- name: assert test mysql_db encoding param not valid - issue 8075 (failed=true)
|
||||
- name: State Present Absent | Assert test mysql_db encoding param not valid - issue 8075 (failed=true)
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
|
@ -100,201 +101,202 @@
|
|||
- "'Unknown character set' in result.msg"
|
||||
|
||||
# ============================================================
|
||||
- name: test mysql_db using a valid encoding utf8 (expect changed=true)
|
||||
- name: State Present Absent | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: 'en{{ db_name }}'
|
||||
state: present
|
||||
encoding: utf8
|
||||
register: result
|
||||
|
||||
- name: assert output message created a database
|
||||
- name: State Present Absent | Assert output message created a database
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'utf8'"]
|
||||
|
||||
- name: test database was created
|
||||
- name: State Present Absent | Test database was created
|
||||
command: "{{ mysql_command }} -e \"SHOW CREATE DATABASE `en{{ db_name }}`\""
|
||||
register: result
|
||||
|
||||
- name: assert created database is of encoding utf8
|
||||
- name: State Present Absent | Assert created database is of encoding utf8
|
||||
assert:
|
||||
that:
|
||||
- "'utf8' in result.stdout"
|
||||
|
||||
- name: remove database
|
||||
- name: State Present Absent | Remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: 'en{{ db_name }}'
|
||||
state: absent
|
||||
|
||||
# ============================================================
|
||||
- name: test mysql_db using valid encoding binary (expect changed=true)
|
||||
- name: State Present Absent | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: 'en{{ db_name }}'
|
||||
state: present
|
||||
encoding: binary
|
||||
register: result
|
||||
|
||||
- name: assert output message that database was created
|
||||
- name: State Present Absent | Assert output message that database was created
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_commands == ["CREATE DATABASE `en{{ db_name }}` CHARACTER SET 'binary'"]
|
||||
|
||||
- name: run command to test database was created
|
||||
- name: State Present Absent | Run command to test database was created
|
||||
command: "{{ mysql_command }} -e \"SHOW CREATE DATABASE `en{{ db_name }}`\""
|
||||
register: result
|
||||
|
||||
- name: assert created database is of encoding binary
|
||||
- name: State Present Absent | Assert created database is of encoding binary
|
||||
assert:
|
||||
that:
|
||||
- "'binary' in result.stdout"
|
||||
|
||||
- name: remove database
|
||||
- name: State Present Absent | Remove database
|
||||
mysql_db:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: 'en{{ db_name }}'
|
||||
state: absent
|
||||
|
||||
# ============================================================
|
||||
- name: create user1 to access database dbuser1
|
||||
- name: State Present Absent | Create user1 to access database dbuser1
|
||||
mysql_user:
|
||||
login_user: '{{ mysql_user }}'
|
||||
login_password: '{{ mysql_password }}'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: user1
|
||||
host: '%'
|
||||
password: 'Hfd6fds^dfA8Ga'
|
||||
priv: '*.*:ALL'
|
||||
state: present
|
||||
|
||||
- name: create database dbuser1 using user1
|
||||
- name: State Present Absent | Create database dbuser1 using user1
|
||||
mysql_db:
|
||||
login_user: user1
|
||||
login_password: 'Hfd6fds^dfA8Ga'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: '{{ db_user1 }}'
|
||||
state: present
|
||||
register: result
|
||||
|
||||
- name: assert output message that database was created
|
||||
- name: State Present Absent | Assert output message that database was created
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
|
||||
- name: run command to test database was created using user1
|
||||
- name: State Present Absent | Run command to test database was created using user1
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_user1 | regex_replace(\"([%_\\\\])\", \"\\\\\\1\") }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database exist
|
||||
- name: State Present Absent | Assert database exist
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_user1 }}' in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: create user2 to access database with privilege select only
|
||||
- name: State Present Absent | 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_host: '{{ mysql_host }}'
|
||||
login_port: '{{ mysql_primary_port }}'
|
||||
name: user2
|
||||
password: 'kjsfd&F7safjad'
|
||||
priv: '*.*:SELECT'
|
||||
state: present
|
||||
|
||||
- name: create database dbuser2 using user2 with no privilege to create (expect failed=true)
|
||||
- name: State Present Absent | Create database dbuser2 using user2 with no privilege to create (expect failed=true)
|
||||
mysql_db:
|
||||
login_user: user2
|
||||
login_password: 'kjsfd&F7safjad'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
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
|
||||
- name: State Present Absent | Assert output message that database was not created using dbuser2
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- "'Access denied' in result.msg"
|
||||
|
||||
- name: run command to test that database was not created
|
||||
- name: State Present Absent | Run command to test that database was not created
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_user2 | regex_replace(\"([%_\\\\])\", \"\\\\\\1\") }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database does not exist
|
||||
- name: State Present Absent | Assert database does not exist
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_user2 }}' not in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: delete database using user2 with no privilege to delete (expect failed=true)
|
||||
- name: State Present Absent | Delete database using user2 with no privilege to delete (expect failed=true)
|
||||
mysql_db:
|
||||
login_user: user2
|
||||
login_password: 'kjsfd&F7safjad'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
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
|
||||
- name: State Present Absent | Assert output message that database was not deleted using dbuser2
|
||||
assert:
|
||||
that:
|
||||
- result is failed
|
||||
- "'Access denied' in result.msg"
|
||||
|
||||
- name: run command to test database was not deleted
|
||||
- name: State Present Absent | Run command to test database was not deleted
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_user1 | regex_replace(\"([%_\\\\])\", \"\\\\\\1\") }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database still exist
|
||||
- name: State Present Absent | Assert database still exist
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_user1 }}' in result.stdout"
|
||||
|
||||
# ============================================================
|
||||
- name: delete database using user1 with all privilege to delete a database (expect changed=true)
|
||||
- name: State Present Absent | Delete database using user1 with all privilege to delete a database (expect changed=true)
|
||||
mysql_db:
|
||||
login_user: user1
|
||||
login_password: 'Hfd6fds^dfA8Ga'
|
||||
login_host: 127.0.0.1
|
||||
login_host: '{{ mysql_host }}'
|
||||
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
|
||||
- name: State Present Absent | Assert output message that database was deleted using user1
|
||||
assert:
|
||||
that:
|
||||
- result is changed
|
||||
- result.executed_commands == ["DROP DATABASE `{{ db_user1 }}`"]
|
||||
|
||||
- name: run command to test database was deleted using user1
|
||||
- name: State Present Absent | Run command to test database was deleted using user1
|
||||
command: "{{ mysql_command }} -e \"show databases like '{{ db_name | regex_replace(\"([%_\\\\])\", \"\\\\\\1\") }}'\""
|
||||
register: result
|
||||
|
||||
- name: assert database does not exist
|
||||
- name: State Present Absent | Assert database does not exist
|
||||
assert:
|
||||
that:
|
||||
- "'{{ db_user1 }}' not in result.stdout"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue