2009-03-04 01:42:32 +08:00
|
|
|
"""
|
|
|
|
tests for
|
2009-03-18 06:41:56 +08:00
|
|
|
- gateway management
|
2009-03-04 01:42:32 +08:00
|
|
|
- manage rsyncing of hosts
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import py
|
2009-03-18 19:18:39 +08:00
|
|
|
from py.__.execnet.gwmanage import GatewayManager, HostRSync
|
2009-03-04 01:42:32 +08:00
|
|
|
|
2009-03-20 02:25:13 +08:00
|
|
|
pytest_plugins = "pytest_pytester"
|
|
|
|
|
2009-03-17 00:53:52 +08:00
|
|
|
class TestGatewayManagerPopen:
|
2009-03-20 02:25:13 +08:00
|
|
|
def test_hostmanager_popen_makegateway(self, eventrecorder):
|
2009-03-17 00:53:52 +08:00
|
|
|
hm = GatewayManager(["popen"] * 2)
|
2009-03-04 01:42:32 +08:00
|
|
|
hm.makegateways()
|
2009-03-20 02:25:13 +08:00
|
|
|
event = eventrecorder.popevent("gwmanage_newgateway")
|
|
|
|
gw = event.args[0]
|
|
|
|
assert gw.id == "[1]"
|
|
|
|
event = eventrecorder.popevent("gwmanage_newgateway")
|
|
|
|
gw = event.args[0]
|
|
|
|
assert gw.id == "[2]"
|
2009-03-17 19:53:09 +08:00
|
|
|
assert len(hm.gateways) == 2
|
2009-03-04 01:42:32 +08:00
|
|
|
hm.exit()
|
2009-03-17 19:53:09 +08:00
|
|
|
assert not len(hm.gateways)
|
2009-03-04 01:42:32 +08:00
|
|
|
|
2009-03-17 00:53:52 +08:00
|
|
|
def test_hostmanager_popens_rsync(self, source):
|
|
|
|
hm = GatewayManager(["popen"] * 2)
|
2009-03-04 01:42:32 +08:00
|
|
|
hm.makegateways()
|
2009-03-17 19:53:09 +08:00
|
|
|
assert len(hm.gateways) == 2
|
|
|
|
for gw in hm.gateways:
|
2009-03-04 01:42:32 +08:00
|
|
|
gw.remote_exec = None
|
|
|
|
l = []
|
|
|
|
hm.rsync(source, notify=lambda *args: l.append(args))
|
|
|
|
assert not l
|
|
|
|
hm.exit()
|
2009-03-17 19:53:09 +08:00
|
|
|
assert not len(hm.gateways)
|
2009-03-04 01:42:32 +08:00
|
|
|
|
2009-03-17 00:53:52 +08:00
|
|
|
def test_hostmanager_rsync_popen_with_path(self, source, dest):
|
2009-03-18 09:13:07 +08:00
|
|
|
hm = GatewayManager(["popen::%s" %dest] * 1)
|
2009-03-04 01:42:32 +08:00
|
|
|
hm.makegateways()
|
|
|
|
source.ensure("dir1", "dir2", "hello")
|
|
|
|
l = []
|
|
|
|
hm.rsync(source, notify=lambda *args: l.append(args))
|
|
|
|
assert len(l) == 1
|
2009-03-17 19:53:09 +08:00
|
|
|
assert l[0] == ("rsyncrootready", hm.gateways[0].spec, source)
|
2009-03-04 01:42:32 +08:00
|
|
|
hm.exit()
|
|
|
|
dest = dest.join(source.basename)
|
|
|
|
assert dest.join("dir1").check()
|
|
|
|
assert dest.join("dir1", "dir2").check()
|
|
|
|
assert dest.join("dir1", "dir2", 'hello').check()
|
|
|
|
|
|
|
|
def XXXtest_ssh_rsync_samehost_twice(self):
|
|
|
|
#XXX we have no easy way to have a temp directory remotely!
|
|
|
|
option = py.test.config.option
|
|
|
|
if option.sshhost is None:
|
|
|
|
py.test.skip("no known ssh target, use -S to set one")
|
|
|
|
host1 = Host("%s" % (option.sshhost, ))
|
|
|
|
host2 = Host("%s" % (option.sshhost, ))
|
|
|
|
hm = HostManager(config, hosts=[host1, host2])
|
|
|
|
events = []
|
|
|
|
hm.init_rsync(events.append)
|
|
|
|
print events
|
|
|
|
assert 0
|
|
|
|
|
2009-03-17 00:53:52 +08:00
|
|
|
def test_multi_chdir_popen_with_path(self, testdir):
|
2009-03-04 01:42:32 +08:00
|
|
|
import os
|
2009-03-18 09:13:07 +08:00
|
|
|
hm = GatewayManager(["popen::hello"] * 2)
|
2009-03-04 01:42:32 +08:00
|
|
|
testdir.tmpdir.chdir()
|
|
|
|
hellopath = testdir.tmpdir.mkdir("hello")
|
|
|
|
hm.makegateways()
|
2009-03-18 06:41:56 +08:00
|
|
|
l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
|
2009-03-17 05:17:14 +08:00
|
|
|
paths = [x[1] for x in l]
|
2009-03-04 01:42:32 +08:00
|
|
|
assert l == [str(hellopath)] * 2
|
2009-03-18 06:41:56 +08:00
|
|
|
py.test.raises(hm.RemoteError, 'hm.multi_chdir("world", inplacelocal=False)')
|
2009-03-04 01:42:32 +08:00
|
|
|
worldpath = hellopath.mkdir("world")
|
|
|
|
hm.multi_chdir("world", inplacelocal=False)
|
2009-03-18 06:41:56 +08:00
|
|
|
l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
|
2009-03-04 01:42:32 +08:00
|
|
|
assert len(l) == 2
|
|
|
|
assert l[0] == l[1]
|
|
|
|
curwd = os.getcwd()
|
|
|
|
assert l[0].startswith(curwd)
|
|
|
|
assert l[0].endswith("world")
|
|
|
|
|
2009-03-17 00:53:52 +08:00
|
|
|
def test_multi_chdir_popen(self, testdir):
|
2009-03-04 01:42:32 +08:00
|
|
|
import os
|
2009-03-17 00:53:52 +08:00
|
|
|
hm = GatewayManager(["popen"] * 2)
|
2009-03-04 01:42:32 +08:00
|
|
|
testdir.tmpdir.chdir()
|
|
|
|
hellopath = testdir.tmpdir.mkdir("hello")
|
|
|
|
hm.makegateways()
|
|
|
|
hm.multi_chdir("hello", inplacelocal=False)
|
2009-03-18 06:41:56 +08:00
|
|
|
l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
|
2009-03-04 01:42:32 +08:00
|
|
|
assert len(l) == 2
|
|
|
|
assert l == [os.getcwd()] * 2
|
|
|
|
|
|
|
|
hm.multi_chdir("hello")
|
2009-03-18 06:41:56 +08:00
|
|
|
l = hm.multi_exec("import os ; channel.send(os.getcwd())").receive_each()
|
2009-03-04 01:42:32 +08:00
|
|
|
assert len(l) == 2
|
|
|
|
assert l[0] == l[1]
|
|
|
|
curwd = os.getcwd()
|
|
|
|
assert l[0].startswith(curwd)
|
|
|
|
assert l[0].endswith("hello")
|
|
|
|
|
|
|
|
def pytest_pyfuncarg_source(pyfuncitem):
|
|
|
|
return py.test.ensuretemp(pyfuncitem.getmodpath()).mkdir("source")
|
|
|
|
def pytest_pyfuncarg_dest(pyfuncitem):
|
|
|
|
return py.test.ensuretemp(pyfuncitem.getmodpath()).mkdir("dest")
|
|
|
|
|
|
|
|
class TestHRSync:
|
|
|
|
def test_hrsync_filter(self, source, dest):
|
|
|
|
source.ensure("dir", "file.txt")
|
|
|
|
source.ensure(".svn", "entries")
|
|
|
|
source.ensure(".somedotfile", "moreentries")
|
|
|
|
source.ensure("somedir", "editfile~")
|
|
|
|
syncer = HostRSync(source)
|
|
|
|
l = list(source.visit(rec=syncer.filter,
|
|
|
|
fil=syncer.filter))
|
|
|
|
assert len(l) == 3
|
|
|
|
basenames = [x.basename for x in l]
|
|
|
|
assert 'dir' in basenames
|
|
|
|
assert 'file.txt' in basenames
|
|
|
|
assert 'somedir' in basenames
|
|
|
|
|
|
|
|
def test_hrsync_one_host(self, source, dest):
|
2009-03-18 19:18:39 +08:00
|
|
|
spec = py.execnet.GatewaySpec("popen::%s" % dest)
|
2009-03-04 01:42:32 +08:00
|
|
|
gw = spec.makegateway()
|
|
|
|
finished = []
|
|
|
|
rsync = HostRSync(source)
|
|
|
|
rsync.add_target_host(gw, finished=lambda: finished.append(1))
|
|
|
|
source.join("hello.py").write("world")
|
|
|
|
rsync.send()
|
|
|
|
gw.exit()
|
|
|
|
assert dest.join(source.basename, "hello.py").check()
|
|
|
|
assert len(finished) == 1
|
|
|
|
|