Ido Barkan has uploaded a new change for review. Change subject: avoid reading ifcfg files when deleting networks ......................................................................
avoid reading ifcfg files when deleting networks Change-Id: I28e2084a15e1f6cc0cb4f20e83d7751fd8ffe37f Signed-off-by: ibarkan <[email protected]> --- M lib/vdsm/netinfo.py M tests/netinfoTests.py M vdsm/network/api.py 3 files changed, 3 insertions(+), 98 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/43/35043/1 diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index 10bbecb..cbffa04 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -32,7 +32,6 @@ import struct from xml.dom import minidom -from .config import config from . import constants from .ipwrapper import drv_name from .ipwrapper import DUMMY_BRIDGE @@ -42,7 +41,6 @@ from .ipwrapper import routeGet from .ipwrapper import routeShowGateways from . import libvirtconnection -from .netconfpersistence import RunningConfig from .utils import memoized from .netlink import link as nl_link from .netlink import addr as nl_addr @@ -350,34 +348,6 @@ except Exception: pass return ifaceCfg - - -def getBootProtocol(iface, persistence=None): - if persistence is None: - persistence = config.get('vars', 'net_persistence') - - if persistence == 'ifcfg': - return getIfaceCfg(iface).get('BOOTPROTO') - elif persistence == 'unified': - runningConfig = RunningConfig() - - # If the network is bridged its iface name will be its network name - network = runningConfig.networks.get(iface) - if network is not None: - return network.get('bootproto') - - # Otherwise we need to search if the iface is the device for a network - for network, attributes in runningConfig.networks.iteritems(): - nic = attributes.get('nic') - bonding = attributes.get('bonding') - vlan = attributes.get('vlan') - if iface in (nic, bonding, - "%s.%s" % (nic, vlan), "%s.%s" % (bonding, vlan)): - return attributes.get('bootproto') - - return None - else: - raise NotImplementedError def permAddr(): diff --git a/tests/netinfoTests.py b/tests/netinfoTests.py index e7a08ee..b415f19 100644 --- a/tests/netinfoTests.py +++ b/tests/netinfoTests.py @@ -26,10 +26,9 @@ import time from vdsm import ipwrapper -from vdsm import netconfpersistence from vdsm import netinfo -from vdsm.netinfo import (getBootProtocol, getDhclientIfaces, BONDING_MASTERS, - BONDING_OPT, _getBondingOptions, OPERSTATE_UP) +from vdsm.netinfo import (getDhclientIfaces, BONDING_MASTERS, BONDING_OPT, + _getBondingOptions, OPERSTATE_UP) from vdsm.netlink import addr as nl_addr from vdsm.tool.dump_bonding_defaults import _random_iface_name @@ -201,27 +200,6 @@ 'devices %s is shown in nics %s' % (hiddens, nics)) - def testGetBootProtocolIfcfg(self): - deviceName = "___This_could_never_be_a_device_name___" - ifcfg = ('DEVICE=%s' % deviceName + '\n' + 'ONBOOT=yes' + '\n' + - 'MTU=1500' + '\n' + 'HWADDR=5e:64:6d:12:16:84' + '\n') - with namedTemporaryDir() as tempDir: - ifcfgPrefix = os.path.join(tempDir, 'ifcfg-') - filePath = ifcfgPrefix + deviceName - - with MonkeyPatchScope([(netinfo, 'NET_CONF_PREF', ifcfgPrefix)]): - with open(filePath, 'w') as ifcfgFile: - ifcfgFile.write(ifcfg + 'BOOTPROTO=dhcp\n') - self.assertEqual(getBootProtocol(deviceName, 'ifcfg'), 'dhcp') - - with open(filePath, 'w') as ifcfgFile: - ifcfgFile.write(ifcfg + 'BOOTPROTO=none\n') - self.assertEqual(getBootProtocol(deviceName, 'ifcfg'), 'none') - - with open(filePath, 'w') as ifcfgFile: - ifcfgFile.write(ifcfg) - self.assertEqual(getBootProtocol(deviceName, 'ifcfg'), None) - def testGetIfaceCfg(self): deviceName = "___This_could_never_be_a_device_name___" ifcfg = ('GATEWAY0=1.1.1.1\n' 'NETMASK=255.255.0.0\n') @@ -236,49 +214,6 @@ netinfo.getIfaceCfg(deviceName)['GATEWAY'], '1.1.1.1') self.assertEqual( netinfo.getIfaceCfg(deviceName)['NETMASK'], '255.255.0.0') - - def testGetBootProtocolUnified(self): - with namedTemporaryDir() as tempDir: - netsDir = os.path.join(tempDir, 'nets') - os.mkdir(netsDir) - networks = { - 'nonVMOverNic': - {"nic": "eth0", "bridged": False, "bootproto": "dhcp"}, - 'bridgeOverNic': - {"nic": "eth1", "bridged": True}, - 'nonVMOverBond': - {"bonding": "bond0", "bridged": False, "bootproto": "dhcp"}, - 'bridgeOverBond': - {"bonding": "bond1", "bridged": True}, - 'vlanOverNic': - {"nic": "eth2", "bridged": False, "vlan": 1, - "bootproto": "dhcp"}, - 'bridgeOverVlan': - {"nic": "eth3", "bridged": True, "vlan": 1}, - 'vlanOverBond': - {"bonding": "bond2", "bridged": False, "bootproto": "dhcp", - "vlan": 1}, - 'bridgeOverVlanOverBond': - {"bonding": "bond3", "bridged": True, "vlan": 1}} - - with MonkeyPatchScope([(netconfpersistence, 'CONF_RUN_DIR', - tempDir)]): - runningConfig = netconfpersistence.RunningConfig() - for network, attributes in networks.iteritems(): - runningConfig.setNetwork(network, attributes) - runningConfig.save() - - for network, attributes in networks.iteritems(): - if attributes.get('bridged') == 'true': - topLevelDevice = network - else: - topLevelDevice = attributes.get('nic') or \ - attributes.get('bonding') - if attributes.get('vlan'): - topLevelDevice += '.%s' % attributes.get('vlan') - self.assertEqual( - getBootProtocol(topLevelDevice, 'unified'), - attributes.get('bootproto')) def testGetDhclientIfaces(self): LEASES = ( diff --git a/vdsm/network/api.py b/vdsm/network/api.py index 1b09c6c..73fa421 100755 --- a/vdsm/network/api.py +++ b/vdsm/network/api.py @@ -435,7 +435,7 @@ bonding=bonding, nics=nics, _netinfo=_netinfo, configurator=configurator, implicitBonding=implicitBonding) - netEnt.ip.bootproto = netinfo.getBootProtocol(netEnt.name) + netEnt.ip.bootproto = _netinfo.networks[network]['bootproto4'] # We must first remove the libvirt network and then the network entity. # Otherwise if we first remove the network entity while the libvirt -- To view, visit http://gerrit.ovirt.org/35043 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I28e2084a15e1f6cc0cb4f20e83d7751fd8ffe37f 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
