Add optional connect timeout to mysql* modules.

pull/18777/head
Matt Clay 9 years ago
parent 12804a80b6
commit b7a5e1e0c8

@ -224,6 +224,7 @@ def main():
ssl_cert=dict(default=None), ssl_cert=dict(default=None),
ssl_key=dict(default=None), ssl_key=dict(default=None),
ssl_ca=dict(default=None), ssl_ca=dict(default=None),
connect_timeout=dict(default=30, type='int'),
config_file=dict(default="~/.my.cnf"), config_file=dict(default="~/.my.cnf"),
), ),
supports_check_mode=True supports_check_mode=True
@ -244,6 +245,7 @@ def main():
ssl_cert = module.params["ssl_cert"] ssl_cert = module.params["ssl_cert"]
ssl_key = module.params["ssl_key"] ssl_key = module.params["ssl_key"]
ssl_ca = module.params["ssl_ca"] ssl_ca = module.params["ssl_ca"]
connect_timeout = module.params['connect_timeout']
config_file = module.params['config_file'] config_file = module.params['config_file']
config_file = os.path.expanduser(os.path.expandvars(config_file)) config_file = os.path.expanduser(os.path.expandvars(config_file))
login_password = module.params["login_password"] login_password = module.params["login_password"]
@ -266,7 +268,8 @@ def main():
if db == 'all': if db == 'all':
module.fail_json(msg="name is not allowed to equal 'all' unless state equals import, or dump.") module.fail_json(msg="name is not allowed to equal 'all' unless state equals import, or dump.")
try: try:
cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca) cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca,
connect_timeout=connect_timeout)
except Exception, e: except Exception, e:
if os.path.exists(config_file): if os.path.exists(config_file):
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. Exception message: %s" % (config_file, e)) module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. Exception message: %s" % (config_file, e))

@ -495,6 +495,7 @@ def main():
append_privs=dict(default=False, type='bool'), append_privs=dict(default=False, type='bool'),
check_implicit_admin=dict(default=False, type='bool'), check_implicit_admin=dict(default=False, type='bool'),
update_password=dict(default="always", choices=["always", "on_create"]), update_password=dict(default="always", choices=["always", "on_create"]),
connect_timeout=dict(default=30, type='int'),
config_file=dict(default="~/.my.cnf"), config_file=dict(default="~/.my.cnf"),
sql_log_bin=dict(default=True, type='bool'), sql_log_bin=dict(default=True, type='bool'),
ssl_cert=dict(default=None), ssl_cert=dict(default=None),
@ -513,6 +514,7 @@ def main():
state = module.params["state"] state = module.params["state"]
priv = module.params["priv"] priv = module.params["priv"]
check_implicit_admin = module.params['check_implicit_admin'] check_implicit_admin = module.params['check_implicit_admin']
connect_timeout = module.params['connect_timeout']
config_file = module.params['config_file'] config_file = module.params['config_file']
append_privs = module.boolean(module.params["append_privs"]) append_privs = module.boolean(module.params["append_privs"])
update_password = module.params['update_password'] update_password = module.params['update_password']
@ -530,12 +532,14 @@ def main():
try: try:
if check_implicit_admin: if check_implicit_admin:
try: try:
cursor = mysql_connect(module, 'root', '', config_file, ssl_cert, ssl_key, ssl_ca, db) cursor = mysql_connect(module, 'root', '', config_file, ssl_cert, ssl_key, ssl_ca, db,
connect_timeout=connect_timeout)
except: except:
pass pass
if not cursor: if not cursor:
cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, db) cursor = mysql_connect(module, login_user, login_password, config_file, ssl_cert, ssl_key, ssl_ca, db,
connect_timeout=connect_timeout)
except Exception, e: except Exception, e:
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. Exception message: %s" % (config_file, e)) module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. Exception message: %s" % (config_file, e))

@ -127,6 +127,7 @@ def main():
ssl_cert=dict(default=None), ssl_cert=dict(default=None),
ssl_key=dict(default=None), ssl_key=dict(default=None),
ssl_ca=dict(default=None), ssl_ca=dict(default=None),
connect_timeout=dict(default=30, type='int'),
config_file=dict(default="~/.my.cnf") config_file=dict(default="~/.my.cnf")
) )
) )
@ -137,6 +138,7 @@ def main():
ssl_cert = module.params["ssl_cert"] ssl_cert = module.params["ssl_cert"]
ssl_key = module.params["ssl_key"] ssl_key = module.params["ssl_key"]
ssl_ca = module.params["ssl_ca"] ssl_ca = module.params["ssl_ca"]
connect_timeout = module.params['connect_timeout']
config_file = module.params['config_file'] config_file = module.params['config_file']
config_file = os.path.expanduser(os.path.expandvars(config_file)) config_file = os.path.expanduser(os.path.expandvars(config_file))
db = 'mysql' db = 'mysql'
@ -153,7 +155,8 @@ def main():
warnings.filterwarnings('error', category=MySQLdb.Warning) warnings.filterwarnings('error', category=MySQLdb.Warning)
try: try:
cursor = mysql_connect(module, user, password, config_file, ssl_cert, ssl_key, ssl_ca, db) cursor = mysql_connect(module, user, password, config_file, ssl_cert, ssl_key, ssl_ca, db,
connect_timeout=connect_timeout)
except Exception, e: except Exception, e:
if os.path.exists(config_file): if os.path.exists(config_file):
module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. Exception message: %s" % (config_file, e)) module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or %s has the credentials. Exception message: %s" % (config_file, e))

Loading…
Cancel
Save