Beispiel #1
0
    def testUuid(self):
        '''
        Test uuid generation
        '''
        console.terse("{0}\n".format(self.testUuid.__doc__))
        uuid = nacling.uuid(16)
        self.assertEqual(len(uuid), 16)
        uuid = nacling.uuid(12)
        self.assertEqual(len(uuid), 16)
        uuid = nacling.uuid(20)
        self.assertEqual(len(uuid), 20)

        uuids = [nacling.uuid(16) for i in range(1024)]
        self.assertEqual(len(uuids), 1024)
        self.assertEqual(len(set(uuids)), len(uuids))
Beispiel #2
0
    def testUuid(self):
        '''
        Test uuid generation
        '''
        console.terse("{0}\n".format(self.testUuid.__doc__))
        uuid = nacling.uuid(16)
        self.assertEqual(len(uuid), 16)
        uuid = nacling.uuid(12)
        self.assertEqual(len(uuid), 16)
        uuid = nacling.uuid(20)
        self.assertEqual(len(uuid), 20)

        uuids = [nacling.uuid(16) for i in range(1024)]
        self.assertEqual(len(uuids), 1024)
        self.assertEqual(len(set(uuids)), len(uuids))
Beispiel #3
0
 def send(self, load, tries=3, timeout=60, raw=False):
     '''
     Send a message load and wait for a relative reply
     One shot wonder
     '''
     self.__prep_stack()
     tried = 1
     start = time.time()
     track = nacling.uuid(18)
     src = (None, self.stack.local.name, track)
     self.route = {'src': src, 'dst': self.dst}
     msg = {'route': self.route, 'load': load}
     self.stack.transmit(msg, self.stack.nameRemotes[self.ryn].uid)
     while track not in jobber_rxMsgs:
         self.stack.serviceAll()
         while self.stack.rxMsgs:
             msg, sender = self.stack.rxMsgs.popleft()
             jobber_rxMsgs[msg['route']['dst'][2]] = msg
             continue
         if track in jobber_rxMsgs:
             break
         if time.time() - start > timeout:
             if tried >= tries:
                 raise ValueError("Message send timed out after '{0} * {1}'"
                          " secs. route = {2} track = {3} load={4}".format(tries,
                                                                    timeout,
                                                                    self.route,
                                                                    track,
                                                                    load))
             self.stack.transmit(msg, self.stack.nameRemotes['manor'].uid)
             tried += 1
         time.sleep(0.01)
     return jobber_rxMsgs.pop(track).get('return', {})
Beispiel #4
0
 def send(self, load, tries=3, timeout=60):
     '''
     Send a message load and wait for a relative reply
     One shot wonder
     '''
     self.__prep_stack()
     tried = 1
     start = time.time()
     mid = self.opts.get('id', None)
     track = nacling.uuid(18)
     src = (mid, self.stack.local.name, track)
     self.route = {'src': src, 'dst': self.dst}
     msg = {'route': self.route, 'load': load}
     self.stack.transmit(msg, self.stack.nameRemotes['manor'].uid)
     while track not in jobber_rxMsgs:
         self.stack.serviceAll()
         while self.stack.rxMsgs:
             msg, sender = self.stack.rxMsgs.popleft()
             jobber_rxMsgs[msg['route']['dst'][2]] = msg
             continue
         if track in jobber_rxMsgs:
             break
         if time.time() - start > timeout:
             if tried >= tries:
                 raise ValueError
             self.stack.transmit(msg, self.stack.nameRemotes['manor'].uid)
             tried += 1
         time.sleep(0.01)
     return jobber_rxMsgs.pop(track).get('return', {})
Beispiel #5
0
 def send(self, load, tries=3, timeout=60):
     '''
     Send a message load and wait for a relative reply
     One shot wonder
     '''
     self.__prep_stack()
     tried = 1
     start = time.time()
     mid = self.opts.get('id', 'master')
     track = nacling.uuid(18)
     src = (mid, self.stack.local.name, track)
     self.route = {'src': src, 'dst': self.dst}
     msg = {'route': self.route, 'load': load}
     self.stack.transmit(msg, self.stack.nameRemotes['manor'].uid)
     while track not in jobber_rxMsgs:
         self.stack.serviceAll()
         while self.stack.rxMsgs:
             msg, sender = self.stack.rxMsgs.popleft()
             jobber_rxMsgs[msg['route']['dst'][2]] = msg
             continue
         if track in jobber_rxMsgs:
             break
         if time.time() - start > timeout:
             if tried >= tries:
                 raise ValueError
             self.stack.transmit(msg, self.stack.nameRemotes['manor'].uid)
             tried += 1
         time.sleep(0.01)
     return jobber_rxMsgs.pop(track).get('return', {})
Beispiel #6
0
    def action(self):

        self.stats_req.value = deque()

        # Create event stack
        name = 'event' + nacling.uuid(size=18)
        lanename = self.lane_stack.value.local.lanename
        sock_dir = self.lane_stack.value.local.dirpath
        ryn = 'manor'
        console.terse("Create stack: name = {0}, lanename = {1}, sock_dir = {2}\n".
                      format(name, lanename, sock_dir))
        stack = LaneStack(
            name=name,
            lanename=lanename,
            sockdirpath=sock_dir)
        stack.addRemote(RemoteYard(stack=stack,
                                   lanename=lanename,
                                   name=ryn,
                                   dirpath=sock_dir))
        self.event_stack.value = stack

        route = {'dst': (None, ryn, 'stats_req'),
                 'src': (None, stack.local.name, None)}
        msg = {'route': route}
        stack.transmit(msg, stack.nameRemotes[ryn].uid)
        serviceLanes([stack, self.lane_stack.value])
Beispiel #7
0
    def testPackParseMsgpack(self):
        '''
        Test basic page pack and parse
        '''
        console.terse("{0}\n".format(self.testPackParseMsgpack.__doc__))
        data = odict(pk=raeting.PackKind.pack.value)
        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn='girl', si=sid, bi=1))
        src = ['mayor', 'main', None]
        dst = ['citizen', 'other', None]
        route = odict([('src', src), ('dst', dst)])

        body = odict([('route', route), ('content', "Hello all yards.")])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        page0.pack()
        self.assertEqual(len(page0.packed), 147)
        self.assertEqual(
            page0.packed,
            ns2b(
                'ri RAET\nvn 0\npk 1\nsn boy\ndn girl\nsi {0:.18s}\nbi 1\npn 0000\npc 0001\n\n\x82\xa5route\x82\xa3src\x93\xa5mayor\xa4main\xc0\xa3dst\x93\xa7citizen\xa5other\xc0\xa7content\xb0Hello all yards.'
                .format(sid)))
        page1 = paging.RxPage(packed=page0.packed)
        page1.parse()
        self.assertDictEqual(page1.body.data, body)
