Fix Flake8 errors
[integration/test.git] / csit / libraries / BgpRpcClient.py
index c744fabdfbacaf06c41816e170e2fe3bf07dc4cb..55dba2b35f52f6b50cf69f3f9ddf660085fd3999 100644 (file)
@@ -6,15 +6,16 @@ exa_ methods apply to test/tools/exabgp_files/exarpc.py
 play_ methods apply to test/tool/fastbgp/play.py  (only with --evpn used)
 """
 
+import re
 import xmlrpclib
 
 
 class BgpRpcClient(object):
     """The client for SimpleXMLRPCServer."""
 
-    def __init__(self, peer_addr):
+    def __init__(self, peer_addr, port=8000):
         """Setup destination point of the rpc server"""
-        self.proxy = xmlrpclib.ServerProxy("http://{}:8000".format(peer_addr))
+        self.proxy = xmlrpclib.ServerProxy("http://{}:{}".format(peer_addr, port))
 
     def exa_announce(self, full_exabgp_cmd):
         """The full command to be passed to exabgp."""
@@ -86,7 +87,7 @@ class BgpRpcClient(object):
 
     def play_send(self, hexstring):
         """Sends given hex data, already encoded bgp update message is expected."""
-        return self.proxy.send(hexstring)
+        return self.proxy.send(hexstring.rstrip())
 
     def play_get(self, what='update'):
         """Gets the last received (update) mesage as hex string."""
@@ -95,3 +96,8 @@ class BgpRpcClient(object):
     def play_clean(self, what='update'):
         """Cleans the message (update) on the server."""
         return self.proxy.clean(what)
+
+    def sum_hex_message(self, hex_string):
+        """Verifies two hex messages are equal even in case, their arguments are misplaced.
+        Converts hex message arguments to integers and sums them up and returns the sum."""
+        return sum(map(lambda x: int(x, 16), re.compile('[a-f\d]{2}').findall(hex_string[32:])))