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

ibarkan at redhat.com ibarkan at redhat.com
Thu Nov 27 16:39:32 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: Icb26c288b8f466e5f1009d889dacf3e17d45891c
Signed-off-by: ibarkan <ibarkan at redhat.com>
---
M vdsm/network/api.py
1 file changed, 53 insertions(+), 37 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/35691/1

diff --git a/vdsm/network/api.py b/vdsm/network/api.py
index 6843789..1fa4445 100755
--- a/vdsm/network/api.py
+++ b/vdsm/network/api.py
@@ -600,6 +600,55 @@
         topNetDev.remove()
 
 
+def _add_missing_networks(configurator, networks_to_add, bondings, force,
+                          logger, _netinfo=None):
+    # We need to use the newest host info
+    if _netinfo is None:
+        _netinfo = netinfo.NetInfo()
+    else:
+        _netinfo.updateDevices()
+
+    for network, attrs in networks_to_add.iteritems():
+        d = dict(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, attrs,
+                                         configurator)
+            raise
+
+        _netinfo.updateDevices()  # Things like a bond mtu can change
+
+
+def _check_connectivity(connectivity_check_networks, networks, bondings,
+                        options, logger):
+    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.
 
@@ -701,44 +750,11 @@
 
         _handleBondings(bondings, configurator)
 
-        # We need to use the newest host info
-        _netinfo.updateDevices()
-        for network, attrs in networks_to_add.iteritems():
-            d = dict(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, _netinfo)
 
-            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, 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(connectivity_check_networks, networks, bondings,
+                            options, logger)
 
     hooks.after_network_setup(_buildSetupHookDict(networks, bondings, options))
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb26c288b8f466e5f1009d889dacf3e17d45891c
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