Skip to content

Commit

Permalink
Bugfix of 54239: mysql_variables not supporting variables name with d…
Browse files Browse the repository at this point in the history
…ot (ansible#66806)

* Bugfix of 54239: mysql_variables not supporting variables name with dot

* add changelog

* add CI tests
  • Loading branch information
Andersson007 authored Feb 1, 2020
1 parent f5e194c commit 3baea92
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- mysql_variable - fix the module doesn't support variables name with dot (https://github.com/ansible/ansible/issues/54239).
2 changes: 1 addition & 1 deletion lib/ansible/module_utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def pg_quote_identifier(identifier, id_type):

def mysql_quote_identifier(identifier, id_type):
identifier_fragments = _identifier_parse(identifier, quote_char='`')
if len(identifier_fragments) > _MYSQL_IDENTIFIER_TO_DOT_LEVEL[id_type]:
if (len(identifier_fragments) - 1) > _MYSQL_IDENTIFIER_TO_DOT_LEVEL[id_type]:
raise SQLParseError('MySQL does not support %s with more than %i dots' % (id_type, _MYSQL_IDENTIFIER_TO_DOT_LEVEL[id_type]))

special_cased_fragments = []
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/database/mysql/mysql_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def main():

if mysqlvar is None:
module.fail_json(msg="Cannot run without variable to operate with")
if match('^[0-9a-z_]+$', mysqlvar) is None:
if match('^[0-9a-z_.]+$', mysqlvar) is None:
module.fail_json(msg="invalid variable name \"%s\"" % mysqlvar)
if mysql_driver is None:
module.fail_json(msg=mysql_driver_fail_msg)
Expand Down
16 changes: 16 additions & 0 deletions test/integration/targets/mysql_variables/tasks/mysql_variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,19 @@
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"]

0 comments on commit 3baea92

Please sign in to comment.