Ema has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/356612 )
Change subject: Add basic BGP.parseUpdate test case
..
Add basic BGP.parseUpdate test case
Change-Id: Ib90d61298f40b6bb0c8ae94c5edd6c56112325bc
---
M pybal/bgp/test/test_bgp.py
1 file changed, 34 insertions(+), 0 deletions(-)
Approvals:
Ema: Verified; Looks good to me, approved
diff --git a/pybal/bgp/test/test_bgp.py b/pybal/bgp/test/test_bgp.py
index e28d8fe..5776ee6 100644
--- a/pybal/bgp/test/test_bgp.py
+++ b/pybal/bgp/test/test_bgp.py
@@ -208,3 +208,37 @@
# Verify parseOpen rejects it
self.proto.parseOpen(self.MSG_DATA_OPEN[bgp.HDR_LEN:])
mock_method.assert_called_with(bgp.ERR_MSG_OPEN_BAD_BGP_ID)
+
+def testParseUpdate(self):
+# Test empty UPDATE
+update = bgp.BGPUpdateMessage()
+self.assertEquals(self.proto.parseUpdate(bytes(update)[bgp.HDR_LEN:]),
([], [], []))
+
+# Add withdrawals
+withdrawals = [ip.IPPrefix("192.168.{0}.0/24".format(i)) for i in
range(100)]
+update.addSomeWithdrawals(set(withdrawals))
+r = self.proto.parseUpdate(bytes(update)[bgp.HDR_LEN:])
+self.assertListEqual(sorted(r[0]), withdrawals)
+self.assertEquals(r[1:], ([], []))
+
+# Add some attributes
+update.addAttributes(BGPUpdateMessageTestCase.attrs)
+r = self.proto.parseUpdate(bytes(update)[bgp.HDR_LEN:])
+self.assertListEqual(sorted(r[0]), withdrawals)
+self.assertEquals(len(r[1]), len(BGPUpdateMessageTestCase.attrs))
+self.assertEquals(r[2:], ([], ))
+
+# ...and some NLRI
+nlri = [ip.IPPrefix("10.{0}.3.0/24".format(i)) for i in range(100)]
+update.addSomeNLRI(set(nlri))
+r = self.proto.parseUpdate(bytes(update)[bgp.HDR_LEN:])
+self.assertListEqual(sorted(r[0]), withdrawals)
+self.assertEquals(len(r[1]), len(BGPUpdateMessageTestCase.attrs))
+self.assertListEqual(sorted(r[2]), nlri)
+
+# Test a malformed message
+# FIXME: Test for specific struct.unpack exception
+# FIXME: fix parseUpdate string slicing code to catch truncated message
+msgdata = bytearray(bytes(update)[bgp.HDR_LEN:])
+msgdata[0] += 66
+self.assertRaises(Exception, self.proto.parseUpdate, msgdata)
--
To view, visit https://gerrit.wikimedia.org/r/356612
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib90d61298f40b6bb0c8ae94c5edd6c56112325bc
Gerrit-PatchSet: 6
Gerrit-Project: operations/debs/pybal
Gerrit-Branch: master
Gerrit-Owner: Mark Bergsma
Gerrit-Reviewer: Ema
Gerrit-Reviewer: Giuseppe Lavagetto
Gerrit-Reviewer: Volans
Gerrit-Reviewer: jenkins-bot <>
___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits