mysql_variables: fix boolean value handling (#653)

* mysql_variables: fix boolean value handling

* fix

* Fix tests

* Fix tests

* Fix

* Fix

* Fix

* Fix comment
This commit is contained in:
Andrew Klychkov 2024-06-28 11:34:59 +02:00 committed by GitHub
parent 33e8754c4e
commit 4912f1a41b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 142 additions and 0 deletions

View file

@ -26,6 +26,7 @@ options:
value:
description:
- If set, then sets variable value to this.
- With boolean values, use C(0)|C(1) or quoted C("ON")|C("OFF").
type: str
mode:
description:
@ -74,6 +75,11 @@ EXAMPLES = r'''
variable: read_only
value: 1
mode: persist
- name: Set a boolean using ON/OFF notation
mysql_variables:
variable: log_slow_replica_statements
value: "ON" # Make sure it's quoted
'''
RETURN = r'''
@ -176,6 +182,18 @@ def setvariable(cursor, mysqlvar, value, mode='global'):
return result
def convert_bool_setting_value_wanted(val):
"""Converts passed value from 0,1,on,off to ON/OFF
as it's represented in the server.
"""
if val in ('on', 1):
val = 'ON'
elif val in ('off', 0):
val = 'OFF'
return val
def main():
argument_spec = mysql_common_argument_spec()
argument_spec.update(
@ -243,6 +261,9 @@ def main():
# Type values before using them
value_wanted = typedvalue(value)
value_actual = typedvalue(mysqlvar_val)
if value_actual in ('ON', 'OFF') and value_wanted not in ('ON', 'OFF'):
value_wanted = convert_bool_setting_value_wanted(value_wanted)
value_in_auto_cnf = None
if var_in_mysqld_auto_cnf is not None:
value_in_auto_cnf = typedvalue(var_in_mysqld_auto_cnf)