Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11008 from SmithSamuelM/sam_raet_17

added msgpack support to StackUxd messages
  • Loading branch information...
commit a5fe64830cf3b619a1a9b4a498f593339f9e5c6f 2 parents 589eba5 + 66fbaf6
@SmithSamuelM SmithSamuelM authored
View
5 salt/transport/road/raet/raeting.py
@@ -183,6 +183,11 @@
Acceptance = namedtuple('Acceptance', ACCEPTANCES.keys())
acceptance = Acceptance(**ACCEPTANCES)
+PACK_KINDS = odict([('json', 0), ('pack', 1)])
+PACK_KIND_NAMES = odict((v, k) for k, v in PACK_KINDS.iteritems()) # inverse map
+PackKind = namedtuple('PackKind', PACK_KINDS.keys())
+packKinds = PackKind(**PACK_KINDS)
+
# head fields that may be included in json header if not default value
PACKET_DEFAULTS = odict([
('sh', DEFAULT_SRC_HOST),
View
39 salt/transport/road/raet/stacking.py
@@ -14,6 +14,11 @@
except ImportError:
import json
+try:
+ import msgpack
+except ImportError:
+ mspack = None
+
# Import ioflo libs
from ioflo.base.odicting import odict
from ioflo.base import aiding
@@ -566,7 +571,7 @@ class StackUxd(object):
RAET protocol UXD (unix domain) socket stack object
'''
Count = 0
- PackKind = raeting.bodyKinds.json
+ Pk = raeting.packKinds.json # serialization pack kind of Uxd message
Accept = True # accept any uxd messages if True from yards not already in lanes
def __init__(self,
@@ -770,17 +775,24 @@ def packUxdTx(self, body=None, name=None, kind=None):
Pack serialize message body data
'''
if kind is None:
- kind = self.PackKind
+ kind = self.Pk
packed = ""
- if kind not in [raeting.bodyKinds.json]:
- emsg = "Invalid body pack kind '{0}'".format(kind)
+ if kind not in [raeting.packKinds.json, raeting.packKinds.pack]:
+ emsg = "Invalid message pack kind '{0}'".format(kind)
raise raeting.StackError(emsg)
- if kind == raeting.bodyKinds.json:
+ if kind == raeting.packKinds.json:
head = 'RAET\njson\n\n'
packed = "".join([head, json.dumps(body, separators=(',', ':'))])
+ elif kind == raeting.packKinds.pack:
+ if not msgpack:
+ emsg = "Msgpack not installed."
+ raise raeting.StackError(emsg)
+ head = 'RAET\npack\n\n'
+ packed = "".join([head, msgpack.dumps(body)])
+
if len(packed) > raeting.MAX_MESSAGE_SIZE:
emsg = "Message length of {0}, exceeds max of {1}".format(
len(packed), raeting.MAX_MESSAGE_SIZE)
@@ -838,16 +850,25 @@ def parseUxdRx(self, packed):
front, sep, back = packed.partition(raeting.HEAD_END)
code, sep, kind = front.partition('\n')
- if kind not in [raeting.BODY_KIND_NAMES[raeting.bodyKinds.json]]:
- emsg = "Unrecognized packed body kind '{0}'".format(kind)
+ if kind not in [raeting.PACK_KIND_NAMES[raeting.packKinds.json],
+ raeting.PACK_KIND_NAMES[raeting.packKinds.pack]]:
+ emsg = "Unrecognized message pack kind '{0}'".format(kind)
raise raeting.StackError(emsg)
- kind = raeting.BODY_KINDS[kind]
- if kind == raeting.bodyKinds.json:
+ kind = raeting.PACK_KINDS[kind]
+ if kind == raeting.packKinds.json:
body = json.loads(back, object_pairs_hook=odict)
if not isinstance(body, Mapping):
emsg = "Message body not a mapping."
raise raeting.PacketError(emsg)
+ elif kind == raeting.packKinds.pack:
+ if not msgpack:
+ emsg = "Msgpack not installed."
+ raise raeting.StackError(emsg)
+ body = msgpack.loads(back, object_pairs_hook=odict)
+ if not isinstance(body, Mapping):
+ emsg = "Message body not a mapping."
+ raise raeting.PacketError(emsg)
return body
View
9 salt/transport/road/raet/test/test_stackUxd.py
@@ -14,13 +14,15 @@
estating, yarding, transacting, stacking)
-def testStackUxd():
+def testStackUxd(kind=raeting.packKinds.json):
'''
initially
'''
- console.reinit(verbosity=console.Wordage.concise)
+ console.reinit(verbosity=console.Wordage.verbose)
+
+ stacking.StackUxd.Pk = kind
#lord stack
#yard0 = yarding.Yard(name='lord')
@@ -203,4 +205,5 @@ def testStackUxd():
if __name__ == "__main__":
- testStackUxd()
+ testStackUxd(raeting.packKinds.json)
+ testStackUxd(raeting.packKinds.pack)
Please sign in to comment.
Something went wrong with that request. Please try again.