[Git][NTPsec/ntpsec][master] Added packetVars() and tests

Ian Bruene gitlab at mg.gitlab.com
Wed Aug 2 20:43:04 UTC 2017


Ian Bruene pushed to branch master at NTPsec / ntpsec


Commits:
9d9b1af6 by Ian Bruene at 2017-08-02T15:32:36-05:00
Added packetVars() and tests

packetVars() returns all variables that are relevant to a packet's
definition in dict form. Intended use is debugging.

- - - - -


2 changed files:

- pylib/agentx.py
- tests/pylib/test_agentx.py


Changes:

=====================================
pylib/agentx.py
=====================================
--- a/pylib/agentx.py
+++ b/pylib/agentx.py
@@ -45,13 +45,40 @@ prefixCount = len(internetPrefix)
 
 
 class AgentXPDU:
-    def __init__(self, pduType, bigEndian, sID, tactID, pktID, context=None):
+    def __init__(self, pduType, bigEndian, sID, tactID, pktID,
+                 hascontext=False, context=None):
         self.pduType = pduType
         self.bigEndian = bigEndian
         self.sessionID = sID
         self.transactionID = tactID
         self.packetID = pktID
         self.context = context
+        self._hascontext = hascontext
+
+    def packetVars(self):
+        pktvars = {}
+        names = dir(self)
+        names.remove("context")
+        for vname in names:
+            if vname[0] == "_":  # ignores specials, and what we want ignored
+                continue
+            var = getattr(self, vname)
+            if callable(var):  # ignores methods
+                # *might* have to rethink this if contents get classified
+                continue
+            pktvars[vname] = var
+        if self._hascontext is True:
+            # context is always present, not always used
+            pktvars["context"] = self.context
+        return pktvars
+
+    def __repr__(self):
+        s = self.__name__ + "("
+        v = []
+        for var in self.printvars:
+            v.append(repr(var))
+        s += ", ".join(v) + ")"
+        return s
 
     def __eq__(self, other):
         if not isinstance(other, self.__class__):
