Mark Wu has uploaded a new change for review.

Change subject: Extract bonding options building into a separate function.
......................................................................

Extract bonding options building into a separate function.

To make setupNetworks shorter, move the bonding options building code
into a separate function.

Signed-off-by: Mark Wu <[email protected]>
Change-Id: I77fefefcefa05f5bd0d7fa2755357d88b7aa615e
---
M vdsm/configNetwork.py
1 file changed, 30 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/85/8885/1

diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index 3940446..6de38e3 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -1249,6 +1249,30 @@
             del bondings[bond]
 
 
+def _buildBondOptions(bondName, bondings):
+    logger = logging.getLogger("_buildBondOptions")
+
+    # We need to use the newest host info
+    _ni = netinfo.NetInfo()
+
+    bond = {}
+    if bondings.get(bondName):
+        bond['nics'] = bondings[bondName]['nics']
+        bond['bondingOptions'] = bondings[bondName].get('options', None)
+    elif bondName in _ni.bondings:
+        # We may not receive any information about the bonding device if it is
+        # unchanged. In this case check whether this bond exists on host and
+        # take its parameters.
+        logger.debug("Fetching bond %r info", bondName)
+        existingBond = _ni.bondings[bondName]
+        bond['nics'] = existingBond['slaves']
+        bond['bondingOptions'] = existingBond['cfg'].get('BONDING_OPTS', None)
+    else:
+        raise ConfigNetworkError(ne.ERR_BAD_PARAMS, "No given bonding option, \
+                                 nor existing bond %s found." % bondName)
+    return bond
+
+
 def setupNetworks(networks={}, bondings={}, **options):
     """Add/Edit/Remove configuration for networks and bondings.
 
@@ -1292,12 +1316,6 @@
         _netinfo = netinfo.NetInfo()
         configWriter = ConfigWriter()
         networksAdded = set()
-        # keep set netsWithNewBonds to be able remove
-        # a new added network if connectivity check fail.
-        # If a new network needs to be created on top of existing bond,
-        # we will need to keep the bond on rollback flow,
-        # else we will break the new created bond.
-        netsWithNewBonds = set()
 
         logger.debug("Setting up network according to configuration: "
                      "networks:%r, bondings:%r, options:%r" % (networks,
@@ -1327,28 +1345,10 @@
             # Check whether bonds should be resized
             _editBondings(bondings, configWriter)
 
-            # We need to use the newest host info
-            _ni = netinfo.NetInfo()
             for network, networkAttrs in networks.iteritems():
                 d = dict(networkAttrs)
                 if 'bonding' in d:
-                    # we may not receive any information
-                    # about the bonding device if it is unchanged
-                    # In this case check whether this bond exists
-                    # on host and take its parameters
-                    if bondings.get(d['bonding']):
-                        d['nics'] = bondings[d['bonding']]['nics']
-                        d['bondingOptions'] = \
-                           bondings[d['bonding']].get('options', None)
-                        # we create a new bond
-                        if network in networksAdded:
-                            netsWithNewBonds.add(network)
-                    elif d['bonding'] in _ni.bondings:
-                        logger.debug("Updating bond %r info", d['bonding'])
-                        d['nics'] = _ni.bondings[d['bonding']]['slaves']
-                        d['bondingOptions'] = \
-                            _ni.bondings[d['bonding']]['cfg'].get(
-                                                         'BONDING_OPTS', None)
+                    d.update(_buildBondOptions(d['bonding'], bondings))
                 else:
                     d['nics'] = [d.pop('nic')]
                 d['force'] = force
@@ -1363,8 +1363,11 @@
                                       CONNECTIVITY_TIMEOUT_DEFAULT))):
                     logger.info('Connectivity check failed, rolling back')
                     for network in networksAdded:
-                        delNetwork(network, force=True,
-                                   implicitBonding=network in netsWithNewBonds)
+                        # If the new added network was created on top of
+                        # existing bond, we need to keep the bond on rollback
+                        # flow, else we will break the new created bond.
+                        isNew = networkAttrs['bonding'] in bondings
+                        delNetwork(network, force=True, implicitBonding=isNew)
                     raise ConfigNetworkError(ne.ERR_LOST_CONNECTION,
                                              'connectivity check failed')
         except:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I77fefefcefa05f5bd0d7fa2755357d88b7aa615e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Mark Wu <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to