예제 #1
0
def testNodeConnection(allPluginsPath, tdirAndLooper, nodeReg):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    tdir, looper = tdirAndLooper
    names = ["Alpha", "Beta"]
    nrg = {n: nodeReg[n] for n in names}
    initLocalKeys(tdir, nrg)

    logger.debug(names)
    nodes = []
    for name in names:
        node = TestNode(name, nrg, basedirpath=tdir,
                        pluginPaths=allPluginsPath)
        nodes.append(node)

    for node in nodes:
        tellKeysToOthers(node, nodes)

    A, B = nodes
    looper.add(A)
    looper.runFor(4)
    logger.debug("wait done")
    looper.add(B)
    looper.runFor(4)
    looper.run(checkNodesConnected([A, B]))
    looper.stopall()
    A.start(looper.loop)
    looper.runFor(4)
    B.start(looper.loop)
    looper.run(checkNodesConnected([A, B]))
    stopNodes([A, B], looper)
def testNodeConnection(allPluginsPath, tconf, tdir,
                       tdir_for_func, tconf_for_func,
                       looper, txnPoolNodeSetNotStarted):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)

    nodes = txnPoolNodeSetNotStarted[:2]

    for node in nodes:
        tellKeysToOthers(node, nodes)

    A, B = nodes
    looper.add(A)
    looper.runFor(4)
    logger.debug("wait done")
    looper.add(B)
    looper.runFor(4)
    looper.run(checkNodesConnected([A, B]))
    looper.stopall()
    looper.removeProdable(A)
    looper.removeProdable(B)
    A = start_stopped_node(A, looper, tconf, tdir, allPluginsPath)
    looper.runFor(4)
    B = start_stopped_node(B, looper, tconf, tdir, allPluginsPath)
    looper.run(checkNodesConnected([A, B]))

    for node in txnPoolNodeSetNotStarted[2:]:
        looper.add(node)
    all_nodes = [A, B] + txnPoolNodeSetNotStarted[2:]
    looper.run(checkNodesConnected(all_nodes))
    stopNodes(all_nodes, looper)
    for node in all_nodes:
        looper.removeProdable(node)
예제 #3
0
def testNodeConnection(allPluginsPath, tdir_for_func, tconf_for_func, looper,
                       txnPoolNodeSetNotStarted):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)

    nodes = txnPoolNodeSetNotStarted[:2]

    for node in nodes:
        tellKeysToOthers(node, nodes)

    A, B = nodes
    looper.add(A)
    looper.runFor(4)
    logger.debug("wait done")
    looper.add(B)
    looper.runFor(4)
    looper.run(checkNodesConnected([A, B]))
    looper.stopall()
    A.start(looper.loop)
    looper.runFor(4)
    B.start(looper.loop)
    looper.run(checkNodesConnected([A, B]))
    stopNodes([A, B], looper)
    for node in [A, B]:
        looper.removeProdable(node)
예제 #4
0
def testNodeConnection(allPluginsPath, tdirAndLooper, nodeReg, conf):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    tdir, looper = tdirAndLooper
    names = ["Alpha", "Beta"]
    if conf.UseZStack:
        genKeys(tdir, names + [_ + CLIENT_STACK_SUFFIX for _ in names])

    logger.debug(names)
    nrg = {n: nodeReg[n] for n in names}
    A, B = [
        TestNode(name, nrg, basedirpath=tdir, pluginPaths=allPluginsPath)
        for name in names
    ]
    looper.add(A)
    looper.runFor(4)
    logger.debug("wait done")
    looper.add(B)
    looper.runFor(4)
    looper.run(checkNodesConnected([A, B]))
    looper.stopall()
    A.start(looper.loop)
    looper.runFor(4)
    B.start(looper.loop)
    looper.run(checkNodesConnected([A, B]))
    stopNodes([A, B], looper)
예제 #5
0
def testNodesComingUpAtDifferentTimes():
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    with TemporaryDirectory() as td:
        print("temporary directory: {}".format(td))
        with Looper() as looper:
            nodes = []

            names = list(nodeReg.keys())
            shuffle(names)
            waits = [randint(1, 10) for _ in names]
            rwaits = [randint(1, 10) for _ in names]

            for i, name in enumerate(names):
                node = TestNode(name, nodeReg, basedirpath=td)
                looper.add(node)
                node.startKeySharing()
                nodes.append(node)
                looper.runFor(waits[i])
            looper.run(checkNodesConnected(nodes, overrideTimeout=10))
            print("connects")
            print("node order: {}".format(names))
            print("waits: {}".format(waits))

            for n in nodes:
                n.stop()
            for i, n in enumerate(nodes):
                n.start(looper.loop)
                looper.runFor(rwaits[i])
            looper.runFor(3)
            looper.run(checkNodesConnected(nodes, overrideTimeout=10))
            print("reconnects")
            print("node order: {}".format(names))
            print("rwaits: {}".format(rwaits))
