Changeset 30b7be6f in trunk
- Timestamp:
- 2020-11-07T01:07:30Z (5 years ago)
- Branches:
- master
- Children:
- c7f4a1a1
- Parents:
- f9231444
- Location:
- integration
- Files:
-
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified integration/conftest.py ¶
rf9231444 r30b7be6f 37 37 TahoeProcess, 38 38 ) 39 from grid import (40 create_port_allocator,41 create_flog_gatherer,42 create_grid,43 )44 39 45 40 … … 76 71 from twisted.internet import reactor as _reactor 77 72 return _reactor 78 79 80 @pytest.fixture(scope='session')81 @log_call(action_type=u"integration:port_allocator", include_result=False)82 def port_allocator(reactor):83 return create_port_allocator(start_port=45000)84 73 85 74 … … 118 107 @log_call(action_type=u"integration:flog_gatherer", include_args=[]) 119 108 def flog_gatherer(reactor, temp_dir, flog_binary, request): 120 fg = pytest_twisted.blockon( 121 create_flog_gatherer(reactor, request, temp_dir, flog_binary) 122 ) 123 return fg 124 125 126 @pytest.fixture(scope='session') 127 @log_call(action_type=u"integration:grid", include_args=[]) 128 def grid(reactor, request, temp_dir, flog_gatherer, port_allocator): 129 g = pytest_twisted.blockon( 130 create_grid(reactor, request, temp_dir, flog_gatherer, port_allocator) 131 ) 132 return g 133 134 135 @pytest.fixture(scope='session') 136 def introducer(grid): 137 return grid.introducer 109 out_protocol = _CollectOutputProtocol() 110 gather_dir = join(temp_dir, 'flog_gather') 111 reactor.spawnProcess( 112 out_protocol, 113 flog_binary, 114 ( 115 'flogtool', 'create-gatherer', 116 '--location', 'tcp:localhost:3117', 117 '--port', '3117', 118 gather_dir, 119 ) 120 ) 121 pytest_twisted.blockon(out_protocol.done) 122 123 twistd_protocol = _MagicTextProtocol("Gatherer waiting at") 124 twistd_process = reactor.spawnProcess( 125 twistd_protocol, 126 which('twistd')[0], 127 ( 128 'twistd', '--nodaemon', '--python', 129 join(gather_dir, 'gatherer.tac'), 130 ), 131 path=gather_dir, 132 ) 133 pytest_twisted.blockon(twistd_protocol.magic_seen) 134 135 def cleanup(): 136 _cleanup_tahoe_process(twistd_process, twistd_protocol.exited) 137 138 flog_file = mktemp('.flog_dump') 139 flog_protocol = _DumpOutputProtocol(open(flog_file, 'w')) 140 flog_dir = join(temp_dir, 'flog_gather') 141 flogs = [x for x in listdir(flog_dir) if x.endswith('.flog')] 142 143 print("Dumping {} flogtool logfiles to '{}'".format(len(flogs), flog_file)) 144 reactor.spawnProcess( 145 flog_protocol, 146 flog_binary, 147 ( 148 'flogtool', 'dump', join(temp_dir, 'flog_gather', flogs[0]) 149 ), 150 ) 151 print("Waiting for flogtool to complete") 152 try: 153 pytest_twisted.blockon(flog_protocol.done) 154 except ProcessTerminated as e: 155 print("flogtool exited unexpectedly: {}".format(str(e))) 156 print("Flogtool completed") 157 158 request.addfinalizer(cleanup) 159 160 with open(join(gather_dir, 'log_gatherer.furl'), 'r') as f: 161 furl = f.read().strip() 162 return furl 163 164 165 @pytest.fixture(scope='session') 166 @log_call( 167 action_type=u"integration:introducer", 168 include_args=["temp_dir", "flog_gatherer"], 169 include_result=False, 170 ) 171 def introducer(reactor, temp_dir, flog_gatherer, request): 172 config = ''' 173 [node] 174 nickname = introducer0 175 web.port = 4560 176 log_gatherer.furl = {log_furl} 177 '''.format(log_furl=flog_gatherer) 178 179 intro_dir = join(temp_dir, 'introducer') 180 print("making introducer", intro_dir) 181 182 if not exists(intro_dir): 183 mkdir(intro_dir) 184 done_proto = _ProcessExitedProtocol() 185 _tahoe_runner_optional_coverage( 186 done_proto, 187 reactor, 188 request, 189 ( 190 'create-introducer', 191 '--listen=tcp', 192 '--hostname=localhost', 193 intro_dir, 194 ), 195 ) 196 pytest_twisted.blockon(done_proto.done) 197 198 # over-write the config file with our stuff 199 with open(join(intro_dir, 'tahoe.cfg'), 'w') as f: 200 f.write(config) 201 202 # on windows, "tahoe start" means: run forever in the foreground, 203 # but on linux it means daemonize. "tahoe run" is consistent 204 # between platforms. 205 protocol = _MagicTextProtocol('introducer running') 206 transport = _tahoe_runner_optional_coverage( 207 protocol, 208 reactor, 209 request, 210 ( 211 'run', 212 intro_dir, 213 ), 214 ) 215 request.addfinalizer(partial(_cleanup_tahoe_process, transport, protocol.exited)) 216 217 pytest_twisted.blockon(protocol.magic_seen) 218 return TahoeProcess(transport, intro_dir) 138 219 139 220 … … 141 222 @log_call(action_type=u"integration:introducer:furl", include_args=["temp_dir"]) 142 223 def introducer_furl(introducer, temp_dir): 143 return introducer.furl 224 furl_fname = join(temp_dir, 'introducer', 'private', 'introducer.furl') 225 while not exists(furl_fname): 226 print("Don't see {} yet".format(furl_fname)) 227 sleep(.1) 228 furl = open(furl_fname, 'r').read() 229 return furl 144 230 145 231 … … 220 306 @log_call( 221 307 action_type=u"integration:storage_nodes", 222 include_args=[" grid"],308 include_args=["temp_dir", "introducer_furl", "flog_gatherer"], 223 309 include_result=False, 224 310 ) 225 def storage_nodes( grid):311 def storage_nodes(reactor, temp_dir, introducer, introducer_furl, flog_gatherer, request): 226 312 nodes_d = [] 227 313 # start all 5 nodes in parallel 228 314 for x in range(5): 229 #nodes_d.append(grid.add_storage_node()) 230 pytest_twisted.blockon(grid.add_storage_node()) 231 315 name = 'node{}'.format(x) 316 web_port= 9990 + x 317 nodes_d.append( 318 _create_node( 319 reactor, request, temp_dir, introducer_furl, flog_gatherer, name, 320 web_port="tcp:{}:interface=localhost".format(web_port), 321 storage=True, 322 ) 323 ) 232 324 nodes_status = pytest_twisted.blockon(DeferredList(nodes_d)) 233 for ok, value in nodes_status: 234 assert ok, "Storage node creation failed: {}".format(value) 235 return grid.storage_servers 325 nodes = [] 326 for ok, process in nodes_status: 327 assert ok, "Storage node creation failed: {}".format(process) 328 nodes.append(process) 329 return nodes 236 330 237 331 -
TabularUnified integration/test_servers_of_happiness.py ¶
rf9231444 r30b7be6f 40 40 yield proto.done 41 41 assert False, "should raise exception" 42 except util.ProcessFailedas e:43 assert "UploadUnhappinessError" in e.output42 except Exception as e: 43 assert isinstance(e, ProcessTerminated) 44 44 45 assert "shares could be placed on only" in proto.output.getvalue() 45 output = proto.output.getvalue() 46 assert "shares could be placed on only" in output -
TabularUnified integration/test_tor.py ¶
rf9231444 r30b7be6f 77 77 web_port = "tcp:{}:interface=localhost".format(control_port + 2000) 78 78 79 if exists(node_dir): 80 raise RuntimeError( 81 "A node already exists in '{}'".format(node_dir) 79 if True: 80 print("creating", node_dir) 81 mkdir(node_dir) 82 proto = util._DumpOutputProtocol(None) 83 reactor.spawnProcess( 84 proto, 85 sys.executable, 86 ( 87 sys.executable, '-m', 'allmydata.scripts.runner', 88 'create-node', 89 '--nickname', name, 90 '--introducer', introducer_furl, 91 '--hide-ip', 92 '--tor-control-port', 'tcp:localhost:{}'.format(control_port), 93 '--listen', 'tor', 94 node_dir, 95 ) 82 96 ) 83 print("creating", node_dir) 84 mkdir(node_dir) 85 proto = util._DumpOutputProtocol(None) 86 reactor.spawnProcess( 87 proto, 88 sys.executable, 89 ( 90 sys.executable, '-m', 'allmydata.scripts.runner', 91 'create-node', 92 '--nickname', name, 93 '--introducer', introducer_furl, 94 '--hide-ip', 95 '--tor-control-port', 'tcp:localhost:{}'.format(control_port), 96 '--listen', 'tor', 97 node_dir, 98 ) 99 ) 100 yield proto.done 97 yield proto.done 101 98 102 99 with open(join(node_dir, 'tahoe.cfg'), 'w') as f: -
TabularUnified integration/test_web.py ¶
rf9231444 r30b7be6f 97 97 """ 98 98 99 url = util.node_url(storage_nodes[0]. process.node_dir, "helper_status")99 url = util.node_url(storage_nodes[0].node_dir, "helper_status") 100 100 resp = requests.get(url) 101 101 assert resp.status_code >= 200 and resp.status_code < 300 … … 417 417 418 418 requests.get( 419 util.node_url(storage0. process.node_dir, u"storage"),419 util.node_url(storage0.node_dir, u"storage"), 420 420 ) 421 421 … … 428 428 429 429 resp = requests.get( 430 util.node_url(storage0. process.node_dir, u"storage"),430 util.node_url(storage0.node_dir, u"storage"), 431 431 params={u"t": u"json"}, 432 432 ) … … 440 440 """ 441 441 resp = requests.get( 442 util.node_url(introducer. process.node_dir, u""),442 util.node_url(introducer.node_dir, u""), 443 443 ) 444 444 assert "Introducer" in resp.content 445 445 446 446 resp = requests.get( 447 util.node_url(introducer. process.node_dir, u""),447 util.node_url(introducer.node_dir, u""), 448 448 params={u"t": u"json"}, 449 449 ) -
TabularUnified integration/util.py ¶
rf9231444 r30b7be6f 6 6 from six.moves import StringIO 7 7 from functools import partial 8 from shutil import rmtree9 8 10 9 from twisted.internet.defer import Deferred, succeed … … 37 36 38 37 39 class ProcessFailed(Exception):40 """41 A subprocess has failed.42 43 :ivar ProcessTerminated reason: the original reason from .processExited44 45 :ivar StringIO output: all stdout and stderr collected to this point.46 """47 48 def __init__(self, reason, output):49 self.reason = reason50 self.output = output51 52 def __str__(self):53 return "<ProcessFailed: {}>:\n{}".format(self.reason, self.output)54 55 56 38 class _CollectOutputProtocol(ProcessProtocol): 57 39 """ … … 60 42 process exits (for any reason). 61 43 """ 62 def __init__(self , stdin=None):44 def __init__(self): 63 45 self.done = Deferred() 64 46 self.output = StringIO() 65 self._stdin = stdin66 67 def connectionMade(self):68 if self._stdin is not None:69 self.transport.write(self._stdin)70 self.transport.closeStdin()71 47 72 48 def processEnded(self, reason): … … 76 52 def processExited(self, reason): 77 53 if not isinstance(reason.value, ProcessDone): 78 self.done.errback( ProcessFailed(reason, self.output.getvalue()))54 self.done.errback(reason) 79 55 80 56 def outReceived(self, data): … … 148 124 print("signaling {} with TERM".format(tahoe_transport.pid)) 149 125 tahoe_transport.signalProcess('TERM') 150 print("signaled, blocking on exit {}".format(exited))126 print("signaled, blocking on exit") 151 127 pytest_twisted.blockon(exited) 152 128 print("exited, goodbye") 153 129 except ProcessExitedAlready: 154 130 pass 155 156 157 def run_tahoe(reactor, request, *args, **kwargs):158 """159 Helper to run tahoe with optional coverage.160 161 :returns: a Deferred that fires when the command is done (or a162 ProcessFailed exception if it exits non-zero)163 """164 stdin = kwargs.get("stdin", None)165 protocol = _CollectOutputProtocol(stdin=stdin)166 process = _tahoe_runner_optional_coverage(protocol, reactor, request, args)167 process.exited = protocol.done168 return protocol.done169 131 170 132 … … 270 232 created_d = succeed(None) 271 233 else: 272 print("creating : {}".format(node_dir))234 print("creating", node_dir) 273 235 mkdir(node_dir) 274 236 done_proto = _ProcessExitedProtocol() … … 295 257 config_path = join(node_dir, 'tahoe.cfg') 296 258 config = get_config(config_path) 297 set_config(config, 'node', 'log_gatherer.furl', flog_gatherer .furl)259 set_config(config, 'node', 'log_gatherer.furl', flog_gatherer) 298 260 write_config(config_path, config) 299 261 created_d.addCallback(created) … … 482 444 483 445 484 def await_client_ready(tahoe, timeout=10, liveness=60*2 , servers=1):446 def await_client_ready(tahoe, timeout=10, liveness=60*2): 485 447 """ 486 448 Uses the status API to wait for a client-type node (in `tahoe`, a … … 506 468 continue 507 469 508 if len(js['servers']) < servers:509 print("waiting because fewer than {} server(s)".format(servers))470 if len(js['servers']) == 0: 471 print("waiting because no servers at all") 510 472 time.sleep(1) 511 473 continue
Note: See TracChangeset
for help on using the changeset viewer.