[svn r38192] streamlining localhost optimization handling,
and simplifying the test a bit. --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									411157756b
								
							
						
					
					
						commit
						6e293f593a
					
				|  | @ -17,14 +17,10 @@ class HostInfo(object): | ||||||
|     def __init__(self, spec): |     def __init__(self, spec): | ||||||
|         parts = spec.split(':', 1) |         parts = spec.split(':', 1) | ||||||
|         self.hostname = parts.pop(0) |         self.hostname = parts.pop(0) | ||||||
|         if parts and parts[0]: |         self.relpath = parts and parts.pop(0) or "" | ||||||
|             self.relpath = parts[0] |         if not self.relpath and self.hostname != "localhost": | ||||||
|         else: |             self.relpath = "pytestcache-%s" % self.hostname | ||||||
|             self.relpath = "pytestcache-" + self.hostname |         assert not parts | ||||||
|         if spec.find(':') == -1 and self.hostname == 'localhost': |  | ||||||
|             self.rsync_flag = False |  | ||||||
|         else: |  | ||||||
|             self.rsync_flag = True |  | ||||||
|         self.hostid = self._getuniqueid(self.hostname)  |         self.hostid = self._getuniqueid(self.hostname)  | ||||||
| 
 | 
 | ||||||
|     def _getuniqueid(self, hostname): |     def _getuniqueid(self, hostname): | ||||||
|  | @ -33,23 +29,24 @@ class HostInfo(object): | ||||||
|         l.append(hostid) |         l.append(hostid) | ||||||
|         return hostid |         return hostid | ||||||
| 
 | 
 | ||||||
|     def initgateway(self, python="python"): |     def initgateway(self, python="python", topdir=None): | ||||||
|         assert not hasattr(self, 'gw') |  | ||||||
|         if self.hostname == "localhost": |         if self.hostname == "localhost": | ||||||
|             gw = py.execnet.PopenGateway(python=python) |             self.gw = py.execnet.PopenGateway(python=python) | ||||||
|         else: |         else: | ||||||
|             gw = py.execnet.SshGateway(self.hostname,  |             self.gw = py.execnet.SshGateway(self.hostname,  | ||||||
|                                             remotepython=python) |                                             remotepython=python) | ||||||
|         self.gw = gw |         relpath = self.relpath or topdir  | ||||||
|         channel = gw.remote_exec(py.code.Source( |         assert relpath  | ||||||
|  |         channel = self.gw.remote_exec(py.code.Source( | ||||||
|             gethomedir,  |             gethomedir,  | ||||||
|             getpath_relto_home, """ |             getpath_relto_home, """ | ||||||
|             import os |             import os | ||||||
|             os.chdir(gethomedir()) |             os.chdir(gethomedir()) | ||||||
|             newdir = getpath_relto_home(%r) |             path = %r | ||||||
|             # we intentionally don't ensure that 'newdir' exists  |             if path: | ||||||
|             channel.send(newdir) |                 path = getpath_relto_home(path) | ||||||
|             """ % str(self.relpath) |             channel.send(path) | ||||||
|  |             """ % str(relpath) | ||||||
|         )) |         )) | ||||||
|         self.gw_remotepath = channel.receive() |         self.gw_remotepath = channel.receive() | ||||||
| 
 | 
 | ||||||
|  | @ -71,13 +68,13 @@ class HostInfo(object): | ||||||
| class HostRSync(py.execnet.RSync): | class HostRSync(py.execnet.RSync): | ||||||
|     """ RSyncer that filters out common files  |     """ RSyncer that filters out common files  | ||||||
|     """ |     """ | ||||||
|     def __init__(self, source, *args, **kwargs): |     def __init__(self, sourcedir, *args, **kwargs): | ||||||
|         self._synced = {} |         self._synced = {} | ||||||
|         ignores= None |         ignores= None | ||||||
|         if 'ignores' in kwargs: |         if 'ignores' in kwargs: | ||||||
|             ignores = kwargs.pop('ignores') |             ignores = kwargs.pop('ignores') | ||||||
|         self._ignores = ignores or [] |         self._ignores = ignores or [] | ||||||
|         super(HostRSync, self).__init__(source, **kwargs) |         super(HostRSync, self).__init__(sourcedir=sourcedir, **kwargs) | ||||||
| 
 | 
 | ||||||
|     def filter(self, path): |     def filter(self, path): | ||||||
|         path = py.path.local(path) |         path = py.path.local(path) | ||||||
|  | @ -91,20 +88,22 @@ class HostRSync(py.execnet.RSync): | ||||||
|                         return True |                         return True | ||||||
| 
 | 
 | ||||||