예제 #6
0
def testNodeConnectionAfterKeysharingRestarted(allPluginsPath, tdirAndLooper):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    tdir, looper = tdirAndLooper
    timeout = 60
    names = ["Alpha", "Beta"]
    logger.debug(names)
    nrg = {n: nodeReg[n] for n in names}
    A, B = [
        TestNode(name,
                 nodeRegistry=nrg,
                 basedirpath=tdir,
                 pluginPaths=allPluginsPath) for name in names
    ]
    looper.add(A)
    A.startKeySharing(timeout=timeout)
    looper.runFor(timeout + 1)
    logger.debug("done waiting for A's timeout")
    looper.add(B)
    B.startKeySharing(timeout=timeout)
    looper.runFor(timeout + 1)
    logger.debug("done waiting for B's timeout")
    A.startKeySharing(timeout=timeout)
    B.startKeySharing(timeout=timeout)
    looper.run(checkNodesConnected([A, B]))
예제 #7
0
def testNodesComingUpAtDifferentTimes(allPluginsPath, tdir_for_func,
                                      tconf_for_func,
                                      looper_without_nodeset_for_func,
                                      nodeReg):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    looper = looper_without_nodeset_for_func

    initLocalKeys(tdir_for_func, tconf_for_func, nodeReg)

    nodes = []

    names = list(nodeReg.keys())

    shuffle(names)
    waits = [randint(1, 10) for _ in names]
    rwaits = [randint(1, 10) for _ in names]

    for name in names:
        config_helper = PNodeConfigHelper(name,
                                          tconf_for_func,
                                          chroot=tdir_for_func)
        node = TestNode(name,
                        nodeReg,
                        config_helper=config_helper,
                        config=tconf_for_func,
                        pluginPaths=allPluginsPath)
        nodes.append(node)

    for node in nodes:
        tellKeysToOthers(node, nodes)

    for i, node in enumerate(nodes):
        looper.add(node)
        looper.runFor(waits[i])
    looper.run(checkNodesConnected(nodes))
    logger.debug("connects")
    logger.debug("node order: {}".format(names))
    logger.debug("waits: {}".format(waits))

    stopNodes(nodes, looper)

    # # Giving some time for sockets to close, use eventually
    # time.sleep(1)

    for i, n in enumerate(nodes):
        n.start(looper.loop)
        looper.runFor(rwaits[i])
    looper.runFor(3)
    looper.run(checkNodesConnected(nodes))
    stopNodes(nodes, looper)
    logger.debug("reconnects")
    logger.debug("node order: {}".format(names))
    logger.debug("rwaits: {}".format(rwaits))
def testNodesComingUpAtDifferentTimes(allPluginsPath, tconf, tdir,
                                      tdir_for_func, tconf_for_func,
                                      looper, txnPoolNodeSetNotStarted):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)

    nodes = txnPoolNodeSetNotStarted

    names = list(node.name for node in nodes)

    shuffle(names)
    waits = [randint(1, 10) for _ in names]
    rwaits = [randint(1, 10) for _ in names]

    for node in nodes:
        tellKeysToOthers(node, nodes)

    for i, node in enumerate(nodes):
        looper.add(node)
        looper.runFor(waits[i])
    looper.run(checkNodesConnected(nodes))
    logger.debug("connects")
    logger.debug("node order: {}".format(names))
    logger.debug("waits: {}".format(waits))

    current_node_set = set(nodes)
    for node in nodes:
        disconnect_node_and_ensure_disconnected(looper,
                                                current_node_set,
                                                node,
                                                timeout=len(nodes),
                                                stopNode=True)
        looper.removeProdable(node)
        current_node_set.remove(node)

    for i, node in enumerate(nodes):
        restarted_node = start_stopped_node(node, looper,
                                            tconf, tdir, allPluginsPath)
        current_node_set.add(restarted_node)
        looper.runFor(rwaits[i])

    looper.runFor(3)
    looper.run(checkNodesConnected(current_node_set))

    stopNodes(current_node_set, looper)
    logger.debug("reconnects")
    logger.debug("node order: {}".format(names))
    logger.debug("rwaits: {}".format(rwaits))
    for node in current_node_set:
        looper.removeProdable(node)
