Beispiel #1
0
def genTestClient(nodes=None,
                  nodeReg=None,
                  tmpdir=None,
                  testClientClass=TestClient,
                  identifier: Identifier = None,
                  verkey: str = None,
                  bootstrapKeys=True,
                  ha=None,
                  usePoolLedger=False,
                  name=None,
                  sighex=None) -> (TestClient, Wallet):
    if not usePoolLedger:
        nReg = nodeReg
        if nodeReg:
            assert isinstance(nodeReg, dict)
        elif hasattr(nodes, "nodeReg"):
            nReg = nodes.nodeReg.extractCliNodeReg()
        else:
            error("need access to nodeReg")
        for k, v in nReg.items():
            assert type(k) == str
            assert (type(v) == HA or type(v[0]) == HA)
    else:
        logger.debug("TestClient using pool ledger")
        nReg = None

    ha = genHa() if not ha else ha
    name = name or "testClient{}".format(ha.port)

    tc = testClientClass(name,
                         nodeReg=nReg,
                         ha=ha,
                         basedirpath=tmpdir,
                         sighex=sighex)

    if not usePoolLedger and nodes:
        for node in nodes:
            stack = node.clientstack
            # TODO: Remove this if condition once raet is removed
            if isinstance(stack, ZStack):
                initRemoteKeys(tc.name,
                               stack.name,
                               tmpdir,
                               stack.verhex,
                               override=True)

    w = None  # type: Wallet
    if bootstrapKeys and nodes:
        if not identifier or not verkey:
            # no identifier or verkey were provided, so creating a wallet
            w = Wallet("test")
            w.addIdentifier()
            identifier = w.defaultId
            verkey = w.getVerkey()
        bootstrapClientKeys(identifier, verkey, nodes)
    return tc, w
Beispiel #2
0
def testClientConnectToRestartedNodes(looper, txnPoolNodeSet, tdirWithPoolTxns,
                                      poolTxnClientNames, poolTxnData, tconf,
                                      poolTxnNodeNames, allPluginsPath):
    name = poolTxnClientNames[-1]
    seed = poolTxnData["seeds"][name]
    newClient, w = genTestClient(tmpdir=tdirWithPoolTxns,
                                 nodes=txnPoolNodeSet,
                                 name=name,
                                 usePoolLedger=True)
    looper.add(newClient)
    ensureClientConnectedToNodesAndPoolLedgerSame(looper, newClient,
                                                  *txnPoolNodeSet)
    sendReqsToNodesAndVerifySuffReplies(looper, w, newClient, 1, 1)
    for node in txnPoolNodeSet:
        node.stop()
        looper.removeProdable(node)

    # looper.run(newClient.ensureDisconnectedToNodes(timeout=60))
    txnPoolNodeSet = []
    for nm in poolTxnNodeNames:
        node = TestNode(nm,
                        basedirpath=tdirWithPoolTxns,
                        config=tconf,
                        pluginPaths=allPluginsPath)
        looper.add(node)
        txnPoolNodeSet.append(node)
    looper.run(checkNodesConnected(txnPoolNodeSet))
    ensureElectionsDone(looper=looper,
                        nodes=txnPoolNodeSet,
                        retryWait=1,
                        timeout=10)

    def chk():
        for node in txnPoolNodeSet:
            assert node.isParticipating

    looper.run(eventually(chk, retryWait=1, timeout=10))

    bootstrapClientKeys(w.defaultId, w.getVerkey(), txnPoolNodeSet)

    req = sendRandomRequest(w, newClient)
    checkSufficientRepliesForRequests(looper,
                                      newClient, [
                                          req,
                                      ],
                                      timeoutPerReq=10)
    ensureClientConnectedToNodesAndPoolLedgerSame(looper, newClient,
                                                  *txnPoolNodeSet)

    sendReqsToNodesAndVerifySuffReplies(looper, w, newClient, 1, 1)
