Hello Dan Kenigsberg, Edward Haas,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/60866

to review the following change.

Change subject: net: common and legacy CachingNetInfo
......................................................................

net: common and legacy CachingNetInfo

CachingNetInfo is not suitable for mixed OVS and Legacy networks.

CachingNetInfo should be used only in legacy networks configuration
where we don't need the whole system netinfo. It contains
updateDevices() method which cannot be easily used with OVS netinfo.

For all the other code newly introduced NetInfo should be used. It
has no implicit arguments. Netinfo dictionary has to be passed to it
every time, so we have full control of its contents.

Legacy netinfo should be divided into NICs netinfo and legacy networks
netinfo.

Change-Id: Ib8c88b1454245364d5dadd4d2baf147658faaef2
Signed-off-by: Petr Horáček <phora...@redhat.com>
Bug-Url: https://bugzilla.redhat.com/1195208
Reviewed-on: https://gerrit.ovirt.org/57441
Reviewed-by: Edward Haas <edwa...@redhat.com>
Continuous-Integration: Jenkins CI
Reviewed-by: Dan Kenigsberg <dan...@redhat.com>
---
M lib/vdsm/network/netinfo/cache.py
M lib/vdsm/tool/unified_persistence.py
M tests/functional/networkTests.py
M tests/network/unified_persistence_test.py
M vdsm/vdsm-restore-net-config
M vdsm_hooks/extra_ipv4_addrs/extra_ipv4_addrs.py
M vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
7 files changed, 39 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/60866/1

diff --git a/lib/vdsm/network/netinfo/cache.py 
b/lib/vdsm/network/netinfo/cache.py
index 43b617c..5676ca7 100644
--- a/lib/vdsm/network/netinfo/cache.py
+++ b/lib/vdsm/network/netinfo/cache.py
@@ -217,21 +217,8 @@
     return data
 
 
-class CachingNetInfo(object):
-    def __init__(self, _netinfo=None):
-        if _netinfo is None:
-            _netinfo = get()
-
-        self.networks = _netinfo['networks']
-        self.vlans = _netinfo['vlans']
-        self.nics = _netinfo['nics']
-        self.bondings = _netinfo['bondings']
-        self.bridges = _netinfo['bridges']
-
-    def updateDevices(self):
-        """Updates the object device information while keeping the cached
-        network information."""
-        _netinfo = get(vdsmnets=self.networks)
+class NetInfo(object):
+    def __init__(self, _netinfo):
         self.networks = _netinfo['networks']
         self.vlans = _netinfo['vlans']
         self.nics = _netinfo['nics']
@@ -354,3 +341,22 @@
             if iface == vdict['iface']:
                 users.add(v)
         return users
+
+
+class CachingNetInfo(NetInfo):
+    def __init__(self, _netinfo=None):
+        if _netinfo is None:
+            _netinfo = get()
+        super(CachingNetInfo, self).__init__(_netinfo)
+
+    def updateDevices(self):
+        """
+        Updates the object device information while keeping the cached network
+        information.
+        """
+        _netinfo = get(vdsmnets=self.networks)
+        self.networks = _netinfo['networks']
+        self.vlans = _netinfo['vlans']
+        self.nics = _netinfo['nics']
+        self.bondings = _netinfo['bondings']
+        self.bridges = _netinfo['bridges']
diff --git a/lib/vdsm/tool/unified_persistence.py 
b/lib/vdsm/tool/unified_persistence.py
index 277732a..9cf6962 100644
--- a/lib/vdsm/tool/unified_persistence.py
+++ b/lib/vdsm/tool/unified_persistence.py
@@ -20,8 +20,9 @@
 import errno
 import logging
 
+from vdsm.network import netswitch
 from vdsm.network.netconfpersistence import RunningConfig
-from vdsm.network.netinfo.cache import CachingNetInfo
+from vdsm.network.netinfo.cache import NetInfo
 from vdsm.network.netinfo import misc, routes
 from .. import utils
 from ..config import config
@@ -128,7 +129,7 @@
 
         return bondings
 
-    netinfo = CachingNetInfo()
+    netinfo = NetInfo(netswitch.netinfo())
     networks = _processNetworks(netinfo)
     bonds = _processBondings(netinfo)
 
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index 004ca93..e7668b8 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -47,6 +47,7 @@
                                               NET_CONF_BACK_DIR)
 from vdsm.network import errors
 from vdsm.network import legacy_switch
+from vdsm.network import netswitch
 from vdsm.network import sourceroute
 from vdsm.network import tc
 
@@ -207,8 +208,8 @@
 def _get_running_and_kernel_config(bare_running_config):
     """:param config: vdsm configuration, could be retrieved from getProxy()
     """
-    bare_kernel_config = kernelconfig.KernelConfig(
-        vdsm.network.netinfo.cache.CachingNetInfo())
+    netinfo = vdsm.network.netinfo.cache.NetInfo(netswitch.netinfo())
+    bare_kernel_config = kernelconfig.KernelConfig(netinfo)
     normalized_running_config = kernelconfig.normalize(bare_running_config)
     # Unify strings to unicode instances so differences are easier to
     # understand. This won't be needed once we move to Python 3.