예제 #9
0
def events(self):
    if not self.start.value:
        self.complete.value = True
        return

    console = getConsole("didery.py", verbosity=self.verbosity.value)

    outputSetupInfo(console, self.servers.value, did=self.did.value)

    data, results = event.getHistoryEvents(self.did.value, self.servers.value)

    outputPulledResult(data, results, console)

    self.complete.value = True
예제 #10
0
def update(self):
    if not self.start.value:
        self.complete.value = True
        return

    console = getConsole("didery.py", verbosity=self.verbosity.value)

    outputSetupInfo(console, self.servers.value, data=self.data.value)

    result = otp.putOtpBlob(self.data.value, self.sk.value, self.servers.value)

    outputPushedResult(result, console, self.verbosity.value)

    self.complete.value = True
예제 #11
0
def download(self):
    if not self.start.value:
        self.complete.value = True
        return

    console = getConsole("didery.py", verbosity=self.verbosity.value)

    outputSetupInfo(console, self.servers.value, did=self.did.value)

    data, results = otp.getOtpBlob(self.did.value, self.servers.value)

    outputPulledResult(data, results, console)

    self.complete.value = True
예제 #12
0
def incept(self):
    if not self.start.value:
        self.complete.value = True
        return

    console = getConsole("didery.py", verbosity=self.verbosity.value)

    outputSetupInfo(console, self.servers.value, data=self.data.value)

    result = hist.postHistory(self.data.value, self.sk.value,
                              self.servers.value)

    outputPushedResult(result, console, self.verbosity.value)

    self.complete.value = True
예제 #13
0
def testNodesComingUpAtDifferentTimes(allPluginsPath, tdirAndLooper, nodeReg,
                                      conf):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    tdir, looper = tdirAndLooper

    nodes = []

    names = list(nodeReg.keys())
    if conf.UseZStack:
        genKeys(tdir, names + [_ + CLIENT_STACK_SUFFIX for _ in names])

    shuffle(names)
    waits = [randint(1, 10) for _ in names]
    rwaits = [randint(1, 10) for _ in names]

    for i, name in enumerate(names):
        node = TestNode(name,
                        nodeReg,
                        basedirpath=tdir,
                        pluginPaths=allPluginsPath)
        looper.add(node)
        nodes.append(node)
        looper.runFor(waits[i])
    looper.run(checkNodesConnected(nodes, overrideTimeout=10))
    logger.debug("connects")
    logger.debug("node order: {}".format(names))
    logger.debug("waits: {}".format(waits))

    stopNodes(nodes, looper)

    # # Giving some time for sockets to close, use eventually
    # time.sleep(1)

    for i, n in enumerate(nodes):
        n.start(looper.loop)
        looper.runFor(rwaits[i])
    looper.runFor(3)
    looper.run(checkNodesConnected(nodes, overrideTimeout=10))
    stopNodes(nodes, looper)
    logger.debug("reconnects")
    logger.debug("node order: {}".format(names))
    logger.debug("rwaits: {}".format(rwaits))
예제 #14
0
def testNodesComingUpAtDifferentTimes(allPluginsPath, tdir_for_func,
                                      tconf_for_func, looper,
                                      txnPoolNodeSetNotStarted):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)

    nodes = txnPoolNodeSetNotStarted

    names = list(node.name for node in nodes)

    shuffle(names)
    waits = [randint(1, 10) for _ in names]
    rwaits = [randint(1, 10) for _ in names]

    for node in nodes:
        tellKeysToOthers(node, nodes)

    for i, node in enumerate(nodes):
        looper.add(node)
        looper.runFor(waits[i])
    looper.run(checkNodesConnected(nodes))
    logger.debug("connects")
    logger.debug("node order: {}".format(names))
    logger.debug("waits: {}".format(waits))

    stopNodes(nodes, looper)

    # # Giving some time for sockets to close, use eventually
    # time.sleep(1)

    for i, n in enumerate(nodes):
        n.start(looper.loop)
        looper.runFor(rwaits[i])
    looper.runFor(3)
    looper.run(checkNodesConnected(nodes))
    stopNodes(nodes, looper)
    logger.debug("reconnects")
    logger.debug("node order: {}".format(names))
    logger.debug("rwaits: {}".format(rwaits))
    for node in nodes:
        looper.removeProdable(node)
