Ido Barkan has uploaded a new change for review. Change subject: net: rename NetInfo to CachingNetInfo ......................................................................
net: rename NetInfo to CachingNetInfo This explains more of what it should do- caching network information. Additional buisness logic should be extracted out of it in order to be available to everyone and leave CachingNetInfo to do exactly one thing. Change-Id: Ic7f24a30d467d6f507f6830767f072734d58d0fa Signed-off-by: Ido Barkan <[email protected]> --- M lib/vdsm/netinfo/__init__.py M lib/vdsm/network/api.py M lib/vdsm/network/models.py M lib/vdsm/tool/unified_persistence.py M tests/configNetworkTests.py M tests/functional/utils.py M tests/netUnifiedPersistenceTests.py M tests/netmodelsTests.py M vdsm/vdsm-restore-net-config M vdsm_hooks/ovs/ovs_before_network_setup_ovs.py 10 files changed, 28 insertions(+), 27 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/98/49998/1 diff --git a/lib/vdsm/netinfo/__init__.py b/lib/vdsm/netinfo/__init__.py index d0921d1..765cada 100644 --- a/lib/vdsm/netinfo/__init__.py +++ b/lib/vdsm/netinfo/__init__.py @@ -217,7 +217,7 @@ return data -class NetInfo(object): +class CachingNetInfo(object): def __init__(self, _netinfo=None): if _netinfo is None: _netinfo = get() diff --git a/lib/vdsm/network/api.py b/lib/vdsm/network/api.py index c31111e..c3ed8b8 100755 --- a/lib/vdsm/network/api.py +++ b/lib/vdsm/network/api.py @@ -33,7 +33,7 @@ from vdsm import kernelconfig from vdsm import netconfpersistence from vdsm.netinfo import (addresses, libvirtNets2vdsm, bridges, - get as netinfo_get, NetInfo, + get as netinfo_get, CachingNetInfo, networks as netinfo_networks, nics as netinfo_nics, NET_PATH) from vdsm import udevadm @@ -128,7 +128,7 @@ if configurator is None: configurator = ConfiguratorClass() if _netinfo is None: - _netinfo = NetInfo() + _netinfo = CachingNetInfo() if opts is None: opts = {} if bootproto == 'none': @@ -256,7 +256,7 @@ defaultRoute=None, blockingdhcp=False, **options): nics = nics or () if _netinfo is None: - _netinfo = NetInfo() + _netinfo = CachingNetInfo() bridged = utils.tobool(bridged) if dhcpv6 is not None: dhcpv6 = utils.tobool(dhcpv6) @@ -354,7 +354,7 @@ def showNetwork(network): - _netinfo = NetInfo() + _netinfo = CachingNetInfo() if network not in _netinfo.networks: print("Network %r doesn't exist" % network) return @@ -380,7 +380,7 @@ def listNetworks(): - _netinfo = NetInfo() + _netinfo = CachingNetInfo() print("Networks:", _netinfo.networks.keys()) print("Vlans:", _netinfo.vlans.keys()) print("Nics:", _netinfo.nics.keys()) @@ -390,7 +390,7 @@ def _delBrokenNetwork(network, netAttr, configurator): '''Adapts the network information of broken networks so that they can be deleted via _delNetwork.''' - _netinfo = NetInfo() + _netinfo = CachingNetInfo() _netinfo.networks[network] = netAttr _netinfo.networks[network]['dhcpv4'] = False @@ -445,7 +445,7 @@ configurator=None, implicitBonding=True, _netinfo=None, keep_bridge=False, **options): if _netinfo is None: - _netinfo = NetInfo() + _netinfo = CachingNetInfo() if configurator is None: configurator = ConfiguratorClass() @@ -645,7 +645,7 @@ """ Add/Edit/Remove bond interface """ logger = logging.getLogger("_handleBondings") - _netinfo = NetInfo() + _netinfo = CachingNetInfo() edition = [] addition = [] @@ -732,7 +732,7 @@ def _emergencyNetworkCleanup(network, networkAttrs, configurator): """Remove all leftovers after failed setupNetwork""" - _netinfo = NetInfo() + _netinfo = CachingNetInfo() topNetDev = None if 'bonding' in networkAttrs: @@ -759,7 +759,7 @@ _netinfo=None): # We need to use the newest host info if _netinfo is None: - _netinfo = NetInfo() + _netinfo = CachingNetInfo() else: _netinfo.updateDevices() @@ -901,7 +901,8 @@ bondings, networks, options = _apply_hook(bondings, networks, options) libvirt_nets = netinfo_networks() - _netinfo = NetInfo(_netinfo=netinfo_get(libvirtNets2vdsm(libvirt_nets))) + _netinfo = CachingNetInfo(_netinfo=netinfo_get( + libvirtNets2vdsm(libvirt_nets))) connectivity_check_networks = set() logger.debug("Applying...") diff --git a/lib/vdsm/network/models.py b/lib/vdsm/network/models.py index 2fa5c0a..a5609fd 100644 --- a/lib/vdsm/network/models.py +++ b/lib/vdsm/network/models.py @@ -22,7 +22,7 @@ import socket import struct -from vdsm.netinfo import bonding, ifaceUsed, mtus, nics, NetInfo +from vdsm.netinfo import bonding, ifaceUsed, mtus, nics, CachingNetInfo from .errors import ConfigNetworkError from . import errors as ne @@ -77,7 +77,7 @@ def __init__(self, name, configurator, ipv4=None, ipv6=None, blockingdhcp=False, mtu=None, _netinfo=None): if _netinfo is None: - _netinfo = NetInfo() + _netinfo = CachingNetInfo() if name not in _netinfo.nics: raise ConfigNetworkError(ne.ERR_BAD_NIC, 'unknown nic: %s' % name) diff --git a/lib/vdsm/tool/unified_persistence.py b/lib/vdsm/tool/unified_persistence.py index 92fa9b6..1975f9c 100644 --- a/lib/vdsm/tool/unified_persistence.py +++ b/lib/vdsm/tool/unified_persistence.py @@ -23,7 +23,7 @@ from .. import utils from ..config import config from ..netconfpersistence import RunningConfig -from ..netinfo import NetInfo +from ..netinfo import CachingNetInfo from ..netinfo import misc, routes from . import expose from .upgrade import apply_upgrade @@ -128,7 +128,7 @@ return bondings - netinfo = NetInfo() + netinfo = CachingNetInfo() networks = _processNetworks(netinfo) bonds = _processBondings(netinfo) diff --git a/tests/configNetworkTests.py b/tests/configNetworkTests.py index 9779bbd..a5fd33f 100644 --- a/tests/configNetworkTests.py +++ b/tests/configNetworkTests.py @@ -93,7 +93,7 @@ 'bondings': {'bond00': {'slaves': ['eth5', 'eth6']}} } - fakeInfo = netinfo.NetInfo(_netinfo) + fakeInfo = netinfo.CachingNetInfo(_netinfo) nics = ['eth2'] # Test for already existing bridge. @@ -157,7 +157,7 @@ api._buildBondOptions('jamesbond', {}, _netinfo=FakeNetInfo()) self.assertEquals(cne.exception.errCode, errors.ERR_BAD_PARAMS) - @MonkeyPatch(netinfo, 'NetInfo', lambda: None) + @MonkeyPatch(netinfo, 'CachingNetInfo', lambda: None) def testValidateNetSetupRemoveParamValidation(self): attrs = dict(nic='dummy', remove=True, bridged=True) diff --git a/tests/functional/utils.py b/tests/functional/utils.py index 404a711..a71fd08 100644 --- a/tests/functional/utils.py +++ b/tests/functional/utils.py @@ -117,7 +117,7 @@ def _get_netinfo(self): response = self.getVdsCapabilities() try: - return netinfo.NetInfo(response[2]) + return netinfo.CachingNetInfo(response[2]) except IndexError: raise Exception('VdsProxy: getVdsCapabilities failed. ' 'code:%s msg:%s' % (response[0], response[1])) diff --git a/tests/netUnifiedPersistenceTests.py b/tests/netUnifiedPersistenceTests.py index 540d962..bd69773 100644 --- a/tests/netUnifiedPersistenceTests.py +++ b/tests/netUnifiedPersistenceTests.py @@ -144,7 +144,7 @@ with _fake_ifcfgs() as ifcfgs_dir: FAKE_NET_CONF_PREF = ifcfgs_dir + '/ifcfg-' with MonkeyPatchScope( - [(unified_persistence, 'NetInfo', _FakeNetInfo), + [(unified_persistence, 'CachingNetInfo', _FakeNetInfo), (misc, 'NET_CONF_PREF', FAKE_NET_CONF_PREF)]): networks, bonds = unified_persistence._getNetInfo() diff --git a/tests/netmodelsTests.py b/tests/netmodelsTests.py index 82a2669..00f1254 100644 --- a/tests/netmodelsTests.py +++ b/tests/netmodelsTests.py @@ -21,7 +21,7 @@ # import os -from vdsm.netinfo import bonding, mtus, NetInfo +from vdsm.netinfo import bonding, mtus, CachingNetInfo from vdsm.network import errors from vdsm.network.models import Bond, Bridge, IPv4, IPv6, Nic, Vlan from vdsm.network.models import hierarchy_backing_device, hierarchy_vlan_tag @@ -135,7 +135,7 @@ _netinfo = {'networks': {}, 'vlans': {}, 'nics': ['testnic1', 'testnic2'], 'bondings': {}, 'bridges': {}} - fakeInfo = NetInfo(_netinfo) + fakeInfo = CachingNetInfo(_netinfo) nic1 = Nic('testnic1', None, _netinfo=fakeInfo) nic2 = Nic('testnic2', None, _netinfo=fakeInfo) bond1 = Bond('bond42', None, slaves=(nic1, nic2)) @@ -171,7 +171,7 @@ _netinfo = {'networks': {}, 'vlans': {}, 'nics': ['testnic1', 'testnic2'], 'bondings': {}, 'bridges': {}} - fakeInfo = NetInfo(_netinfo) + fakeInfo = CachingNetInfo(_netinfo) # Vlanned and bonded VM network nic1 = Nic('testnic1', configurator=None, _netinfo=fakeInfo) nic2 = Nic('testnic2', configurator=None, _netinfo=fakeInfo) diff --git a/vdsm/vdsm-restore-net-config b/vdsm/vdsm-restore-net-config index 08e7a87..74d1bdd 100755 --- a/vdsm/vdsm-restore-net-config +++ b/vdsm/vdsm-restore-net-config @@ -30,7 +30,7 @@ from vdsm.config import config from vdsm import ipwrapper -from vdsm.netinfo import nics, misc, NetInfo +from vdsm.netinfo import nics, misc, CachingNetInfo from vdsm import kernelconfig from vdsm.constants import P_VDSM_RUN from vdsm.netconfpersistence import RunningConfig, PersistentConfig, \ @@ -237,7 +237,7 @@ """filter-out unchanged networks and bond, so that we are left only with changes that must be applied""" - kernel_config = kernelconfig.KernelConfig(NetInfo()) + kernel_config = kernelconfig.KernelConfig(CachingNetInfo()) normalized_config = kernelconfig.normalize(persistent_config) changed_bonds_names = _find_changed_or_missing(normalized_config.bonds, diff --git a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py index 5f38773..29abf45 100644 --- a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py +++ b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py @@ -22,7 +22,7 @@ import six -from vdsm.netinfo import NetInfo +from vdsm.netinfo import CachingNetInfo import hooking @@ -255,7 +255,7 @@ def _handle_setup(nets, bonds, running_config, nets_by_nic): commands = [] - netinfo = NetInfo() + netinfo = CachingNetInfo() for bond, attrs in six.iteritems(bonds): if 'remove' not in attrs: _validate_bond_configuration(attrs, netinfo) -- To view, visit https://gerrit.ovirt.org/49998 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic7f24a30d467d6f507f6830767f072734d58d0fa Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Ido Barkan <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
