[PATCH 14/15] remove Network(): write (configuration) method
Radek Vykydal
rvykydal at redhat.com
Thu Jul 19 10:02:47 UTC 2012
It got reduced just to writing of /etc/sysconfig/network.
We'll need to review how much of it is still needed/relevant.
---
pyanaconda/__init__.py | 2 +-
pyanaconda/network.py | 105 +++++++++++++-------------------
pyanaconda/yuminstall.py | 2 +-
tests/pyanaconda_test/network_test.py | 19 ------
4 files changed, 45 insertions(+), 83 deletions(-)
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 4763def..0b2e93a 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -287,7 +287,7 @@ class Anaconda(object):
self.timezone.write()
if not self.ksdata:
self.instClass.setNetworkOnbootDefault(self.network)
- self.network.write()
+ network.write_sysconfig_network()
network.disableIPV6()
network.copyConfigToPath(ROOT_PATH)
network.disableNMForStorageDevices(self.storage)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py
index b26240f..bf94b1d 100644
--- a/pyanaconda/network.py
+++ b/pyanaconda/network.py
@@ -429,72 +429,11 @@ class Network:
self.netdevices[iface] = device
- @property
- def gateway(self):
- """GATEWAY - last device in list wins"""
- for dev in reversed(self.netdevices.values()):
- if (dev.get('GATEWAY') and
- dev.get('DEFROUTE') != "no"):
- return dev.get('GATEWAY')
- return ""
-
- @property
- def ipv6_defaultgw(self):
- """IPV6_DEFAULTGW - last device in list wins"""
- for dev in reversed(self.netdevices.values()):
- if (dev.get('IPV6_DEFAULTGW') and
- dev.get('DEFROUTE') != "no"):
- return dev.get('IPV6_DEFAULTGW')
- return ""
-
- # TODO:
- # - do not write ifcfg files
- # - separate function for sysconfig/network
- # - separate fnc for ipv6
- def write(self):
- ifcfglog.debug("Network.write() called")
-
- # /etc/sysconfig/network
- if flags.imageInstall:
- # don't write files into host's /etc/sysconfig on image installs
- newnetwork = "/tmp/sysconfig-network"
- else:
- newnetwork = "%s.new" % (networkConfFile)
-
- f = open(newnetwork, "w")
- f.write("NETWORKING=yes\n")
- f.write("HOSTNAME=")
-
- hostname = getHostname()
- if hostname:
- f.write(hostname + "\n")
- else:
- f.write("localhost.localdomain\n")
-
- if self.gateway:
- f.write("GATEWAY=%s\n" % self.gateway)
-
- if self.ipv6_defaultgw:
- f.write("IPV6_DEFAULTGW=%s\n" % self.ipv6_defaultgw)
-
- f.close()
- if flags.imageInstall:
- # for image installs, all we want to write out is the contents of
- # /etc/sysconfig/network
- ifcfglog.debug("not writing per-device configs for image install")
- return
- else:
- shutil.move(newnetwork, networkConfFile)
-
- devices = self.netdevices.values()
-
- # /etc/resolv.conf is managed by NM
-
# write out current configuration state and wait for NetworkManager
# to bring the device up, watch NM state and return to the caller
# once we have a state
def bringUp(self):
- self.write()
+ write_sysconfig_network()
if waitForConnection():
resetResolver()
return True
@@ -880,6 +819,48 @@ def get_ifcfg_value(iface, key, root_path=""):
dev.loadIfcfgFile()
return dev.get(key)
+def write_sysconfig_network():
+
+ if flags.imageInstall:
+ # don't write files into host's /etc/sysconfig on image installs
+ newnetwork = "/tmp/sysconfig-network"
+ else:
+ newnetwork = "%s.new" % (networkConfFile)
+
+ f = open(newnetwork, "w")
+ f.write("# Generated by anaconda")
+ f.write("NETWORKING=yes\n")
+ f.write("HOSTNAME=")
+
+ hostname = getHostname()
+ if hostname:
+ f.write(hostname + "\n")
+ else:
+ f.write("localhost.localdomain\n")
+
+ gateway = ipv6_defaultgw = None
+ for iface in reversed(getDevices()):
+ dev = NetworkDevice(netscriptsDir, iface)
+ dev.loadIfcfgFile()
+ if dev.get('DEFROUTE') != "no":
+ continue
+ if dev.get('GATEWAY'):
+ gateway = dev.get('GATEWAY')
+ if dev.get('IPV6_DEFAULTGW'):
+ ipv6_defaultgw = dev.get('IPV6_DEFAULTGW')
+ if gateway and ipv6_defaultgw:
+ break
+
+ if gateway:
+ f.write("GATEWAY=%s\n" % gateway)
+
+ if ipv6_defaultgw:
+ f.write("IPV6_DEFAULTGW=%s\n" % ipv6_defaultgw)
+ f.close()
+
+ if not flags.imageInstall:
+ shutil.move(newnetwork, networkConfFile)
+
# TODO: do it right in sysroot (instead of copying the files later)?
def disableIPV6():
if ('noipv6' in flags.cmdline
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index a80bcbb..fd7ba3e 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -1625,7 +1625,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
ROOT_PATH + "/etc/modprobe.d/anaconda.conf")
if not anaconda.ksdata:
anaconda.instClass.setNetworkOnbootDefault(anaconda.network)
- anaconda.network.write()
+ network.write_sysconfig_network()
network.disableIPV6()
network.copyConfigToPath(ROOT_PATH)
anaconda.storage.write()
diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py
index 4a92135..734878c 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_write_test(self):
- import pyanaconda.network
- pyanaconda.network.shutil = mock.Mock()
- pyanaconda.network.os = mock.Mock()
- pyanaconda.network.os.path.isfile.return_value = True
- self.fs.open(self.NETWORKCONFFILE, 'w')
-
- device = pyanaconda.network.NetworkDevice(
- self.NETSCRIPTSDIR, self.DEVICE)
- device.loadIfcfgFile()
-
- nw = pyanaconda.network.Network()
- nw.domains = ['localdomain']
- nw.netdevices[self.DEVICE] = device
- nw.write()
-
- self.assertEqual(self.fs['%s.new' % self.NETWORKCONFFILE],
- 'NETWORKING=yes\nHOSTNAME=localhost.localdomain\n')
-
def network_wait_for_connection_1_test(self):
import pyanaconda.network
pyanaconda.network.dbus = mock.Mock()
--
1.7.4
More information about the anaconda-patches
mailing list