Nir Soffer has uploaded a new change for review.
Change subject: netinfo: Replace misused asserts with InvalidConfiguration
......................................................................
netinfo: Replace misused asserts with InvalidConfiguration
The code was assuming that asserts are always available, and if running
with in optimized mode, the code would skip the assert and use invalid
configuration, possibly corrupting application state or failing with
unrelated errors, hiding the root cause of the error.
The asserts are replaced now with new InvalidConfiguration exception and
the error messages are improved.
Change-Id: I99ee49aa7e2364f57112e2452e3eab3940b6b00a
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M lib/vdsm/netinfo.py
1 file changed, 17 insertions(+), 5 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/61/34361/1
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index d818249..e848abc 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -84,6 +84,10 @@
DUMMY_BRIDGE # Appease flake8 since dummy bridge should be exported from here
+class InvalidConfiguration(Exception):
+ """ Raise when getting an invalid conifguration """
+
+
def _visible_devs(predicate):
"""Returns a list of visible (vdsm manageable) links for which the
predicate is True"""
@@ -834,8 +838,9 @@
bondings = [b for (b, attrs) in self.bondings.iteritems() if
nic in attrs['slaves']]
if bondings:
- assert len(bondings) == 1, \
- "Unexpected configuration: More than one bonding per nic"
+ if len(bondings) != 1:
+ raise InvalidConfiguration(
+ "Unexpected configuration: More than one bonding per nic")
return bondings[0]
return None
@@ -853,13 +858,20 @@
for port in ports:
if port in self.vlans:
- assert vlan is None
+ if vlan is not None:
+ raise InvalidConfiguration(
+ "Unexpected vlan: %s exepected: None" % (vlan,))
nic = getVlanDevice(port)
vlan = getVlanID(port)
- assert self.vlans[port]['iface'] == nic
+ if self.vlans[port]['iface'] != nic:
+ raise InvalidConfiguration(
+ "Unexpected iface: %s expected: %s" %
+ (self.vlans[port]['iface'], nic))
port = nic
if port in self.bondings:
- assert bonding is None
+ if bonding is not None:
+ raise InvalidConfiguration(
+ "Unexpected bonding: %s expected: None" % bonding)
bonding = port
lnics += self.bondings[bonding]['slaves']
elif port in self.nics:
--
To view, visit
http://gerrit.ovirt.org/34361
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I99ee49aa7e2364f57112e2452e3eab3940b6b00a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>