Beispiel #8
0
    def _setup_stack(self, ryn="manor"):
        """
        Setup and return the LaneStack and Yard used by by channel when global
        not already setup such as in salt-call to communicate to-from the minion

        """
        role = self.opts.get("id")
        if not role:
            emsg = "Missing role('id') required to setup RAETReqChannel."
            log.error(emsg + "\n")
            raise ValueError(emsg)

        kind = self.opts.get("__role")  # application kind 'master', 'minion', etc
        if kind not in kinds.APPL_KINDS:
            emsg = "Invalid application kind = '{0}' for RAETReqChannel.".format(kind)
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind in [kinds.APPL_KIND_NAMES[kinds.applKinds.master], kinds.APPL_KIND_NAMES[kinds.applKinds.syndic]]:
            lanename = "master"
        elif kind in [kinds.APPL_KIND_NAMES[kinds.applKinds.minion], kinds.APPL_KIND_NAMES[kinds.applKinds.caller]]:
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = "Unsupported application kind '{0}' for RAETReqChannel.".format(kind)
            log.error(emsg + "\n")
            raise ValueError(emsg)

        name = "channel" + nacling.uuid(size=18)
        stack = LaneStack(name=name, lanename=lanename, sockdirpath=self.opts["sock_dir"])

        stack.Pk = raeting.PackKind.pack
        stack.addRemote(RemoteYard(stack=stack, name=ryn, lanename=lanename, dirpath=self.opts["sock_dir"]))
        log.debug("Created Channel Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #9
0
    def testPackParseMsgpack(self):
        """
        Test basic page pack and parse
        """
        console.terse("{0}\n".format(self.testPackParseMsgpack.__doc__))
        data = odict(pk=raeting.PackKind.pack.value)
        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn="girl", si=sid, bi=1))
        src = ["mayor", "main", None]
        dst = ["citizen", "other", None]
        route = odict([("src", src), ("dst", dst)])

        body = odict([("route", route), ("content", "Hello all yards.")])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        page0.pack()
        self.assertEqual(len(page0.packed), 147)
        self.assertEqual(
            page0.packed,
            ns2b(
                "ri RAET\nvn 0\npk 1\nsn boy\ndn girl\nsi {0:.18s}\nbi 1\npn 0000\npc 0001\n\n\x82\xa5route\x82\xa3src\x93\xa5mayor\xa4main\xc0\xa3dst\x93\xa7citizen\xa5other\xc0\xa7content\xb0Hello all yards.".format(
                    sid
                )
            ),
        )
        page1 = paging.RxPage(packed=page0.packed)
        page1.parse()
        self.assertDictEqual(page1.body.data, body)
Beispiel #10
0
    def action(self):

        self.presence_req.value = deque()
        self.availables.value = set()
        self.alloweds.value = odict()
        self.aliveds.value = odict()
        self.reapeds.value = odict()

        # Create event stack
        name = 'event' + nacling.uuid(size=18)
        lanename = self.lane_stack.value.local.lanename
        sock_dir = self.lane_stack.value.local.dirpath
        ryn = 'manor'
        console.terse(
            "Create stack: name = {0}, lanename = {1}, sock_dir = {2}\n".
            format(name, lanename, sock_dir))
        stack = LaneStack(name=name, lanename=lanename, sockdirpath=sock_dir)
        stack.addRemote(
            RemoteYard(stack=stack,
                       lanename=lanename,
                       name=ryn,
                       dirpath=sock_dir))
        self.event_stack.value = stack

        route = {
            'dst': (None, ryn, 'presence_req'),
            'src': (None, stack.local.name, None)
        }
        msg = {'route': route}
        stack.transmit(msg, stack.nameRemotes[ryn].uid)
        serviceLanes([stack, self.lane_stack.value])
 def pub(self,
         tgt,
         fun,
         arg=(),
         expr_form='glob',
         ret='',
         jid='',
         timeout=5,
         **kwargs):
     '''
     Publish the command!
     '''
     payload_kwargs = self._prep_pub(
             tgt,
             fun,
             arg=arg,
             expr_form=expr_form,
             ret=ret,
             jid=jid,
             timeout=timeout,
             **kwargs)
     kind = self.opts['__role']
     if kind == 'master':
         lanename = 'master'  # self.opts.value.get('id', self.main.data.lanename)
     else:  # workers currently are only supported for masters
         emsg = ("Invalid application kind '{0}' for client.".format(kind))
         log.error(emsg + '\n')
         raise ValueError(emsg)
     name = 'client' + nacling.uuid(size=18)
     stack = LaneStack(
             name=name,
             lanename=lanename,
             sockdirpath=self.opts['sock_dir'])
     stack.Pk = raeting.packKinds.pack
     router_yard = RemoteYard(
             stack=stack,
             lanename=lanename,
             name='manor',
             dirpath=self.opts['sock_dir'])
     stack.addRemote(router_yard)
     route = {'dst': (None, router_yard.name, 'local_cmd'),
              'src': (None, stack.local.name, None)}
     msg = {'route': route, 'load': payload_kwargs}
     stack.transmit(msg)
     stack.serviceAll()
     while True:
         time.sleep(0.01)
         stack.serviceAll()
         while stack.rxMsgs:
             msg, sender = stack.rxMsgs.popleft()
             ret = msg.get('return', {})
             if 'ret' in ret:
                 stack.server.close()
                 return ret['ret']
             stack.server.close()
             return ret
Beispiel #12
0
 def pub(self,
         tgt,
         fun,
         arg=(),
         expr_form='glob',
         ret='',
         jid='',
         timeout=5,
         **kwargs):
     '''
     Publish the command!
     '''
     payload_kwargs = self._prep_pub(tgt,
                                     fun,
                                     arg=arg,
                                     expr_form=expr_form,
                                     ret=ret,
                                     jid=jid,
                                     timeout=timeout,
                                     **kwargs)
     kind = self.opts['__role']
     if kind == 'master':
         lanename = 'master'  # self.opts.value.get('id', self.main.data.lanename)
     else:  # workers currently are only supported for masters
         emsg = ("Invalid application kind '{0}' for client.".format(kind))
         log.error(emsg + '\n')
         raise ValueError(emsg)
     name = 'client' + nacling.uuid(size=18)
     stack = LaneStack(name=name,
                       lanename=lanename,
                       sockdirpath=self.opts['sock_dir'])
     stack.Pk = raeting.packKinds.pack
     router_yard = RemoteYard(stack=stack,
                              lanename=lanename,
                              name='manor',
                              dirpath=self.opts['sock_dir'])
     stack.addRemote(router_yard)
     route = {
         'dst': (None, router_yard.name, 'local_cmd'),
         'src': (None, stack.local.name, None)
     }
     msg = {'route': route, 'load': payload_kwargs}
     stack.transmit(msg)
     stack.serviceAll()
     while True:
         time.sleep(0.01)
         stack.serviceAll()
         while stack.rxMsgs:
             msg, sender = stack.rxMsgs.popleft()
             ret = msg.get('return', {})
             if 'ret' in ret:
                 stack.server.close()
                 return ret['ret']
             stack.server.close()
             return ret
Beispiel #13
0
    def _setup_stack(self, ryn='manor'):
        kind = self.opts.get('__role', '')  # opts optional for master
        if kind:  # not all uses of Raet SaltEvent has opts defined
            if kind not in kinds.APPL_KINDS:
                emsg = ("Invalid application kind = '{0}' for RAET SaltEvent.".
                        format(kind))
                log.error(emsg + "\n")
                raise ValueError(emsg)
            if kind != self.node:
                emsg = ("Mismatch between node = '{0}' and kind = '{1}' in "
                        "RAET SaltEvent.".format(self.node, kind))
                log.error(emsg + '\n')
                raise ValueError(emsg)

        if self.node in [
                kinds.APPL_KIND_NAMES[kinds.applKinds.master],
                kinds.APPL_KIND_NAMES[kinds.applKinds.syndic]
        ]:  # []'master', 'syndic']
            lanename = 'master'
        elif self.node in [
                kinds.APPL_KIND_NAMES[kinds.applKinds.minion],
                kinds.APPL_KIND_NAMES[kinds.applKinds.caller]
        ]:  # ['minion', 'caller']
            role = self.opts.get('id', '')  # opts required for minion
            if not role:
                emsg = ("Missing role required to setup RAET SaltEvent.")
                log.error(emsg + "\n")
                raise ValueError(emsg)
            if not kind:
                emsg = "Missing kind required to setup RAET SaltEvent."
                log.error(emsg + '\n')
                raise ValueError(emsg)
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = (
                "Unsupported application node kind '{0}' for RAET SaltEvent.".
                format(self.node))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        name = 'event' + nacling.uuid(size=18)
        cachedir = self.opts.get('cachedir',
                                 os.path.join(syspaths.CACHE_DIR, self.node))

        stack = LaneStack(name=name,
                          lanename=lanename,
                          sockdirpath=self.sock_dir)
        stack.Pk = raeting.PackKind.pack.value
        stack.addRemote(
            RemoteYard(stack=stack,
                       lanename=lanename,
                       name=ryn,
                       dirpath=self.sock_dir))
        return stack