diff --git a/tests/network/unified_persistence_test.py 
b/tests/network/unified_persistence_test.py
index eebff02..a459cd4 100644
--- a/tests/network/unified_persistence_test.py
+++ b/tests/network/unified_persistence_test.py
@@ -78,6 +78,7 @@
             'netmask': '', 'ipv4addrs': [], 'hwaddr': 'ba:8d:23:4d:d7:41',
             'slaves': [NIC_NAME], 'opts': {'miimon': '150', 'mode': '4',
                                            'arp_all_targets': '0'}}},
+    'bridges': {},
     'networks': {
         NETWORK_NAME: {
             'iface': NETWORK_NAME, 'addr': '', 'cfg': {
@@ -89,10 +90,6 @@
             'ipv4addrs': [], 'mtu': '1500', 'ipv6gateway': '::', 'ports':
             [BOND_NAME + '.' + VLAN]}}}
 
-
-class _FakeNetInfo:
-    def __init__(self):
-        self.__dict__.update(FAKE_NETINFO)
 
 FAKE_IFCFGS = {
     NETWORK_NAME: (
@@ -149,7 +146,8 @@
         with _fake_ifcfgs() as ifcfgs_dir:
             FAKE_NET_CONF_PREF = ifcfgs_dir + '/ifcfg-'
             with MonkeyPatchScope(
-                [(unified_persistence, 'CachingNetInfo', _FakeNetInfo),
+                [(unified_persistence.netswitch, 'netinfo',
+                  lambda: FAKE_NETINFO),
                  (misc, 'NET_CONF_PREF', FAKE_NET_CONF_PREF)]):
                 networks, bonds = unified_persistence._getNetInfo()
 
diff --git a/vdsm/vdsm-restore-net-config b/vdsm/vdsm-restore-net-config
index 125f6e4..8733821 100755
--- a/vdsm/vdsm-restore-net-config
+++ b/vdsm/vdsm-restore-net-config
@@ -33,9 +33,10 @@
 from vdsm import hostdev
 from vdsm.network import ipwrapper
 from vdsm.network import kernelconfig
+from vdsm.network import netswitch
 from vdsm.network.netinfo import nics, misc
 from vdsm.network.netinfo.misc import ipv6_supported
-from vdsm.network.netinfo.cache import CachingNetInfo
+from vdsm.network.netinfo.cache import NetInfo
 from vdsm.constants import P_VDSM_RUN
 from vdsm.network.netconfpersistence import RunningConfig, PersistentConfig, \
     CONF_PERSIST_DIR, BaseConfig
@@ -258,7 +259,7 @@
     """filter-out unchanged networks and bond, so that we are left only with
     changes that must be applied"""
 
-    kernel_config = kernelconfig.KernelConfig(CachingNetInfo())
+    kernel_config = kernelconfig.KernelConfig(NetInfo(netswitch.netinfo()))
     normalized_config = kernelconfig.normalize(persistent_config)
 
     changed_bonds_names = _find_changed_or_missing(normalized_config.bonds,
diff --git a/vdsm_hooks/extra_ipv4_addrs/extra_ipv4_addrs.py 
b/vdsm_hooks/extra_ipv4_addrs/extra_ipv4_addrs.py
index 8b9bb88..c316990 100644
--- a/vdsm_hooks/extra_ipv4_addrs/extra_ipv4_addrs.py
+++ b/vdsm_hooks/extra_ipv4_addrs/extra_ipv4_addrs.py
@@ -24,6 +24,7 @@
 
 from vdsm.network import ipwrapper
 from vdsm.network import netinfo
+from vdsm.network import netswitch
 from vdsm import utils
 
 
@@ -68,8 +69,8 @@
     if utils.tobool(attrs.get('bridged')):
         return network
     # bridgeless
-    nics, vlan, _, bonding = netinfo.cache.CachingNetInfo().\
-        getNicsVlanAndBondingForNetwork(network)
+    nics, vlan, _, bonding = netinfo.cache.NetInfo(
+        netswitch.netinfo()).getNicsVlanAndBondingForNetwork(network)
     return vlan or bonding or nics[0]
 
 
diff --git a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py 
b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
index 8a79568..7bcee58 100644
--- a/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
+++ b/vdsm_hooks/ovs/ovs_before_network_setup_ovs.py
@@ -23,7 +23,8 @@
 
 from vdsm.compat import suppress
 from vdsm.network import libvirt
-from vdsm.network.netinfo.cache import CachingNetInfo
+from vdsm.network import netswitch
+from vdsm.network.netinfo.cache import NetInfo
 from vdsm.network.netinfo.bonding import parse_bond_options
 from vdsm.utils import rget
 
@@ -279,7 +280,7 @@
 
 def _handle_setup(nets, bonds, running_config, nets_by_nic):
     commands = []
-    netinfo = CachingNetInfo()
+    netinfo = NetInfo(netswitch.netinfo())
     for bond, attrs in six.iteritems(bonds):
         if 'remove' not in attrs:
             _validate_bond_configuration(attrs, netinfo)


-- 
To view, visit https://gerrit.ovirt.org/60866
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib8c88b1454245364d5dadd4d2baf147658faaef2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-4.0
Gerrit-Owner: Petr Horáček <phora...@redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <dan...@redhat.com>
Gerrit-Reviewer: Edward Haas <edwa...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org

Reply via email to