Merge "Create remote paths before syncing"

This commit is contained in:
Jenkins 2016-03-02 14:45:40 +00:00 committed by Gerrit Code Review
commit dae395fc2e
3 changed files with 37 additions and 16 deletions

View File

@ -27,4 +27,4 @@ class NaiveSync(BaseHandler):
# to understand where src comes from
for item in args['sources']:
self.transport_sync.copy(resource, item['src'], item['dst'])
self.transport_sync.sync_all()
self.transport_sync.sync_all()

View File

@ -54,10 +54,14 @@ class RsyncSyncTransport(SyncTransport):
def copy(self, resource, _from, _to, use_sudo=False):
log.debug("RSYNC: %s -> %s", _from, _to)
if use_sudo:
rsync_path = "sudo rsync"
if os.path.isdir(_from):
r_dir_path = _to
else:
rsync_path = "rsync"
r_dir_path = _to.rsplit('/', 1)[0]
if use_sudo:
rsync_path = "sudo mkdir -p {} && sudo rsync".format(r_dir_path)
else:
rsync_path = "mkdir -p {} && rsync".format(r_dir_path)
rsync_props = self._rsync_props(resource)
ssh_cmd = ' '.join(self._ssh_cmd(rsync_props))

View File

@ -65,21 +65,38 @@ class SSHSyncTransport(SyncTransport, _SSHTransport):
_SSHTransport.__init__(self)
SyncTransport.__init__(self)
def _ensure_remote_dir_exists(self, resource, _from, _to, use_sudo=False):
# NOTE(jnowak): it's not efficient way to do so, but also this
# transport is not that efficient
if os.path.isdir(_from):
r_dir_path = _to
else:
r_dir_path = _to.rsplit('/', 1)[0]
self.other(resource).run(resource,
'mkdir',
'-p',
r_dir_path,
use_sudo=use_sudo)
def _copy_file(self, resource, _from, _to, use_sudo=False):
executor = lambda transport: fabric_project.put(
remote_path=_to,
local_path=_from,
use_sudo=use_sudo
)
return executor
def wrp(transport):
self._ensure_remote_dir_exists(resource, _from, _to, use_sudo)
return fabric_project.put(
remote_path=_to,
local_path=_from,
use_sudo=use_sudo
)
return wrp
def _copy_directory(self, resource, _from, _to, use_sudo=False):
executor = lambda transport: fabric_project.upload_project(
remote_dir=_to,
local_dir=_from,
use_sudo=use_sudo
)
return executor
def wrp(transport):
self._ensure_remote_dir_exists(resource, _from, _to, use_sudo)
return fabric_project.upload_project(
remote_dir=_to,
local_dir=_from,
use_sudo=use_sudo
)
return wrp
def copy(self, resource, _from, _to, use_sudo=False):
log.debug('SCP: %s -> %s', _from, _to)