Changeset 30b7be6f in trunk


Ignore:
Timestamp:
2020-11-07T01:07:30Z (5 years ago)
Author:
meejah <meejah@…>
Branches:
master
Children:
c7f4a1a1
Parents:
f9231444
Message:

remove integration tests/refactoring

Location:
integration
Files:
2 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified integration/conftest.py

    rf9231444 r30b7be6f  
    3737    TahoeProcess,
    3838)
    39 from grid import (
    40     create_port_allocator,
    41     create_flog_gatherer,
    42     create_grid,
    43 )
    4439
    4540
     
    7671    from twisted.internet import reactor as _reactor
    7772    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)
    8473
    8574
     
    118107@log_call(action_type=u"integration:flog_gatherer", include_args=[])
    119108def 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)
     171def introducer(reactor, temp_dir, flog_gatherer, request):
     172    config = '''
     173[node]
     174nickname = introducer0
     175web.port = 4560
     176log_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)
    138219
    139220
     
    141222@log_call(action_type=u"integration:introducer:furl", include_args=["temp_dir"])
    142223def 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
    144230
    145231
     
    220306@log_call(
    221307    action_type=u"integration:storage_nodes",
    222     include_args=["grid"],
     308    include_args=["temp_dir", "introducer_furl", "flog_gatherer"],
    223309    include_result=False,
    224310)
    225 def storage_nodes(grid):
     311def storage_nodes(reactor, temp_dir, introducer, introducer_furl, flog_gatherer, request):
    226312    nodes_d = []
    227313    # start all 5 nodes in parallel
    228314    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        )
    232324    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
    236330
    237331
  • TabularUnified integration/test_servers_of_happiness.py

    rf9231444 r30b7be6f  
    4040        yield proto.done
    4141        assert False, "should raise exception"
    42     except util.ProcessFailed as e:
    43         assert "UploadUnhappinessError" in e.output
     42    except Exception as e:
     43        assert isinstance(e, ProcessTerminated)
    4444
    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  
    7777    web_port = "tcp:{}:interface=localhost".format(control_port + 2000)
    7878
    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            )
    8296        )
    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
    10198
    10299    with open(join(node_dir, 'tahoe.cfg'), 'w') as f:
  • TabularUnified integration/test_web.py

    rf9231444 r30b7be6f  
    9797    """
    9898
    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")
    100100    resp = requests.get(url)
    101101    assert resp.status_code >= 200 and resp.status_code < 300
     
    417417
    418418    requests.get(
    419         util.node_url(storage0.process.node_dir, u"storage"),
     419        util.node_url(storage0.node_dir, u"storage"),
    420420    )
    421421
     
    428428
    429429    resp = requests.get(
    430         util.node_url(storage0.process.node_dir, u"storage"),
     430        util.node_url(storage0.node_dir, u"storage"),
    431431        params={u"t": u"json"},
    432432    )
     
    440440    """
    441441    resp = requests.get(
    442         util.node_url(introducer.process.node_dir, u""),
     442        util.node_url(introducer.node_dir, u""),
    443443    )
    444444    assert "Introducer" in resp.content
    445445
    446446    resp = requests.get(
    447         util.node_url(introducer.process.node_dir, u""),
     447        util.node_url(introducer.node_dir, u""),
    448448        params={u"t": u"json"},
    449449    )
  • TabularUnified integration/util.py

    rf9231444 r30b7be6f  
    66from six.moves import StringIO
    77from functools import partial
    8 from shutil import rmtree
    98
    109from twisted.internet.defer import Deferred, succeed
     
    3736
    3837
    39 class ProcessFailed(Exception):
    40     """
    41     A subprocess has failed.
    42 
    43     :ivar ProcessTerminated reason: the original reason from .processExited
    44 
    45     :ivar StringIO output: all stdout and stderr collected to this point.
    46     """
    47 
    48     def __init__(self, reason, output):
    49         self.reason = reason
    50         self.output = output
    51 
    52     def __str__(self):
    53         return "<ProcessFailed: {}>:\n{}".format(self.reason, self.output)
    54 
    55 
    5638class _CollectOutputProtocol(ProcessProtocol):
    5739    """
     
    6042    process exits (for any reason).
    6143    """
    62     def __init__(self, stdin=None):
     44    def __init__(self):
    6345        self.done = Deferred()
    6446        self.output = StringIO()
    65         self._stdin = stdin
    66 
    67     def connectionMade(self):
    68         if self._stdin is not None:
    69             self.transport.write(self._stdin)
    70             self.transport.closeStdin()
    7147
    7248    def processEnded(self, reason):
     
    7652    def processExited(self, reason):
    7753        if not isinstance(reason.value, ProcessDone):
    78             self.done.errback(ProcessFailed(reason, self.output.getvalue()))
     54            self.done.errback(reason)
    7955
    8056    def outReceived(self, data):
     
    148124        print("signaling {} with TERM".format(tahoe_transport.pid))
    149125        tahoe_transport.signalProcess('TERM')
    150         print("signaled, blocking on exit {}".format(exited))
     126        print("signaled, blocking on exit")
    151127        pytest_twisted.blockon(exited)
    152128        print("exited, goodbye")
    153129    except ProcessExitedAlready:
    154130        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 a
    162         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.done
    168     return protocol.done
    169131
    170132
     
    270232        created_d = succeed(None)
    271233    else:
    272         print("creating: {}".format(node_dir))
     234        print("creating", node_dir)
    273235        mkdir(node_dir)
    274236        done_proto = _ProcessExitedProtocol()
     
    295257            config_path = join(node_dir, 'tahoe.cfg')
    296258            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)
    298260            write_config(config_path, config)
    299261        created_d.addCallback(created)
     
    482444
    483445
    484 def await_client_ready(tahoe, timeout=10, liveness=60*2, servers=1):
     446def await_client_ready(tahoe, timeout=10, liveness=60*2):
    485447    """
    486448    Uses the status API to wait for a client-type node (in `tahoe`, a
     
    506468            continue
    507469
    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")
    510472            time.sleep(1)
    511473            continue
Note: See TracChangeset for help on using the changeset viewer.