Change in vdsm[master]: net: api: drop isolatedCommand handling
phoracek at redhat.com
phoracek at redhat.com
Fri Feb 12 15:49:39 UTC 2016
Petr Horáček has uploaded a new change for review.
Change subject: net: api: drop isolatedCommand handling
......................................................................
net: api: drop isolatedCommand handling
Since addNetwork and delNetwork API was dropped, we don't need
isolatedCommand handling anymore.
Change-Id: If6aa5052eb63a90269bdad8fa543fdb2ef0c8bc7
Signed-off-by: Petr Horáček <phoracek at redhat.com>
---
M lib/vdsm/network/api.py
M tests/configNetworkTests.py
2 files changed, 25 insertions(+), 40 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/81/53481/1
diff --git a/lib/vdsm/network/api.py b/lib/vdsm/network/api.py
index 2dcaf0f..de8df5e 100644
--- a/lib/vdsm/network/api.py
+++ b/lib/vdsm/network/api.py
@@ -192,34 +192,22 @@
attrs = kwargs.copy()
attrs.update(dict(zip(spec.args, args)))
- isolatedCommand = attrs.get('configurator') is None
- # Detect if we are running an isolated command, i.e., a command that is
- # not called as part of composed API operation like setupNetworks, but
- # rather as its own API verb. This is necessary in order to maintain
- # behavior of the addNetwork and delNetwork API verbs
- if isolatedCommand:
- attrs['configurator'] = configurator = ConfiguratorClass()
- configurator.begin()
- else:
- configurator = attrs['configurator']
-
ret = func(**attrs)
+ configurator = attrs['configurator']
if func.__name__ == '_delNetwork':
configurator.runningConfig.removeNetwork(attrs.pop('network'))
else:
configurator.runningConfig.setNetwork(attrs.pop('network'), attrs)
- if isolatedCommand: # Commit the no-rollback transaction.
- configurator.commit()
return ret
return wrapped
@_alterRunningConfig
-def _addNetwork(network, vlan=None, bonding=None, nic=None, ipaddr=None,
- netmask=None, prefix=None, mtu=None, gateway=None, dhcpv6=None,
- ipv6addr=None, ipv6gateway=None, ipv6autoconf=None,
- configurator=None, bridged=True, _netinfo=None, hostQos=None,
+def _addNetwork(network, configurator, vlan=None, bonding=None, nic=None,
+ ipaddr=None, netmask=None, prefix=None, mtu=None, gateway=None,
+ dhcpv6=None, ipv6addr=None, ipv6gateway=None,
+ ipv6autoconf=None, bridged=True, _netinfo=None, hostQos=None,
defaultRoute=None, blockingdhcp=False, **options):
if _netinfo is None:
_netinfo = CachingNetInfo()
@@ -254,9 +242,6 @@
logging.info('Adding network %s with vlan=%s, bonding=%s, nic=%s, '
'mtu=%s, bridged=%s, defaultRoute=%s, options=%s', network,
vlan, bonding, nic, mtu, bridged, defaultRoute, options)
-
- if configurator is None:
- configurator = ConfiguratorClass()
bootproto = options.pop('bootproto', None)
@@ -368,7 +353,7 @@
libvirt.removeNetwork(network)
configurator.runningConfig.removeNetwork(network)
return
- _delNetwork(network, configurator=configurator, bypassValidation=True,
+ _delNetwork(network, configurator, bypassValidation=True,
implicitBonding=False, _netinfo=_netinfo)
@@ -401,14 +386,11 @@
@_alterRunningConfig
-def _delNetwork(network, vlan=None, bonding=None, bypassValidation=False,
- configurator=None, implicitBonding=True, _netinfo=None,
+def _delNetwork(network, configurator, vlan=None, bonding=None,
+ bypassValidation=False, implicitBonding=True, _netinfo=None,
keep_bridge=False, **options):
if _netinfo is None:
_netinfo = CachingNetInfo()
-
- if configurator is None:
- configurator = ConfiguratorClass()
if network not in _netinfo.networks:
logging.info("Network %r: doesn't exist in libvirt database", network)
@@ -731,8 +713,8 @@
logger.debug("Adding network %r", network)
try:
- _addNetwork(network, configurator=configurator,
- implicitBonding=True, _netinfo=_netinfo, **attrs)
+ _addNetwork(network, configurator, implicitBonding=True,
+ _netinfo=_netinfo, **attrs)
except ConfigNetworkError as cne:
if cne.errCode == ne.ERR_FAILED_IFUP:
logger.debug("Adding network %r failed. Running "
@@ -758,9 +740,10 @@
# 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, bypassValidation=True,
- implicitBonding=networks[network].
- get('bonding') in bondings)
+ _delNetwork(network, ConfiguratorClass(),
+ bypassValidation=True,
+ implicitBonding=networks[network].get('bonding')
+ in bondings)
raise ConfigNetworkError(ne.ERR_LOST_CONNECTION,
'connectivity check failed')
@@ -882,9 +865,8 @@
net_kernel_config=kernel_config.networks[network]
)
- _delNetwork(network, configurator=configurator,
- implicitBonding=False, _netinfo=_netinfo,
- keep_bridge=keep_bridge)
+ _delNetwork(network, configurator, implicitBonding=False,
+ _netinfo=_netinfo, keep_bridge=keep_bridge)
_netinfo.del_network(network)
_netinfo.updateDevices()
elif network in libvirt_nets:
diff --git a/tests/configNetworkTests.py b/tests/configNetworkTests.py
index afe6d4d..181d730 100644
--- a/tests/configNetworkTests.py
+++ b/tests/configNetworkTests.py
@@ -46,12 +46,6 @@
class TestConfigNetwork(TestCaseBase):
- def _addNetworkWithExc(self, netName, opts, errCode):
- with self.assertRaises(errors.ConfigNetworkError) as cneContext:
- canonize_networks({netName: opts})
- api._addNetwork(netName, **opts)
- self.assertEqual(cneContext.exception.errCode, errCode)
-
# Monkey patch the real network detection from the netinfo module.
@MonkeyPatch(netinfo, 'networks', _fakeNetworks)
@MonkeyPatch(mtus, 'getMaxMtu', lambda *x: 1500)
@@ -63,6 +57,15 @@
@MonkeyPatch(Nic, 'configure', lambda *x: _raiseInvalidOpException())
@MonkeyPatch(Vlan, 'configure', lambda *x: _raiseInvalidOpException())
def testAddNetworkValidation(self):
+
+ configurator = api.ConfiguratorClass()
+
+ def _addNetworkWithExc(self, netName, opts, errCode):
+ with self.assertRaises(errors.ConfigNetworkError) as cneContext:
+ canonize_networks({netName: opts})
+ api._addNetwork(netName, configurator, **opts)
+ self.assertEqual(cneContext.exception.errCode, errCode)
+
_netinfo = {
'networks': {
'fakent': {'iface': 'fakeint', 'bridged': False},
--
To view, visit https://gerrit.ovirt.org/53481
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If6aa5052eb63a90269bdad8fa543fdb2ef0c8bc7
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Petr Horáček <phoracek at redhat.com>
More information about the vdsm-patches
mailing list