generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql_mode can be set in session, therefore we should look for ANSI_QUOTES in session variable instead of global variable #677
Open
SoledaD208
wants to merge
2
commits into
ansible-collections:main
Choose a base branch
from
SoledaD208:check_ansi_quotes_in_session_variable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
tests/integration/targets/test_mysql_user/tasks/issue-671.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
# Due to https://bugs.mysql.com/bug.php?id=115953, in Mysql 8, if ANSI_QUOTES is enabled, | ||
# backticks will be used instead of double quotes to quote functions or procedures name. | ||
# As a consequence, mysql_user and mysql_roles will always report "changed" for functions | ||
# and procedures no matter the privileges are granted or not. | ||
# Workaround for the mysql bug 116953 is removing ANSI_QUOTES from the module's session | ||
# sql_mode. But because issue 671, ANSI_QUOTES is always got from GLOBAL sql_mode, thus | ||
# this workaround can't work. Even without the Mysql bug, because sql_mode in session | ||
# precedes GLOBAL sql_mode. we should check for sql_mode in session variable instead of | ||
# the GLOBAL one. | ||
- vars: | ||
mysql_parameters: &mysql_params | ||
login_user: '{{ mysql_user }}' | ||
login_password: '{{ mysql_password }}' | ||
login_host: '{{ mysql_host }}' | ||
login_port: '{{ mysql_primary_port }}' | ||
|
||
block: | ||
- name: Issue-671| test setup | drop database | ||
mysql_db: | ||
<<: *mysql_params | ||
name: "{{ item }}" | ||
state: absent | ||
loop: | ||
- foo | ||
- bar | ||
|
||
- name: Issue-671| test setup | create database | ||
mysql_db: | ||
<<: *mysql_params | ||
name: "{{ item }}" | ||
state: present | ||
loop: | ||
- foo | ||
- bar | ||
|
||
- name: Issue-671| test setup | get value of GLOBAL.sql_mode | ||
mysql_query: | ||
<<: *mysql_params | ||
query: 'select @@GLOBAL.sql_mode AS sql_mode' | ||
register: sql_mode_orig | ||
|
||
- name: Issue-671| enable sql_mode ANSI_QUOTES | ||
mysql_variables: | ||
<<: *mysql_params | ||
variable: sql_mode | ||
value: '{{ sql_mode_orig.query_result[0][0].sql_mode }},ANSI_QUOTES' | ||
mode: "{% if db_engine == 'mariadb' %}global{% else %}persist{% endif %}" | ||
|
||
- name: Issue-671| test setup | get value of GLOBAL.sql_mode | ||
mysql_query: | ||
<<: *mysql_params | ||
query: 'select @@GLOBAL.sql_mode' | ||
|
||
- name: Issue-671| Copy SQL scripts to remote | ||
copy: | ||
src: "{{ item }}" | ||
dest: "{{ remote_tmp_dir }}/{{ item | basename }}" | ||
with_items: | ||
- create-function.sql | ||
- create-procedure.sql | ||
|
||
- name: Issue-671| Create function for test | ||
shell: "{{ mysql_command }} < {{ remote_tmp_dir }}/create-function.sql" | ||
|
||
- name: Issue-671| Create procedure for test | ||
shell: "{{ mysql_command }} < {{ remote_tmp_dir }}/create-procedure.sql" | ||
|
||
- name: Issue-671| 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' | ||
|
||
- name: Issue-671| Grant the privileges again, remove ANSI_QUOTES from the session variable | ||
mysql_user: | ||
<<: *mysql_params | ||
session_vars: | ||
sql_mode: "" | ||
name: '{{ user_name_2 }}' | ||
password: '{{ user_password_2 }}' | ||
state: present | ||
priv: 'FUNCTION foo.function:EXECUTE/foo.*:SELECT/PROCEDURE bar.procedure:EXECUTE' | ||
register: result | ||
|
||
- name: Issue-671| Assert Create user with FUNCTION and PROCEDURE privileges | ||
assert: | ||
that: | ||
- result is success | ||
- result is not changed | ||
|
||
- name: Issue-671| Test teardown | cleanup databases | ||
mysql_db: | ||
<<: *mysql_params | ||
name: "{{ item }}" | ||
state: absent | ||
loop: | ||
- foo | ||
- bar | ||
|
||
- name: Issue-671| set sql_mode back to original value | ||
mysql_variables: | ||
<<: *mysql_params | ||
variable: sql_mode | ||
value: '{{ sql_mode_orig.query_result[0][0].sql_mode }}' | ||
mode: "{% if db_engine == 'mariadb' %}global{% else %}persist{% endif %}" | ||
|
||
- include_tasks: utils/remove_user.yml | ||
vars: | ||
user_name: "{{ user_name_2 }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you like to
assert:
this one too? I see you assert the second one calledresult
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, let me check and add the assert. by the way, due to some reasons, I will need to close this PR and open another via other account.