Beispiel #14
0
 def pub(self,
         tgt,
         fun,
         arg=(),
         expr_form='glob',
         ret='',
         jid='',
         timeout=5,
         **kwargs):
     '''
     Publish the command!
     '''
     payload_kwargs = self._prep_pub(
             tgt,
             fun,
             arg=arg,
             expr_form=expr_form,
             ret=ret,
             jid=jid,
             timeout=timeout,
             **kwargs)
     yid = nacling.uuid(size=18)
     stack = LaneStack(
             name=('client' + yid),
             yid=yid,
             lanename='master',
             sockdirpath=self.opts['sock_dir'])
     stack.Pk = raeting.packKinds.pack
     router_yard = RemoteYard(
             stack=stack,
             lanename='master',
             yid=0,
             name='manor',
             dirpath=self.opts['sock_dir'])
     stack.addRemote(router_yard)
     route = {'dst': (None, router_yard.name, 'local_cmd'),
              'src': (None, stack.local.name, None)}
     msg = {'route': route, 'load': payload_kwargs}
     stack.transmit(msg)
     stack.serviceAll()
     while True:
         time.sleep(0.01)
         stack.serviceAll()
         while stack.rxMsgs:
             msg, sender = stack.rxMsgs.popleft()
             ret = msg.get('return', {})
             if 'ret' in ret:
                 stack.server.close()
                 return ret['ret']
             stack.server.close()
             return ret
Beispiel #15
0
 def pub(self,
         tgt,
         fun,
         arg=(),
         expr_form='glob',
         ret='',
         jid='',
         timeout=5,
         **kwargs):
     '''
     Publish the command!
     '''
     payload_kwargs = self._prep_pub(
             tgt,
             fun,
             arg=arg,
             expr_form=expr_form,
             ret=ret,
             jid=jid,
             timeout=timeout,
             **kwargs)
     uid = nacling.uuid(size=18)
     stack = LaneStack(
             name=('client' + uid),
             uid=uid,
             lanename='master',
             sockdirpath=self.opts['sock_dir'])
     stack.Pk = raeting.packKinds.pack
     router_yard = RemoteYard(
             stack=stack,
             lanename='master',
             uid=0,
             name='manor',
             dirpath=self.opts['sock_dir'])
     stack.addRemote(router_yard)
     route = {'dst': (None, router_yard.name, 'local_cmd'),
              'src': (None, stack.local.name, None)}
     msg = {'route': route, 'load': payload_kwargs}
     stack.transmit(msg)
     stack.serviceAll()
     while True:
         time.sleep(0.01)
         stack.serviceAll()
         while stack.rxMsgs:
             msg, sender = stack.rxMsgs.popleft()
             ret = msg.get('return', {})
             if 'ret' in ret:
                 stack.server.close()
                 return ret['ret']
             stack.server.close()
             return ret