예제 #15
0
def testNodeConnectionAfterKeysharingRestarted():
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    with TemporaryDirectory() as td:
        print("temporary directory: {}".format(td))
        with Looper() as looper:
            timeout = 60
            names = ["Alpha", "Beta"]
            print(names)
            nrg = {n: nodeReg[n] for n in names}
            A, B = [TestNode(name, nrg, basedirpath=td) for name in names]
            looper.add(A)
            A.startKeySharing(timeout=timeout)
            looper.runFor(timeout + 1)
            print("done waiting for A's timeout")
            looper.add(B)
            B.startKeySharing(timeout=timeout)
            looper.runFor(timeout + 1)
            print("done waiting for B's timeout")
            A.startKeySharing(timeout=timeout)
            B.startKeySharing(timeout=timeout)
            looper.run(checkNodesConnected([A, B]))
예제 #16
0
def testNodeConnection(allPluginsPath, tdir_for_func, tconf_for_func,
                       looper_without_nodeset_for_func, nodeReg):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    looper = looper_without_nodeset_for_func
    names = ["Alpha", "Beta"]
    nrg = {n: nodeReg[n] for n in names}
    initLocalKeys(tdir_for_func, tconf_for_func, nrg)

    logger.debug(names)
    nodes = []
    for name in names:
        config_helper = PNodeConfigHelper(name,
                                          tconf_for_func,
                                          chroot=tdir_for_func)
        node = TestNode(name,
                        nrg,
                        config_helper=config_helper,
                        config=tconf_for_func,
                        pluginPaths=allPluginsPath)
        nodes.append(node)

    for node in nodes:
        tellKeysToOthers(node, nodes)

    A, B = nodes
    looper.add(A)
    looper.runFor(4)
    logger.debug("wait done")
    looper.add(B)
    looper.runFor(4)
    looper.run(checkNodesConnected([A, B]))
    looper.stopall()
    A.start(looper.loop)
    looper.runFor(4)
    B.start(looper.loop)
    looper.run(checkNodesConnected([A, B]))
    stopNodes([A, B], looper)
예제 #17
0
def testNodeConnectionAfterKeysharingRestarted():
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    with TemporaryDirectory() as td:
        print("temporary directory: {}".format(td))
        with Looper() as looper:
            timeout = 60
            names = ["Alpha", "Beta"]
            print(names)
            nrg = {n: nodeReg[n] for n in names}
            A, B = [Node(name, nrg, basedirpath=td)
                    for name in names]
            looper.add(A)
            A.startKeySharing(timeout=timeout)
            looper.runFor(timeout+1)
            print("done waiting for A's timeout")
            looper.add(B)
            B.startKeySharing(timeout=timeout)
            looper.runFor(timeout+1)
            print("done waiting for B's timeout")
            A.startKeySharing(timeout=timeout)
            B.startKeySharing(timeout=timeout)
            looper.run(checkNodesConnected([A, B]))
예제 #18
0
def testNodeConnection():
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    with TemporaryDirectory() as td:
        print("temporary directory: {}".format(td))
        with Looper() as looper:
            names = ["Alpha", "Beta"]
            print(names)
            nrg = {n: nodeReg[n] for n in names}
            A, B = [TestNode(name, nrg, basedirpath=td) for name in names]
            looper.add(A)
            A.startKeySharing()
            looper.runFor(4)
            print("wait done")
            looper.add(B)
            B.startKeySharing()
            looper.runFor(4)
            looper.run(checkNodesConnected([A, B]))
            looper.stopall()
            A.start(looper.loop)
            looper.runFor(4)
            B.start(looper.loop)
            looper.run(checkNodesConnected([A, B]))
예제 #19
0
def testNodeConnection(allPluginsPath, tdirAndLooper):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    tdir, looper = tdirAndLooper
    names = ["Alpha", "Beta"]
    logger.debug(names)
    nrg = {n: nodeReg[n] for n in names}
    A, B = [TestNode(name, nrg, basedirpath=tdir,
                     pluginPaths=allPluginsPath)
            for name in names]
    looper.add(A)
    A.startKeySharing()
    looper.runFor(4)
    logger.debug("wait done")
    looper.add(B)
    B.startKeySharing()
    looper.runFor(4)
    looper.run(checkNodesConnected([A, B]))
    looper.stopall()
    A.start(looper.loop)
    looper.runFor(4)
    B.start(looper.loop)
    looper.run(checkNodesConnected([A, B]))
