[PATCH 12/15] remove Network(): post-configuration of devices used for storage
Radek Vykydal
rvykydal at redhat.com
Thu Jul 19 10:02:45 UTC 2012
---
pyanaconda/__init__.py | 5 +-
pyanaconda/gui.py | 3 +-
pyanaconda/network.py | 102 ++++++++++++++++----------------
tests/pyanaconda_test/network_test.py | 19 ------
4 files changed, 56 insertions(+), 73 deletions(-)
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 4510a7a..db835c4 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -280,6 +280,7 @@ class Anaconda(object):
self.methodstr = methodstr
def write(self):
+ import network
self.writeXdriver()
self.instLanguage.write()
@@ -288,8 +289,8 @@ class Anaconda(object):
self.instClass.setNetworkOnbootDefault(self.network)
self.network.write()
network.copyConfigToPath(ROOT_PATH)
- self.network.disableNMForStorageDevices(self)
- self.network.autostartFCoEDevices(self)
+ network.disableNMForStorageDevices(self.storage)
+ network.autostartFCoEDevices(self.storage)
self.desktop.write()
self.users.write()
self.security.write()
diff --git a/pyanaconda/gui.py b/pyanaconda/gui.py
index 308ee86..370f925 100755
--- a/pyanaconda/gui.py
+++ b/pyanaconda/gui.py
@@ -911,7 +911,8 @@ class InstallInterface(InstallInterfaceBase):
# delete ifcfg file in nm-c-e
nm_controlled_devices = [devname for (devname, dev)
in self.anaconda.network.netdevices.items()
- if not dev.usedByFCoE(self.anaconda)]
+ if not network.usedByFCoE(devname,
+ self.anaconda.storage)]
if not just_setup and not nm_controlled_devices:
return False
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index 4fed523..ef15463 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -39,6 +39,7 @@ from flags import flags
from simpleconfig import IfcfgFile
from pyanaconda.constants import ROOT_PATH
import urlgrabber.grabber
+from pyanaconda.storage.devices import FcoeDiskDevice, iScsiDiskDevice
import gettext
_ = lambda x: gettext.ldgettext("anaconda", x)
@@ -331,28 +332,6 @@ class NetworkDevice(IfcfgFile):
f.close()
return content
- def usedByFCoE(self, anaconda):
- import storage
- for d in anaconda.storage.devices:
- if (isinstance(d, storage.devices.FcoeDiskDevice) and
- d.nic == self.iface):
- return True
- return False
-
- def usedByRootOnISCSI(self, anaconda):
- import storage
- rootdev = anaconda.storage.rootDevice
- for d in anaconda.storage.devices:
- if (isinstance(d, storage.devices.iScsiDiskDevice) and
- rootdev.dependsOn(d)):
- if d.nic == "default":
- if self.iface == ifaceForHostIP(d.host_address):
- return True
- elif d.nic == self.iface:
- return True
-
- return False
-
def setGateway(self, gw):
if ':' in gw:
self.set(('IPV6_DEFAULTGW', gw))
@@ -468,35 +447,6 @@ class Network:
return dev.get('IPV6_DEFAULTGW')
return ""
- def disableNMForStorageDevices(self, anaconda):
- for devName, device in self.netdevices.items():
- if (device.usedByFCoE(anaconda) or
- device.usedByRootOnISCSI(anaconda)):
- dev = NetworkDevice(ROOT_PATH + netscriptsDir, devName)
- if os.access(dev.path, os.R_OK):
- dev.loadIfcfgFile()
- dev.set(('NM_CONTROLLED', 'no'))
- dev.writeIfcfgFile()
- log.info("network device %s used by storage will not be "
- "controlled by NM" % device.path)
- else:
- log.warning("disableNMForStorageDevices: %s file not found" %
- device.path)
-
- def autostartFCoEDevices(self, anaconda):
- for devName, device in self.netdevices.items():
- if device.usedByFCoE(anaconda):
- dev = NetworkDevice(ROOT_PATH + netscriptsDir, devName)
- if os.access(dev.path, os.R_OK):
- dev.loadIfcfgFile()
- dev.set(('ONBOOT', 'yes'))
- dev.writeIfcfgFile()
- log.debug("setting ONBOOT=yes for network device %s used by fcoe"
- % device.path)
- else:
- log.warning("autoconnectFCoEDevices: %s file not found" %
- device.path)
-
# TODO:
# - do not write ifcfg files
# - separate function for sysconfig/network
@@ -935,3 +885,53 @@ def get_ksdevice_name(ksspec=""):
break
return ksdevice
+
+
+def disableNMForStorageDevices(storage):
+ for devname in getDevices():
+ if (usedByFCoE(devname, storage) or
+ usedByRootOnISCSI(devname, storage)):
+ dev = NetworkDevice(ROOT_PATH + netscriptsDir, devname)
+ if os.access(dev.path, os.R_OK):
+ dev.loadIfcfgFile()
+ dev.set(('NM_CONTROLLED', 'no'))
+ dev.writeIfcfgFile()
+ log.info("network device %s used by storage will not be "
+ "controlled by NM" % devname)
+ else:
+ log.warning("disableNMForStorageDevices: ifcfg file for %s not found" %
+ devname)
+
+def autostartFCoEDevices(storage):
+ for devname in getDevices():
+ if usedByFCoE(devname, storage):
+ dev = NetworkDevice(ROOT_PATH + netscriptsDir, devname)
+ if os.access(dev.path, os.R_OK):
+ dev.loadIfcfgFile()
+ dev.set(('ONBOOT', 'yes'))
+ dev.writeIfcfgFile()
+ log.debug("setting ONBOOT=yes for network device %s used by fcoe"
+ % devname)
+ else:
+ log.warning("autoconnectFCoEDevices: ifcfg file for %s not found" %
+ devname)
+
+def usedByFCoE(iface, storage):
+ for d in storage.devices:
+ if (isinstance(d, FcoeDiskDevice) and
+ d.nic == iface):
+ return True
+ return False
+
+def usedByRootOnISCSI(iface, storage):
+ rootdev = storage.rootDevice
+ for d in storage.devices:
+ if (isinstance(d, iScsiDiskDevice) and
+ rootdev.dependsOn(d)):
+ if d.nic == "default":
+ if iface == ifaceForHostIP(d.host_address):
+ return True
+ elif d.nic == iface:
+ return True
+
+ return False
diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py
index b85bb4f..4a92135 100644
--- a/tests/pyanaconda_test/network_test.py
+++ b/tests/pyanaconda_test/network_test.py
@@ -349,25 +349,6 @@ class NetworkTest(mock.TestCase):
self.assertEqual(self.fs[TMPFILE],
'network --device eth0 --bootproto dhcp --noipv6\n')
- def network_disable_nm_for_storage_devices_test(self):
- import pyanaconda.network
- pyanaconda.network.NetworkDevice = mock.Mock()
- pyanaconda.network.os = mock.Mock()
- pyanaconda.network.os.access.return_value = True
-
- nw = pyanaconda.network.Network()
- nw.netdevices['dev'] = mock.Mock()
- anaconda= mock.Mock()
-
- nw.disableNMForStorageDevices(anaconda)
- self.assertEqual(pyanaconda.network.NetworkDevice.call_args_list,
- [(('/mnt/sysimage/tmp/etc/sysconfig/network-scripts', 'dev'), {})])
- self.assertEqual(pyanaconda.network.NetworkDevice().method_calls,
- [('loadIfcfgFile', (), {}),
- ('set', (('NM_CONTROLLED', 'no'),), {}),
- ('writeIfcfgFile', (), {})]
- )
-
def network_write_test(self):
import pyanaconda.network
pyanaconda.network.shutil = mock.Mock()
--
1.7.4
More information about the anaconda-patches
mailing list