예제 #1
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)
예제 #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=TEMPDIR)
        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.clearAllKeep(mainDirpath)
        keeping.clearAllKeep(otherDirpath)

        self.main = stacking.RoadStack(
            store=self.store,
            name=mainName,
            main=True,
            auto=raeting.autoModes.once,
            sigkey=mainSignKeyHex,
            prikey=mainPriKeyHex,
            dirpath=mainDirpath,
        )

        self.other = stacking.RoadStack(
            store=self.store,
            name=otherName,
            auto=raeting.autoModes.once,
            ha=("", raeting.RAET_TEST_PORT),
            sigkey=otherSignKeyHex,
            prikey=otherPriKeyHex,
            dirpath=otherDirpath,
        )
예제 #3
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
예제 #4
0
    def createRoadStack(self, data, keep,  eid=0, main=None, ha=None):
        '''
        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

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

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

        return stack
예제 #5
0
    def createRoadStack(self, data, eid=0, main=None, auto=None, ha=None):
        '''
        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

        '''
        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 if auto is not None else data['auto'],
                                   main=main,
                                   dirpath=data['dirpath'],
                                   store=self.store)

        return stack
예제 #6
0
    def createRoadStack(
        self,
        data,
        uid=None,
        ha=None,
        main=None,
        auto=None,
    ):
        '''
        Creates stack and local estate from data with
        and overrides with parameters

        returns stack

        '''
        stack = stacking.RoadStack(
            store=self.store,
            name=data['name'],
            uid=uid,
            ha=ha or data['ha'],
            sigkey=data['sighex'],
            prikey=data['prihex'],
            auto=auto or data['auto'],
            main=main or data['main'],
            dirpath=data['dirpath'],
        )

        return stack
예제 #7
0
파일: testing.py 프로젝트: spivachuk/raet
    def createStack(self, name, port):
        '''
        Create a RoadStack object bound to the specified port on localhost.

        :param name: stack name
        :param port: port to bind to
        :return: the stack
        '''
        dirpath = os.path.join(self.baseDirpath, 'road', 'keep', name)
        signer = nacling.Signer()
        mainSignKeyHex = signer.keyhex
        privateer = nacling.Privateer()
        mainPriKeyHex = privateer.keyhex

        keeping.clearAllKeep(dirpath)

        return stacking.RoadStack(store=self.store,
                                  name=name,
                                  main=True,
                                  auto=raeting.AutoMode.once.value,
                                  ha=("", port),
                                  sigkey=mainSignKeyHex,
                                  prikey=mainPriKeyHex,
                                  dirpath=dirpath,
                                  )
예제 #8
0
    def testNormalizeHost(self):
        '''
        Test normalizeHost method
        '''
        console.terse("{0}\n".format(self.testNormalizeHost.__doc__))
        stack = stacking.RoadStack()
        estate = estating.Estate(stack, ha=("", 7540), iha=("", 7540))
        self.assertEqual(estate.ha, ('127.0.0.1', 7540))
        self.assertEqual(estate.iha, ('127.0.0.1', 7540))

        estate = estating.Estate(stack, ha=("::", 7540), iha=("::", 7540))
        self.assertEqual(estate.ha, ('::1', 7540))
        self.assertEqual(estate.iha, ('::1', 7540))

        host = estate.normalizeHost("216.58.193.78")
        self.assertEqual(host, "216.58.193.78")
        host = estate.normalizeHost("2607:f8b0:400a:809::200e")
        self.assertEqual(host, '2607:f8b0:400a:809::200e')

        stack.server.close()
예제 #9
0
    def setUp(self):
        self.store = Store(stamp=0.0)
        self.timer = StoreTimer(store=self.store, duration=1.0)

        self.dirpathBase = tempfile.mkdtemp(prefix="raet",
                                            suffix="base",
                                            dir=TEMPDIR)
        stacking.RoadStack.Bk = raeting.BodyKind.json.value

        #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.clearAllKeep(mainDirpath)
        keeping.clearAllKeep(otherDirpath)

        self.main = stacking.RoadStack(name=mainName,
                                       uid=1,
                                       sigkey=mainSignKeyHex,
                                       prikey=mainPriKeyHex,
                                       auto=raeting.AutoMode.once.value,
                                       main=True,
                                       dirpath=mainDirpath,
                                       store=self.store)

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

        self.other = stacking.RoadStack(name=otherName,
                                        uid=2,
                                        auto=raeting.AutoMode.once.value,
                                        ha=("", raeting.RAET_TEST_PORT),
                                        sigkey=otherSignKeyHex,
                                        prikey=otherPriKeyHex,
                                        dirpath=otherDirpath,
                                        store=self.store)

        remote0 = estating.RemoteEstate(
            stack=self.other,
            uid=3,
            name=mainName,
            ha=('127.0.0.1', raeting.RAET_PORT),
            verkey=mainVerKeyHex,
            pubkey=mainPubKeyHex,
        )
        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 = ns2b("".join(stuff))

        self.data = odict(hk=raeting.HeadKind.raet.value)
예제 #10
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()
예제 #11
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)
예제 #12
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)
예제 #13
0
    def testBasic(self):
        '''
        Basic keep setup for stack keep and safe persistence load and dump
        '''
        console.terse("{0}\n".format(self.testBasic.__doc__))
        base = '/tmp/raet/'
        auto = True
        data = self.createRoadData(name='main', base=base)
        stack = self.createRoadStack(data=data,
                                     eid=1,
                                     main=True,
                                     auto=auto,
                                     ha=None)
        #default ha is ("", raeting.RAET_PORT)

        console.terse("{0} keep dirpath = {1} safe dirpath = {0}\n".format(
            stack.name, stack.keep.dirpath, stack.safe.dirpath))
        self.assertEqual(stack.keep.dirpath, '/tmp/raet/road/keep/main')
        self.assertEqual(stack.safe.dirpath, '/tmp/raet/road/keep/main')
        self.assertEqual(stack.local.ha, ("0.0.0.0", raeting.RAET_PORT))

        # test round trip
        stack.clearLocal()
        stack.clearRemoteKeeps()

        stack.dumpLocal()
        stack.dumpRemotes()

        localKeepData = stack.keep.loadLocalData()
        console.terse("Local keep data = '{0}'\n".format(localKeepData))
        validLocalKeepData = odict([
            ('eid', 1),
            ('name', 'main'),
            ('main', True),
            ('host', '0.0.0.0'),
            ('port', 7530),
            ('sid', 0),
        ])
        self.assertDictEqual(localKeepData, validLocalKeepData)

        remoteKeepData = stack.keep.loadAllRemoteData()
        console.terse("Remote keep data = '{0}'\n".format(remoteKeepData))
        self.assertDictEqual(remoteKeepData, {})

        localSafeData = stack.safe.loadLocalData()
        console.terse("Local safe data = '{0}'\n".format(localSafeData))
        validLocalSafeData = odict([
            ('eid', 1),
            ('name', 'main'),
            ('sighex', data['sighex']),
            ('prihex', data['prihex']),
        ])
        self.assertDictEqual(localSafeData, validLocalSafeData)

        remoteSafeData = stack.safe.loadAllRemoteData()
        console.terse("Remote safe data = '{0}'\n".format(remoteSafeData))
        self.assertDictEqual(remoteSafeData, {})

        # test round trip with stack methods
        stack.loadLocal()
        localKeepData = odict([
            ('eid', stack.local.eid),
            ('name', stack.local.name),
            ('main', stack.local.main),
            ('host', stack.local.host),
            ('port', stack.local.port),
            ('sid', stack.local.sid),
        ])
        self.assertDictEqual(localKeepData, validLocalKeepData)

        localSafeData = odict([
            ('eid', stack.local.eid),
            ('name', stack.local.name),
            ('sighex', stack.local.signer.keyhex),
            ('prihex', stack.local.priver.keyhex),
        ])
        self.assertDictEqual(localSafeData, validLocalSafeData)

        stack.removeAllRemotes()
        stack.loadRemotes()
        self.assertDictEqual(stack.remotes, {})

        # round trip with non empty remote data
        other1Data = self.createRoadData(name='other1', base=base)
        stack.addRemote(
            estating.RemoteEstate(
                eid=2,
                name=other1Data['name'],
                ha=('127.0.0.1', 7531),
                verkey=other1Data['verhex'],
                pubkey=other1Data['pubhex'],
            ))

        other2Data = self.createRoadData(name='other2', base=base)
        stack.addRemote(
            estating.RemoteEstate(
                eid=3,
                name=other2Data['name'],
                ha=('127.0.0.1', 7532),
                verkey=other2Data['verhex'],
                pubkey=other2Data['pubhex'],
            ))

        stack.dumpRemotes()
        remoteKeepData = stack.keep.loadAllRemoteData()
        console.terse("Remote keep data = '{0}'\n".format(remoteKeepData))
        validRemoteKeepData = {
            '2': {
                'eid': 2,
                'name': other1Data['name'],
                'host': '127.0.0.1',
                'port': 7531,
                'sid': 0,
                'rsid': 0
            },
            '3': {
                'eid': 3,
                'name': other2Data['name'],
                'host': '127.0.0.1',
                'port': 7532,
                'sid': 0,
                'rsid': 0
            }
        }
        self.assertDictEqual(remoteKeepData, validRemoteKeepData)

        remoteSafeData = stack.safe.loadAllRemoteData()
        console.terse("Remote safe data = '{0}'\n".format(remoteSafeData))
        validRemoteSafeData = {
            '2': {
                'eid': 2,
                'name': other1Data['name'],
                'acceptance': None,
                'verhex': other1Data['verhex'],
                'pubhex': other1Data['pubhex']
            },
            '3': {
                'eid': 3,
                'name': other2Data['name'],
                'acceptance': None,
                'verhex': other2Data['verhex'],
                'pubhex': other2Data['pubhex']
            }
        }
        self.assertDictEqual(remoteSafeData, validRemoteSafeData)

        # stack method

        #convert string uid keys into int uid keys
        temp = validRemoteKeepData
        validRemoteKeepData = odict()
        for uid in temp:
            validRemoteKeepData[int(uid)] = temp[uid]

        temp = validRemoteSafeData
        validRemoteSafeData = odict()
        for uid in temp:
            validRemoteSafeData[int(uid)] = temp[uid]

        stack.removeAllRemotes()
        stack.loadRemotes()
        remoteKeepData = odict()
        for remote in stack.remotes.values():
            remoteKeepData[remote.uid] = odict([
                ('eid', remote.eid),
                ('name', remote.name),
                ('host', remote.host),
                ('port', remote.port),
                ('sid', remote.sid),
                ('rsid', remote.rsid),
            ])
        self.assertDictEqual(remoteKeepData, validRemoteKeepData)

        remoteSafeData = odict()
        for remote in stack.remotes.values():
            remoteSafeData[remote.uid] = odict([
                ('eid', remote.eid),
                ('name', remote.name),
                ('acceptance', remote.acceptance),
                ('verhex', remote.verfer.keyhex),
                ('pubhex', remote.pubber.keyhex),
            ])
        self.assertDictEqual(remoteSafeData, validRemoteSafeData)

        stack.server.close()

        # bootstrap new stack from stored keep and safe data
        stack = stacking.RoadStack(name=data['name'],
                                   auto=auto,
                                   dirpath=data['dirpath'],
                                   store=self.store)

        localKeepData = odict([
            ('eid', stack.local.eid),
            ('name', stack.local.name),
            ('main', stack.local.main),
            ('host', stack.local.host),
            ('port', stack.local.port),
            ('sid', stack.local.sid),
        ])
        console.terse("Local keep data = '{0}'\n".format(localKeepData))
        self.assertDictEqual(localKeepData, validLocalKeepData)

        localSafeData = odict([
            ('eid', stack.local.eid),
            ('name', stack.local.name),
            ('sighex', stack.local.signer.keyhex),
            ('prihex', stack.local.priver.keyhex),
        ])
        console.terse("Local safe data = '{0}'\n".format(localSafeData))
        self.assertDictEqual(localSafeData, validLocalSafeData)

        remoteKeepData = odict()
        for remote in stack.remotes.values():
            remoteKeepData[remote.uid] = odict([
                ('eid', remote.eid),
                ('name', remote.name),
                ('host', remote.host),
                ('port', remote.port),
                ('sid', remote.sid),
                ('rsid', remote.rsid),
            ])
        self.assertDictEqual(remoteKeepData, validRemoteKeepData)

        remoteSafeData = odict()
        for remote in stack.remotes.values():
            remoteSafeData[remote.uid] = odict([
                ('eid', remote.eid),
                ('name', remote.name),
                ('acceptance', remote.acceptance),
                ('verhex', remote.verfer.keyhex),
                ('pubhex', remote.pubber.keyhex),
            ])
        self.assertDictEqual(remoteSafeData, validRemoteSafeData)

        stack.server.close()
        stack.clearLocal()
        stack.clearRemoteKeeps()
예제 #14
0
    def testBasic(self):
        '''
        Basic keep setup for stack keep and safe persistence load and dump
        '''
        console.terse("{0}\n".format(self.testBasic.__doc__))

        opts = self.createOpts(name='main',
                               dirpath=self.tempDirpath,
                               openMode=True,
                               autoAccept=True)
        mainData = self.createRoadData(name='main', cachedirpath=opts['cachedir'] )
        mainKeep = salting.SaltKeep(opts=opts,
                                    basedirpath=mainData['basedirpath'],
                                    stackname=mainData['name'])

        self.assertEqual(mainKeep.loadLocalData(), None)
        self.assertEqual(mainKeep.loadAllRemoteData(), {})

        main = self.createRoadStack(data=mainData,
                                     eid=1,
                                     main=True,
                                     ha=None, #default ha is ("", raeting.RAET_PORT)
                                     keep=mainKeep)

        console.terse("{0}\nkeep dirpath = {1}\n".format(
                main.name, main.keep.dirpath))
        self.assertTrue(main.keep.dirpath.endswith('main/raet/main'))
        self.assertTrue(main.local.ha, ("0.0.0.0", raeting.RAET_PORT))
        self.assertTrue(main.keep.auto)
        self.assertDictEqual(main.keep.loadLocalData(), {'uid': 1,
                                                         'name': 'main',
                                                         'ha': ['0.0.0.0', 7530],
                                                         'main': True,
                                                         'sid': 0,
                                                         'neid': 1,
                                                         'sighex': mainData['sighex'],
                                                         'prihex': mainData['prihex'],
                                                         'auto': True,
                                                         })

        data1 = self.createRoadData(name='remote1', cachedirpath=opts['cachedir'])
        main.addRemote(estating.RemoteEstate(stack=main,
                                             eid=3,
                                             name=data1['name'],
                                             ha=('127.0.0.1', 7532),
                                             verkey=data1['verhex'],
                                             pubkey=data1['pubhex'],
                                             period=main.period,
                                             offset=main.offset, ))

        data2 = self.createRoadData(name='remote2', cachedirpath=opts['cachedir'])
        main.addRemote(estating.RemoteEstate(stack=main,
                                             eid=4,
                                             name=data2['name'],
                                             ha=('127.0.0.1', 7533),
                                             verkey=data2['verhex'],
                                             pubkey=data2['pubhex'],
                                             period=main.period,
                                             offset=main.offset,))

        main.dumpRemotes()

        self.assertDictEqual(main.keep.loadAllRemoteData(),
            {
                'remote1':
                    {'uid': 3,
                     'name': data1['name'],
                     'ha': ['127.0.0.1', 7532],
                     'sid': 0,
                     'joined': None,
                     'acceptance': 1,
                     'verhex': data1['verhex'],
                     'pubhex': data1['pubhex']},
                'remote2':
                    {'uid': 4,
                     'name': data2['name'],
                     'ha': ['127.0.0.1', 7533],
                     'sid': 0,
                     'joined': None,
                     'acceptance': 1,
                     'verhex': data2['verhex'],
                     'pubhex': data2['pubhex']}})

        # now recreate with saved data
        main.server.close()
        mainKeep = salting.SaltKeep(opts=opts,
                                     basedirpath=mainData['basedirpath'],
                                     stackname=mainData['name'])
        main = stacking.RoadStack(name=mainData['name'],
                                  store=self.store,
                                  keep=mainKeep)

        self.assertEqual(main.local.priver.keyhex, mainData['prihex'])
        self.assertEqual(main.local.signer.keyhex, mainData['sighex'])

        self.assertEqual(len(main.remotes.values()), 2)

        # other stack
        opts = self.createOpts(name='other',
                               dirpath=self.tempDirpath,
                               openMode=True,
                               autoAccept=True)
        otherData = self.createRoadData(name='other', cachedirpath=opts['cachedir'] )
        otherKeep = salting.SaltKeep(opts=opts,
                                      basedirpath=otherData['basedirpath'],
                                      stackname=otherData['name'])

        self.assertEqual(otherKeep.loadLocalData(), None)
        self.assertEqual(otherKeep.loadAllRemoteData(), {})

        other = self.createRoadStack(data=otherData,
                                     eid=0,
                                     main=None,
                                     ha=("", raeting.RAET_TEST_PORT),
                                     keep=otherKeep)

        console.terse("{0} keep dirpath = {1}\n".format(
                other.name, other.keep.dirpath))
        self.assertTrue(other.keep.dirpath.endswith('other/raet/other'))
        self.assertEqual(other.local.ha, ("0.0.0.0", raeting.RAET_TEST_PORT))

        self.assertDictEqual(other.keep.loadLocalData(),
                            {
                                'uid': 0,
                                'name': 'other',
                                'ha': ['0.0.0.0', 7531],
                                'main': None,
                                'sid': 0,
                                'neid': 1,
                                'sighex': otherData['sighex'],
                                'prihex': otherData['prihex'],
                                'auto': True,
                            })

        data3 = self.createRoadData(name='remote3', cachedirpath=opts['cachedir'])
        other.addRemote(estating.RemoteEstate(stack=other,
                                              eid=3,
                                              name=data3['name'],
                                              ha=('127.0.0.1', 7534),
                                              verkey=data3['verhex'],
                                              pubkey=data3['pubhex'],
                                              period=main.period,
                                              offset=main.offset,))

        data4 = self.createRoadData(name='remote4', cachedirpath=opts['cachedir'])
        other.addRemote(estating.RemoteEstate(stack=other,
                                              eid=4,
                                              name=data4['name'],
                                              ha=('127.0.0.1', 7535),
                                              verkey=data4['verhex'],
                                              pubkey=data4['pubhex'],
                                             period=main.period,
                                             offset=main.offset,))

        other.dumpRemotes()
        self.assertDictEqual(other.keep.loadAllRemoteData(),
            {
                'remote3':
                {
                    'uid': 3,
                    'name': data3['name'],
                    'ha': ['127.0.0.1', 7534],
                    'sid': 0,
                    'joined': None,
                    'acceptance': 1,
                    'verhex': data3['verhex'],
                    'pubhex': data3['pubhex']
                },
                'remote4':
                {
                    'uid': 4,
                    'name': data4['name'],
                    'ha': ['127.0.0.1', 7535],
                    'sid': 0,
                    'joined': None,
                    'acceptance': 1,
                    'verhex': data4['verhex'],
                    'pubhex': data4['pubhex']
                }
            })

        main.server.close()
        other.server.close()
예제 #15
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()
예제 #16
0
    def testBasic(self):
        '''
        Basic keep setup for stack keep and safe persistence load and dump
        '''
        console.terse("{0}\n".format(self.testBasic.__doc__))

        self.assertEqual(self.mainSafe.loadLocalData(), None)
        self.assertEqual(self.mainSafe.loadAllRemoteData(), {})

        dataMain = self.createRoadData(name='main', base=self.baseDirpath)
        main = self.createRoadStack(data=dataMain,
                                     eid=1,
                                     main=True,
                                     ha=None, #default ha is ("", raeting.RAET_PORT)
                                     safe=self.mainSafe)

        console.terse("{0}\nkeep dirpath = {1}\nsafe dirpath = {2}\n".format(
                main.name, main.keep.dirpath, main.safe.dirpath))
        self.assertTrue(main.keep.dirpath.endswith('road/keep/main'))
        self.assertTrue(main.safe.dirpath.endswith('pki'))
        self.assertTrue(main.local.ha, ("0.0.0.0", raeting.RAET_PORT))
        self.assertTrue(main.safe.auto)
        self.assertDictEqual(main.keep.loadLocalData(), {'uid': 1,
                                                         'name': 'main',
                                                         'ha': ['0.0.0.0', 7530],
                                                         'main': True,
                                                         'sid': 0})
        self.assertDictEqual(main.safe.loadLocalData(), {'prihex': dataMain['prihex'],
                                                     'sighex': dataMain['sighex'],
                                                     'auto': True})


        data1 = self.createRoadData(name='remote1', base=self.baseDirpath)
        main.addRemote(estating.RemoteEstate(stack=main,
                                             eid=3,
                                             name=data1['name'],
                                             ha=('127.0.0.1', 7532),
                                             verkey=data1['verhex'],
                                             pubkey=data1['pubhex'],
                                             period=main.period,
                                             offset=main.offset, ))

        data2 = self.createRoadData(name='remote2', base=self.baseDirpath)
        main.addRemote(estating.RemoteEstate(stack=main,
                                             eid=4,
                                             name=data2['name'],
                                             ha=('127.0.0.1', 7533),
                                             verkey=data2['verhex'],
                                             pubkey=data2['pubhex'],
                                             period=main.period,
                                             offset=main.offset,))

        main.dumpRemotes()

        self.assertDictEqual(main.safe.loadAllRemoteData(),
            {'3':
                {'uid': 3,
                 'name': data1['name'],
                 'acceptance': 1,
                 'verhex': data1['verhex'],
                 'pubhex': data1['pubhex']},
            '4':
                {'uid': 4,
                 'name': data2['name'],
                 'acceptance': 1,
                 'verhex': data2['verhex'],
                 'pubhex': data2['pubhex']}})

        self.assertDictEqual(main.keep.loadAllRemoteData(),
            {'3':
                {'uid': 3,
                 'name': 'remote1',
                 'ha': ['127.0.0.1', 7532],
                 'sid': 0,
                 'rsid': 0},
            '4':
                {'uid': 4,
                 'name': 'remote2',
                 'ha': ['127.0.0.1', 7533],
                 'sid': 0,
                 'rsid': 0}})

        # now recreate with saved data
        main.server.close()
        main = stacking.RoadStack(name='main',
                                  dirpath=dataMain['dirpath'],
                                  store=self.store,
                                  safe=self.mainSafe)

        self.assertEqual(main.local.priver.keyhex, dataMain['prihex'])
        self.assertEqual(main.local.signer.keyhex, dataMain['sighex'])

        self.assertEqual(len(main.remotes.values()), 2)

        self.assertEqual(self.otherSafe.loadLocalData(), None)
        self.assertEqual(self.otherSafe.loadAllRemoteData(), {})

        # other stack

        dataOther = self.createRoadData(name='other', base=self.baseDirpath)
        other = self.createRoadStack(data=dataOther,
                                     eid=0,
                                     main=None,
                                     ha=("", raeting.RAET_TEST_PORT),
                                     safe=self.otherSafe)

        console.terse("{0} keep dirpath = {1} safe dirpath = {2}\n".format(
                other.name, other.keep.dirpath, other.safe.dirpath))
        self.assertTrue(other.keep.dirpath.endswith('road/keep/other'))
        self.assertTrue(other.safe.dirpath.endswith('pki'))
        self.assertEqual(other.local.ha, ("0.0.0.0", raeting.RAET_TEST_PORT))

        self.assertDictEqual(other.safe.loadLocalData(), {'prihex': dataOther['prihex'],
                                                        'sighex': dataOther['sighex'],
                                                        'auto': True,})

        data3 = self.createRoadData(name='remote3', base=self.baseDirpath)
        other.addRemote(estating.RemoteEstate(stack=other,
                                              eid=3,
                                              name=data3['name'],
                                              ha=('127.0.0.1', 7534),
                                              verkey=data3['verhex'],
                                              pubkey=data3['pubhex'],
                                              period=main.period,
                                              offset=main.offset,))

        data4 = self.createRoadData(name='remote4', base=self.baseDirpath)
        other.addRemote(estating.RemoteEstate(stack=other,
                                              eid=4,
                                              name=data4['name'],
                                              ha=('127.0.0.1', 7535),
                                              verkey=data4['verhex'],
                                              pubkey=data4['pubhex'],
                                             period=main.period,
                                             offset=main.offset,))

        other.dumpRemotes()
        self.assertDictEqual(other.safe.loadAllRemoteData(),
            {'3':
                {'uid': 3,
                 'name': data3['name'],
                 'acceptance': 1,
                 'verhex': data3['verhex'],
                 'pubhex': data3['pubhex']},
            '4':
                {'uid': 4,
                 'name': data4['name'],
                 'acceptance': 1,
                 'verhex': data4['verhex'],
                 'pubhex': data4['pubhex']}})
        other.server.close()

        self.assertDictEqual(other.keep.loadAllRemoteData(),
            {'3':
                {'uid': 3,
                 'name': 'remote3',
                 'ha': ['127.0.0.1', 7534],
                 'sid': 0,
                 'rsid': 0},
            '4':
                {'uid': 4,
                 'name': 'remote4',
                 'ha': ['127.0.0.1', 7535],
                 'sid': 0,
                 'rsid': 0}})

        main.server.close()
        other.server.close()
예제 #17
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)