Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_rsync_non_verbose(self, capsys, dirs, gw1):
source = dirs.source
source.ensure("hello")
rsync = RSync(source, verbose=False)
rsync.add_target(gw1, dirs.dest1)
rsync.send()
out, err = capsys.readouterr()
assert not out
assert not err
def test_notargets(self, dirs):
rsync = RSync(dirs.source)
with pytest.raises(IOError):
rsync.send()
assert rsync.send(raises=False) is None
def test_rsync_default_reporting(self, capsys, dirs, gw1):
source = dirs.source
source.ensure("hello")
rsync = RSync(source)
rsync.add_target(gw1, dirs.dest1)
rsync.send()
out, err = capsys.readouterr()
assert out.find("hello") != -1
def test_permissions(self, dirs, gw1, gw2):
source = dirs.source
dest = dirs.dest1
onedir = dirs.source.ensure("one", dir=1)
onedir.chmod(448)
onefile = dirs.source.ensure("file")
onefile.chmod(504)
onefile_mtime = onefile.stat().mtime
rsync = RSync(source)
rsync.add_target(gw1, dest)
rsync.send()
destdir = dirs.dest1.join(onedir.basename)
destfile = dirs.dest1.join(onefile.basename)
assert destfile.stat().mode & 511 == 504
mode = destdir.stat().mode
assert mode & 511 == 448
# transfer again with changed permissions
onedir.chmod(504)
onefile.chmod(448)
onefile.setmtime(onefile_mtime)
rsync = RSync(source)
rsync.add_target(gw1, dest)
except IOError:
cluster = imp.load_source('cluster',
os.path.expanduser('~/.sailfish/{0}'.format(self.config.cluster_spec)))
self._cluster_gateways = []
self._node_subdomains = split_subdomains_between_nodes(cluster.nodes, subdomains)
import execnet
for _, node in zip(self._node_subdomains, cluster.nodes):
self._cluster_gateways.append(execnet.makegateway(node.host))
# Copy files to remote nodes if necessary.
if self.config.cluster_sync:
local, dest = self.config.cluster_sync.split(':')
assert dest[0] != '/', 'Only relative paths are supported on remote nodes.'
rsync = execnet.RSync(local)
for gw in self._cluster_gateways:
rsync.add_target(gw, dest)
rsync.send()
subdomain_id_to_addr = {}
for node_id, subdomains in enumerate(self._node_subdomains):
for subdomain in subdomains:
subdomain_id_to_addr[subdomain.id] = cluster.nodes[node_id].addr
self._cluster_channels = []
import sys
for i, (node, gw) in enumerate(zip(cluster.nodes, self._cluster_gateways)):
# Assign specific GPUs from this node, as defined by the cluster
# config file.
node_config = copy.copy(self.config)
node_config.gpus = cluster.nodes[i].gpus
def update(self, host):
env = self.environment
blacklist = ['.batou', 'work', '.git', '.hg', '.vagrant', '.kitchen',
'.batou-lock']
for candidate in os.listdir(env.base_dir):
if candidate in blacklist:
continue
source = os.path.join(env.base_dir, candidate)
target = os.path.join(host.remote_base, candidate)
output.annotate("rsync: {} -> {}".format(source, target),
debug=True)
rsync = execnet.RSync(source, verbose=False)
rsync.add_target(host.gateway, target, delete=True)
rsync.send()
def update_rsync(self):
env = self.deployment.environment
blacklist = ['.batou', 'work', '.git', '.hg', '.vagrant']
for source in os.listdir(env.base_dir):
if source in blacklist:
continue
rsync = execnet.RSync(os.path.join(env.base_dir, source))
rsync.add_target(self.gateway,
os.path.join(self.remote_base, source))
rsync.send()
bundle_range = self.branch
else:
head = head.decode('ascii')
bundle_range = '{head}..{branch}'.format(
head=head, branch=self.branch)
fd, bundle_file = tempfile.mkstemp()
os.close(fd)
out, err = cmd('git bundle create {file} {range}'.format(
file=bundle_file, range=bundle_range),
acceptable_returncodes=[0, 128])
if 'create empty bundle' in err:
return
change_size = os.stat(bundle_file).st_size
output.annotate(
'Sending {} bytes of changes'.format(change_size), debug=True)
rsync = execnet.RSync(bundle_file, verbose=False)
rsync.add_target(host.gateway,
host.remote_repository + '/batou-bundle.git')
rsync.send()
os.unlink(bundle_file)
output.annotate(
'Unbundling changes', debug=True)
host.rpc.git_unbundle_code()