Exemple #1
0
    def createRoadStack(self, data, eid=0, main=False, auto=False, ha=None):
        '''
        Clears any old keep data from data['dirpath']
        Creates stack and local estate from data with
        local estate.eid = eid
        stack.main = main
        stack.auto = auto
        stack.name = data['name']
        local estate.name = data['name']
        local estate.ha = ha

        returns stack

        '''
        keeping.clearAllKeepSafe(data['dirpath'])

        local = estating.LocalEstate(
            eid=eid,
            name=data['name'],
            ha=ha,
            sigkey=data['sighex'],
            prikey=data['prihex'],
        )

        stack = stacking.RoadStack(name=data['name'],
                                   local=local,
                                   auto=auto,
                                   main=main,
                                   dirpath=data['dirpath'],
                                   store=self.store)

        return stack
Exemple #2
0
    def setUp(self):
        self.store = storing.Store(stamp=0.0)
        self.timer = StoreTimer(store=self.store, duration=1.0)

        self.baseDirpath=tempfile.mkdtemp(prefix="raet",  suffix="base", dir='/tmp')
        stacking.RoadStack.Bk = raeting.bodyKinds.json

        #main stack
        mainName = "main"
        mainDirpath = os.path.join(self.baseDirpath, 'road', 'keep', mainName)
        signer = nacling.Signer()
        mainSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        mainPriKeyHex = privateer.keyhex


        #other stack
        otherName = "other"
        otherDirpath = os.path.join(self.baseDirpath, 'road', 'keep', otherName)
        signer = nacling.Signer()
        otherSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        otherPriKeyHex = privateer.keyhex


        keeping.clearAllKeepSafe(mainDirpath)
        keeping.clearAllKeepSafe(otherDirpath)

        local = estating.LocalEstate(eid=1,
                                     name=mainName,
                                     sigkey=mainSignKeyHex,
                                     prikey=mainPriKeyHex,)

        self.main = stacking.RoadStack(name=mainName,
                                         local=local,
                                         auto=True,
                                         main=True,
                                         dirpath=mainDirpath,
                                         store=self.store)

        local = estating.LocalEstate(eid=0,
                                     name=otherName,
                                     ha=("", raeting.RAET_TEST_PORT),
                                     sigkey=otherSignKeyHex,
                                     prikey=otherPriKeyHex,)

        self.other = stacking.RoadStack(name=otherName,
                                         local=local,
                                         dirpath=otherDirpath,
                                         store=self.store)
Exemple #3
0
    def setUp(self):
        self.store = storing.Store(stamp=0.0)

        dirpathBase='/tmp/raet/'

        #main stack
        mainName = "main"
        mainDirpath = os.path.join(dirpathBase, 'road', 'keep', mainName)
        signer = nacling.Signer()
        mainSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        mainPriKeyHex = privateer.keyhex


        #other stack
        otherName = "other"
        otherDirpath = os.path.join(dirpathBase, 'road', 'keep', otherName)
        signer = nacling.Signer()
        otherSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        otherPriKeyHex = privateer.keyhex


        keeping.clearAllKeepSafe(mainDirpath)
        keeping.clearAllKeepSafe(otherDirpath)

        local = estating.LocalEstate(eid=1,
                                     name=mainName,
                                     sigkey=mainSignKeyHex,
                                     prikey=mainPriKeyHex,)

        self.main = stacking.RoadStack(name=mainName,
                                         local=local,
                                         auto=True,
                                         main=True,
                                         dirpath=mainDirpath,
                                         store=self.store)

        local = estating.LocalEstate(eid=0,
                                     name=otherName,
                                     ha=("", raeting.RAET_TEST_PORT),
                                     sigkey=otherSignKeyHex,
                                     prikey=otherPriKeyHex,)

        self.other = stacking.RoadStack(name=otherName,
                                         local=local,
                                         dirpath=otherDirpath,
                                         store=self.store)

        self.timer = StoreTimer(store=self.store, duration=1.0)
Exemple #4
0
    def createRoadStack(self, data, eid=0, main=False, auto=False, ha=None):
        """
        Clears any old keep data from data['dirpath']
        Creates stack and local estate from data with
        local estate.eid = eid
        stack.main = main
        stack.auto = auto
        stack.name = data['name']
        local estate.name = data['name']
        local estate.ha = ha

        returns stack

        """
        keeping.clearAllKeepSafe(data["dirpath"])

        local = estating.LocalEstate(eid=eid, name=data["name"], ha=ha, sigkey=data["sighex"], prikey=data["prihex"])

        stack = stacking.RoadStack(
            name=data["name"], local=local, auto=auto, main=main, dirpath=data["dirpath"], store=self.store
        )

        return stack