Beispiel #3
0
def testClientConnectToRestartedNodes(looper, txnPoolNodeSet, tdirWithPoolTxns,
                                      tdir, tdirWithClientPoolTxns,
                                      poolTxnClientNames, poolTxnData, tconf,
                                      poolTxnNodeNames, allPluginsPath):
    name = poolTxnClientNames[-1]
    newClient, w = genTestClient(tmpdir=tdirWithClientPoolTxns,
                                 nodes=txnPoolNodeSet,
                                 name=name,
                                 usePoolLedger=True)
    looper.add(newClient)
    ensureClientConnectedToNodesAndPoolLedgerSame(looper, newClient,
                                                  *txnPoolNodeSet)
    sendReqsToNodesAndVerifySuffReplies(looper, w, newClient, 1, 1)
    for node in txnPoolNodeSet:
        node.stop()
        looper.removeProdable(node)

    # looper.run(newClient.ensureDisconnectedToNodes(timeout=60))
    txnPoolNodeSet = []
    for nm in poolTxnNodeNames:
        config_helper = PNodeConfigHelper(nm, tconf, chroot=tdir)
        node = TestNode(nm,
                        ledger_dir=config_helper.ledger_dir,
                        keys_dir=config_helper.keys_dir,
                        genesis_dir=config_helper.genesis_dir,
                        plugins_dir=config_helper.plugins_dir,
                        config=tconf,
                        pluginPaths=allPluginsPath)
        looper.add(node)
        txnPoolNodeSet.append(node)
    looper.run(checkNodesConnected(txnPoolNodeSet))
    ensureElectionsDone(looper=looper, nodes=txnPoolNodeSet)

    def chk():
        for node in txnPoolNodeSet:
            assert node.isParticipating

    timeout = waits.expectedPoolGetReadyTimeout(len(txnPoolNodeSet))
    looper.run(eventually(chk, retryWait=1, timeout=timeout))

    bootstrapClientKeys(w.defaultId, w.getVerkey(), txnPoolNodeSet)

    req = sendRandomRequest(w, newClient)
    waitForSufficientRepliesForRequests(looper, newClient, requests=[req])
    ensureClientConnectedToNodesAndPoolLedgerSame(looper, newClient,
                                                  *txnPoolNodeSet)

    sendReqsToNodesAndVerifySuffReplies(looper, w, newClient, 3, 1)
def testClientConnectToRestartedNodes(looper, txnPoolNodeSet, tdirWithPoolTxns,
                                      poolTxnClientNames, poolTxnData, tconf,
                                      poolTxnNodeNames,
                                      allPluginsPath):
    name = poolTxnClientNames[-1]
    seed = poolTxnData["seeds"][name]
    newClient, w = genTestClient(tmpdir=tdirWithPoolTxns, nodes=txnPoolNodeSet,
                                 name=name, usePoolLedger=True)
    looper.add(newClient)
    ensureClientConnectedToNodesAndPoolLedgerSame(looper, newClient,
                                                  *txnPoolNodeSet)
    sendReqsToNodesAndVerifySuffReplies(looper, w, newClient, 1, 1)
    for node in txnPoolNodeSet:
        node.stop()
        looper.removeProdable(node)

    # looper.run(newClient.ensureDisconnectedToNodes(timeout=60))
    txnPoolNodeSet = []
    for nm in poolTxnNodeNames:
        node = TestNode(nm, basedirpath=tdirWithPoolTxns,
                        config=tconf, pluginPaths=allPluginsPath)
        looper.add(node)
        txnPoolNodeSet.append(node)
    looper.run(checkNodesConnected(txnPoolNodeSet))
    ensureElectionsDone(looper=looper, nodes=txnPoolNodeSet, retryWait=1,
                        timeout=10)

    def chk():
        for node in txnPoolNodeSet:
            assert node.isParticipating

    looper.run(eventually(chk, retryWait=1, timeout=10))

    bootstrapClientKeys(w.defaultId, w.getVerkey(), txnPoolNodeSet)

    req = sendRandomRequest(w, newClient)
    checkSufficientRepliesForRequests(looper, newClient, [req, ],
                                      timeoutPerReq=10)
    ensureClientConnectedToNodesAndPoolLedgerSame(looper, newClient,
                                                  *txnPoolNodeSet)

    sendReqsToNodesAndVerifySuffReplies(looper, w, newClient, 1, 1)