XenAPI: resolve the fetch_bandwidth failure

When introducing interim bridge for XenAPI, it introduced a interface
which is connected to the interim bridge and it has the name as
vifxxxxxxxx-xx. In the xenapi plugin of bandwidth, it uses
the pattern of "^vif*" to filter out VM's interfaces. Due to the
existing of vifxxxxxxxx-xx, it will get exception when parsing the
interface's name basing on "vif<dom#>.<dev>".
So let's give more restrict pattern to filter VM's vifs e.g. change from
"^vif*" to "^vif<dom#>.<dev#>". May consider to use another interface
name for the interface on interim bridge; but need cover both name
patterns when delete interfaces to avoid upgrade issues which may make
things complicated.

Change-Id: I36b96bbe2bb764f3d60cbeb43aa3dbd9a0a43f61
Closes-Bug: #1597551
This commit is contained in:
Jianghua Wang 2016-09-06 11:14:05 +08:00
parent ab5e67f8ea
commit 676babbd9a
2 changed files with 6 additions and 2 deletions

View File

@ -32,7 +32,8 @@ class BandwidthTestCase(plugin_test.PluginTestBase):
'if|bw_in i1 i2 i3 i4 i5 i6 i7|bw_out o1 o2 o3 o4 o5 o6 o7',
'xenbr1: 1 0 0 0 0 0 0 0 11 0 0 0 0 0 0 0',
'vif2.0: 2 0 0 0 0 0 0 0 12 0 0 0 0 0 0 0',
'vif2.1: 3 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0\n']
'vif2.1: 3 0 0 0 0 0 0 0 13 0 0 0 0 0 0 0',
'vifabcd1234-c: 4 0 0 0 0 0 0 0 14 0 0 0 0 0 0 0\n']
expect_devmap = {'2': {'1': {'bw_in': 13, 'bw_out': 3},
'0': {'bw_in': 12, 'bw_out': 2}
}

View File

@ -24,6 +24,8 @@ import utils
import pluginlib_nova
import re
pluginlib_nova.configure_logging('bandwidth')
@ -40,7 +42,8 @@ def _get_bandwitdth_from_proc():
devs = [l.strip() for l in _read_proc_net()]
# ignore headers
devs = devs[2:]
dlist = [d.split(':', 1) for d in devs if d.startswith('vif')]
vif_pattern = re.compile("^vif(\d+)\.(\d+)")
dlist = [d.split(':', 1) for d in devs if vif_pattern.match(d)]
devmap = dict()
for name, stats in dlist:
slist = stats.split()