Beispiel #16
0
    def _setup(opts, ryn='manor'):
        '''
        Setup the LaneStack lane_stack and RemoteYard lane_remote_yard global
        '''
        global lane_stack, remote_yard  # pylint: disable=W0602

        role = opts.get('id')
        if not role:
            emsg = ("Missing role required to setup LaneStack.")
            log.error(emsg + "\n")
            raise ValueError(emsg)

        kind = opts.get('__role')  # application kind 'master', 'minion', etc
        if kind not in kinds.APPL_KINDS:
            emsg = (
                "Invalid application kind = '{0}' for LaneStack.".format(kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind in [
                kinds.APPL_KIND_NAMES[kinds.applKinds.master],
                kinds.APPL_KIND_NAMES[kinds.applKinds.syndic]
        ]:
            lanename = 'master'
        elif kind == [
                kinds.APPL_KIND_NAMES[kinds.applKinds.minion],
                kinds.APPL_KIND_NAMES[kinds.applKinds.caller]
        ]:
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = ("Unsupported application kind '{0}' for LaneStack.".format(
                kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        name = 'lanestack' + nacling.uuid(size=18)
        lane_stack = LaneStack(name=name,
                               lanename=lanename,
                               sockdirpath=opts['sock_dir'])

        lane_stack.Pk = raeting.PackKind.pack.value
        log.debug("Created new LaneStack and local Yard named {0} at {1}\n"
                  "".format(lane_stack.name, lane_stack.ha))
        remote_yard = RemoteYard(stack=lane_stack,
                                 name=ryn,
                                 lanename=lanename,
                                 dirpath=opts['sock_dir'])
        lane_stack.addRemote(remote_yard)
        log.debug("Added to LaneStack {0} remote Yard named {1} at {2}\n"
                  "".format(lane_stack.name, remote_yard.name, remote_yard.ha))
Beispiel #17
0
    def __prep_stack(self):
        kind = self.opts.get('__role', '')  # opts optional for master
        if kind:  # not all uses of Raet SaltEvent has opts defined
            if kind not in daemons.APPL_KINDS:
                emsg = ("Invalid application kind = '{0}' for RAET SaltEvent.".
                        format(kind))
                log.error(emsg + "\n")
                raise ValueError(emsg)
            if kind != self.node:
                emsg = ("Mismatch between node = '{0}' and kind = '{1}' in "
                        "RAET SaltEvent.".format(self.node, kind))
                log.error(emsg + '\n')
                raise ValueError(emsg)

        if self.node == 'master':
            lanename = 'master'
        elif self.node in ['minion', 'syndic',
                           'call']:  # see daemons.APPL_KINDS
            role = self.opts.get('id', '')  # opts required for minion
            if not role:
                emsg = ("Missing role required to setup RAET SaltEvent.")
                log.error(emsg + "\n")
                raise ValueError(emsg)
            if not kind:
                emsg = "Missing kind required to setup RAET SaltEvent."
                log.error(emsg + '\n')
                raise ValueError(emsg)
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = (
                "Unsupported application node kind '{0}' for RAET SaltEvent.".
                format(self.node))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        name = 'event' + nacling.uuid(size=18)
        cachedir = self.opts.get('cachedir',
                                 os.path.join(syspaths.CACHE_DIR, self.node))
        self.connected = False
        self.stack = LaneStack(name=name,
                               lanename=lanename,
                               sockdirpath=self.sock_dir)
        self.stack.Pk = raeting.packKinds.pack
        self.router_yard = RemoteYard(stack=self.stack,
                                      lanename=lanename,
                                      name='manor',
                                      dirpath=self.sock_dir)
        self.stack.addRemote(self.router_yard)
        self.connect_pub()
Beispiel #18
0
    def _setup_stack(self, ryn='manor'):
        '''
        Setup and return the LaneStack and Yard used by by channel when global
        not already setup such as in salt-call to communicate to-from the minion

        '''
        role = self.opts.get('id')
        if not role:
            emsg = ("Missing role(\'id\') required to setup RAETReqChannel.")
            log.error(emsg + "\n")
            raise ValueError(emsg)

        kind = self.opts.get(
            '__role')  # application kind 'master', 'minion', etc
        if kind not in kinds.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}' for RAETReqChannel.".
                    format(kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind in [
                kinds.APPL_KIND_NAMES[kinds.applKinds.master],
                kinds.APPL_KIND_NAMES[kinds.applKinds.syndic]
        ]:
            lanename = 'master'
        elif kind == [
                kinds.APPL_KIND_NAMES[kinds.applKinds.minion],
                kinds.APPL_KIND_NAMES[kinds.applKinds.caller]
        ]:
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = ("Unsupported application kind '{0}' for RAETReqChannel.".
                    format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        name = 'channel' + nacling.uuid(size=18)
        stack = LaneStack(name=name,
                          lanename=lanename,
                          sockdirpath=self.opts['sock_dir'])

        stack.Pk = raeting.packKinds.pack
        stack.addRemote(
            RemoteYard(stack=stack,
                       name=ryn,
                       lanename=lanename,
                       dirpath=self.opts['sock_dir']))
        log.debug("Created Channel Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #19
0
    def __prep_stack(self):
        kind = self.opts.get('__role', '')  # opts optional for master
        if kind:  # not all uses of Raet SaltEvent has opts defined
            if kind not in kinds.APPL_KINDS:
                emsg = ("Invalid application kind = '{0}' for RAET SaltEvent.".format(kind))
                log.error(emsg + "\n")
                raise ValueError(emsg)
            if kind != self.node:
                emsg = ("Mismatch between node = '{0}' and kind = '{1}' in "
                        "RAET SaltEvent.".format(self.node, kind))
                log.error(emsg + '\n')
                raise ValueError(emsg)

        if self.node == kinds.APPL_KIND_NAMES[kinds.applKinds.master]:  # 'master'
            lanename = 'master'
        elif self.node in [kinds.APPL_KIND_NAMES[kinds.applKinds.minion],
                           kinds.APPL_KIND_NAMES[kinds.applKinds.syndic],
                           kinds.APPL_KIND_NAMES[kinds.applKinds.caller]]:  # ['minion', 'syndic', 'caller']
            role = self.opts.get('id', '')  # opts required for minion
            if not role:
                emsg = ("Missing role required to setup RAET SaltEvent.")
                log.error(emsg + "\n")
                raise ValueError(emsg)
            if not kind:
                emsg = "Missing kind required to setup RAET SaltEvent."
                log.error(emsg + '\n')
                raise ValueError(emsg)
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = ("Unsupported application node kind '{0}' for RAET SaltEvent.".format(self.node))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        name = 'event' + nacling.uuid(size=18)
        cachedir = self.opts.get('cachedir', os.path.join(syspaths.CACHE_DIR, self.node))
        self.connected = False
        self.stack = LaneStack(
                name=name,
                lanename=lanename,
                sockdirpath=self.sock_dir)
        self.stack.Pk = raeting.packKinds.pack
        self.router_yard = RemoteYard(
                stack=self.stack,
                lanename=lanename,
                name='manor',
                dirpath=self.sock_dir)
        self.stack.addRemote(self.router_yard)
        self.connect_pub()
Beispiel #20
0
    def _setup_caller_stack(self, opts):
        '''
        Setup and return the LaneStack and Yard used by by channel when global
        not already setup such as in salt-call to communicate to-from the minion

        '''
        role = opts.get('id')
        if not role:
            emsg = ("Missing role required to setup RAETChannel.")
            log.error(emsg + "\n")
            raise ValueError(emsg)

        kind = opts.get('__role')  # application kind 'master', 'minion', etc
        if kind not in daemons.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}' for RAETChannel.".format(
                kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind == 'minion':
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = ("Unsupported application kind '{0}' for RAETChannel.".
                    format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        sockdirpath = opts['sock_dir']
        stackname = 'caller' + nacling.uuid(size=18)
        stack = LaneStack(name=stackname,
                          lanename=lanename,
                          sockdirpath=sockdirpath)

        stack.Pk = raeting.packKinds.pack
        stack.addRemote(
            RemoteYard(stack=stack,
                       name='manor',
                       lanename=lanename,
                       dirpath=sockdirpath))
        log.debug("Created Caller Jobber Stack {0}\n".format(stack.name))

        # name of Road Estate for this caller
        estatename = "{0}_{1}".format(role, kind)
        # name of Yard for this caller
        yardname = stack.local.name

        # return identifiers needed to route back to this callers master
        return (stack, estatename, yardname)
    def __prep_stack(self):
        if self.node == 'master':
            lanename = 'master'
            if self.opts:
                kind = self.opts.get('__role', '')  # opts optional for master
                if kind and kind != self.node:
                    emsg = ("Mismatch between node '{0}' and kind '{1}' in setup "
                            "of SaltEvent on Raet.".format(self.node, kind))
                    log.error(emsg + '\n')
                    raise ValueError(emsg)
        elif self.node == 'minion':
            role = self.opts.get('id', '')  # opts required for minion
            if not role:
                emsg = ("Missing opts['id'] required by SaltEvent on Raet with "
                       "node kind {0}.".format(self.node))
                log.error(emsg + '\n')
                raise ValueError(emsg)
            kind = self.opts.get('__role', '')
            if kind != self.node:
                emsg = ("Mismatch between node '{0}' and kind '{1}' in setup "
                       "of SaltEvent on Raet.".format(self.node, kind))
                log.error(emsg + '\n')
                raise ValueError(emsg)
            lanename = role  # add '_minion'
        else:
            emsg = ("Unsupported application node kind '{0}' for SaltEvent "
                    "Raet.".format(self.node))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        name = 'event' + nacling.uuid(size=18)
        cachedir = self.opts.get('cachedir', os.path.join(syspaths.CACHE_DIR, self.node))
        self.connected = False
        self.stack = LaneStack(
                name=name,
                lanename=lanename,
                sockdirpath=self.sock_dir)
        self.stack.Pk = raeting.packKinds.pack
        self.router_yard = RemoteYard(
                stack=self.stack,
                lanename=lanename,
                name='manor',
                dirpath=self.sock_dir)
        self.stack.addRemote(self.router_yard)
        self.connect_pub()
Beispiel #22
0
 def __prep_stack(self):
     self.yid = nacling.uuid(size=18)
     name = 'event' + self.yid
     cachedir = self.opts.get('cachedir',
                              os.path.join(syspaths.CACHE_DIR, self.node))
     self.connected = False
     self.stack = LaneStack(name=name,
                            uid=self.yid,
                            lanename=self.node,
                            sockdirpath=self.sock_dir)
     self.stack.Pk = raeting.packKinds.pack
     self.router_yard = RemoteYard(stack=self.stack,
                                   lanename=self.node,
                                   uid=0,
                                   name='manor',
                                   dirpath=self.sock_dir)
     self.stack.addRemote(self.router_yard)
     self.connect_pub()
Beispiel #23
0
def _setup(opts, ryn='manor'):
    '''
    Setup the LaneStack lane_stack and RemoteYard lane_remote_yard global
    '''
    global lane_stack, remote_yard  # pylint: disable=W0602

    role = opts.get('id')
    if not role:
        emsg = ("Missing role required to setup LaneStack.")
        log.error(emsg + "\n")
        raise ValueError(emsg)

    kind = opts.get('__role')  # application kind 'master', 'minion', etc
    if kind not in kinds.APPL_KINDS:
        emsg = ("Invalid application kind = '{0}' for LaneStack.".format(kind))
        log.error(emsg + "\n")
        raise ValueError(emsg)
    if kind in [kinds.APPL_KIND_NAMES[kinds.applKinds.master],
                kinds.APPL_KIND_NAMES[kinds.applKinds.syndic]]:
        lanename = 'master'
    elif kind == [kinds.APPL_KIND_NAMES[kinds.applKinds.minion],
                  kinds.APPL_KIND_NAMES[kinds.applKinds.caller]]:
        lanename = "{0}_{1}".format(role, kind)
    else:
        emsg = ("Unsupported application kind '{0}' for LaneStack.".format(kind))
        log.error(emsg + '\n')
        raise ValueError(emsg)

    name = 'lanestack' + nacling.uuid(size=18)
    lane_stack = LaneStack(name=name,
                      lanename=lanename,
                      sockdirpath=opts['sock_dir'])

    lane_stack.Pk = raeting.PackKind.pack.value
    log.debug("Created new LaneStack and local Yard named {0} at {1}\n"
              "".format(lane_stack.name, lane_stack.ha))
    remote_yard = RemoteYard(stack=lane_stack,
                             name=ryn,
                             lanename=lanename,
                             dirpath=opts['sock_dir'])
    lane_stack.addRemote(remote_yard)
    log.debug("Added to LaneStack {0} remote Yard named {1} at {2}\n"
              "".format(lane_stack.name, remote_yard.name, remote_yard.ha))
Beispiel #24
0
 def __prep_stack(self):
     self.yid = nacling.uuid(size=18)
     name = 'event' + self.yid
     cachedir = self.opts.get('cachedir', os.path.join(syspaths.CACHE_DIR, self.node))
     self.connected = False
     self.stack = LaneStack(
             name=name,
             yid=self.yid,
             lanename=self.node,
             sockdirpath=self.sock_dir)
     self.stack.Pk = raeting.packKinds.pack
     self.router_yard = RemoteYard(
             stack=self.stack,
             lanename=self.node,
             yid=0,
             name='manor',
             dirpath=self.sock_dir)
     self.stack.addRemote(self.router_yard)
     self.connect_pub()
Beispiel #25
0
    def testSectionedMsgpack(self):
        '''
        Test sectioned pack and parse msgpack packing
        '''
        console.terse("{0}\n".format(self.testSectionedMsgpack.__doc__))
        data = odict(pk=raeting.packKinds.pack)
        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn='girl', si=sid, bi=1))
        src = ['mayor', 'main', None]
        dst = ['citizen', 'other', None]
        route = odict([('src', src), ('dst', dst)])

        stuff = []
        for i in range(10000):
            stuff.append(str(i).rjust(10, " "))
        stuff = "".join(stuff)
        self.assertEqual(len(stuff), 100000)
        self.assertTrue(len(stuff) > raeting.UXD_MAX_PACKET_SIZE)

        body = odict([('route', route), ('content', stuff)])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        self.assertRaises(raeting.PageError, page0.pack)

        book0 = paging.TxBook(data=data, body=body)
        book0.pack()
        self.assertEqual(len(book0.packed), 100058)
        self.assertEqual(len(book0.pages), 2)
        self.assertEqual(book0.index, ('boy', 'girl', sid, 1))

        book1 = paging.RxBook()
        for page in book0.pages:
            page = paging.RxPage(packed=page.packed)
            page.head.parse()  #parse head to get data
            book1.parse(page)

        self.assertEqual(book1.index, ('girl', 'boy', sid, 1))
        self.assertDictEqual(book1.body, body)
        self.assertEqual(book1.data['sn'], 'boy')
        self.assertEqual(book1.data['dn'], 'girl')
        self.assertEqual(book1.data['si'], sid)
        self.assertEqual(book1.data['bi'], 1)
Beispiel #26
0
    def _setup_stack(self):
        '''
        Setup and return the LaneStack and Yard used by by channel when global
        not already setup such as in salt-call to communicate to-from the minion

        '''
        kind = self.opts.get('__role',
                             '')  # application kind 'master', 'minion', etc
        if not kind:
            emsg = ("Missing opts['__role']. required to setup RAETChannel.")
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind == 'master':
            lanename = 'master'
        elif kind == 'minion':
            role = self.opts.get('id', '')
            if not role:
                emsg = ("Missing opts['id']. required to setup RAETChannel.")
                log.error(emsg + "\n")
                raise ValueError(emsg)
            lanename = role  # add kind later
        else:
            emsg = ("Unsupported application kind '{0}' for RAETChannel "
                    "Raet.".format(self.node))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        mid = self.opts.get('id', 'master')
        uid = nacling.uuid(size=18)
        name = 'channel' + uid
        stack = LaneStack(name=name,
                          lanename=lanename,
                          sockdirpath=self.opts['sock_dir'])

        stack.Pk = raeting.packKinds.pack
        stack.addRemote(
            RemoteYard(stack=stack,
                       name='manor',
                       lanename=lanename,
                       dirpath=self.opts['sock_dir']))
        log.debug("Created Channel Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #27
0
    def testSectionedMsgpack(self):
        '''
        Test sectioned pack and parse msgpack packing
        '''
        console.terse("{0}\n".format(self.testSectionedMsgpack.__doc__))
        data = odict(pk=raeting.PackKind.pack.value)
        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn='girl', si=sid, bi=1))
        src = ['mayor', 'main', None]
        dst = ['citizen', 'other', None]
        route = odict([('src', src), ('dst', dst)])

        stuff = []
        for i in range(10000):
            stuff.append(str(i).rjust(10, " "))
        stuff = "".join(stuff)
        self.assertEqual(len(stuff), 100000)
        self.assertTrue(len(stuff) > raeting.UXD_MAX_PACKET_SIZE)

        body = odict([('route', route), ('content', stuff)])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        self.assertRaises(raeting.PageError, page0.pack)

        book0 = paging.TxBook(data=data, body=body)
        book0.pack()
        self.assertEqual(len(book0.packed), 100058)
        self.assertEqual(len(book0.pages), 2)
        self.assertEqual(book0.index, ('boy', 'girl', sid, 1))

        book1 = paging.RxBook()
        for page in book0.pages:
            page = paging.RxPage(packed=page.packed)
            page.head.parse() #parse head to get data
            book1.parse(page)

        self.assertEqual(book1.index, ('girl', 'boy', sid, 1))
        self.assertDictEqual(book1.body, body)
        self.assertEqual(book1.data['sn'], 'boy')
        self.assertEqual(book1.data['dn'], 'girl')
        self.assertEqual(book1.data['si'], sid)
        self.assertEqual(book1.data['bi'], 1)
Beispiel #28
0
    def testSectionedMsgpack(self):
        """
        Test sectioned pack and parse msgpack packing
        """
        console.terse("{0}\n".format(self.testSectionedMsgpack.__doc__))
        data = odict(pk=raeting.PackKind.pack.value)
        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn="girl", si=sid, bi=1))
        src = ["mayor", "main", None]
        dst = ["citizen", "other", None]
        route = odict([("src", src), ("dst", dst)])

        stuff = []
        for i in range(10000):
            stuff.append(str(i).rjust(10, " "))
        stuff = "".join(stuff)
        self.assertEqual(len(stuff), 100000)
        self.assertTrue(len(stuff) > raeting.UXD_MAX_PACKET_SIZE)

        body = odict([("route", route), ("content", stuff)])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        self.assertRaises(raeting.PageError, page0.pack)

        book0 = paging.TxBook(data=data, body=body)
        book0.pack()
        self.assertEqual(len(book0.packed), 100058)
        self.assertEqual(len(book0.pages), 2)
        self.assertEqual(book0.index, ("boy", "girl", sid, 1))

        book1 = paging.RxBook()
        for page in book0.pages:
            page = paging.RxPage(packed=page.packed)
            page.head.parse()  # parse head to get data
            book1.parse(page)

        self.assertEqual(book1.index, ("girl", "boy", sid, 1))
        self.assertDictEqual(book1.body, body)
        self.assertEqual(book1.data["sn"], "boy")
        self.assertEqual(book1.data["dn"], "girl")
        self.assertEqual(book1.data["si"], sid)
        self.assertEqual(book1.data["bi"], 1)
Beispiel #29
0
    def _setup_jobber_stack(self):
        '''
        Setup and return the LaneStack and Yard used by the jobber yard
        to communicate with the minion manor yard

        '''
        role = self.opts.get('id', '')
        if not role:
            emsg = ("Missing role required to setup Jobber Lane.")
            log.error(emsg + "\n")
            raise ValueError(emsg)

        kind = self.opts['__role']
        if kind not in kinds.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}' for Jobber lane.".format(
                kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)

        if kind == 'minion':
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = ("Unsupported application kind = '{0}' for Jobber Lane.".
                    format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        sockdirpath = self.opts['sock_dir']
        name = 'jobber' + nacling.uuid(size=18)
        stack = LaneStack(name=name,
                          lanename=lanename,
                          sockdirpath=sockdirpath)

        stack.Pk = raeting.PackKind.pack.value
        # add remote for the manor yard
        stack.addRemote(
            RemoteYard(stack=stack,
                       name='manor',
                       lanename=lanename,
                       dirpath=sockdirpath))
        console.concise("Created Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #30
0
    def _setup_caller_stack(self, opts):
        '''
        Setup and return the LaneStack and Yard used by by channel when global
        not already setup such as in salt-call to communicate to-from the minion

        '''
        mid = opts['id']
        sockdirpath = opts['sock_dir']
        uid = nacling.uuid(size=18)
        name = 'caller' + uid
        stack = LaneStack(name=name, lanename=mid, sockdirpath=sockdirpath)

        stack.Pk = raeting.packKinds.pack
        stack.addRemote(
            RemoteYard(stack=stack,
                       name='manor',
                       lanename=mid,
                       dirpath=sockdirpath))
        log.debug("Created Caller Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #31
0
    def _setup_jobber_stack(self):
        '''
        Setup and return the LaneStack and Yard used by the jobber to communicate to-from
        the minion

        '''
        mid = self.opts['id']
        yid = nacling.uuid(size=18)
        name = 'jobber' + yid
        stack = LaneStack(
                name=name,
                lanename=mid,
                sockdirpath=self.opts['sock_dir'])

        stack.Pk = raeting.packKinds.pack
        stack.addRemote(RemoteYard(stack=stack,
                                   name='manor',
                                   lanename=mid,
                                   dirpath=self.opts['sock_dir']))
        console.concise("Created Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #32
0
    def _setup_jobber_stack(self):
        '''
        Setup and return the LaneStack and Yard used by the jobber to communicate to-from
        the minion

        '''
        mid = self.opts['id']
        yid = nacling.uuid(size=18)
        name = 'jobber' + yid
        stack = LaneStack(name=name,
                          lanename=mid,
                          sockdirpath=self.opts['sock_dir'])

        stack.Pk = raeting.packKinds.pack
        stack.addRemote(
            RemoteYard(stack=stack,
                       name='manor',
                       lanename=mid,
                       dirpath=self.opts['sock_dir']))
        console.concise("Created Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #33
0
    def testPackParseMsgpack(self):
        '''
        Test basic page pack and parse
        '''
        console.terse("{0}\n".format(self.testPackParseMsgpack.__doc__))
        data = odict(pk=raeting.packKinds.pack)
        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn='girl', si=sid, bi=1))
        src = ['mayor', 'main', None]
        dst = ['citizen', 'other', None]
        route = odict([('src', src), ('dst', dst)])

        body = odict([('route', route), ('content', "Hello all yards.")])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        page0.pack()
        self.assertEqual(len(page0.packed), 147)
        self.assertEqual(page0.packed, 'ri RAET\nvn 0\npk 1\nsn boy\ndn girl\nsi {0:.18s}\nbi 1\npn 0000\npc 0001\n\n\x82\xa5route\x82\xa3src\x93\xa5mayor\xa4main\xc0\xa3dst\x93\xa7citizen\xa5other\xc0\xa7content\xb0Hello all yards.'.format(sid))
        page1 = paging.RxPage(packed=page0.packed)
        page1.parse()
        self.assertDictEqual(page1.body.data, body)
Beispiel #34
0
    def _setup_stack(self):
        '''
        Setup and return the LaneStack and Yard used by by channel when global
        not already setup such as in salt-call to communicate to-from the minion

        '''
        import wingdbstub
        mid = self.opts['id']
        yid = nacling.uuid(size=18)
        name = 'channel' + yid
        stack = LaneStack(name=name,
                          lanename=mid,
                          sockdirpath=self.opts['sock_dir'])

        stack.Pk = raeting.packKinds.pack
        stack.addRemote(RemoteYard(stack=stack,
                                   name='manor',
                                   lanename=mid,
                                   dirpath=self.opts['sock_dir']))
        log.debug("Created Channel Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #35
0
    def _setup_jobber_stack(self):
        '''
        Setup and return the LaneStack and Yard used by the jobber yard
        to communicate with the minion manor yard

        '''
        role = self.opts.get('id', '')
        if not role:
            emsg = ("Missing role required to setup Jobber Lane.")
            log.error(emsg + "\n")
            raise ValueError(emsg)

        kind = self.opts['__role']
        if kind not in kinds.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}' for Jobber lane.".format(kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)

        if kind == 'minion':
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = ("Unsupported application kind = '{0}' for Jobber Lane.".format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        sockdirpath = self.opts['sock_dir']
        name = 'jobber' + nacling.uuid(size=18)
        stack = LaneStack(
                name=name,
                lanename=lanename,
                sockdirpath=sockdirpath)

        stack.Pk = raeting.packKinds.pack
        # add remote for the manor yard
        stack.addRemote(RemoteYard(stack=stack,
                                   name='manor',
                                   lanename=lanename,
                                   dirpath=sockdirpath))
        console.concise("Created Jobber Stack {0}\n".format(stack.name))
        return stack
    def _setup_stack(self):
        '''
        Setup and return the LaneStack and Yard used by by channel when global
        not already setup such as in salt-call to communicate to-from the minion

        '''
        kind = self.opts.get('__role', '')  # application kind 'master', 'minion', etc
        if not kind:
            emsg = ("Missing opts['__role']. required to setup RAETChannel.")
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind == 'master':
            lanename = 'master'
        elif kind == 'minion':
            role = self.opts.get('id', '')
            if not role:
                emsg = ("Missing opts['id']. required to setup RAETChannel.")
                log.error(emsg + "\n")
                raise ValueError(emsg)
            lanename = role  # add kind later
        else:
            emsg = ("Unsupported application kind '{0}' for RAETChannel "
                                "Raet.".format(self.node))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        mid = self.opts.get('id', 'master')
        uid = nacling.uuid(size=18)
        name = 'channel' + uid
        stack = LaneStack(name=name,
                          lanename=lanename,
                          sockdirpath=self.opts['sock_dir'])

        stack.Pk = raeting.packKinds.pack
        stack.addRemote(RemoteYard(stack=stack,
                                   name='manor',
                                   lanename=lanename,
                                   dirpath=self.opts['sock_dir']))
        log.debug("Created Channel Jobber Stack {0}\n".format(stack.name))
        return stack
Beispiel #37
0
    def _setup_caller_stack(self, opts):
        '''
        Setup and return the LaneStack and Yard used by by channel when global
        not already setup such as in salt-call to communicate to-from the minion

        '''
        role = opts.get('id')
        if not role:
            emsg = ("Missing role required to setup RAETChannel.")
            log.error(emsg + "\n")
            raise ValueError(emsg)

        kind = opts.get('__role')  # application kind 'master', 'minion', etc
        if kind not in kinds.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}' for RAETChannel.".format(kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind in [kinds.APPL_KIND_NAMES[kinds.applKinds.minion],
                    kinds.APPL_KIND_NAMES[kinds.applKinds.caller], ]:
            lanename = "{0}_{1}".format(role, kind)
        else:
            emsg = ("Unsupported application kind '{0}' for RAETChannel.".format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        sockdirpath = opts['sock_dir']
        stackname = 'caller' + nacling.uuid(size=18)
        stack = LaneStack(name=stackname,
                          lanename=lanename,
                          sockdirpath=sockdirpath)

        stack.Pk = raeting.PackKind.pack.value
        stack.addRemote(RemoteYard(stack=stack,
                                   name='manor',
                                   lanename=lanename,
                                   dirpath=sockdirpath))
        log.debug("Created Caller Jobber Stack {0}\n".format(stack.name))

        return stack
Beispiel #38
0
    def action(self):

        self.presence_req.value = deque()
        self.availables.value = set()
        self.alloweds.value = odict()
        self.aliveds.value = odict()
        self.reapeds.value = odict()

        # Create event stack
        name = "event" + nacling.uuid(size=18)
        lanename = self.lane_stack.value.local.lanename
        sock_dir = self.lane_stack.value.local.dirpath
        ryn = "manor"
        console.terse("Create stack: name = {0}, lanename = {1}, sock_dir = {2}\n".format(name, lanename, sock_dir))
        stack = LaneStack(name=name, lanename=lanename, sockdirpath=sock_dir)
        stack.addRemote(RemoteYard(stack=stack, lanename=lanename, name=ryn, dirpath=sock_dir))
        self.event_stack.value = stack

        route = {"dst": (None, ryn, "presence_req"), "src": (None, stack.local.name, None)}
        msg = {"route": route}
        stack.transmit(msg, stack.nameRemotes[ryn].uid)
        serviceLanes([stack, self.lane_stack.value])
Beispiel #39
0
    def pub(self,
            tgt,
            fun,
            arg=(),
            tgt_type='glob',
            ret='',
            jid='',
            timeout=5,
            **kwargs):
        '''
        Publish the command!
        '''
        if 'expr_form' in kwargs:
            salt.utils.warn_until(
                'Fluorine',
                'The target type should be passed using the \'tgt_type\' '
                'argument instead of \'expr_form\'. Support for using '
                '\'expr_form\' will be removed in Salt Fluorine.'
            )
            tgt_type = kwargs.pop('expr_form')

        payload_kwargs = self._prep_pub(
                tgt,
                fun,
                arg=arg,
                tgt_type=tgt_type,
                ret=ret,
                jid=jid,
                timeout=timeout,
                **kwargs)

        kind = self.opts['__role']
        if kind not in kinds.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}' for Raet LocalClient.".format(kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind in [kinds.APPL_KIND_NAMES[kinds.applKinds.master],
                    kinds.APPL_KIND_NAMES[kinds.applKinds.syndic]]:
            lanename = 'master'
        else:
            emsg = ("Unsupported application kind '{0}' for Raet LocalClient.".format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        sockdirpath = self.opts['sock_dir']
        name = 'client' + nacling.uuid(size=18)
        stack = LaneStack(
                name=name,
                lanename=lanename,
                sockdirpath=sockdirpath)
        stack.Pk = raeting.PackKind.pack.value
        manor_yard = RemoteYard(
                stack=stack,
                lanename=lanename,
                name='manor',
                dirpath=sockdirpath)
        stack.addRemote(manor_yard)
        route = {'dst': (None, manor_yard.name, 'local_cmd'),
                 'src': (None, stack.local.name, None)}
        msg = {'route': route, 'load': payload_kwargs}
        stack.transmit(msg)
        stack.serviceAll()
        while True:
            time.sleep(0.01)
            stack.serviceAll()
            while stack.rxMsgs:
                msg, sender = stack.rxMsgs.popleft()
                ret = msg.get('return', {})
                if 'ret' in ret:
                    stack.server.close()
                    return ret['ret']
                stack.server.close()
                return ret
Beispiel #40
0
    def testPackParseJson(self):
        '''
        Test basic page pack and parse
        '''
        console.terse("{0}\n".format(self.testPackParseJson.__doc__))
        data = odict(pk=raeting.PackKind.json.value)
        src = ['mayor', 'main', None]
        dst = ['citizen', 'other', None]
        route = odict([('src', src), ('dst', dst)])

        body = odict([('route', route), ('content', "Hello all yards.")])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        page0.pack()
        self.assertEqual(len(page0.packed), 169)
        self.assertEqual(page0.packed, b'ri RAET\nvn 0\npk 0\nsn \ndn \nsi 000000000000000000\nbi 0\npn 0000\npc 0001\n\n{"route":{"src":["mayor","main",null],"dst":["citizen","other",null]},"content":"Hello all yards."}')
        page1 = paging.RxPage(packed=page0.packed)
        page1.parse()
        self.assertDictEqual(page1.body.data, body)

        stuff = []
        for i in range(10000):
            stuff.append(str(i).rjust(10, " "))
        stuff = "".join(stuff)
        body = odict(msg=stuff)
        page0 = paging.TxPage(data=data, embody=body)
        self.assertRaises(raeting.PageError, page0.pack)

        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn='girl', si=sid, bi=1))
        book0 = paging.TxBook(data=data, body=body)
        book0.pack()
        self.assertEqual(len(book0.pages), 2)
        self.assertEqual(book0.packed, page0.body.packed)
        self.assertDictEqual(book0.pages[0].data, {'ri': 'RAET',
                                                   'vn': 0,
                                                   'pk': 0,
                                                   'sn': 'boy',
                                                   'dn': 'girl',
                                                   'si': sid,
                                                   'bi': 1,
                                                   'pn': 0,
                                                   'pc': 2})
        self.assertEqual(len(book0.pages[0].packed), 65533)
        self.assertDictEqual(book0.pages[1].data, {'ri': 'RAET',
                                                   'vn': 0,
                                                   'pk': 0,
                                                   'sn': 'boy',
                                                   'dn': 'girl',
                                                   'si': sid,
                                                   'bi': 1,
                                                   'pn': 1,
                                                   'pc': 2})
        self.assertEqual(len(book0.pages[1].packed), 34631)
        self.assertEqual(book0.index, ('boy', 'girl', sid, 1))

        book1 = paging.RxBook()
        for page in book0.pages:
            page = paging.RxPage(packed=page.packed) # simulate received packed
            page.head.parse() #parse head to get data
            book1.parse(page)

        self.assertDictEqual(body, book1.body)
        self.assertDictEqual(book1.data, {'ri': 'RAET',
                                          'vn': 0,
                                          'pk': 0,
                                          'sn': 'boy',
                                          'dn': 'girl',
                                          'si': sid,
                                          'bi': 1,
                                          'pn': 0,
                                          'pc': 2})
        self.assertEqual(book1.index, ('girl', 'boy', sid, 1))