@@ -177,19 +204,20 @@ class RegisterPDU(AgentXPDU):
                  timeout, priority, subtree,
                  rangeSubid=0, upperBound=None, context=None):
         AgentXPDU.__init__(self, PDU_REGISTER,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
         self.timeout = timeout
         self.priority = priority
         self.subtree = subtree
         self.rangeSubid = rangeSubid
         self.upperBound = upperBound
-        self.instReg = True  # so we don't have to write two encode()s
+        self._instReg = True  # so we don't have to write two encode()s
 
     def __eq__(self, other):
         if AgentXPDU.__eq__(self, other) is not True:
             return False
-        if self.timeout != other.timeout:
-            return False
+        if hasattr(self, "timeout"):
+            if self.timeout != other.timeout:
+                return False
         if self.priority != other.priority:
             return False
         if self.subtree != other.subtree:
@@ -214,7 +242,7 @@ class RegisterPDU(AgentXPDU):
             if self.upperBound is None:
                 raise ValueError("upperBound must be set if rangeSubid is set")
             payload += struct.pack(endianToken + "I", self.upperBound)
-        header = encode_pduheader(self.pduType, self.instReg, False, False,
+        header = encode_pduheader(self.pduType, self._instReg, False, False,
                                   contextP, self.bigEndian,
                                   self.sessionID, self.transactionID,
                                   self.packetID, len(payload))
@@ -222,14 +250,15 @@ class RegisterPDU(AgentXPDU):
         return packet
 
 
-class UnregisterPDU(RegisterPDU):  # These could inherit in either direction
+class UnregisterPDU(RegisterPDU):
     def __init__(self, bigEndian, sID, tactID, pktID, priority, subtree,
                  rangeSubid=0, upperBound=None, context=None):
         RegisterPDU.__init__(self, bigEndian, sID, tactID, pktID,
                              None, priority, subtree,
                              rangeSubid, upperBound, context)
         self.pduType = PDU_UNREGISTER
-        self.instReg = False
+        del self.timeout  # Unregister doesn't have a timeout
+        self._instReg = False
 
 
 def decode_xGetPDU(data, header):
@@ -251,9 +280,9 @@ def decode_xGetPDU(data, header):
 class GetPDU(AgentXPDU):
     def __init__(self, bigEndian, sID, tactID, pktID, oidranges, context=None):
         AgentXPDU.__init__(self, PDU_GET,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
         self.oidranges = oidranges
-        self.nullTerm = True
+        self._nullTerm = True
 
     def __eq__(self, other):
         if AgentXPDU.__eq__(self, other) is not True:
@@ -265,7 +294,7 @@ class GetPDU(AgentXPDU):
     def encode(self):
         contextP, payload = encode_context(self.bigEndian, self.context)
         payload += encode_searchrange_list(self.bigEndian,
-                                           self.oidranges, self.nullTerm)
+                                           self.oidranges, self._nullTerm)
         header = encode_pduheader(self.pduType, False, False, False,
                                   contextP, self.bigEndian,
                                   self.sessionID, self.transactionID,
@@ -278,7 +307,7 @@ class GetNextPDU(GetPDU):
         GetPDU.__init__(self, bigEndian, sID, tactID, pktID,
                         oidranges, context)
         self.pduType = PDU_GET_NEXT
-        self.nullTerm = False
+        self._nullTerm = False
 
 
 def decode_GetBulkPDU(data, header):
@@ -298,7 +327,7 @@ class GetBulkPDU(AgentXPDU):
     def __init__(self, bigEndian, sID, tactID, pktID,
                  nonReps, maxReps, oidranges, context=None):
         AgentXPDU.__init__(self, PDU_GET_BULK,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
         self.nonReps = nonReps
         self.maxReps = maxReps
         self.oidranges = oidranges
@@ -340,7 +369,7 @@ def decode_TestSetPDU(data, header):
 class TestSetPDU(AgentXPDU):
     def __init__(self, bigEndian, sID, tactID, pktID, varbinds, context=None):
         AgentXPDU.__init__(self, PDU_TEST_SET,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
         self.varbinds = varbinds
 
     def __eq__(self, other):
@@ -432,7 +461,7 @@ def decode_PingPDU(data, header):
 class PingPDU(AgentXPDU):
     def __init__(self, bigEndian, sID, tactID, pktID, context=None):
         AgentXPDU.__init__(self, PDU_PING,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
 
     def encode(self):
         contextP, payload = encode_context(self.bigEndian, self.context)
@@ -456,7 +485,7 @@ def decode_NotifyPDU(data, header):
 class NotifyPDU(AgentXPDU):
     def __init__(self, bigEndian, sID, tactID, pktID, varbinds, context=None):
         AgentXPDU.__init__(self, PDU_NOTIFY,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
         self.varbinds = varbinds
 
     def __eq__(self, other):
@@ -493,7 +522,7 @@ class IndexAllocPDU(AgentXPDU):
     def __init__(self, bigEndian, sID, tactID, pktID,
                  newIndex, anyIndex, varbinds, context=None):
         AgentXPDU.__init__(self, PDU_INDEX_ALLOC,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
         self.newIndex = newIndex
         self.anyIndex = anyIndex
         self.varbinds = varbinds
@@ -543,7 +572,7 @@ class AddAgentCapsPDU(AgentXPDU):
     def __init__(self, bigEndian, sID, tactID, pktID,
                  oid, description, context=None):
         AgentXPDU.__init__(self, PDU_ADD_AGENT_CAPS,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
         self.oid = oid
         self.description = description
 
@@ -580,7 +609,7 @@ def decode_RMAgentCapsPDU(data, header):
 class RMAgentCapsPDU(AgentXPDU):
     def __init__(self, bigEndian, sID, tactID, pktID, oid, context=None):
         AgentXPDU.__init__(self, PDU_RM_AGENT_CAPS,
-                           bigEndian, sID, tactID, pktID, context)
+                           bigEndian, sID, tactID, pktID, True, context)
         self.oid = oid
 
     def __eq__(self, other):


=====================================
tests/pylib/test_agentx.py
=====================================
--- a/tests/pylib/test_agentx.py
+++ b/tests/pylib/test_agentx.py
@@ -145,6 +145,16 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(basicPkt_new.oid, {"subids": (1, 2, 3, 4),
                                             "include": False})
         self.assertEqual(basicPkt_new.description, "foo")
+        # Test packetVars
+        self.assertEqual(basicPkt_new.packetVars(),
+                         {"pduType": 1,
+                          "bigEndian": False,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "timeout": 4,
+                          "oid": {"subids": (1, 2, 3, 4), "include": False},
+                          "description": "foo"})
 
     def test_ClosePDU(self):
         dec = ntp.agentx.decode_ClosePDU
@@ -174,6 +184,14 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.transactionID, 2)
         self.assertEqual(pkt_new.packetID, 3)
         self.assertEqual(pkt_new.reason, x.RSN_OTHER)
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 2,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "reason": x.RSN_OTHER})
 
     def test_RegisterPDU(self):
         dec = ntp.agentx.decode_xRegisterPDU
@@ -254,6 +272,19 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(fancyPkt_new.rangeSubid, 5)
         self.assertEqual(fancyPkt_new.upperBound, 23)
         self.assertEqual(fancyPkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(basicPkt_new.packetVars(),
+                         {"pduType": 3,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "timeout": 4,
+                          "priority": 5,
+                          "subtree": {"subids": (1, 2, 3), "include": False},
+                          "rangeSubid": 0,
+                          "upperBound": None,
+                          "context": None})
 
     def test_UnregisterPDU(self):
         dec = ntp.agentx.decode_xRegisterPDU
@@ -265,7 +296,6 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(basicPkt.sessionID, 1)
         self.assertEqual(basicPkt.transactionID, 2)
         self.assertEqual(basicPkt.packetID, 3)
-        self.assertEqual(basicPkt.timeout, None)
         self.assertEqual(basicPkt.priority, 5)
         self.assertEqual(basicPkt.subtree, (1, 2, 3))
         self.assertEqual(basicPkt.rangeSubid, 0)
@@ -278,7 +308,6 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(fancyPkt.sessionID, 1)
         self.assertEqual(fancyPkt.transactionID, 2)
         self.assertEqual(fancyPkt.packetID, 3)
-        self.assertEqual(fancyPkt.timeout, None)
         self.assertEqual(fancyPkt.priority, 5)
         self.assertEqual(fancyPkt.subtree, (1, 2, 3))
         self.assertEqual(fancyPkt.rangeSubid, 5)
@@ -312,7 +341,6 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(basicPkt_new.sessionID, 1)
         self.assertEqual(basicPkt_new.transactionID, 2)
         self.assertEqual(basicPkt_new.packetID, 3)
-        self.assertEqual(basicPkt_new.timeout, None)
         self.assertEqual(basicPkt_new.priority, 5)
         self.assertEqual(basicPkt_new.subtree, {"subids": (1, 2, 3),
                                                 "include": False})
@@ -327,13 +355,24 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(fancyPkt_new.sessionID, 1)
         self.assertEqual(fancyPkt_new.transactionID, 2)
         self.assertEqual(fancyPkt_new.packetID, 3)
-        self.assertEqual(fancyPkt_new.timeout, None)
         self.assertEqual(fancyPkt_new.priority, 5)
         self.assertEqual(fancyPkt_new.subtree, {"subids": (1, 2, 3),
                                                 "include": False})
         self.assertEqual(fancyPkt_new.rangeSubid, 5)
         self.assertEqual(fancyPkt_new.upperBound, 23)
         self.assertEqual(fancyPkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(basicPkt_new.packetVars(),
+                         {"pduType": 4,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "priority": 5,
+                          "subtree": {"subids": (1, 2, 3), "include": False},
+                          "rangeSubid": 0,
+                          "upperBound": None,
+                          "context": None})
 
     def test_GetPDU(self):
         dec = ntp.agentx.decode_xGetPDU
@@ -404,6 +443,15 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                           {"start": {"subids": (10, 20), "include": True},
                            "end": {"subids": (30, 40), "include": False}}))
         self.assertEqual(fullPkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(nullPkt_new.packetVars(),
+                         {"pduType": 5,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "oidranges": (),
+                          "context": None})
 
     def test_GetNextPDU(self):
         dec = ntp.agentx.decode_xGetPDU
@@ -472,6 +520,15 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                           {"start": {"subids": (10, 20), "include": True},
                            "end": {"subids": (30, 40), "include": False}}))
         self.assertEqual(fullPkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(nullPkt_new.packetVars(),
+                         {"pduType": 6,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "oidranges": (),
+                          "context": None})
 
     def test_GetBulkPDU(self):
         dec = ntp.agentx.decode_GetBulkPDU
@@ -520,6 +577,24 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                           {"start": {"subids": (6, 7), "include": True},
                            "end": {"subids": (8, 9), "include": False}}))
         self.assertEqual(pkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 7,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "nonReps": 1,
+                          "maxReps": 5,
+                          "oidranges": ({"start": {"subids": (1, 2),
+                                                   "include": False},
+                                         "end": {"subids": (3, 4),
+                                                 "include": False}},
+                                        {"start": {"subids": (6, 7),
+                                                   "include": True},
+                                         "end": {"subids": (8, 9),
+                                                 "include": False}}),
+                          "context": "blah"})
 
     def test_TestSetPDU(self):
         dec = ntp.agentx.decode_TestSetPDU
@@ -571,6 +646,23 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                            "name": {"subids": (1, 2, 4), "include": False},
                            "data": "blah"}))
         self.assertEqual(pkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 8,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "varbinds": ({"type": x.OID,
+                                        "name": {"subids": (1, 2, 3),
+                                                 "include": False},
+                                        "data": {"subids": (4, 5, 6),
+                                                 "include": False}},
+                                       {"type": x.OCTET_STR,
+                                        "name": {"subids": (1, 2, 4),
+                                                 "include": False},
+                                        "data": "blah"}),
+                         "context": "blah"})
 
     def test_CommitSetPDU(self):
         dec = ntp.agentx.decode_CommitSetPDU