예제 #20
0
def testNodesComingUpAtDifferentTimes(allPluginsPath, tdirAndLooper, nodeReg):
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    tdir, looper = tdirAndLooper

    nodes = []

    names = list(nodeReg.keys())
    shuffle(names)
    waits = [randint(1, 10) for _ in names]
    rwaits = [randint(1, 10) for _ in names]

    for i, name in enumerate(names):
        node = TestNode(name, nodeReg, basedirpath=tdir,
                        pluginPaths=allPluginsPath)
        looper.add(node)
        node.startKeySharing()
        nodes.append(node)
        looper.runFor(waits[i])
    looper.run(checkNodesConnected(nodes,
                                   overrideTimeout=10))
    logger.debug("connects")
    logger.debug("node order: {}".format(names))
    logger.debug("waits: {}".format(waits))

    stopNodes(nodes, looper)

    for i, n in enumerate(nodes):
        n.start(looper.loop)
        looper.runFor(rwaits[i])
    looper.runFor(3)
    looper.run(checkNodesConnected(nodes,
                                   overrideTimeout=10))
    stopNodes(nodes, looper)
    logger.debug("reconnects")
    logger.debug("node order: {}".format(names))
    logger.debug("rwaits: {}".format(rwaits))
예제 #21
0
def testNodesComingUpAtDifferentTimes():
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    with TemporaryDirectory() as td:
        print("temporary directory: {}".format(td))
        with Looper() as looper:
            nodes = []

            names = list(nodeReg.keys())
            shuffle(names)
            waits = [randint(1, 10) for _ in names]
            rwaits = [randint(1, 10) for _ in names]

            for i, name in enumerate(names):
                node = Node(name, nodeReg, basedirpath=td)
                looper.add(node)
                node.startKeySharing()
                nodes.append(node)
                looper.runFor(waits[i])
            looper.run(checkNodesConnected(nodes,
                                           overrideTimeout=10))
            print("connects")
            print("node order: {}".format(names))
            print("waits: {}".format(waits))

            for n in nodes:
                n.stop()
            for i, n in enumerate(nodes):
                n.start()
                looper.runFor(rwaits[i])
            looper.runFor(3)
            looper.run(checkNodesConnected(nodes,
                                           overrideTimeout=10))
            print("reconnects")
            print("node order: {}".format(names))
            print("rwaits: {}".format(rwaits))
예제 #22
0
def testNodeConnection():
    console = getConsole()
    console.reinit(flushy=True, verbosity=console.Wordage.verbose)
    with TemporaryDirectory() as td:
        print("temporary directory: {}".format(td))
        with Looper() as looper:
            names = ["Alpha", "Beta"]
            print(names)
            nrg = {n: nodeReg[n] for n in names}
            A, B = [Node(name, nrg, basedirpath=td)
                    for name in names]
            looper.add(A)
            A.startKeySharing()
            looper.runFor(4)
            print("wait done")
            looper.add(B)
            B.startKeySharing()
            looper.runFor(4)
            looper.run(checkNodesConnected([A, B]))
            looper.stopall()
            A.start()
            looper.runFor(4)
            B.start()
            looper.run(checkNodesConnected([A, B]))
예제 #23
0
Unittests
"""
from __future__ import absolute_import, division, print_function

import sys

import unittest

import os
from collections import deque

from ioflo.aid.sixing import *
from ioflo.test import testing
from ioflo.aid import getConsole, odict

console = getConsole()


from ioflo.base import storing


def setUpModule():
    console.reinit(verbosity=console.Wordage.concise)

def tearDownModule():
    console.reinit(verbosity=console.Wordage.concise)

class BasicTestCase(unittest.TestCase):
    """
    Test Case
    """
예제 #24
0
    import unittest2 as unittest
else:
    import unittest

import os

from binascii import hexlify
import time

# Import ioflo libs
from ioflo.aid.sixing import *
from ioflo.aid.byting import hexify, bytify, unbytify, packify, unpackify
from ioflo.aid.timing import Timer, StoreTimer, Stamper
from ioflo.aid import getConsole

console = getConsole()

from ioflo.aio.proto import stacking, devicing, packeting

def setUpModule():
    console.reinit(verbosity=console.Wordage.concise)

def tearDownModule():
    console.reinit(verbosity=console.Wordage.concise)

class BasicTestCase(unittest.TestCase):
    """
    Test Case
    """

    def setUp(self):