Beispiel #41
0
    def testPackParseJson(self):
        '''
        Test basic page pack and parse
        '''
        console.terse("{0}\n".format(self.testPackParseJson.__doc__))
        data = odict(pk=raeting.packKinds.json)
        src = ['mayor', 'main', None]
        dst = ['citizen', 'other', None]
        route = odict([('src', src), ('dst', dst)])

        body = odict([('route', route), ('content', "Hello all yards.")])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        page0.pack()
        self.assertEqual(len(page0.packed), 169)
        self.assertEqual(
            page0.packed,
            'ri RAET\nvn 0\npk 0\nsn \ndn \nsi 000000000000000000\nbi 0\npn 0000\npc 0001\n\n{"route":{"src":["mayor","main",null],"dst":["citizen","other",null]},"content":"Hello all yards."}'
        )
        page1 = paging.RxPage(packed=page0.packed)
        page1.parse()
        self.assertDictEqual(page1.body.data, body)

        stuff = []
        for i in range(10000):
            stuff.append(str(i).rjust(10, " "))
        stuff = "".join(stuff)
        body = odict(msg=stuff)
        page0 = paging.TxPage(data=data, embody=body)
        self.assertRaises(raeting.PageError, page0.pack)

        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn='girl', si=sid, bi=1))
        book0 = paging.TxBook(data=data, body=body)
        book0.pack()
        self.assertEqual(len(book0.pages), 2)
        self.assertEqual(book0.packed, page0.body.packed)
        self.assertDictEqual(
            book0.pages[0].data, {
                'ri': 'RAET',
                'vn': 0,
                'pk': 0,
                'sn': 'boy',
                'dn': 'girl',
                'si': sid,
                'bi': 1,
                'pn': 0,
                'pc': 2
            })
        self.assertEqual(len(book0.pages[0].packed), 65533)
        self.assertDictEqual(
            book0.pages[1].data, {
                'ri': 'RAET',
                'vn': 0,
                'pk': 0,
                'sn': 'boy',
                'dn': 'girl',
                'si': sid,
                'bi': 1,
                'pn': 1,
                'pc': 2
            })
        self.assertEqual(len(book0.pages[1].packed), 34631)
        self.assertEqual(book0.index, ('boy', 'girl', sid, 1))

        book1 = paging.RxBook()
        for page in book0.pages:
            page = paging.RxPage(
                packed=page.packed)  # simulate received packed
            page.head.parse()  #parse head to get data
            book1.parse(page)

        self.assertDictEqual(body, book1.body)
        self.assertDictEqual(
            book1.data, {
                'ri': 'RAET',
                'vn': 0,
                'pk': 0,
                'sn': 'boy',
                'dn': 'girl',
                'si': sid,
                'bi': 1,
                'pn': 0,
                'pc': 2
            })
        self.assertEqual(book1.index, ('girl', 'boy', sid, 1))
