Fix for the new import code when password is empty

This commit is contained in:
Toshio Kuratomi 2015-05-27 20:27:51 -07:00
parent 415815ef45
commit 2b5e932cfb

View file

@ -164,14 +164,19 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
if not os.path.exists(target): if not os.path.exists(target):
return module.fail_json(msg="target %s does not exist on the host" % target) return module.fail_json(msg="target %s does not exist on the host" % target)
cmd = module.get_bin_path('mysql', True) cmd = [module.get_bin_path('mysql', True)]
cmd += " --user=%s --password=%s" % (pipes.quote(user), pipes.quote(password)) if user:
cmd.append("--user=%s" % pipes.quote(user))
if password:
cmd.append("--password=%s" % pipes.quote(password))
if socket is not None: if socket is not None:
cmd += " --socket=%s" % pipes.quote(socket) cmd.append("--socket=%s" % pipes.quote(socket))
else: else:
cmd += " --host=%s --port=%i" % (pipes.quote(host), port) cmd.append("--host=%s" % pipes.quote(host))
cmd.append("--port=%i" % port)
if not all_databases: if not all_databases:
cmd += " -D %s" % pipes.quote(db_name) cmd.append("-D")
cmd.append(pipes.quote(db_name))
comp_prog_path = None comp_prog_path = None
if os.path.splitext(target)[-1] == '.gz': if os.path.splitext(target)[-1] == '.gz':
@ -183,7 +188,7 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
if comp_prog_path: if comp_prog_path:
p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p1 = subprocess.Popen([comp_prog_path, '-dc', target], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p2 = subprocess.Popen(cmd.split(' '), stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p2 = subprocess.Popen(cmd, stdin=p1.stdout, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout2, stderr2) = p2.communicate() (stdout2, stderr2) = p2.communicate()
p1.stdout.close() p1.stdout.close()
p1.wait() p1.wait()
@ -193,6 +198,7 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
else: else:
return p2.returncode, stdout2, stderr2 return p2.returncode, stdout2, stderr2
else: else:
cmd = ' '.join(cmd)
cmd += " < %s" % pipes.quote(target) cmd += " < %s" % pipes.quote(target)
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True) rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
return rc, stdout, stderr return rc, stdout, stderr