@@ -596,6 +688,13 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.sessionID, 1)
         self.assertEqual(pkt_new.transactionID, 2)
         self.assertEqual(pkt_new.packetID, 3)
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 9,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3})
 
     def test_UndoSetPDU(self):
         dec = ntp.agentx.decode_UndoSetPDU
@@ -621,6 +720,13 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.sessionID, 1)
         self.assertEqual(pkt_new.transactionID, 2)
         self.assertEqual(pkt_new.packetID, 3)
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 10,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3})
 
     def test_CleanupSetPDU(self):
         dec = ntp.agentx.decode_CleanupSetPDU
@@ -646,6 +752,13 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.sessionID, 1)
         self.assertEqual(pkt_new.transactionID, 2)
         self.assertEqual(pkt_new.packetID, 3)
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 11,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3})
 
     def test_PingPDU(self):
         dec = ntp.agentx.decode_PingPDU
@@ -674,6 +787,14 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.transactionID, 2)
         self.assertEqual(pkt_new.packetID, 3)
         self.assertEqual(pkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 13,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "context": "blah"})
 
     def test_NotifyPDU(self):
         dec = ntp.agentx.decode_NotifyPDU
@@ -725,6 +846,23 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                            "name": {"subids": (1, 2, 4), "include": False},
                            "data": "blah"}))
         self.assertEqual(pkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 12,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "varbinds": ({"type": x.OID,
+                                        "name": {"subids": (1, 2, 3),
+                                                 "include": False},
+                                        "data": {"subids": (4, 5, 6),
+                                                 "include": False}},
+                                       {"type": x.OCTET_STR,
+                                        "name": {"subids": (1, 2, 4),
+                                                 "include": False},
+                                        "data": "blah"}),
+                          "context": "blah"})
 
     def test_IndexAllocPDU(self):
         dec = ntp.agentx.decode_xIndexAllocPDU
