Change in vdsm[master]: Fix checking bonding options for missing bonds.

asegurap at redhat.com asegurap at redhat.com
Mon Mar 4 22:02:25 UTC 2013


Antoni Segura Puimedon has uploaded a new change for review.

Change subject: Fix checking bonding options for missing bonds.
......................................................................

Fix checking bonding options for missing bonds.

Right up until now, we were checking the options for a bond A
that would have to be potentially created by checking for the
existance of /sys/class/net/A/bonding/<opt>. Obviously, if the
bond had not been created at that point, the option validation
would fail.

This patch makes the option validation be done on whichever bond
is present on the system and, if none are, it creates the bond
to check the options.

Change-Id: I023a5bb8a52719559bb9d4716f25e0cba8b3530b
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
Bug-Url: https://bugzilla.redhat.com/649239
---
M vdsm/configNetwork.py
1 file changed, 34 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/01/12701/1

diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index f245af1..dedcaf3 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -27,6 +27,7 @@
 import logging
 import threading
 from xml.sax.saxutils import escape
+from contextlib import contextmanager
 import glob
 import socket
 import shutil
@@ -47,6 +48,8 @@
 MAX_BRIDGE_NAME_LEN = 15
 ILLEGAL_BRIDGE_CHARS = frozenset(':. \t')
 DEFAULT_MTU = '1500'
+
+BONDING_MASTERS = '/sys/class/net/bonding_masters'
 
 
 class ConfigNetworkError(Exception):
@@ -493,9 +496,8 @@
                              bootproto, mtu, onboot, **kwargs)
 
         # create the bonding device to avoid initscripts noise
-        bondMastersPath = '/sys/class/net/bonding_masters'
-        if bonding not in open(bondMastersPath).read().split():
-            open(bondMastersPath, 'w').write('+%s\n' % bonding)
+        if bonding not in open(BONDING_MASTERS).read().split():
+            open(BONDING_MASTERS, 'w').write('+%s\n' % bonding)
 
     def addNic(self, nic, bonding=None, bridge=None, mtu=None,
                ipaddr=None, netmask=None, gateway=None, bootproto=None,
@@ -727,16 +729,36 @@
 
 def validateBondingOptions(bonding, bondingOptions):
     'Example: BONDING_OPTS="mode=802.3ad miimon=150"'
+    with validationBond(bonding) as bond:
+        try:
+            for option in bondingOptions.split():
+                key, value = option.split('=')
+                if not os.path.exists(
+                        '/sys/class/net/%s/bonding/%s' % (bond, key)):
+                    raise ConfigNetworkError(ne.ERR_BAD_BONDING, '%r is not a '
+                                             'valid bonding option' % key)
+        except ValueError:
+            raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Error parsing '
+                                     'bonding options: %r' % bondingOptions)
+
+
+ at contextmanager
+def validationBond(bonding):
+    bond_created = False
     try:
-        for option in bondingOptions.split():
-            key, value = option.split('=')
-            if not os.path.exists(
-                    '/sys/class/net/%(bonding)s/bonding/%(key)s' % locals()):
-                raise ConfigNetworkError(ne.ERR_BAD_BONDING, '%r is not a '
-                                         'valid bonding option' % key)
-    except ValueError:
-        raise ConfigNetworkError(ne.ERR_BAD_BONDING, 'Error parsing bonding '
-                                 'options: %r' % bondingOptions)
+        bonding = open(BONDING_MASTERS, 'r').read().split()[0]
+    except IndexError:
+        open(BONDING_MASTERS, 'w').write('+%s\n' % bonding)
+        bond_created = True
+    try:
+        yield bonding
+    except Exception:
+        if bond_created:
+            try:
+                open(BONDING_MASTERS, 'w').write('-%s\n' % bonding)
+            except IOError:
+                pass
+        raise
 
 
 def validateVlanId(vlan):


--
To view, visit http://gerrit.ovirt.org/12701
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I023a5bb8a52719559bb9d4716f25e0cba8b3530b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>


More information about the vdsm-patches mailing list