Пример #1
0
    def action(self):
        '''
        enter action
        should only run once to setup road stack.
        moved from postinitio so can do clean up before stack is initialized

        do salt raet road stack setup at enter
        '''
        kind = self.opts.value['__role']  # application kind
        if kind not in daemons.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}'.".format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)
        role = self.opts.value.get('id', '')
        if not role:
            emsg = ("Missing role required to setup RoadStack.")
            log.error(emsg + "\n")
            raise ValueError(emsg)

        name = "{0}_{1}".format(role, kind)
        sigkey = self.local.data.sigkey
        prikey = self.local.data.prikey
        main = self.opts.value.get('raet_main', self.local.data.main)
        mutable = self.opts.value.get('raet_mutable', self.local.data.mutable)
        always = self.opts.value.get('open_mode', False)
        mutable = mutable or always  # open_made when True takes precedence
        uid = self.local.data.uid

        ha = (self.opts.value['interface'], self.opts.value['raet_port'])

        basedirpath = os.path.abspath(
            os.path.join(self.opts.value['cachedir'], 'raet'))

        txMsgs = self.txmsgs.value
        rxMsgs = self.rxmsgs.value

        keep = salting.SaltKeep(opts=self.opts.value,
                                basedirpath=basedirpath,
                                stackname=name)

        self.stack.value = RoadStack(store=self.store,
                                     keep=keep,
                                     name=name,
                                     uid=uid,
                                     ha=ha,
                                     role=role,
                                     sigkey=sigkey,
                                     prikey=prikey,
                                     main=main,
                                     kind=daemons.APPL_KINDS[kind],
                                     mutable=mutable,
                                     txMsgs=txMsgs,
                                     rxMsgs=rxMsgs,
                                     period=3.0,
                                     offset=0.5)

        if self.opts.value.get('raet_clear_remotes'):
            for remote in self.stack.value.remotes.values():
                self.stack.value.removeRemote(remote, clear=True)
            self.stack.puid = self.stack.value.Uid  # reset puid
Пример #2
0
    def action(self):
        '''
        enter action
        should only run once to setup road stack.
        moved from postinitio so can do clean up before stack is initialized

        do salt raet road stack setup at enter
        '''
        role = self.opts.value.get('id', self.local.data.role)
        kind = self.opts.value['__role']  # application kind
        sigkey = self.local.data.sigkey
        prikey = self.local.data.prikey
        #name = self.opts.value.get('id', self.local.data.name)
        #name = LocalEstate.nameGuid(prefix='road') # name is  guid
        #name = 'stack_' +  role
        name = role
        main = self.opts.value.get('raet_main', self.local.data.main)
        mutable = self.opts.value.get('raet_mutable', self.local.data.mutable)
        always = self.opts.value.get('open_mode', False)
        mutable = mutable or always  # open_made when True takes precedence
        uid = self.local.data.uid

        ha = (self.opts.value['interface'], self.opts.value['raet_port'])

        basedirpath = os.path.abspath(
            os.path.join(self.opts.value['cachedir'], 'raet'))

        txMsgs = self.txmsgs.value
        rxMsgs = self.rxmsgs.value

        keep = salting.SaltKeep(opts=self.opts.value,
                                basedirpath=basedirpath,
                                stackname=name)

        self.stack.value = RoadStack(store=self.store,
                                     keep=keep,
                                     name=name,
                                     uid=uid,
                                     ha=ha,
                                     role=role,
                                     sigkey=sigkey,
                                     prikey=prikey,
                                     main=main,
                                     mutable=mutable,
                                     txMsgs=txMsgs,
                                     rxMsgs=rxMsgs,
                                     period=3.0,
                                     offset=0.5)
Пример #3
0
    def action(self):
        '''
        enter action
        should only run once to setup road stack.
        moved from postinitio so can do clean up before stack is initialized

        do salt raet road stack setup at enter
        '''
        name = self.opts.value.get('id', self.local.data.name)
        sigkey = self.local.data.sigkey
        prikey = self.local.data.prikey
        auto = self.local.data.auto
        main = self.local.data.main
        eid = self.local.data.eid

        ha = (self.opts.value['interface'], self.opts.value['raet_port'])

        basedirpath = os.path.abspath(
            os.path.join(self.opts.value['cachedir'], 'raet'))

        local = LocalEstate(eid=eid,
                            name=name,
                            main=main,
                            ha=ha,
                            sigkey=sigkey,
                            prikey=prikey)
        txMsgs = self.txmsgs.value
        rxMsgs = self.rxmsgs.value

        keep = salting.SaltKeep(opts=self.opts.value,
                                basedirpath=basedirpath,
                                stackname=name,
                                auto=auto)

        self.stack.value = RoadStack(local=local,
                                     store=self.store,
                                     name=name,
                                     main=main,
                                     keep=keep,
                                     txMsgs=txMsgs,
                                     rxMsgs=rxMsgs,
                                     period=3.0,
                                     offset=0.5)
Пример #4
0
    def action(self):
        '''
        Register presence requests
        Iterate over the registered presence yards and fire!
        '''
        pkiDirpath = os.path.join('/tmp', 'raet', 'test', self.role, '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', self.role)
        if not os.path.exists(cacheDirpath):
            os.makedirs(cacheDirpath)

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

        self.opts.value = dict(
            id=self.role,
            __role=self.role,
            ioflo_period=0.1,
            ioflo_realtime=True,
            ioflo_verbose=2,
            interface="",
            raet_port=self.raet_port,
            transport='raet',
            client_acl=dict(),
            pki_dir=pkiDirpath,
            sock_dir=sockDirpath,
            cachedir=cacheDirpath,
            open_mode=True,
            auto_accept=True,
        )

        name = "{0}_{1}".format(self.role, self.role)
        basedirpath = os.path.abspath(os.path.join(cacheDirpath, 'raet'))
        keep = salting.SaltKeep(opts=self.opts.value,
                                basedirpath=basedirpath,
                                stackname=name)
        keep.clearLocalData()
        keep.clearLocalRoleData()
        keep.clearAllRemoteData()
        keep.clearAllRemoteRoleData()
Пример #5
0
    def testBootstrapClean(self):
        '''
        Bootstap to allowed
        '''
        console.terse("{0}\n".format(self.testBootstrapClean.__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,
                                                         })

        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,
                            })

        self.join(other, main)
        self.assertEqual(len(main.transactions), 0)
        remote = main.remotes.values()[0]
        self.assertTrue(remote.joined)
        self.assertEqual(len(other.transactions), 0)
        remote = other.remotes.values()[0]
        self.assertTrue(remote.joined)

        self.allow(other, main)
        self.assertEqual(len(main.transactions), 0)
        remote = main.remotes.values()[0]
        self.assertTrue(remote.allowed)
        self.assertEqual(len(other.transactions), 0)
        remote = other.remotes.values()[0]
        self.assertTrue(remote.allowed)

        for remote in main.remotes.values():
            path = os.path.join(main.keep.remotedirpath,
                    "{0}.{1}.{2}".format(main.keep.prefix, remote.name, main.keep.ext))
            self.assertTrue(os.path.exists(path))


        # now delete a key and see if road keep file is also deleted
        main.keep.saltRaetKey.delete_key(match=other.local.name)
        remote = main.remotes[other.local.uid]
        path = os.path.join(main.keep.remotedirpath,
                "{0}.{1}.{2}".format(main.keep.prefix, remote.name, main.keep.ext))
        self.assertFalse(os.path.exists(path))

        main.server.close()
        other.server.close()
Пример #6
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()