Fix for the new import code when password is empty
This commit is contained in:
parent
415815ef45
commit
2b5e932cfb
1 changed files with 12 additions and 6 deletions
|
@ -164,14 +164,19 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
|
|||
if not os.path.exists(target):
|
||||
return module.fail_json(msg="target %s does not exist on the host" % target)
|
||||
|
||||
cmd = module.get_bin_path('mysql', True)
|
||||
cmd += " --user=%s --password=%s" % (pipes.quote(user), pipes.quote(password))
|
||||
cmd = [module.get_bin_path('mysql', True)]
|
||||
if user:
|
||||
cmd.append("--user=%s" % pipes.quote(user))
|
||||
if password:
|
||||
cmd.append("--password=%s" % pipes.quote(password))
|
||||
if socket is not None:
|
||||
cmd += " --socket=%s" % pipes.quote(socket)
|
||||
cmd.append("--socket=%s" % pipes.quote(socket))
|
||||
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:
|
||||
cmd += " -D %s" % pipes.quote(db_name)
|
||||
cmd.append("-D")
|
||||
cmd.append(pipes.quote(db_name))
|
||||
|
||||
comp_prog_path = None
|
||||
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:
|
||||
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()
|
||||
p1.stdout.close()
|
||||
p1.wait()
|
||||
|
@ -193,6 +198,7 @@ def db_import(module, host, user, password, db_name, target, all_databases, port
|
|||
else:
|
||||
return p2.returncode, stdout2, stderr2
|
||||
else:
|
||||
cmd = ' '.join(cmd)
|
||||
cmd += " < %s" % pipes.quote(target)
|
||||
rc, stdout, stderr = module.run_command(cmd, use_unsafe_shell=True)
|
||||
return rc, stdout, stderr
|
||||
|
|
Loading…
Reference in a new issue