Fix the SCP issue when using password
Change-Id: Id104c06a110210a9c4e1f2f0a4327583950b7b45
This commit is contained in:
parent
997817601c
commit
e487bba02c
@ -16,7 +16,6 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
|
||||||
|
|
||||||
import monitor
|
import monitor
|
||||||
from netaddr import IPAddress
|
from netaddr import IPAddress
|
||||||
@ -243,28 +242,14 @@ class Instance(object):
|
|||||||
self.buginf('tool %s already present - skipping install',
|
self.buginf('tool %s already present - skipping install',
|
||||||
tool_name)
|
tool_name)
|
||||||
return True
|
return True
|
||||||
# scp over the tool binary
|
|
||||||
# first chmod the local copy since git does not keep the permission
|
# first chmod the local copy since git does not keep the permission
|
||||||
os.chmod(source, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
os.chmod(source, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
||||||
|
|
||||||
# scp to the target
|
# scp over the tool binary
|
||||||
scp_opts = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
|
|
||||||
scp_cmd = 'scp -i %s %s %s %s@%s:%s' % (self.config.private_key_file,
|
|
||||||
scp_opts,
|
|
||||||
source,
|
|
||||||
self.ssh_access.username,
|
|
||||||
self.ssh_access.host,
|
|
||||||
dest)
|
|
||||||
self.buginf('Copying %s to target...', tool_name)
|
self.buginf('Copying %s to target...', tool_name)
|
||||||
self.buginf(scp_cmd)
|
rc = self.ssh.put_file_to_host(source, dest)
|
||||||
devnull = open(os.devnull, 'wb')
|
|
||||||
rc = subprocess.call(scp_cmd, shell=True,
|
return True if rc else False
|
||||||
stdout=devnull, stderr=devnull)
|
|
||||||
if rc:
|
|
||||||
self.display('Copy to target failed rc=%d', rc)
|
|
||||||
self.display(scp_cmd)
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def get_cmd_duration(self):
|
def get_cmd_duration(self):
|
||||||
'''Get the duration of the client run
|
'''Get the duration of the client run
|
||||||
|
@ -413,14 +413,28 @@ class SSH(object):
|
|||||||
def get_file_from_host(self, from_path, to_path):
|
def get_file_from_host(self, from_path, to_path):
|
||||||
'''
|
'''
|
||||||
A wrapper api on top of paramiko scp module, to scp
|
A wrapper api on top of paramiko scp module, to scp
|
||||||
a local file to the host.
|
a remote file to the local.
|
||||||
'''
|
'''
|
||||||
sshcon = self._get_client()
|
sshcon = self._get_client()
|
||||||
scpcon = scp.SCPClient(sshcon.get_transport())
|
scpcon = scp.SCPClient(sshcon.get_transport())
|
||||||
try:
|
try:
|
||||||
scpcon.get(from_path, to_path)
|
scpcon.get(from_path, to_path)
|
||||||
except scp.SCPException as exp:
|
except scp.SCPException as exp:
|
||||||
print ("Send failed: [%s]", exp)
|
print "Receive failed: [%s]" % exp
|
||||||
|
return 0
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def put_file_to_host(self, from_path, to_path):
|
||||||
|
'''
|
||||||
|
A wrapper api on top of paramiko scp module, to scp
|
||||||
|
a local file to the remote.
|
||||||
|
'''
|
||||||
|
sshcon = self._get_client()
|
||||||
|
scpcon = scp.SCPClient(sshcon.get_transport())
|
||||||
|
try:
|
||||||
|
scpcon.put(from_path, remote_path=to_path)
|
||||||
|
except scp.SCPException as exp:
|
||||||
|
print "Send failed: [%s]" % exp
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user