@@ -740,6 +878,8 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt.sessionID, 1)
         self.assertEqual(pkt.transactionID, 2)
         self.assertEqual(pkt.packetID, 3)
+        self.assertEqual(pkt.newIndex, True)
+        self.assertEqual(pkt.anyIndex, True)
         self.assertEqual(pkt.varbinds,
                          ((x.OID, (1, 2, 3), (4, 5, 6), False),
                           (x.OCTET_STR, (1, 2, 4), "blah")))
@@ -768,6 +908,8 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.sessionID, 1)
         self.assertEqual(pkt_new.transactionID, 2)
         self.assertEqual(pkt_new.packetID, 3)
+        self.assertEqual(pkt.newIndex, True)
+        self.assertEqual(pkt.anyIndex, True)
         self.assertEqual(pkt_new.varbinds,
                          ({"type": x.OID,
                            "name": {"subids": (1, 2, 3), "include": False},
@@ -776,6 +918,25 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                            "name": {"subids": (1, 2, 4), "include": False},
                            "data": "blah"}))
         self.assertEqual(pkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 14,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "newIndex": True,
+                          "anyIndex": True,
+                          "varbinds": ({"type": x.OID,
+                                        "name": {"subids": (1, 2, 3),
+                                                 "include": False},
+                                        "data": {"subids": (4, 5, 6),
+                                                 "include": False}},
+                                       {"type": x.OCTET_STR,
+                                        "name": {"subids": (1, 2, 4),
+                                                 "include": False},
+                                        "data": "blah"}),
+                          "context": "blah"})
 
     def test_IndexDeallocPDU(self):
         dec = ntp.agentx.decode_xIndexAllocPDU
