commit b4fc922bb51920eca03b9c2236d0a48f77c4fff4 Author: Ondrej Lichtner olichtne@redhat.com Date: Mon Oct 14 14:34:19 2013 +0200
update pyrout2 use
The new version of pyroute2 has a new feature that was added partially on my request- the IPRSocket. This commit updates the code where we use pyroute2 to use this feature.
This feature is available from pyroute2 version 0.1.11 which already is available as a package in Fedora 19.
Signed-off-by: Ondrej Lichtner olichtne@redhat.com Signed-off-by: Jiri Pirko jiri@resnulli.us
lnst/Common/ConnectionHandler.py | 11 ++++------- lnst/Common/NetUtils.py | 11 +++-------- lnst/Slave/NetTestSlave.py | 25 +++---------------------- 3 files changed, 10 insertions(+), 37 deletions(-) --- diff --git a/lnst/Common/ConnectionHandler.py b/lnst/Common/ConnectionHandler.py index b44f159..c0a43fa 100644 --- a/lnst/Common/ConnectionHandler.py +++ b/lnst/Common/ConnectionHandler.py @@ -15,8 +15,7 @@ import select import cPickle import socket from _multiprocessing import Connection -from pyroute2.netlink import NetlinkSocket -from pyroute2.netlink.iproute import MarshalRtnl +from pyroute2 import IPRSocket
def send_data(s, data): try: @@ -35,11 +34,9 @@ def send_data(s, data): return True
def recv_data(s): - if isinstance(s, NetlinkSocket): - marshaller = MarshalRtnl() - msg = s.recv(16384) - decoded_msg = marshaller.parse(msg) - data = {"type": "netlink", "data": decoded_msg} + if isinstance(s, IPRSocket): + msg = s.get() + data = {"type": "netlink", "data": msg} elif isinstance(s, socket.SocketType): length = "" while True: diff --git a/lnst/Common/NetUtils.py b/lnst/Common/NetUtils.py index efa14f5..b649483 100644 --- a/lnst/Common/NetUtils.py +++ b/lnst/Common/NetUtils.py @@ -15,14 +15,11 @@ import os import re import socket import subprocess -from resource import getpagesize -from pyroute2.netlink import NetlinkSocket +from pyroute2 import IPRSocket from pyroute2.netlink import NLM_F_REQUEST from pyroute2.netlink import NLM_F_DUMP from pyroute2.netlink import NLMSG_DONE from pyroute2.netlink import NLMSG_ERROR -from pyroute2.netlink.generic import NETLINK_ROUTE -from pyroute2.netlink.iproute import MarshalRtnl from pyroute2.netlink.iproute import RTM_GETLINK from pyroute2.netlink.iproute import RTM_NEWLINK from pyroute2.netlink.rtnl.ifinfmsg import ifinfmsg @@ -32,7 +29,7 @@ def normalize_hwaddr(hwaddr):
def scan_netdevs(): scan = [] - nl_socket = NetlinkSocket(family=NETLINK_ROUTE) + nl_socket = IPRSocket() msg = ifinfmsg() msg["family"] = socket.AF_UNSPEC msg["header"]["type"] = RTM_GETLINK @@ -44,10 +41,8 @@ def scan_netdevs(): nl_socket.sendto(msg.buf.getvalue(), (0,0))
finished = False - marshal = MarshalRtnl() while not finished: - response = nl_socket.recv(getpagesize()) - parts = marshal.parse(response) + parts = nl_socket.get() for part in parts: if part["header"]["type"] in [NLMSG_DONE, NLMSG_ERROR]: finished = True diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py index 76359d5..f8dad2b 100644 --- a/lnst/Slave/NetTestSlave.py +++ b/lnst/Slave/NetTestSlave.py @@ -37,26 +37,7 @@ from lnst.Common.ConnectionHandler import recv_data, send_data from lnst.Common.ConnectionHandler import ConnectionHandler from lnst.Common.Config import lnst_config from lnst.Common.NetTestCommand import NetTestCommandConfig - -#TODO this is temporary, until python-pyroute2 package is updated -from pyroute2.netlink import NetlinkSocket -from pyroute2.netlink.generic import NETLINK_ROUTE - -RTNLGRP_LINK = 0x1 -RTNLGRP_NEIGH = 0x4 -RTNLGRP_TC = 0x8 -RTNLGRP_IPV4_IFADDR = 0x10 -RTNLGRP_IPV4_ROUTE = 0x40 -RTNLGRP_IPV6_IFADDR = 0x100 -RTNLGRP_IPV6_ROUTE = 0x400 - -RTNL_GROUPS = RTNLGRP_IPV4_IFADDR |\ - RTNLGRP_IPV6_IFADDR |\ - RTNLGRP_IPV4_ROUTE |\ - RTNLGRP_IPV6_ROUTE |\ - RTNLGRP_NEIGH |\ - RTNLGRP_LINK |\ - RTNLGRP_TC +from pyroute2 import IPRSocket
DefaultRPCPort = 9999
@@ -455,8 +436,8 @@ class NetTestSlave:
self._log_ctl = log_ctl
- self._nl_socket = NetlinkSocket(family=NETLINK_ROUTE) - self._nl_socket.bind(RTNL_GROUPS) + self._nl_socket = IPRSocket() + self._nl_socket.bind() self._server_handler.add_connection('netlink', self._nl_socket)
def run(self):
lnst-developers@lists.fedorahosted.org