|     def add_target_host(self, host, reporter=lambda x: None, |     def add_target_host(self, host, reporter=lambda x: None, | ||||||
|                         destrelpath=None, finishedcallback=None): |                         destrelpath="", finishedcallback=None): | ||||||
|         key = host.hostname, host.relpath  |         remotepath = host.relpath | ||||||
|         if not host.rsync_flag or key in self._synced: |         key = host.hostname, remotepath | ||||||
|  |         if host.hostname == "localhost" and not remotepath:  | ||||||
|  |             p = py.path.local(host.gw_remotepath) | ||||||
|  |             assert p.join(destrelpath) == self._sourcedir | ||||||
|  |             self._synced[key] = True | ||||||
|  |         if key in self._synced: | ||||||
|             if finishedcallback: |             if finishedcallback: | ||||||
|                 finishedcallback() |                 finishedcallback() | ||||||
|             return False |             return False | ||||||
|         self._synced[key] = True |         self._synced[key] = True | ||||||
|         # the follow attributes are set from host.initgateway() |         # the follow attributes are set from host.initgateway() | ||||||
|         gw = host.gw |         if destrelpath: | ||||||
|         remotepath = host.gw_remotepath |  | ||||||
|         if destrelpath is not None: |  | ||||||
|             remotepath = os.path.join(remotepath, destrelpath) |             remotepath = os.path.join(remotepath, destrelpath) | ||||||
|         super(HostRSync, self).add_target(gw,  |         super(HostRSync, self).add_target(host.gw, remotepath,  | ||||||
|                                           remotepath,  |  | ||||||
|                                           finishedcallback, |                                           finishedcallback, | ||||||
|                                           delete=True, |                                           delete=True, | ||||||
|                                           ) |                                           ) | ||||||
|  | @ -123,9 +122,9 @@ class HostManager(object): | ||||||
|         self.roots = roots |         self.roots = roots | ||||||
| 
 | 
 | ||||||
|     def prepare_gateways(self, reporter): |     def prepare_gateways(self, reporter): | ||||||
|         dist_remotepython = self.config.getvalue("dist_remotepython") |         python = self.config.getvalue("dist_remotepython") | ||||||
|         for host in self.hosts: |         for host in self.hosts: | ||||||
|             host.initgateway(python=dist_remotepython) |             host.initgateway(python=python, topdir=self.config.topdir) | ||||||
|             reporter(repevent.HostGatewayReady(host, self.roots)) |             reporter(repevent.HostGatewayReady(host, self.roots)) | ||||||
|             host.gw.host = host |             host.gw.host = host | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ class TestHostInfo(DirSetup): | ||||||
|     def test_defaultpath(self): |     def test_defaultpath(self): | ||||||
|         x = HostInfo("localhost:") |         x = HostInfo("localhost:") | ||||||
|         assert x.hostname == "localhost" |         assert x.hostname == "localhost" | ||||||
|         assert x.relpath == "pytestcache-" + x.hostname  |         assert not x.relpath | ||||||
| 
 | 
 | ||||||
|     def test_path(self): |     def test_path(self): | ||||||
|         x = HostInfo("localhost:/tmp") |         x = HostInfo("localhost:/tmp") | ||||||
|  | @ -193,18 +193,15 @@ class TestHostManager(DirSetup): | ||||||
|         assert not self.dest.join("dir6").check() |         assert not self.dest.join("dir6").check() | ||||||
| 
 | 
 | ||||||
|     def test_hostmanage_optimise_localhost(self): |     def test_hostmanage_optimise_localhost(self): | ||||||
|         def add_target(self, a, b, c): |         hosts = [HostInfo("localhost") for i in range(3)] | ||||||
|             assert 0, "Should not rsync here" |  | ||||||
|         try: |  | ||||||
|         config = py.test.config._reparse([self.source]) |         config = py.test.config._reparse([self.source]) | ||||||
|             old_add_target = HostRSync.add_target |         hm = HostManager(config, hosts=hosts) | ||||||
|             HostRSync.add_target = add_target |  | ||||||
|             hm = HostManager(config, hosts=[HostInfo('localhost') for i in |  | ||||||
|                                             range(3)]) |  | ||||||
|         events = [] |         events = [] | ||||||
|             hm.init_rsync(reporter=events.append) |         hm.init_rsync(events.append) | ||||||
|         finally: |         for host in hosts: | ||||||
|             HostRSync.add_target = old_add_target |             assert host.gw_remotepath == str(self.source) | ||||||
|  |             assert not host.relpath  | ||||||
|  |         assert events | ||||||
| 
 | 
 | ||||||
| def test_getpath_relto_home(): | def test_getpath_relto_home(): | ||||||
|     x = getpath_relto_home("hello") |     x = getpath_relto_home("hello") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue