Change in vdsm[master]: Revert "Use 'ip link' to get different kinds of interfaces"
wudxw at linux.vnet.ibm.com
wudxw at linux.vnet.ibm.com
Tue Apr 23 06:17:18 UTC 2013
Mark Wu has uploaded a new change for review.
Change subject: Revert "Use 'ip link' to get different kinds of interfaces"
......................................................................
Revert "Use 'ip link' to get different kinds of interfaces"
This reverts commit 8febe0e40650983d809abaa10be983bc1953ef1e.
The netlink support for bridge is only available on kernel 3.0+.
Please see the following commit for details.
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=bb900b27a2f49b37bc38c08e656ea13048fee13b
Add netlink support for bond is also added after kernel 2.6.32.
So this solution doesn't work on RHEL6 system. We have to revert
it.
Change-Id: I9d3f037a9e837fd97cb8808b7bf4b72026ec77c5
Signed-off-by: Mark Wu <wudxw at linux.vnet.ibm.com>
---
M lib/vdsm/netinfo.py
M tests/Makefile.am
D tests/ip_details_link.out
M tests/netinfoTests.py
M vdsm.spec.in
M vdsm/clientIF.py
M vdsm/neterrors.py
7 files changed, 28 insertions(+), 114 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/57/14157/1
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index 3ecc483..3abe601 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -19,7 +19,6 @@
#
import os
-import re
import errno
import glob
import ethtool
@@ -30,14 +29,11 @@
from fnmatch import fnmatch
from xml.dom import minidom
from itertools import chain
-from collections import namedtuple
import libvirtconnection
import constants
-import neterrors as ne
from config import config
-from storage.misc import execCmd
NET_CONF_DIR = '/etc/sysconfig/network-scripts/'
NET_CONF_BACK_DIR = constants.P_VDSM_LIB + 'netconfback/'
@@ -58,61 +54,33 @@
return any(map(lambda p: fnmatch(nic, p), patterns))
-def _parseIpLinkOutput(links):
- interfaces = {'nic': [], 'bond': [], 'vlan': [], 'bridge': [], 'fake': []}
- IP_LINK_RE = re.compile(r'^\d+: (?P<name>\S+):.*\n'
- ' {4}link/(?P<link>\w+).*\n'
- '( {4}(?P<type>\w+))?', re.MULTILINE)
-
- for match in re.finditer(IP_LINK_RE, links):
- name = match.group('name')
- ifaceType = match.group('type')
- link = match.group('link')
- if ifaceType:
- if ifaceType in ('tun', 'dummy'):
- ifaceType = 'fake'
- interfaces[ifaceType].append(name)
- elif link == 'ether':
- interfaces['nic'].append(name)
-
- return interfaces
-
-
-def getInterfaces():
- Interfaces = namedtuple('Interfaces', ('nics, bonds, vlans, bridges'))
+def nics():
+ res = []
hidden_nics = config.get('vars', 'hidden_nics').split(',')
fake_nics = config.get('vars', 'fake_nics').split(',')
- rc, out, err = execCmd([constants.EXT_IPROUTE, '--details',
- 'link', 'show'], raw=True)
- if rc != 0:
- raise ne.NetInfoError(err)
- interfaces = _parseIpLinkOutput(out)
+ for b in glob.glob('/sys/class/net/*'):
+ nic = b.split('/')[-1]
+ if not os.path.exists(os.path.join(b, 'device')):
+ if _match_nic_name(nic, fake_nics):
+ res.append(nic)
+ elif not _match_nic_name(nic, hidden_nics):
+ res.append(nic)
- return Interfaces([nic for nic in interfaces['nic']
- if not _match_nic_name(nic, hidden_nics)] +
- [nic for nic in interfaces['fake']
- if _match_nic_name(nic, fake_nics)],
- interfaces['bond'],
- [vlan.split('@')[0] for vlan in interfaces['vlan']],
- [br for br in interfaces['bridge']
- if br != DUMMY_BRIDGE])
-
-
-def nics():
- return getInterfaces().nics
+ return res
def bondings():
- return getInterfaces().bondings
+ return [b.split('/')[-2] for b in glob.glob('/sys/class/net/*/bonding')]
def vlans():
- return getInterfaces().vlans
+ return [b.split('/')[-1] for b in glob.glob('/sys/class/net/*.*')]
def bridges():
- return getInterfaces().bridges
+ return [b.split('/')[-2] for b in glob.glob('/sys/class/net/*/bridge')
+ if b.split('/')[-2] != DUMMY_BRIDGE]
def networks():
@@ -239,14 +207,13 @@
def graph():
- _, bondings, vlans, bridges = getInterfaces()
- for bridge in bridges:
+ for bridge in bridges():
print bridge
for iface in ports(bridge):
print '\t' + iface
- if iface in vlans:
+ if iface in vlans():
iface = iface.split('.')[0]
- if iface in bondings:
+ if iface in bondings():
for slave in slaves(iface):
print '\t\t' + slave
@@ -254,15 +221,14 @@
def getVlanBondingNic(bridge):
"""Return the (vlan, bonding, nics) tupple that belongs to bridge."""
- _, bondings, vlans, bridges = getInterfaces()
- if bridge not in bridges:
+ if bridge not in bridges():
raise ValueError('unknown bridge %s' % bridge)
vlan = bonding = ''
nics = []
for iface in ports(bridge):
- if iface in vlans:
+ if iface in vlans():
iface, vlan = iface.split('.')
- if iface in bondings:
+ if iface in bondings():
bonding = iface
nics = slaves(iface)
else:
@@ -350,9 +316,9 @@
return d
-def permAddr(bondings):
+def permAddr():
paddr = {}
- for b in bondings:
+ for b in bondings():
slave = ''
for line in file('/proc/net/bonding/' + b):
if line.startswith('Slave Interface: '):
@@ -434,8 +400,7 @@
d = {}
routes = getRoutes()
ipv6routes = getIPv6Routes()
- nics, bondings, vlans, bridges = getInterfaces()
- paddr = permAddr(bondings)
+ paddr = permAddr()
d['networks'] = {}
for net, netAttr in networks().iteritems():
@@ -447,10 +412,10 @@
continue # Do not report missing libvirt networks.
d['bridges'] = dict([_bridgeinfo(bridge, routes, ipv6routes)
- for bridge in bridges])
- d['nics'] = dict([_nicinfo(nic, paddr) for nic in nics])
- d['bondings'] = dict([_bondinfo(bond) for bond in bondings])
- d['vlans'] = dict([_vlaninfo(vlan) for vlan in vlans])
+ for bridge in bridges()])
+ d['nics'] = dict([_nicinfo(nic, paddr) for nic in nics()])
+ d['bondings'] = dict([_bondinfo(bond) for bond in bondings()])
+ d['vlans'] = dict([_vlaninfo(vlan) for vlan in vlans()])
return d
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7a8c204..1038cfb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -74,7 +74,6 @@
glob_1c60971a-8647-44ac-ae33-6520887f8843.out \
glusterVolumeProfileInfo.xml \
glusterVolumeProfileInfoNfs.xml \
- ip_details_link.out \
lvs_3386c6f2-926f-42c4-839c-38287fac8998.out \
netmaskconversions \
route_info.out \
diff --git a/tests/ip_details_link.out b/tests/ip_details_link.out
deleted file mode 100644
index 3145b6b..0000000
--- a/tests/ip_details_link.out
+++ /dev/null
@@ -1,32 +0,0 @@
-1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN mode DEFAULT
- link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
-2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master ovirtmgmt state UP mode DEFAULT qlen 1000
- link/ether 00:16:3e:e3:68:64 brd ff:ff:ff:ff:ff:ff
-3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
- link/ether 52:54:00:de:44:dd brd ff:ff:ff:ff:ff:ff
-4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
- link/ether 52:54:00:df:89:d9 brd ff:ff:ff:ff:ff:ff
-5: ovirtmgmt: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT
- link/ether 00:16:3e:e3:68:64 brd ff:ff:ff:ff:ff:ff
- bridge
-7: ;vdsmdummy;: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT
- link/ether 92:63:1c:88:31:ef brd ff:ff:ff:ff:ff:ff
- bridge
-8: bond0: <NO-CARRIER,BROADCAST,MULTICAST,MASTER,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT
- link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
- bond
-9: bond4: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN mode DEFAULT
- link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
- bond
-10: eth0.10 at eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT
- link/ether 00:16:3e:e3:68:64 brd ff:ff:ff:ff:ff:ff
- vlan id 10 <REORDER_HDR>
-11: eth2.20 at eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT
- link/ether 52:54:00:df:89:d9 brd ff:ff:ff:ff:ff:ff
- vlan id 20 <REORDER_HDR>
-12: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr1 state UNKNOWN mode DEFAULT qlen 500
- link/ether fe:16:3e:e3:68:64 brd ff:ff:ff:ff:ff:ff
- tun
-13: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT
- link/ether 22:f8:79:a7:3d:00 brd ff:ff:ff:ff:ff:ff
- dummy
diff --git a/tests/netinfoTests.py b/tests/netinfoTests.py
index fca9547..5e0716e 100644
--- a/tests/netinfoTests.py
+++ b/tests/netinfoTests.py
@@ -85,15 +85,3 @@
def testMatchNicName(self):
self.assertTrue(netinfo._match_nic_name('test1', ['test0', 'test1']))
-
- def testParseIpLinkOutput(self):
- outFile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
- "ip_details_link.out")
- with open(outFile) as f:
- links = f.read()
- interfaces = netinfo._parseIpLinkOutput(links)
- self.assertEqual(interfaces['nic'], ['eth0', 'eth1', 'eth2'])
- self.assertEqual(interfaces['bond'], ['bond0', 'bond4'])
- self.assertEqual(interfaces['vlan'], ['eth0.10 at eth0', 'eth2.20 at eth2'])
- self.assertEqual(interfaces['bridge'], ['ovirtmgmt', ';vdsmdummy;'])
- self.assertEqual(interfaces['fake'], ['vnet0', 'dummy0'])
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 1966835..644ec59 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -955,7 +955,6 @@
%{_datadir}/%{vdsm_name}/tests/caps_libvirt_amd_6274.out
%{_datadir}/%{vdsm_name}/tests/caps_libvirt_intel_E31220.out
%{_datadir}/%{vdsm_name}/tests/glob_1c60971a-8647-44ac-ae33-6520887f8843.out
-%{_datadir}/%{vdsm_name}/tests/ip_details_link.out
%{_datadir}/%{vdsm_name}/tests/lvs_3386c6f2-926f-42c4-839c-38287fac8998.out
%{_datadir}/%{vdsm_name}/tests/netmaskconversions
%{_datadir}/%{vdsm_name}/tests/run_tests.sh
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index 7b7f5b9..ed7db4b 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -82,8 +82,7 @@
self.gluster = None
try:
self.vmContainer = {}
- nics, bondings, _, _ = netinfo.getInterfaces()
- ifids = nics + bondings
+ ifids = netinfo.nics() + netinfo.bondings()
ifrates = map(netinfo.speed, ifids)
self._hostStats = sampling.HostStatsThread(
cif=self, log=log, ifids=ifids,
diff --git a/vdsm/neterrors.py b/vdsm/neterrors.py
index c2f98af..034414c 100644
--- a/vdsm/neterrors.py
+++ b/vdsm/neterrors.py
@@ -36,7 +36,3 @@
self.errCode = errCode
self.message = message
Exception.__init__(self, self.errCode, self.message)
-
-
-class NetInfoError(Exception):
- pass
--
To view, visit http://gerrit.ovirt.org/14157
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d3f037a9e837fd97cb8808b7bf4b72026ec77c5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <wudxw at linux.vnet.ibm.com>
More information about the vdsm-patches
mailing list