Change in vdsm[master]: factor out parts of setupNetworks for better readability

ibarkan at redhat.com ibarkan at redhat.com
Thu Nov 27 12:11:06 UTC 2014


Ido Barkan has uploaded a new change for review.

Change subject: factor out parts of setupNetworks for better readability
......................................................................

factor out parts of setupNetworks for better readability

Change-Id: I0c3355aab2804ffaaf8b611de224ef3d2e616eef
Signed-off-by: ibarkan <ibarkan at redhat.com>
---
M vdsm/network/api.py
1 file changed, 50 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/59/35659/1

diff --git a/vdsm/network/api.py b/vdsm/network/api.py
index 5650703..f8ad505 100755
--- a/vdsm/network/api.py
+++ b/vdsm/network/api.py
@@ -600,6 +600,52 @@
         topNetDev.remove()
 
 
+def _add_missing_networks(configurator, networks_to_add, bondings, force,
+                          logger):
+    # We need to use the newest host info
+    _netinfo = netinfo.NetInfo()
+    _netinfo.updateDevices()
+    for network, network_attrs in networks_to_add.iteritems():
+        d = dict(network_attrs)
+        if 'bonding' in d:
+            d.update(_buildBondOptions(d['bonding'], bondings, _netinfo))
+        else:
+            d['nics'] = [d.pop('nic')] if 'nic' in d else []
+        d['force'] = force
+
+        logger.debug("Adding network %r", network)
+        try:
+            addNetwork(network, configurator=configurator,
+                       implicitBonding=True, _netinfo=_netinfo, **d)
+        except ConfigNetworkError as cne:
+            if cne.errCode == ne.ERR_FAILED_IFUP:
+                logger.debug("Adding network %r failed. Running "
+                             "orphan-devices cleanup", network)
+                _emergencyNetworkCleanup(network, network_attrs,
+                                         configurator)
+            raise
+
+        _netinfo.updateDevices()  # Things like a bond mtu can change
+
+
+def _check_connectivity(bondings, connectivity_check_networks, logger,
+                        networks, options):
+    if utils.tobool(options.get('connectivityCheck', True)):
+        logger.debug('Checking connectivity...')
+        if not clientSeen(int(options.get('connectivityTimeout',
+                                          CONNECTIVITY_TIMEOUT_DEFAULT))):
+            logger.info('Connectivity check failed, rolling back')
+            for network in connectivity_check_networks:
+                # 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.
+                delNetwork(network, force=True,
+                           implicitBonding=networks[network].
+                           get('bonding') in bondings)
+            raise ConfigNetworkError(ne.ERR_LOST_CONNECTION,
+                                     'connectivity check failed')
+
+
 def setupNetworks(networks, bondings, **options):
     """Add/Edit/Remove configuration for networks and bondings.
 
@@ -700,44 +746,11 @@
 
         _handleBondings(bondings, configurator)
 
-        # We need to use the newest host info
-        _netinfo.updateDevices()
-        for network, network_attrs in networks_to_add.iteritems():
-            d = dict(network_attrs)
-            if 'bonding' in d:
-                d.update(_buildBondOptions(d['bonding'], bondings, _netinfo))
-            else:
-                d['nics'] = [d.pop('nic')] if 'nic' in d else []
-            d['force'] = force
+        _add_missing_networks(configurator, networks_to_add, bondings, force,
+                              logger)
 
-            logger.debug("Adding network %r", network)
-            try:
-                addNetwork(network, configurator=configurator,
-                           implicitBonding=True, _netinfo=_netinfo, **d)
-            except ConfigNetworkError as cne:
-                if cne.errCode == ne.ERR_FAILED_IFUP:
-                    logger.debug("Adding network %r failed. Running "
-                                 "orphan-devices cleanup", network)
-                    _emergencyNetworkCleanup(network, network_attrs,
-                                             configurator)
-                raise
-
-            _netinfo.updateDevices()  # Things like a bond mtu can change
-
-        if utils.tobool(options.get('connectivityCheck', True)):
-            logger.debug('Checking connectivity...')
-            if not clientSeen(int(options.get('connectivityTimeout',
-                                  CONNECTIVITY_TIMEOUT_DEFAULT))):
-                logger.info('Connectivity check failed, rolling back')
-                for network in connectivity_check_networks:
-                    # 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.
-                    delNetwork(network, force=True,
-                               implicitBonding=networks[network].
-                               get('bonding') in bondings)
-                raise ConfigNetworkError(ne.ERR_LOST_CONNECTION,
-                                         'connectivity check failed')
+        _check_connectivity(bondings, connectivity_check_networks, logger,
+                            networks, options)
 
     hooks.after_network_setup(_buildSetupHookDict(networks, bondings, options))
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0c3355aab2804ffaaf8b611de224ef3d2e616eef
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ido Barkan <ibarkan at redhat.com>


More information about the vdsm-patches mailing list