@@ -791,6 +952,8 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt.sessionID, 1)
         self.assertEqual(pkt.transactionID, 2)
         self.assertEqual(pkt.packetID, 3)
+        self.assertEqual(pkt.newIndex, True)
+        self.assertEqual(pkt.anyIndex, True)
         self.assertEqual(pkt.varbinds,
                          ((x.OID, (1, 2, 3), (4, 5, 6), False),
                           (x.OCTET_STR, (1, 2, 4), "blah")))
@@ -819,6 +982,8 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.sessionID, 1)
         self.assertEqual(pkt_new.transactionID, 2)
         self.assertEqual(pkt_new.packetID, 3)
+        self.assertEqual(pkt.newIndex, True)
+        self.assertEqual(pkt.anyIndex, True)
         self.assertEqual(pkt_new.varbinds,
                          ({"type": x.OID,
                            "name": {"subids": (1, 2, 3), "include": False},
@@ -827,6 +992,25 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                            "name": {"subids": (1, 2, 4), "include": False},
                            "data": "blah"}))
         self.assertEqual(pkt_new.context, "blah")
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 15,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "newIndex": True,
+                          "anyIndex": True,
+                          "varbinds": ({"type": x.OID,
+                                        "name": {"subids": (1, 2, 3),
+                                                 "include": False},
+                                        "data": {"subids": (4, 5, 6),
+                                                 "include": False}},
+                                       {"type": x.OCTET_STR,
+                                        "name": {"subids": (1, 2, 4),
+                                                 "include": False},
+                                        "data": "blah"}),
+                          "context": "blah"})
 
     def test_AddAgentCapsPDU(self):
         dec = ntp.agentx.decode_AddAgentCapsPDU
@@ -863,6 +1047,16 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                                        "include": False})
         self.assertEqual(pkt_new.description, "blah")
         self.assertEqual(pkt_new.context, "bluh")
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 16,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "oid": {"subids": (4, 5, 6), "include": False},
+                          "description": "blah",
+                          "context": "bluh"})
 
     def test_RMAgentCapsPDU(self):
         dec = ntp.agentx.decode_RMAgentCapsPDU
@@ -896,6 +1090,15 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
         self.assertEqual(pkt_new.oid, {"subids": (4, 5, 6),
                                        "include": False})
         self.assertEqual(pkt_new.context, "bluh")
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 17,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "oid": {"subids": (4, 5, 6), "include": False},
+                          "context": "bluh"})
 
     def test_ResponsePDU(self):
         dec = ntp.agentx.decode_ResponsePDU
@@ -950,6 +1153,25 @@ class TestNtpclientsNtpsnmpd(unittest.TestCase):
                           {"type": x.OCTET_STR,
                            "name": {"subids": (1, 2, 4), "include": False},
                            "data": "blah"}))
+        # Test packetVars
+        self.assertEqual(pkt_new.packetVars(),
+                         {"pduType": 18,
+                          "bigEndian": True,
+                          "sessionID": 1,
+                          "transactionID": 2,
+                          "packetID": 3,
+                          "sysUptime": 4,
+                          "resError": 5,
+                          "resIndex": 6,
+                          "varbinds": ({"type": x.OID,
+                                        "name": {"subids": (1, 2, 3),
+                                                 "include": False},
+                                        "data": {"subids": (4, 5, 6),
+                                                 "include": False}},
+                                       {"type": x.OCTET_STR,
+                                        "name": {"subids": (1, 2, 4),
+                                                 "include": False},
+                                        "data": "blah"})})
 
     #
     # Data type tests



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9d9b1af6f977b709019bd174dc5537f4f7d6367c

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/9d9b1af6f977b709019bd174dc5537f4f7d6367c
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170802/a43123c3/attachment.html>


More information about the vc mailing list