Change in vdsm[master]: netinfo: 'interface' may be an empty element, so fix an exis...

osvoboda at redhat.com osvoboda at redhat.com
Mon Mar 2 19:22:23 UTC 2015


Ondřej Svoboda has uploaded a new change for review.

Change subject: netinfo: 'interface' may be an empty element, so fix an existence test
......................................................................

netinfo: 'interface' may be an empty element, so fix an existence test

A network's interface was previously obtained by getElementsByTagName() which
returns a list. ElementTree's find(), however, returns the first element of
such a list (unlike findall() which is a counterpart of getElementsByTagName).

Since the 'interface' element may be empty and its boolean value is tied to
the number of its subelements we have to check against None this time,
otherwise 0 (the length) is interpreted as a negative condition.

An example of an empty 'interface':
  <interface dev='bond11'/>

Change-Id: I54ad89e7ac307fc6bc7f48a45d00b0f3a177cd58
Signed-off-by: Ondřej Svoboda <osvoboda at redhat.com>
---
M lib/vdsm/netinfo.py
1 file changed, 3 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/94/38294/1

diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index 007f127..0e06503 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -115,7 +115,9 @@
             nets[netname] = {}
             xml = etree.fromstring(net.XMLDesc(0))
             interfaces = xml.find('.//interface')
-            if interfaces:
+            # len() called on an empty Element like "<interface dev='bond11'/>"
+            # returns 0 so we have to test against None
+            if interfaces is not None:
                 nets[netname]['iface'] = interfaces.get('dev')
                 nets[netname]['bridged'] = False
             else:


-- 
To view, visit https://gerrit.ovirt.org/38294
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I54ad89e7ac307fc6bc7f48a45d00b0f3a177cd58
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <osvoboda at redhat.com>


More information about the vdsm-patches mailing list