Remove pyudev dependency

pyudev was only used by the linuxbridge-agent to get the list
of virtual network devices. This can be got from /sys instead.
This patch fixes the problem where testr could not import the
lb-agent module because pyudev was not in requirements.txt.

Change-Id: I0a78c91e97de4413f2ecf6fb56d2ff61b36baa78
Closes-Bug: 1269040
This commit is contained in:
Darragh O'Reilly 2014-01-14 15:02:17 +00:00
parent ee0788b9b3
commit f74e8f1ecb
3 changed files with 14 additions and 28 deletions

View File

@ -25,7 +25,5 @@ def setup_hook(config):
if sys.platform == 'win32': if sys.platform == 'win32':
requires.append('pywin32') requires.append('pywin32')
requires.append('wmi') requires.append('wmi')
elif sys.platform.startswith('linux'):
requires.append('pyudev')
metadata['requires_dist'] = "\n".join(requires) metadata['requires_dist'] = "\n".join(requires)
config['metadata'] = metadata config['metadata'] = metadata

View File

@ -30,7 +30,6 @@ import time
import eventlet import eventlet
from oslo.config import cfg from oslo.config import cfg
import pyudev
from neutron.agent import l2population_rpc as l2pop_rpc from neutron.agent import l2population_rpc as l2pop_rpc
from neutron.agent.linux import ip_lib from neutron.agent.linux import ip_lib
@ -88,10 +87,6 @@ class LinuxBridgeManager:
# Store network mapping to segments # Store network mapping to segments
self.network_map = {} self.network_map = {}
self.udev = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(self.udev)
monitor.filter_by('net')
def device_exists(self, device): def device_exists(self, device):
"""Check if ethernet device exists.""" """Check if ethernet device exists."""
try: try:
@ -501,7 +496,7 @@ class LinuxBridgeManager:
LOG.debug(_("Done deleting vxlan interface %s"), interface) LOG.debug(_("Done deleting vxlan interface %s"), interface)
def update_devices(self, registered_devices): def update_devices(self, registered_devices):
devices = self.udev_get_tap_devices() devices = self.get_tap_devices()
if devices == registered_devices: if devices == registered_devices:
return return
added = devices - registered_devices added = devices - registered_devices
@ -510,20 +505,13 @@ class LinuxBridgeManager:
'added': added, 'added': added,
'removed': removed} 'removed': removed}
def udev_get_tap_devices(self): def get_tap_devices(self):
devices = set() devices = set()
for device in self.udev.list_devices(subsystem='net'): for device in os.listdir(BRIDGE_FS):
name = self.udev_get_name(device) if device.startswith(TAP_INTERFACE_PREFIX):
if self.is_tap_device(name): devices.add(device)
devices.add(name)
return devices return devices
def is_tap_device(self, name):
return name.startswith(TAP_INTERFACE_PREFIX)
def udev_get_name(self, device):
return device.sys_name
def check_vxlan_support(self): def check_vxlan_support(self):
kernel_version = dist_version.LooseVersion(platform.release()) kernel_version = dist_version.LooseVersion(platform.release())
if cfg.CONF.VXLAN.l2_population and ( if cfg.CONF.VXLAN.l2_population and (
@ -633,7 +621,7 @@ class LinuxBridgeRpcCallbacks(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
# Check port exists on node # Check port exists on node
port = kwargs.get('port') port = kwargs.get('port')
tap_device_name = self.agent.br_mgr.get_tap_device_name(port['id']) tap_device_name = self.agent.br_mgr.get_tap_device_name(port['id'])
devices = self.agent.br_mgr.udev_get_tap_devices() devices = self.agent.br_mgr.get_tap_devices()
if tap_device_name not in devices: if tap_device_name not in devices:
return return
@ -798,7 +786,7 @@ class LinuxBridgeNeutronAgentRPC(sg_rpc.SecurityGroupAgentRpcMixin):
def _report_state(self): def _report_state(self):
try: try:
devices = len(self.br_mgr.udev_get_tap_devices()) devices = len(self.br_mgr.get_tap_devices())
self.agent_state.get('configurations')['devices'] = devices self.agent_state.get('configurations')['devices'] = devices
self.state_rpc.report_state(self.context, self.state_rpc.report_state(self.context,
self.agent_state) self.agent_state)

View File

@ -599,7 +599,7 @@ class TestLinuxBridgeManager(base.BaseTestCase):
self.assertTrue(exec_fn.called) self.assertTrue(exec_fn.called)
def test_update_devices(self): def test_update_devices(self):
with mock.patch.object(self.lbm, "udev_get_tap_devices") as gt_fn: with mock.patch.object(self.lbm, "get_tap_devices") as gt_fn:
gt_fn.return_value = set(["dev1"]) gt_fn.return_value = set(["dev1"])
self.assertIsNone(self.lbm.update_devices(set(["dev1"]))) self.assertIsNone(self.lbm.update_devices(set(["dev1"])))
@ -710,7 +710,7 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase):
mock.patch.object(self.lb_rpc.agent.br_mgr, mock.patch.object(self.lb_rpc.agent.br_mgr,
"get_tap_device_name"), "get_tap_device_name"),
mock.patch.object(self.lb_rpc.agent.br_mgr, mock.patch.object(self.lb_rpc.agent.br_mgr,
"udev_get_tap_devices"), "get_tap_devices"),
mock.patch.object(self.lb_rpc.agent.br_mgr, mock.patch.object(self.lb_rpc.agent.br_mgr,
"get_bridge_name"), "get_bridge_name"),
mock.patch.object(self.lb_rpc.agent.br_mgr, mock.patch.object(self.lb_rpc.agent.br_mgr,
@ -720,10 +720,10 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase):
"plugin_rpc", create=True), "plugin_rpc", create=True),
mock.patch.object(self.lb_rpc.sg_agent, mock.patch.object(self.lb_rpc.sg_agent,
"refresh_firewall", create=True) "refresh_firewall", create=True)
) as (get_tap_fn, udev_fn, getbr_fn, remif_fn, ) as (get_tap_fn, get_tap_devs_fn, getbr_fn, remif_fn,
addif_fn, rpc_obj, reffw_fn): addif_fn, rpc_obj, reffw_fn):
get_tap_fn.return_value = "tap123" get_tap_fn.return_value = "tap123"
udev_fn.return_value = ["tap123", "tap124"] get_tap_devs_fn.return_value = set(["tap123", "tap124"])
port = {"admin_state_up": True, port = {"admin_state_up": True,
"id": "1234-5678", "id": "1234-5678",
"network_id": "123-123"} "network_id": "123-123"}
@ -814,7 +814,7 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase):
mock.patch.object(self.lb_rpc.agent.br_mgr, mock.patch.object(self.lb_rpc.agent.br_mgr,
"get_tap_device_name"), "get_tap_device_name"),
mock.patch.object(self.lb_rpc.agent.br_mgr, mock.patch.object(self.lb_rpc.agent.br_mgr,
"udev_get_tap_devices"), "get_tap_devices"),
mock.patch.object(self.lb_rpc.agent.br_mgr, mock.patch.object(self.lb_rpc.agent.br_mgr,
"get_bridge_name"), "get_bridge_name"),
mock.patch.object(self.lb_rpc.agent.br_mgr, mock.patch.object(self.lb_rpc.agent.br_mgr,
@ -825,9 +825,9 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase):
mock.patch.object(self.lb_rpc.agent, mock.patch.object(self.lb_rpc.agent,
"plugin_rpc", create=True), "plugin_rpc", create=True),
mock.patch.object(linuxbridge_neutron_agent.LOG, 'error'), mock.patch.object(linuxbridge_neutron_agent.LOG, 'error'),
) as (get_tap_fn, udev_fn, _, _, _, _, plugin_rpc, log): ) as (get_tap_fn, get_tap_devs_fn, _, _, _, _, plugin_rpc, log):
get_tap_fn.return_value = "tap123" get_tap_fn.return_value = "tap123"
udev_fn.return_value = ["tap123", "tap124"] get_tap_devs_fn.return_value = set(["tap123", "tap124"])
port = {"admin_state_up": True, port = {"admin_state_up": True,
"id": "1234-5678", "id": "1234-5678",
"network_id": "123-123"} "network_id": "123-123"}