Beispiel #42
0
    def pub(self,
            tgt,
            fun,
            arg=(),
            tgt_type='glob',
            ret='',
            jid='',
            timeout=5,
            **kwargs):
        '''
        Publish the command!
        '''
        if 'expr_form' in kwargs:
            salt.utils.warn_until(
                'Fluorine',
                'The target type should be passed using the \'tgt_type\' '
                'argument instead of \'expr_form\'. Support for using '
                '\'expr_form\' will be removed in Salt Fluorine.'
            )
            tgt_type = kwargs.pop('expr_form')

        payload_kwargs = self._prep_pub(
                tgt,
                fun,
                arg=arg,
                tgt_type=tgt_type,
                ret=ret,
                jid=jid,
                timeout=timeout,
                **kwargs)

        kind = self.opts['__role']
        if kind not in kinds.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}' for Raet LocalClient.".format(kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind in [kinds.APPL_KIND_NAMES[kinds.applKinds.master],
                    kinds.APPL_KIND_NAMES[kinds.applKinds.syndic]]:
            lanename = 'master'
        else:
            emsg = ("Unsupported application kind '{0}' for Raet LocalClient.".format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        sockdirpath = self.opts['sock_dir']
        name = 'client' + nacling.uuid(size=18)
        stack = LaneStack(
                name=name,
                lanename=lanename,
                sockdirpath=sockdirpath)
        stack.Pk = raeting.PackKind.pack.value
        manor_yard = RemoteYard(
                stack=stack,
                lanename=lanename,
                name='manor',
                dirpath=sockdirpath)
        stack.addRemote(manor_yard)
        route = {'dst': (None, manor_yard.name, 'local_cmd'),
                 'src': (None, stack.local.name, None)}
        msg = {'route': route, 'load': payload_kwargs}
        stack.transmit(msg)
        stack.serviceAll()
        while True:
            time.sleep(0.01)
            stack.serviceAll()
            while stack.rxMsgs:
                msg, sender = stack.rxMsgs.popleft()
                ret = msg.get('return', {})
                if 'ret' in ret:
                    stack.server.close()
                    return ret['ret']
                stack.server.close()
                return ret
Beispiel #43
0
    def testPackParseJson(self):
        """
        Test basic page pack and parse
        """
        console.terse("{0}\n".format(self.testPackParseJson.__doc__))
        data = odict(pk=raeting.PackKind.json.value)
        src = ["mayor", "main", None]
        dst = ["citizen", "other", None]
        route = odict([("src", src), ("dst", dst)])

        body = odict([("route", route), ("content", "Hello all yards.")])
        page0 = paging.TxPage(data=data, embody=body)
        self.assertDictEqual(page0.body.data, body)
        page0.pack()
        self.assertEqual(len(page0.packed), 169)
        self.assertEqual(
            page0.packed,
            b'ri RAET\nvn 0\npk 0\nsn \ndn \nsi 000000000000000000\nbi 0\npn 0000\npc 0001\n\n{"route":{"src":["mayor","main",null],"dst":["citizen","other",null]},"content":"Hello all yards."}',
        )
        page1 = paging.RxPage(packed=page0.packed)
        page1.parse()
        self.assertDictEqual(page1.body.data, body)

        stuff = []
        for i in range(10000):
            stuff.append(str(i).rjust(10, " "))
        stuff = "".join(stuff)
        body = odict(msg=stuff)
        page0 = paging.TxPage(data=data, embody=body)
        self.assertRaises(raeting.PageError, page0.pack)

        sid = nacling.uuid(size=18)
        data.update(odict(sn="boy", dn="girl", si=sid, bi=1))
        book0 = paging.TxBook(data=data, body=body)
        book0.pack()
        self.assertEqual(len(book0.pages), 2)
        self.assertEqual(book0.packed, page0.body.packed)
        self.assertDictEqual(
            book0.pages[0].data,
            {"ri": "RAET", "vn": 0, "pk": 0, "sn": "boy", "dn": "girl", "si": sid, "bi": 1, "pn": 0, "pc": 2},
        )
        self.assertEqual(len(book0.pages[0].packed), 65533)
        self.assertDictEqual(
            book0.pages[1].data,
            {"ri": "RAET", "vn": 0, "pk": 0, "sn": "boy", "dn": "girl", "si": sid, "bi": 1, "pn": 1, "pc": 2},
        )
        self.assertEqual(len(book0.pages[1].packed), 34631)
        self.assertEqual(book0.index, ("boy", "girl", sid, 1))

        book1 = paging.RxBook()
        for page in book0.pages:
            page = paging.RxPage(packed=page.packed)  # simulate received packed
            page.head.parse()  # parse head to get data
            book1.parse(page)

        self.assertDictEqual(body, book1.body)
        self.assertDictEqual(
            book1.data,
            {"ri": "RAET", "vn": 0, "pk": 0, "sn": "boy", "dn": "girl", "si": sid, "bi": 1, "pn": 0, "pc": 2},
        )
        self.assertEqual(book1.index, ("girl", "boy", sid, 1))
Beispiel #44
0
    def pub(self,
            tgt,
            fun,
            arg=(),
            expr_form='glob',
            ret='',
            jid='',
            timeout=5,
            **kwargs):
        '''
        Publish the command!
        '''
        payload_kwargs = self._prep_pub(tgt,
                                        fun,
                                        arg=arg,
                                        expr_form=expr_form,
                                        ret=ret,
                                        jid=jid,
                                        timeout=timeout,
                                        **kwargs)

        kind = self.opts['__role']
        if kind not in kinds.APPL_KINDS:
            emsg = ("Invalid application kind = '{0}' for Raet LocalClient.".
                    format(kind))
            log.error(emsg + "\n")
            raise ValueError(emsg)
        if kind in [
                kinds.APPL_KIND_NAMES[kinds.applKinds.master],
                kinds.APPL_KIND_NAMES[kinds.applKinds.syndic]
        ]:
            lanename = 'master'
        else:
            emsg = ("Unsupported application kind '{0}' for Raet LocalClient.".
                    format(kind))
            log.error(emsg + '\n')
            raise ValueError(emsg)

        sockdirpath = self.opts['sock_dir']
        name = 'client' + nacling.uuid(size=18)
        stack = LaneStack(name=name,
                          lanename=lanename,
                          sockdirpath=sockdirpath)
        stack.Pk = raeting.packKinds.pack
        manor_yard = RemoteYard(stack=stack,
                                lanename=lanename,
                                name='manor',
                                dirpath=sockdirpath)
        stack.addRemote(manor_yard)
        route = {
            'dst': (None, manor_yard.name, 'local_cmd'),
            'src': (None, stack.local.name, None)
        }
        msg = {'route': route, 'load': payload_kwargs}
        stack.transmit(msg)
        stack.serviceAll()
        while True:
            time.sleep(0.01)
            stack.serviceAll()
            while stack.rxMsgs:
                msg, sender = stack.rxMsgs.popleft()
                ret = msg.get('return', {})
                if 'ret' in ret:
                    stack.server.close()
                    return ret['ret']
                stack.server.close()
                return ret