Exemple #5
0
def test(preClearMaster=False,
         preClearMinion=False,
         postClearMaster=False,
         postClearMinion=False):
    '''
    initially
    master on port 7530 with eid of 1
    minion on port 7531 with eid of 0
    eventually
    master eid of 1
    minion eid of 2
    '''
    console.reinit(verbosity=console.Wordage.concise)

    #transacting.Joiner.Timeout = 0 # make join go on forever

    store = storing.Store(stamp=0.0)

    #master stack
    masterName = "master"
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterDirpath = os.path.join('/tmp/raet/road', 'keep', masterName)

    #minion0 stack
    minionName0 = "minion0"
    signer = nacling.Signer()
    minionSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    minionPriKeyHex = privateer.keyhex
    m0Dirpath = os.path.join('/tmp/raet/road', 'keep', minionName0)

    if preClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if preClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)

    local = estating.LocalEstate(
        eid=1,
        name=masterName,
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(name=masterName,
                                local=local,
                                store=store,
                                main=True,
                                dirpath=masterDirpath)

    local = estating.LocalEstate(
        eid=0,
        name=minionName0,
        ha=("", raeting.RAET_TEST_PORT),
        sigkey=minionSignKeyHex,
        prikey=minionPriKeyHex,
    )
    stack1 = stacking.RoadStack(name=minionName0,
                                local=local,
                                store=store,
                                dirpath=m0Dirpath)

    print "\n********* Join Transaction **********"
    stack1.join()
    #timer = StoreTimer(store=store, duration=3.0)
    while stack1.transactions or stack0.transactions:
        stack1.serviceAll()
        stack0.serviceAll()
        if store.stamp >= 0.3:
            for remote in stack0.remotes.values():
                if remote.acceptance == raeting.acceptances.pending:
                    stack0.safe.acceptRemote(remote)
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "Remote Estate {0} joined= {1}".format(remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "Remote Estate {0} joined= {1}".format(remote.eid, remote.joined)

    print "{0} eid={1}".format(stack0.name, stack0.local.uid)
    print "{0} remotes=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions)
    print "{0} eid={1}".format(stack1.name, stack1.local.uid)
    print "{0} remotes=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions)

    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()
    print

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    stack0.server.close()
    stack1.server.close()

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)
Exemple #6
0
    def setUp(self):
        self.store = storing.Store(stamp=0.0)
        self.timer = StoreTimer(store=self.store, duration=1.0)

        self.dirpathBase = tempfile.mkdtemp(prefix="raet",
                                            suffix="base",
                                            dir='/tmp')
        stacking.RoadStack.Bk = raeting.bodyKinds.json

        #main stack
        mainName = "main"
        mainDirpath = os.path.join(self.dirpathBase, 'road', 'keep', mainName)
        signer = nacling.Signer()
        mainSignKeyHex = signer.keyhex
        mainVerKeyHex = signer.verhex
        privateer = nacling.Privateer()
        mainPriKeyHex = privateer.keyhex
        mainPubKeyHex = privateer.pubhex

        #other stack
        otherName = "other"
        otherDirpath = os.path.join(self.dirpathBase, 'road', 'keep',
                                    otherName)
        signer = nacling.Signer()
        otherSignKeyHex = signer.keyhex
        otherVerKeyHex = signer.verhex
        privateer = nacling.Privateer()
        otherPriKeyHex = privateer.keyhex
        otherPubKeyHex = privateer.pubhex

        keeping.clearAllKeepSafe(mainDirpath)
        keeping.clearAllKeepSafe(otherDirpath)

        local = estating.LocalEstate(
            eid=1,
            name=mainName,
            sigkey=mainSignKeyHex,
            prikey=mainPriKeyHex,
        )

        self.main = stacking.RoadStack(name=mainName,
                                       local=local,
                                       auto=True,
                                       main=True,
                                       dirpath=mainDirpath,
                                       store=self.store)

        remote1 = estating.RemoteEstate(
            stack=self.main,
            eid=2,
            name=otherName,
            ha=("127.0.0.1", raeting.RAET_TEST_PORT),
            verkey=otherVerKeyHex,
            pubkey=otherPubKeyHex,
            period=self.main.period,
            offset=self.main.offset,
        )
        self.main.addRemote(remote1)

        local = estating.LocalEstate(
            eid=2,
            name=otherName,
            ha=("", raeting.RAET_TEST_PORT),
            sigkey=otherSignKeyHex,
            prikey=otherPriKeyHex,
        )

        self.other = stacking.RoadStack(name=otherName,
                                        local=local,
                                        dirpath=otherDirpath,
                                        store=self.store)

        remote0 = estating.RemoteEstate(
            stack=self.other,
            eid=1,
            name=mainName,
            ha=('127.0.0.1', raeting.RAET_PORT),
            verkey=mainVerKeyHex,
            pubkey=mainPubKeyHex,
            period=self.other.period,
            offset=self.other.offset,
        )
        self.other.addRemote(remote0)

        remote0.publee = nacling.Publican(key=remote1.privee.pubhex)
        remote1.publee = nacling.Publican(key=remote0.privee.pubhex)

        stuff = []
        for i in range(300):
            stuff.append(str(i).rjust(4, " "))
        self.stuff = "".join(stuff)

        self.data = odict(hk=raeting.headKinds.raet)
def test(preClearMaster=True, preClearMinion=True, postClearMaster=True, postClearMinion=True):
    """
    initially
    master on port 7530 with eid of 1
    minion on port 7531 with eid of 0
    eventually
    master eid of 1
    minion eid of 2
    """
    console.reinit(verbosity=console.Wordage.concise)

    store = storing.Store(stamp=0.0)

    # master stack
    masterName = "master"
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterDirpath = os.path.join("/tmp/raet/road", "keep", masterName)

    # minion0 stack
    minionName0 = "minion0"
    signer = nacling.Signer()
    minionSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    minionPriKeyHex = privateer.keyhex
    m0Dirpath = os.path.join("/tmp/raet/road", "keep", minionName0)

    if preClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if preClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)

    local = estating.LocalEstate(eid=1, name=masterName, sigkey=masterSignKeyHex, prikey=masterPriKeyHex)
    stack0 = stacking.RoadStack(name=masterName, local=local, auto=True, store=store, main=True, dirpath=masterDirpath)

    local = estating.LocalEstate(
        eid=0, name=minionName0, ha=("", raeting.RAET_TEST_PORT), sigkey=minionSignKeyHex, prikey=minionPriKeyHex
    )
    stack1 = stacking.RoadStack(name=minionName0, local=local, store=store, dirpath=m0Dirpath)

    print "\n********* Join Forever Transaction **********"
    # transacting.Joiner.Timeout = 0 # make join go on forever
    stack1.join(timeout=0.0)  # make join go on forever
    timer = StoreTimer(store=store, duration=30.0)
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    print "\n********* Join Default Timeout Transaction **********"
    stack1.join(timeout=None)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(stack1.name, remote.eid, remote.joined)
    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    for uid in stack0.remotes:
        stack0.removeRemote(uid)
    for uid in stack1.remotes:
        stack1.removeRemote(uid)

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)

    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()
    print

    print "\n********* Join Default Timeout Transaction After Clear Keeps **********"
    stack1.join(timeout=None)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    print "\n********* Join Forever Timeout Transaction After Clear Keeps**********"
    stack1.join(timeout=0.0)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    stack0.server.close()
    stack1.server.close()

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)
Exemple #8
0
    def testAllowUnjoinedOther(self):
        '''
        Test allow transaction for other to main unjoined on main
        '''
        console.terse("{0}\n".format(self.testAllowUnjoinedOther.__doc__))

        mainData = self.createRoadData(name='main', base=self.base, auto=True)
        keeping.clearAllKeepSafe(mainData['dirpath'])
        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     auto=mainData['auto'],
                                     ha=None)

        otherData = self.createRoadData(name='other', base=self.base)
        keeping.clearAllKeepSafe(otherData['dirpath'])
        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", raeting.RAET_TEST_PORT))

        self.join(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes.values()[0]
        self.assertTrue(otherRemote.joined)
        self.assertTrue(mainRemote.joined)

        otherRemote.joined = None
        mainRemote.joined = None
        main.dumpRemote(otherRemote)
        other.dumpRemote(mainRemote)

        console.terse("\nBoth unjoined Allow Other to Main *********\n")
        self.assertEqual(len(main.remotes), 1)
        self.assertEqual(len(other.remotes), 1)
        self.assertIs(otherRemote.joined, None)
        self.assertIs(mainRemote.joined, None)

        self.allow(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes[main.local.uid]
        self.assertIs(otherRemote.joined, True)
        self.assertIs(mainRemote.joined,  True)
        self.assertIs(otherRemote.allowed,  None)
        self.assertIs(mainRemote.allowed,  None)

        self.allow(other, main, deid=main.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertIs(otherRemote.allowed, True)
        self.assertIs(mainRemote.allowed,  True)

        console.terse("\nAllow Main to Other *********\n")
        otherRemote.alived = None
        mainRemote.alived = None
        self.assertIs(otherRemote.alived, None)
        self.assertIs(mainRemote.alived, None)

        self.allow(main, other, deid=other.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertTrue(otherRemote.allowed)
        self.assertTrue(mainRemote.allowed)

        console.terse("\nBoth unjoined Allow Other to Main Cascade *********\n")
        main.server.close()
        other.server.close()
        keeping.clearAllKeepSafe(mainData['dirpath'])
        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     auto=mainData['auto'],
                                     ha=None)

        keeping.clearAllKeepSafe(otherData['dirpath'])
        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", raeting.RAET_TEST_PORT))

        self.assertEqual(len(main.remotes), 0)
        self.assertEqual(len(other.remotes), 0)

        self.join(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes.values()[0]
        self.assertTrue(otherRemote.joined)
        self.assertTrue(mainRemote.joined)

        otherRemote.joined = None
        mainRemote.joined = None
        main.dumpRemote(otherRemote)
        other.dumpRemote(mainRemote)


        self.allow(other, main, cascade=True)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes[main.local.uid]
        self.assertIs(otherRemote.joined, True)
        self.assertIs(mainRemote.joined,  True)
        self.assertIs(otherRemote.allowed,  True)
        self.assertIs(mainRemote.allowed,  True)
        self.assertIs(otherRemote.alived,  True)
        self.assertIs(mainRemote.alived,  True)


        main.server.close()
        main.clearLocal()
        main.clearRemoteKeeps()

        other.server.close()
        other.clearLocal()
        other.clearRemoteKeeps()
Exemple #9
0
    def testAliveMultiple(self):
        '''
        Test alive transaction with multiple remotes
        '''
        console.terse("{0}\n".format(self.testAliveMultiple.__doc__))

        mainData = self.createRoadData(name='main', base=self.base, auto=True)
        keeping.clearAllKeepSafe(mainData['dirpath'])
        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     auto=mainData['auto'],
                                     ha=None)

        otherData = self.createRoadData(name='other', base=self.base)
        keeping.clearAllKeepSafe(otherData['dirpath'])
        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", raeting.RAET_TEST_PORT))


        self.join(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes.values()[0]
        self.assertTrue(otherRemote.joined)
        self.assertTrue(mainRemote.joined)

        self.allow(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes.values()[0]
        self.assertTrue(otherRemote.allowed)
        self.assertTrue(mainRemote.allowed)


        other1Data = self.createRoadData(name='other1', base=self.base)
        keeping.clearAllKeepSafe(other1Data['dirpath'])
        other1 = self.createRoadStack(data=other1Data,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", 7532))


        self.join(other1, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other1.transactions), 0)
        other1Remote = main.remotes[other1.local.uid]
        main1Remote = other1.remotes.values()[0]
        self.assertTrue(other1Remote.joined)
        self.assertTrue(main1Remote.joined)

        self.allow(other1, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other1.transactions), 0)
        other1Remote = main.remotes[other1.local.uid]
        main1Remote = other1.remotes.values()[0]
        self.assertTrue(other1Remote.allowed)
        self.assertTrue(main1Remote.allowed)

        console.terse("\nAlive Other to Main *********\n")
        self.assertIs(otherRemote.alived, None)
        self.assertIs(mainRemote.alived, None)

        self.alive(other, main, deid=main.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertTrue(otherRemote.alived)
        self.assertTrue(mainRemote.alived)

        console.terse("\nAlive Main to Other *********\n")
        otherRemote.alived = None
        mainRemote.alived = None
        self.assertIs(otherRemote.alived, None)
        self.assertIs(mainRemote.alived, None)

        self.alive(main, other, deid=other.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertTrue(otherRemote.alived)
        self.assertTrue(mainRemote.alived)

        console.terse("\nAlive Other1 to Main *********\n")
        self.assertIs(other1Remote.alived, None)
        self.assertIs(main1Remote.alived, None)

        self.alive(other1, main, deid=main.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other1.transactions), 0)
        self.assertTrue(other1Remote.alived)
        self.assertTrue(main1Remote.alived)

        console.terse("\nAlive Main to Other1 *********\n")
        other1Remote.alived = None
        main1Remote.alived = None
        self.assertIs(other1Remote.alived, None)
        self.assertIs(main1Remote.alived, None)

        self.alive(main, other1, deid=other1.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other1.transactions), 0)
        self.assertTrue(other1Remote.alived)
        self.assertTrue(main1Remote.alived)

        console.terse("\nDead Other Alive Other1, from Main *********\n")
        self.assertTrue(main.remotes[other.local.uid].alived)
        self.assertTrue(main.remotes[other1.local.uid].alived)
        main.alive(duid=other.local.uid)
        main.alive(duid=other1.local.uid)
        # don't service other stack so it appears to be dead
        self.serviceStacks([main, other1], duration=3.0)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other1.transactions), 0)
        #self.assertTrue(other.local.uid not in main.remotes)
        self.assertIs(main.remotes[other.local.uid].alived, False)
        self.assertTrue(main.remotes[other1.local.uid].alived)

        self.serviceStacks([other, main], duration=3.0) #clean up
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertEqual(len(other1.transactions), 0)

        #bring it back to life
        console.terse("\nReliven other *********\n")
        other.alive(duid=main.local.uid, cascade=True)
        self.serviceStacks([other, main], duration=3.0)
        self.assertIs(main.remotes[other.local.uid].alived, True)
        self.assertIs(other.remotes[main.local.uid].alived, True)

        console.terse("\nAlive Other Dead Other 1 from Main *********\n")
        main.alive(duid=other.local.uid)
        main.alive(duid=other1.local.uid)
        self.serviceStacks([main, other], duration=3.0)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertFalse(other1Remote.alived)
        self.assertTrue(otherRemote.alived)

        self.serviceStacks([other1,  main], duration=3.0)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertEqual(len(other1.transactions), 0)

        #bring it back to life
        console.terse("\nReliven other1 *********\n")
        other1.alive(duid=main.local.uid, cascade=True)
        self.serviceStacks([other1, main], duration=3.0)
        self.assertIs(main.remotes[other1.local.uid].alived, True)
        self.assertIs(other1.remotes[main.local.uid].alived, True)

        main.server.close()
        main.clearLocal()
        main.clearRemoteKeeps()

        other.server.close()
        other.clearLocal()
        other.clearRemoteKeeps()

        other1.server.close()
        other1.clearLocal()
        other1.clearRemoteKeeps()
Exemple #10
0
    def testAliveUnjoinedMain(self):
        '''
        Test alive transaction for other to main unjoined on main
        '''
        console.terse("{0}\n".format(self.testAliveUnjoinedOther.__doc__))

        mainData = self.createRoadData(name='main', base=self.base, auto=True)
        keeping.clearAllKeepSafe(mainData['dirpath'])
        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     auto=mainData['auto'],
                                     ha=None)

        otherData = self.createRoadData(name='other', base=self.base)
        keeping.clearAllKeepSafe(otherData['dirpath'])
        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", raeting.RAET_TEST_PORT))

        # join and allow
        self.join(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes[main.local.uid]
        self.assertIs(otherRemote.joined, True)
        self.assertIs(mainRemote.joined,  True)

        self.allow(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertIs(otherRemote.allowed, True)
        self.assertIs(mainRemote.allowed,  True)

        console.terse("\nBoth unjoined Alive Other to Main *********\n")
        # set main's remote of other to not joined or allowed
        otherRemote.alived = None
        otherRemote.joined = None
        otherRemote.allowed = None

        self.alive(other, main, mha=('127.0.0.1', main.local.port))
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes[main.local.uid]
        self.assertIs(otherRemote.joined, True)
        self.assertIs(mainRemote.joined,  True)
        self.assertIs(otherRemote.alived,  None)
        self.assertIs(mainRemote.alived,  None)

        self.alive(other, main, deid=main.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertIs(otherRemote.allowed, True)
        self.assertIs(mainRemote.allowed,  True)
        self.assertIs(otherRemote.alived,  None)
        self.assertIs(mainRemote.alived,  None)

        self.alive(other, main, deid=main.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertIs(otherRemote.alived,  True)
        self.assertIs(mainRemote.alived,  True)

        console.terse("\nAlive Main to Other *********\n")
        otherRemote.alived = None
        mainRemote.alived = None
        self.assertIs(otherRemote.alived, None)
        self.assertIs(mainRemote.alived, None)

        self.alive(main, other, deid=other.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertTrue(otherRemote.alived)
        self.assertTrue(mainRemote.alived)

        main.server.close()
        main.clearLocal()
        main.clearRemoteKeeps()

        other.server.close()
        other.clearLocal()
        other.clearRemoteKeeps()
Exemple #11
0
    def testAlive(self):
        '''
        Test basic alive transaction
        '''
        console.terse("{0}\n".format(self.testAlive.__doc__))

        mainData = self.createRoadData(name='main', base=self.base, auto=True)
        keeping.clearAllKeepSafe(mainData['dirpath'])
        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     auto=mainData['auto'],
                                     ha=None)

        otherData = self.createRoadData(name='other', base=self.base)
        keeping.clearAllKeepSafe(otherData['dirpath'])
        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", raeting.RAET_TEST_PORT))


        self.join(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes.values()[0]
        self.assertTrue(otherRemote.joined)
        self.assertTrue(mainRemote.joined)

        self.allow(other, main)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes.values()[0]
        self.assertTrue(otherRemote.allowed)
        self.assertTrue(mainRemote.allowed)

        console.terse("\nAlive Other to Main *********\n")
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes.values()[0]
        self.assertIs(otherRemote.alived, None)
        self.assertIs(mainRemote.alived, None)

        self.alive(other, main, deid=main.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertTrue(otherRemote.alived)
        self.assertTrue(mainRemote.alived)

        console.terse("\nAlive Main to Other *********\n")
        otherRemote.alived = None
        mainRemote.alived = None
        self.assertIs(otherRemote.alived, None)
        self.assertIs(mainRemote.alived, None)

        self.alive(main, other, deid=other.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertTrue(otherRemote.alived)
        self.assertTrue(mainRemote.alived)


        console.terse("\nDead Other from Main *********\n")
        self.assertTrue(otherRemote.alived)
        self.assertTrue(mainRemote.alived)
        main.alive(duid=other.local.uid)
        self.serviceStack(main, duration=3.0)
        self.assertEqual(len(main.transactions), 0)
        self.assertFalse(otherRemote.alived)
        self.serviceStack(other, duration=3.0)

        console.terse("\nDead Main from Other *********\n")
        self.assertTrue(mainRemote.alived)
        other.alive(duid=main.local.uid)
        self.serviceStack(other, duration=3.0)
        self.assertEqual(len(other.transactions), 0)
        self.assertFalse(mainRemote.alived)
        self.serviceStack(main, duration=3.0)

        main.server.close()
        main.clearLocal()
        main.clearRemoteKeeps()

        other.server.close()
        other.clearLocal()
        other.clearRemoteKeeps()
Exemple #12
0
    def testManageMainRebootCascade(self):
        '''
        Test stack manage remotes as if main were rebooted
        '''
        console.terse("{0}\n".format(self.testManageMainRebootCascade.__doc__))

        mainData = self.createRoadData(name='main', base=self.base, auto=True)
        mainDirpath = mainData['dirpath']
        keeping.clearAllKeepSafe(mainData['dirpath'])
        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     auto=mainData['auto'],
                                     ha=None)

        otherData = self.createRoadData(name='other', base=self.base)
        otherDirpath = otherData['dirpath']
        keeping.clearAllKeepSafe(otherData['dirpath'])
        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", raeting.RAET_TEST_PORT))

        other1Data = self.createRoadData(name='other1', base=self.base)
        other1Dirpath = other1Data['dirpath']
        keeping.clearAllKeepSafe(other1Data['dirpath'])
        other1 = self.createRoadStack(data=other1Data,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", 7532))


        self.join(other, main)
        self.join(other1, main)
        self.allow(other, main)
        self.allow(other1, main)

        console.terse("\nTest manage remotes presence *********\n")
        console.terse("\nMake all alive *********\n")
        stacks = [main, other, other1]
        for remote in main.remotes.values(): #make all alive
            main.alive(duid=remote.uid)
        self.serviceStacks(stacks, duration=3.0)
        for remote in main.remotes.values():
            self.assertTrue(remote.alived)

        main.manage(immediate=True)
        self.assertEqual(len(main.transactions), 2) # started 2 alive transactions
        for remote in main.remotes.values(): # should reset alive to None
            self.assertIs(remote.alived, None)

        self.serviceStacks(stacks, duration=3.0)
        for stack in stacks:
            self.assertEqual(len(stack.transactions), 0)
        for remote in main.remotes.values():
            self.assertTrue(remote.alived)

        # now close down main and reload from saved data and manage
        console.terse("\nMake all alive with cascade after main reboots *********\n")
        main.server.close()
        main = stacking.RoadStack(dirpath=mainDirpath, store=self.store)
        stacks = [main, other, other1]

        for remote in main.remotes.values():
            self.assertIs(remote.joined, None)
            self.assertIs(remote.allowed, None)
            self.assertIs(remote.alived, None)

        main.manage(immediate=True, cascade=True)
        self.assertEqual(len(main.transactions), 2) # started 2 alive transactions
        for remote in main.remotes.values(): # should reset alive to None
            self.assertIs(remote.alived, None)
        self.serviceStacks(stacks, duration=3.0)
        for stack in stacks:
            self.assertEqual(len(stack.transactions), 0)
        for remote in main.remotes.values():
            self.assertIs(remote.joined, True)
            self.assertIs(remote.allowed, True)
            self.assertIs(remote.alived, True)

        # Now test as if others are rebooted
        console.terse("\nMake all alive with cascade after others reboot *********\n")
        other.server.close()
        other1.server.close()
        other = stacking.RoadStack(dirpath=otherDirpath, store=self.store)
        other1 = stacking.RoadStack(dirpath=other1Dirpath, store=self.store)
        stacks = [main, other, other1]

        self.assertIs(other.remotes[main.local.uid].joined, None)
        self.assertIs(other.remotes[main.local.uid].allowed, None)
        self.assertIs(other.remotes[main.local.uid].alived, None)
        self.assertIs(other1.remotes[main.local.uid].joined, None)
        self.assertIs(other1.remotes[main.local.uid].allowed, None)
        self.assertIs(other1.remotes[main.local.uid].alived, None)

        main.manage(immediate=True, cascade=True)
        self.assertEqual(len(main.transactions), 2) # started 2 alive transactions
        for remote in main.remotes.values(): # should reset alive to None
            self.assertIs(remote.alived, None)
        self.serviceStacks(stacks, duration=3.0)
        for stack in stacks:
            self.assertEqual(len(stack.transactions), 0)
        self.assertIs(other.remotes[main.local.uid].joined, True)
        self.assertIs(other.remotes[main.local.uid].allowed, True)
        self.assertIs(other.remotes[main.local.uid].alived, True)
        self.assertIs(other1.remotes[main.local.uid].joined, True)
        self.assertIs(other1.remotes[main.local.uid].allowed, True)
        self.assertIs(other1.remotes[main.local.uid].alived, True)

        main.server.close()
        main.clearLocal()
        main.clearRemoteKeeps()

        other.server.close()
        other.clearLocal()
        other.clearRemoteKeeps()

        other1.server.close()
        other1.clearLocal()
        other1.clearRemoteKeeps()
Exemple #13
0
    def setUp(self):
        self.store = storing.Store(stamp=0.0)
        self.timer = StoreTimer(store=self.store, duration=1.0)

        self.dirpathBase=tempfile.mkdtemp(prefix="raet",  suffix="base", dir='/tmp')
        stacking.RoadStack.Bk = raeting.bodyKinds.json

        #main stack
        mainName = "main"
        mainDirpath = os.path.join(self.dirpathBase, 'road', 'keep', mainName)
        signer = nacling.Signer()
        mainSignKeyHex = signer.keyhex
        mainVerKeyHex = signer.verhex
        privateer = nacling.Privateer()
        mainPriKeyHex = privateer.keyhex
        mainPubKeyHex = privateer.pubhex

        #other stack
        otherName = "other"
        otherDirpath = os.path.join(self.dirpathBase, 'road', 'keep', otherName)
        signer = nacling.Signer()
        otherSignKeyHex = signer.keyhex
        otherVerKeyHex = signer.verhex
        privateer = nacling.Privateer()
        otherPriKeyHex = privateer.keyhex
        otherPubKeyHex = privateer.pubhex

        keeping.clearAllKeepSafe(mainDirpath)
        keeping.clearAllKeepSafe(otherDirpath)

        local = estating.LocalEstate(eid=1,
                                     name=mainName,
                                     sigkey=mainSignKeyHex,
                                     prikey=mainPriKeyHex,)

        self.main = stacking.RoadStack(name=mainName,
                                       local=local,
                                       auto=True,
                                       main=True,
                                       dirpath=mainDirpath,
                                       store=self.store)

        remote1 = estating.RemoteEstate(stack=self.main,
                                        eid=2,
                                        name=otherName,
                                        ha=("127.0.0.1", raeting.RAET_TEST_PORT),
                                        verkey=otherVerKeyHex,
                                        pubkey=otherPubKeyHex,
                                        period=self.main.period,
                                        offset=self.main.offset,)
        self.main.addRemote(remote1)


        local = estating.LocalEstate(eid=2,
                                     name=otherName,
                                     ha=("", raeting.RAET_TEST_PORT),
                                     sigkey=otherSignKeyHex,
                                     prikey=otherPriKeyHex,)

        self.other = stacking.RoadStack(name=otherName,
                                         local=local,
                                         dirpath=otherDirpath,
                                         store=self.store)

        remote0 = estating.RemoteEstate(stack=self.other,
                                        eid=1,
                                        name=mainName,
                                        ha=('127.0.0.1', raeting.RAET_PORT),
                                        verkey=mainVerKeyHex,
                                        pubkey=mainPubKeyHex,
                                        period=self.other.period,
                                        offset=self.other.offset,)
        self.other.addRemote(remote0)

        remote0.publee = nacling.Publican(key=remote1.privee.pubhex)
        remote1.publee = nacling.Publican(key=remote0.privee.pubhex)

        stuff = []
        for i in range(300):
            stuff.append(str(i).rjust(4, " "))
        self.stuff = "".join(stuff)

        self.data = odict(hk=raeting.headKinds.raet)
Exemple #14
0
def test(preClearMaster=True,
         preClearMinion=True,
         postClearMaster=True,
         postClearMinion=True):
    '''
    initially
    master on port 7530 with eid of 1
    minion on port 7531 with eid of 0
    eventually
    master eid of 1
    minion eid of 2
    '''
    console.reinit(verbosity=console.Wordage.concise)

    store = storing.Store(stamp=0.0)

    #master stack
    masterName = "master"
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterDirpath = os.path.join('/tmp/raet/road', 'keep', masterName)

    #minion0 stack
    minionName0 = "minion0"
    signer = nacling.Signer()
    minionSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    minionPriKeyHex = privateer.keyhex
    m0Dirpath = os.path.join('/tmp/raet/road', 'keep', minionName0)

    if preClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if preClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)

    local = estating.LocalEstate(
        eid=1,
        name=masterName,
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(name=masterName,
                                local=local,
                                auto=True,
                                store=store,
                                main=True,
                                dirpath=masterDirpath)

    local = estating.LocalEstate(
        eid=0,
        name=minionName0,
        ha=("", raeting.RAET_TEST_PORT),
        sigkey=minionSignKeyHex,
        prikey=minionPriKeyHex,
    )
    stack1 = stacking.RoadStack(name=minionName0,
                                local=local,
                                store=store,
                                dirpath=m0Dirpath)

    print "\n********* Join Forever Transaction **********"
    #transacting.Joiner.Timeout = 0 # make join go on forever
    stack1.join(timeout=0.0)  # make join go on forever
    timer = StoreTimer(store=store, duration=30.0)
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    print "\n********* Join Default Timeout Transaction **********"
    stack1.join(timeout=None)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack1.name, remote.eid, remote.joined)
    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    for uid in stack0.remotes:
        stack0.removeRemote(uid)
    for uid in stack1.remotes:
        stack1.removeRemote(uid)

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)

    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()
    print

    print "\n********* Join Default Timeout Transaction After Clear Keeps **********"
    stack1.join(timeout=None)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    print "\n********* Join Forever Timeout Transaction After Clear Keeps**********"
    stack1.join(timeout=0.0)
    timer.restart()
    while (stack1.transactions or stack0.transactions) and not timer.expired:
        stack1.serviceAll()
        if timer.elapsed > 20.0:
            stack0.serviceAll()
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack0.name, remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "{0} Remote Estate {1} joined= {2}".format(
            stack1.name, remote.eid, remote.joined)

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    stack0.server.close()
    stack1.server.close()

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)
Exemple #15
0
def test():
    '''
    Test keeping.
    '''
    pkiDirpath = os.path.join('/tmp', 'raet', 'keyo', 'master', 'pki')
    if not os.path.exists(pkiDirpath):
        os.makedirs(pkiDirpath)

    acceptedDirpath = os.path.join(pkiDirpath, 'accepted')
    if not os.path.exists(acceptedDirpath):
        os.makedirs(acceptedDirpath)

    pendingDirpath = os.path.join(pkiDirpath, 'pending')
    if not os.path.exists(pendingDirpath):
        os.makedirs(pendingDirpath)

    rejectedDirpath = os.path.join(pkiDirpath, 'rejected')
    if not os.path.exists(rejectedDirpath):
        os.makedirs(rejectedDirpath)

    localFilepath = os.path.join(pkiDirpath, 'local.key')
    if os.path.exists(localFilepath):
        mode = os.stat(localFilepath).st_mode
        print mode
        os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IRUSR)
        mode = os.stat(localFilepath).st_mode
        print mode

    cacheDirpath = os.path.join('/tmp/raet', 'cache', 'master')
    if not os.path.exists(cacheDirpath):
        os.makedirs(cacheDirpath)

    sockDirpath = os.path.join('/tmp/raet', 'sock', 'master')
    if not os.path.exists(sockDirpath):
        os.makedirs(sockDirpath)

    opts = dict(
        pki_dir=pkiDirpath,
        sock_dir=sockDirpath,
        cachedir=cacheDirpath,
        open_mode=True,
        auto_accept=True,
        transport='raet',
    )

    masterSafe = salting.SaltSafe(opts=opts)
    print("masterSafe local =\n{0}".format(masterSafe.loadLocalData()))
    print("masterSafe remote =\n{0}".format(masterSafe.loadAllRemoteData()))

    pkiDirpath = os.path.join('/tmp', 'raet', 'keyo', 'minion', 'pki')
    if not os.path.exists(pkiDirpath):
        os.makedirs(pkiDirpath)

    acceptedDirpath = os.path.join(pkiDirpath, 'accepted')
    if not os.path.exists(acceptedDirpath):
        os.makedirs(acceptedDirpath)

    pendingDirpath = os.path.join(pkiDirpath, 'pending')
    if not os.path.exists(pendingDirpath):
        os.makedirs(pendingDirpath)

    rejectedDirpath = os.path.join(pkiDirpath, 'rejected')
    if not os.path.exists(rejectedDirpath):
        os.makedirs(rejectedDirpath)

    localFilepath = os.path.join(pkiDirpath, 'local.key')
    if os.path.exists(localFilepath):
        mode = os.stat(localFilepath).st_mode
        print mode
        os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IRUSR)
        mode = os.stat(localFilepath).st_mode
        print mode

    cacheDirpath = os.path.join('/tmp/raet', 'cache', 'minion')
    sockDirpath = os.path.join('/tmp/raet', 'sock', 'minion')

    opts = dict(
        pki_dir=pkiDirpath,
        sock_dir=sockDirpath,
        cachedir=cacheDirpath,
        open_mode=True,
        auto_accept=True,
        transport='raet',
    )

    minionSafe = salting.SaltSafe(opts=opts)
    print("minionSafe local =\n{0}".format(minionSafe.loadLocalData()))
    print("minionSafe remote =\n{0}".format(minionSafe.loadAllRemoteData()))

    masterName = 'master'
    masterDirpath = os.path.join('/tmp', 'raet', 'keep', masterName)
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    masterVerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterPubKeyHex = privateer.pubhex

    m1Name = 'minion1'
    m1Dirpath = os.path.join('/tmp', 'raet', 'keep', m1Name)
    signer = nacling.Signer()
    m1SignKeyHex = signer.keyhex
    m1VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m1PriKeyHex = privateer.keyhex
    m1PubKeyHex = privateer.pubhex

    m2Name = 'minion2'
    signer = nacling.Signer()
    m2SignKeyHex = signer.keyhex
    m2VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m2PriKeyHex = privateer.keyhex
    m2PubKeyHex = privateer.pubhex

    m3Name = 'minion3'
    signer = nacling.Signer()
    m3SignKeyHex = signer.keyhex
    m3VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m3PriKeyHex = privateer.keyhex
    m3PubKeyHex = privateer.pubhex

    keeping.clearAllKeepSafe(masterDirpath)
    keeping.clearAllKeepSafe(m1Dirpath)

    #saltsafe = salting.SaltSafe(opts=opts)
    #print saltsafe.loadLocalData()
    #print saltsafe.loadAllRemoteData()

    #master stack
    local = estating.LocalEstate(
        eid=1,
        name=masterName,
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(local=local,
                                dirpath=masterDirpath,
                                safe=masterSafe)

    stack0.addRemote(
        estating.RemoteEstate(
            eid=2,
            name=m1Name,
            ha=('127.0.0.1', 7532),
            verkey=m1VerKeyHex,
            pubkey=m1PubKeyHex,
        ))

    stack0.addRemote(
        estating.RemoteEstate(
            eid=3,
            name=m2Name,
            ha=('127.0.0.1', 7533),
            verkey=m2VerKeyHex,
            pubkey=m2PubKeyHex,
        ))

    #minion stack
    local = estating.LocalEstate(
        eid=2,
        name=m1Name,
        ha=("", raeting.RAET_TEST_PORT),
        sigkey=m1SignKeyHex,
        prikey=m1PriKeyHex,
    )
    stack1 = stacking.RoadStack(local=local,
                                dirpath=m1Dirpath,
                                safe=minionSafe)

    stack1.addRemote(
        estating.RemoteEstate(
            eid=1,
            name=masterName,
            ha=('127.0.0.1', 7532),
            verkey=masterVerKeyHex,
            pubkey=masterPubKeyHex,
        ))

    stack1.addRemote(
        estating.RemoteEstate(
            eid=4,
            name=m3Name,
            ha=('127.0.0.1', 7534),
            verkey=m3VerKeyHex,
            pubkey=m3PubKeyHex,
        ))

    #stack0.clearLocal()
    stack0.clearRemoteKeeps()
    #stack1.clearLocal()
    stack1.clearRemoteKeeps()

    stack0.dumpLocal()
    stack0.dumpRemotes()

    stack1.dumpLocal()
    stack1.dumpRemotes()

    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()

    stack0.server.close()
    stack1.server.close()

    #master stack
    dirpath = os.path.join('/tmp/raet', 'keep', 'master')
    local = estating.LocalEstate(
        eid=1,
        name='master',
        sigkey=masterSignKeyHex,
        prikey=masterPriKeyHex,
    )
    stack0 = stacking.RoadStack(local=local,
                                dirpath=masterDirpath,
                                safe=masterSafe)

    #minion stack
    dirpath = os.path.join('/tmp/raet', 'keep', 'minion1')
    local = estating.LocalEstate(
        eid=2,
        name='minion1',
        ha=("", raeting.RAET_TEST_PORT),
        sigkey=m1SignKeyHex,
        prikey=m1PriKeyHex,
    )
    stack1 = stacking.RoadStack(local=local,
                                dirpath=m1Dirpath,
                                safe=minionSafe)

    stack0.loadLocal()
    print stack0.local.name, stack0.local.eid, stack0.local.sid, stack0.local.ha, stack0.local.signer, stack0.local.priver
    stack1.loadLocal()
    print stack1.local.name, stack1.local.eid, stack1.local.sid, stack1.local.ha, stack1.local.signer, stack1.local.priver

    stack0.clearLocal()
    stack0.clearRemoteKeeps()
    stack1.clearLocal()
    stack1.clearRemoteKeeps()
Exemple #16
0
def test(preClearMaster=False, preClearMinion=False, postClearMaster=False, postClearMinion=False):
    '''
    initially
    master on port 7530 with eid of 1
    minion on port 7531 with eid of 0
    eventually
    master eid of 1
    minion eid of 2
    '''
    console.reinit(verbosity=console.Wordage.concise)

    #transacting.Joiner.Timeout = 0 # make join go on forever

    store = storing.Store(stamp=0.0)

    #master stack
    masterName = "master"
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterDirpath = os.path.join('/tmp/raet/road', 'keep', masterName)

    #minion0 stack
    minionName0 = "minion0"
    signer = nacling.Signer()
    minionSignKeyHex = signer.keyhex
    privateer = nacling.Privateer()
    minionPriKeyHex = privateer.keyhex
    m0Dirpath = os.path.join('/tmp/raet/road', 'keep', minionName0)

    if preClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if preClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)


    local = estating.LocalEstate(  eid=1,
                                    name=masterName,
                                    sigkey=masterSignKeyHex,
                                    prikey=masterPriKeyHex,)
    stack0 = stacking.RoadStack(name=masterName,
                               local=local,
                               store=store,
                               main=True,
                               dirpath=masterDirpath)


    local = estating.LocalEstate(  eid=0,
                                    name=minionName0,
                                    ha=("", raeting.RAET_TEST_PORT),
                                    sigkey=minionSignKeyHex,
                                    prikey=minionPriKeyHex,)
    stack1 = stacking.RoadStack(name=minionName0,
                               local=local,
                               store=store,
                               dirpath=m0Dirpath)


    print "\n********* Join Transaction **********"
    stack1.join()
    #timer = StoreTimer(store=store, duration=3.0)
    while stack1.transactions or stack0.transactions:
        stack1.serviceAll()
        stack0.serviceAll()
        if store.stamp >= 0.3:
            for remote in stack0.remotes.values():
                if remote.acceptance == raeting.acceptances.pending:
                    stack0.safe.acceptRemote(remote)
        store.advanceStamp(0.1)

    for remote in stack0.remotes.values():
        print "Remote Estate {0} joined= {1}".format(remote.eid, remote.joined)
    for remote in stack1.remotes.values():
        print "Remote Estate {0} joined= {1}".format(remote.eid, remote.joined)


    print "{0} eid={1}".format(stack0.name, stack0.local.uid)
    print "{0} remotes=\n{1}".format(stack0.name, stack0.remotes)
    print "{0} transactions=\n{1}".format(stack0.name, stack0.transactions)
    print "{0} eid={1}".format(stack1.name, stack1.local.uid)
    print "{0} remotes=\n{1}".format(stack1.name, stack1.remotes)
    print "{0} transactions=\n{1}".format(stack1.name, stack1.transactions)


    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()
    print

    print "{0} Stats".format(stack0.name)
    for key, val in stack0.stats.items():
        print "   {0}={1}".format(key, val)
    print
    print "{0} Stats".format(stack1.name)
    for key, val in stack1.stats.items():
        print "   {0}={1}".format(key, val)
    print

    stack0.server.close()
    stack1.server.close()

    if postClearMaster:
        keeping.clearAllKeepSafe(masterDirpath)
    if postClearMinion:
        keeping.clearAllKeepSafe(m0Dirpath)
Exemple #17
0
    def testManage(self):
        '''
        Test stack manage remotes
        '''
        console.terse("{0}\n".format(self.testManage.__doc__))

        mainData = self.createRoadData(name='main', base=self.base, auto=True)
        keeping.clearAllKeepSafe(mainData['dirpath'])
        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     auto=mainData['auto'],
                                     ha=None)

        otherData = self.createRoadData(name='other', base=self.base)
        keeping.clearAllKeepSafe(otherData['dirpath'])
        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", raeting.RAET_TEST_PORT))

        other1Data = self.createRoadData(name='other1', base=self.base)
        keeping.clearAllKeepSafe(other1Data['dirpath'])
        other1 = self.createRoadStack(data=other1Data,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", 7532))


        self.join(other, main)
        self.join(other1, main)
        self.allow(other, main)
        self.allow(other1, main)

        console.terse("\nTest manage remotes presence *********\n")
        console.terse("\nMake all alive *********\n")
        stacks = [main, other, other1]
        for remote in main.remotes.values(): #make all alive
            main.alive(duid=remote.uid)
        self.serviceStacks(stacks, duration=3.0)
        for remote in main.remotes.values():
            self.assertTrue(remote.alived)

        main.manage()
        for stack in stacks: # no alive transactions started
            self.assertEqual(len(stack.transactions), 0)

        console.terse("\nMake all expired so send alive *********\n")
        # advance clock so remote keep alive timers expire
        self.store.advanceStamp(estating.RemoteEstate.Period + estating.RemoteEstate.Offset)
        main.manage()
        for remote in main.remotes.values(): # should start
            self.assertIs(remote.alived, None)

        self.assertEqual(len(main.transactions), 2) # started 2 alive transactions

        self.serviceStacks(stacks, duration=3.0)
        for stack in stacks:
            self.assertEqual(len(stack.transactions), 0)
        for remote in main.remotes.values():
            self.assertTrue(remote.alived)


        main.server.close()
        main.clearLocal()
        main.clearRemoteKeeps()

        other.server.close()
        other.clearLocal()
        other.clearRemoteKeeps()

        other1.server.close()
        other1.clearLocal()
        other1.clearRemoteKeeps()
Exemple #18
0
def test():
    '''
    Test keeping.
    '''
    pkiDirpath = os.path.join('/tmp', 'raet', 'keyo', 'master', 'pki')
    if not os.path.exists(pkiDirpath):
            os.makedirs(pkiDirpath)

    acceptedDirpath = os.path.join(pkiDirpath, 'accepted')
    if not os.path.exists(acceptedDirpath):
        os.makedirs(acceptedDirpath)

    pendingDirpath = os.path.join(pkiDirpath, 'pending')
    if not os.path.exists(pendingDirpath):
        os.makedirs(pendingDirpath)

    rejectedDirpath = os.path.join(pkiDirpath, 'rejected')
    if not os.path.exists(rejectedDirpath):
        os.makedirs(rejectedDirpath)

    localFilepath = os.path.join(pkiDirpath, 'local.key')
    if os.path.exists(localFilepath):
        mode = os.stat(localFilepath).st_mode
        print mode
        os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IRUSR)
        mode = os.stat(localFilepath).st_mode
        print mode


    cacheDirpath = os.path.join('/tmp/raet', 'cache', 'master')
    sockDirpath = os.path.join('/tmp/raet', 'sock', 'master')

    opts = dict(
                pki_dir=pkiDirpath,
                sock_dir=sockDirpath,
                cachedir=cacheDirpath,
                open_mode=True,
                auto_accept=True,
                transport='raet',
                )

    masterSafe = salting.SaltSafe(opts=opts)
    print("masterSafe local =\n{0}".format(masterSafe.loadLocalData()))
    print("masterSafe remote =\n{0}".format(masterSafe.loadAllRemoteData()))

    pkiDirpath = os.path.join('/tmp', 'raet', 'keyo', 'minion', 'pki')
    if not os.path.exists(pkiDirpath):
            os.makedirs(pkiDirpath)

    acceptedDirpath = os.path.join(pkiDirpath, 'accepted')
    if not os.path.exists(acceptedDirpath):
        os.makedirs(acceptedDirpath)

    pendingDirpath = os.path.join(pkiDirpath, 'pending')
    if not os.path.exists(pendingDirpath):
        os.makedirs(pendingDirpath)

    rejectedDirpath = os.path.join(pkiDirpath, 'rejected')
    if not os.path.exists(rejectedDirpath):
        os.makedirs(rejectedDirpath)

    localFilepath = os.path.join(pkiDirpath, 'local.key')
    if os.path.exists(localFilepath):
        mode = os.stat(localFilepath).st_mode
        print mode
        os.chmod(localFilepath, mode | stat.S_IWUSR | stat.S_IRUSR)
        mode = os.stat(localFilepath).st_mode
        print mode

    cacheDirpath = os.path.join('/tmp/raet', 'cache', 'minion')
    sockDirpath = os.path.join('/tmp/raet', 'sock', 'minion')

    opts = dict(
                pki_dir=pkiDirpath,
                sock_dir=sockDirpath,
                cachedir=cacheDirpath,
                open_mode=True,
                auto_accept=True,
                transport='raet',
                )

    minionSafe = salting.SaltSafe(opts=opts)
    print("minionSafe local =\n{0}".format(minionSafe.loadLocalData()))
    print("minionSafe remote =\n{0}".format(minionSafe.loadAllRemoteData()))

    masterName = 'master'
    masterDirpath = os.path.join('/tmp', 'raet', 'keep', masterName )
    signer = nacling.Signer()
    masterSignKeyHex = signer.keyhex
    masterVerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    masterPriKeyHex = privateer.keyhex
    masterPubKeyHex = privateer.pubhex

    m1Name = 'minion1'
    m1Dirpath = os.path.join('/tmp', 'raet', 'keep', m1Name)
    signer = nacling.Signer()
    m1SignKeyHex = signer.keyhex
    m1VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m1PriKeyHex = privateer.keyhex
    m1PubKeyHex = privateer.pubhex

    m2Name = 'minion2'
    signer = nacling.Signer()
    m2SignKeyHex = signer.keyhex
    m2VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m2PriKeyHex = privateer.keyhex
    m2PubKeyHex = privateer.pubhex

    m3Name = 'minion3'
    signer = nacling.Signer()
    m3SignKeyHex = signer.keyhex
    m3VerKeyHex = signer.verhex
    privateer = nacling.Privateer()
    m3PriKeyHex = privateer.keyhex
    m3PubKeyHex = privateer.pubhex

    keeping.clearAllKeepSafe(masterDirpath)
    keeping.clearAllKeepSafe(m1Dirpath)

    #saltsafe = salting.SaltSafe(opts=opts)
    #print saltsafe.loadLocalData()
    #print saltsafe.loadAllRemoteData()

    #master stack
    local = estating.LocalEstate(  eid=1,
                                    name=masterName,
                                    sigkey=masterSignKeyHex,
                                    prikey=masterPriKeyHex,)
    stack0 = stacking.RoadStack(local=local,
                               dirpath=masterDirpath,
                               safe=masterSafe)

    stack0.addRemote(estating.RemoteEstate(eid=2,
                                    name=m1Name,
                                    ha=('127.0.0.1', 7532),
                                    verkey=m1VerKeyHex,
                                    pubkey=m1PubKeyHex,))

    stack0.addRemote(estating.RemoteEstate(eid=3,
                                    name=m2Name,
                                    ha=('127.0.0.1', 7533),
                                    verkey=m2VerKeyHex,
                                    pubkey=m2PubKeyHex,))

    #minion stack
    local = estating.LocalEstate(   eid=2,
                                     name=m1Name,
                                     ha=("", raeting.RAET_TEST_PORT),
                                     sigkey=m1SignKeyHex,
                                     prikey=m1PriKeyHex,)
    stack1 = stacking.RoadStack(local=local,
                               dirpath=m1Dirpath,
                               safe=minionSafe)


    stack1.addRemote(estating.RemoteEstate(eid=1,
                                    name=masterName,
                                    ha=('127.0.0.1', 7532),
                                    verkey=masterVerKeyHex,
                                    pubkey=masterPubKeyHex,))

    stack1.addRemote(estating.RemoteEstate(eid=4,
                                    name=m3Name,
                                    ha=('127.0.0.1', 7534),
                                    verkey=m3VerKeyHex,
                                    pubkey=m3PubKeyHex,))

    #stack0.clearLocal()
    stack0.clearRemoteKeeps()
    #stack1.clearLocal()
    stack1.clearRemoteKeeps()

    stack0.dumpLocal()
    stack0.dumpRemotes()

    stack1.dumpLocal()
    stack1.dumpRemotes()

    print "Road {0}".format(stack0.name)
    print stack0.keep.loadLocalData()
    print stack0.keep.loadAllRemoteData()
    print "Safe {0}".format(stack0.name)
    print stack0.safe.loadLocalData()
    print stack0.safe.loadAllRemoteData()
    print

    print "Road {0}".format(stack1.name)
    print stack1.keep.loadLocalData()
    print stack1.keep.loadAllRemoteData()
    print "Safe {0}".format(stack1.name)
    print stack1.safe.loadLocalData()
    print stack1.safe.loadAllRemoteData()

    stack0.server.close()
    stack1.server.close()

    #master stack
    dirpath = os.path.join('/tmp/raet', 'keep', 'master')
    local = estating.LocalEstate(  eid=1,
                                    name='master',
                                    sigkey=masterSignKeyHex,
                                    prikey=masterPriKeyHex,)
    stack0 = stacking.RoadStack(local=local,
                               dirpath=masterDirpath,
                               safe=masterSafe)

    #minion stack
    dirpath = os.path.join('/tmp/raet', 'keep', 'minion1')
    local = estating.LocalEstate(   eid=2,
                                     name='minion1',
                                     ha=("", raeting.RAET_TEST_PORT),
                                     sigkey=m1SignKeyHex,
                                     prikey=m1PriKeyHex,)
    stack1 = stacking.RoadStack(local=local,
                               dirpath=m1Dirpath,
                               safe=minionSafe)


    stack0.loadLocal()
    print stack0.local.name, stack0.local.eid, stack0.local.sid, stack0.local.ha, stack0.local.signer, stack0.local.priver
    stack1.loadLocal()
    print stack1.local.name, stack1.local.eid, stack1.local.sid, stack1.local.ha, stack1.local.signer, stack1.local.priver

    stack0.clearLocal()
    stack0.clearRemoteKeeps()
    stack1.clearLocal()
    stack1.clearRemoteKeeps()
Exemple #19
0
    def testAliveUnjoinedFromMain(self):
        '''
        Test alive transaction for unjoined main to other
        '''
        console.terse("{0}\n".format(self.testAliveUnjoinedOther.__doc__))

        mainData = self.createRoadData(name='main', base=self.base, auto=True)
        keeping.clearAllKeepSafe(mainData['dirpath'])
        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     auto=mainData['auto'],
                                     ha=None)

        otherData = self.createRoadData(name='other', base=self.base)
        keeping.clearAllKeepSafe(otherData['dirpath'])
        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     auto=None,
                                     ha=("", raeting.RAET_TEST_PORT))

        console.terse("\nBoth unjoined Alive Main to Other *********\n")
        self.assertEqual(len(main.remotes), 0)
        self.assertEqual(len(other.remotes), 0)

        #now create remote for other and add to main
        main.addRemote(estating.RemoteEstate(stack=main,
                                             eid=2,
                                             name=otherData['name'],
                                             ha=('127.0.0.1', other.local.port),
                                             verkey=otherData['verhex'],
                                             pubkey=otherData['pubhex'],
                                             period=main.period,
                                             offset=main.offset))

        self.alive(main, other, mha=('127.0.0.1', other.local.port))
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        otherRemote = main.remotes[other.local.uid]
        mainRemote = other.remotes[main.local.uid]
        self.assertIs(otherRemote.joined, True)
        self.assertIs(mainRemote.joined,  True)
        self.assertIs(otherRemote.alived,  None)
        self.assertIs(mainRemote.alived,  None)

        self.alive(main, other, deid=other.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertIs(otherRemote.allowed, True)
        self.assertIs(mainRemote.allowed,  True)
        self.assertIs(otherRemote.alived,  None)
        self.assertIs(mainRemote.alived,  None)

        self.alive(main, other, deid=other.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertIs(otherRemote.alived,  True)
        self.assertIs(mainRemote.alived,  True)

        console.terse("\nAlive Other to Main *********\n")
        otherRemote.alived = None
        mainRemote.alived = None
        self.assertIs(otherRemote.alived, None)
        self.assertIs(mainRemote.alived, None)

        self.alive(other, main, deid=main.local.uid)
        self.assertEqual(len(main.transactions), 0)
        self.assertEqual(len(other.transactions), 0)
        self.assertTrue(otherRemote.alived)
        self.assertTrue(mainRemote.alived)

        main.server.close()
        main.clearLocal()
        main.clearRemoteKeeps()

        other.server.close()
        other.clearLocal()
        other.clearRemoteKeeps()