This patchset is removing anaconda.network with the goal to use only ksdata to store network configuration.
See [15/15] for details and what will follow.
I want to do also some furher cleanup, review of hostname setting, /etc/sysconfig/network setting etc.
--- pyanaconda/network.py | 121 +++++++++++++++++++++++++------------------------ 1 files changed, 62 insertions(+), 59 deletions(-)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 0a5ad61..b75f826 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -728,7 +728,6 @@ class Network:
# get a kernel cmdline string for dracut needed for access to host host def dracutSetupArgs(self, networkStorageDevice): - netargs=set()
if networkStorageDevice.nic == "default": nic = ifaceForHostIP(networkStorageDevice.host_address) @@ -741,64 +740,9 @@ class Network: log.error('Unknown network interface: %s' % nic) return ""
- dev = self.netdevices[nic] - - if dev.get('BOOTPROTO') == 'ibft': - netargs.add("ip=ibft") - elif networkStorageDevice.host_address: - if self.hostname: - hostname = self.hostname - else: - hostname = "" - - # if using ipv6 - if ':' in networkStorageDevice.host_address: - if dev.get('DHCPV6C') == "yes": - # XXX combination with autoconf not yet clear, - # support for dhcpv6 is not yet implemented in NM/ifcfg-rh - netargs.add("ip=%s:dhcp6" % nic) - elif dev.get('IPV6_AUTOCONF') == "yes": - netargs.add("ip=%s:auto6" % nic) - elif dev.get('IPV6ADDR'): - ipaddr = "[%s]" % dev.get('IPV6ADDR') - if dev.get('IPV6_DEFAULTGW'): - gateway = "[%s]" % dev.get('IPV6_DEFAULTGW') - else: - gateway = "" - netargs.add("ip=%s::%s:%s:%s:%s:none" % (ipaddr, gateway, - dev.get('PREFIX'), hostname, nic)) - else: - if dev.get('bootproto').lower() == 'dhcp': - netargs.add("ip=%s:dhcp" % nic) - else: - if dev.get('GATEWAY'): - gateway = dev.get('GATEWAY') - else: - gateway = "" - - netmask = dev.get('netmask') - prefix = dev.get('prefix') - if not netmask and prefix: - netmask = isys.prefix2netmask(int(prefix)) - - netargs.add("ip=%s::%s:%s:%s:%s:none" % (dev.get('ipaddr'), - gateway, netmask, hostname, nic)) - - hwaddr = dev.get("HWADDR") - if hwaddr: - netargs.add("ifname=%s:%s" % (nic, hwaddr.lower())) - - nettype = dev.get("NETTYPE") - subchannels = dev.get("SUBCHANNELS") - if iutil.isS390() and nettype and subchannels: - znet = "rd.znet=%s,%s" % (nettype, subchannels) - options = dev.get("OPTIONS").strip("'"") - if options: - options = filter(lambda x: x != '', options.split(' ')) - znet += ",%s" % (','.join(options)) - netargs.add(znet) - - return netargs + return dracutBootArguments(self.netdevices[nic], + networkStorageDevice.host_address, + self.hostname)
def waitForDevicesActivation(devices): waited_devs_props = {} @@ -849,6 +793,65 @@ def waitForConnection(): return False
+def dracutBootArguments(ifcfg, storage_ipaddr, hostname=None): + + netargs = set() + devname = ifcfg.iface + + if ifcfg.get('BOOTPROTO') == 'ibft': + netargs.add("ip=ibft") + elif storage_ipaddr: + if hostname is None: + hostname = "" + # if using ipv6 + if ':' in storage_ipaddr: + if ifcfg.get('DHCPV6C') == "yes": + # XXX combination with autoconf not yet clear, + # support for dhcpv6 is not yet implemented in NM/ifcfg-rh + netargs.add("ip=%s:dhcp6" % devname) + elif ifcfg.get('IPV6_AUTOCONF') == "yes": + netargs.add("ip=%s:auto6" % devname) + elif ifcfg.get('IPV6ADDR'): + ipaddr = "[%s]" % ifcfg.get('IPV6ADDR') + if ifcfg.get('IPV6_DEFAULTGW'): + gateway = "[%s]" % ifcfg.get('IPV6_DEFAULTGW') + else: + gateway = "" + netargs.add("ip=%s::%s:%s:%s:%s:none" % (ipaddr, gateway, + ifcfg.get('PREFIX'), hostname, devname)) + else: + if ifcfg.get('bootproto').lower() == 'dhcp': + netargs.add("ip=%s:dhcp" % devname) + else: + if ifcfg.get('GATEWAY'): + gateway = ifcfg.get('GATEWAY') + else: + gateway = "" + + netmask = ifcfg.get('netmask') + prefix = ifcfg.get('prefix') + if not netmask and prefix: + netmask = isys.prefix2netmask(int(prefix)) + + netargs.add("ip=%s::%s:%s:%s:%s:none" % (ifcfg.get('ipaddr'), + gateway, netmask, hostname, devname)) + + hwaddr = ifcfg.get("HWADDR") + if hwaddr: + netargs.add("ifname=%s:%s" % (devname, hwaddr.lower())) + + nettype = ifcfg.get("NETTYPE") + subchannels = ifcfg.get("SUBCHANNELS") + if iutil.isS390() and nettype and subchannels: + znet = "rd.znet=%s,%s" % (nettype, subchannels) + options = ifcfg.get("OPTIONS").strip("'"") + if options: + options = filter(lambda x: x != '', options.split(' ')) + znet += ",%s" % (','.join(options)) + netargs.add(znet) + + return netargs + def kickstartNetworkData(ifcfg, hostname=None):
from pyanaconda.kickstart import NetworkData
--- pyanaconda/network.py | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py index b75f826..c35793c 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -704,8 +704,7 @@ class Network:
# disable ipv6 if ('noipv6' in flags.cmdline - and not [dev for dev in devices - if dev.get('IPV6INIT') == "yes"]): + and not any(dev.get('IPV6INIT') == "yes" for dev in devices)): if os.path.exists(ipv6ConfFile): log.warning('Not disabling ipv6, %s exists' % ipv6ConfFile) else:
--- pyanaconda/iw/network_gui.py | 4 +--- pyanaconda/network.py | 9 --------- pyanaconda/textw/netconfig_text.py | 4 +--- tests/pyanaconda_test/network_test.py | 22 ---------------------- 4 files changed, 2 insertions(+), 37 deletions(-)
diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py index f1c19c0..f1eee76f 100644 --- a/pyanaconda/iw/network_gui.py +++ b/pyanaconda/iw/network_gui.py @@ -155,9 +155,7 @@ def selectInstallNetDeviceDialog(network, devices = None): store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING) combo.set_model(store)
- ksdevice = network.getKSDevice() - if ksdevice: - ksdevice = ksdevice.iface + ksdevice = network.ksdevice preselected = None
for dev in devices: diff --git a/pyanaconda/network.py b/pyanaconda/network.py index c35793c..2f2f329 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -494,15 +494,6 @@ class Network: self.ksdevice = dev break
- def getKSDevice(self): - if self.ksdevice is None: - return None - - try: - return self.netdevices[self.ksdevice] - except: - return None - @property def gateway(self): """GATEWAY - last device in list wins""" diff --git a/pyanaconda/textw/netconfig_text.py b/pyanaconda/textw/netconfig_text.py index ed1fff2..40a31cb 100644 --- a/pyanaconda/textw/netconfig_text.py +++ b/pyanaconda/textw/netconfig_text.py @@ -72,9 +72,7 @@ class NetworkConfiguratorText: devnames.sort()
# Preselect device set in kickstart - ksdevice = self.anaconda.network.getKSDevice() - if ksdevice: - ksdevice = ksdevice.iface + ksdevice = self.anaconda.ksdevice
for devname in devnames: hwaddr = self.netdevs[devname].get("HWADDR") diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py index 7ad58cf..26c1b46 100644 --- a/tests/pyanaconda_test/network_test.py +++ b/tests/pyanaconda_test/network_test.py @@ -316,28 +316,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(pyanaconda.network.shutil.move.call_args[0], (TMP_FILE, '%s/keys-%s' % (TMP_DIR, self.DEVICE)))
- def network_get_ks_device_1_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.ksdevice = None - ret = nw.getKSDevice() - self.assertEqual(ret, None) - - def network_get_ks_device_2_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.ksdevice = 'ksdev' - ret = nw.getKSDevice() - self.assertEqual(ret, None) - - def network_get_ks_device_3_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices['ksdev'] = 'device' - nw.ksdevice = 'ksdev' - ret = nw.getKSDevice() - self.assertEqual(ret, 'device') - def network_write_ifcfg_files_test(self): import pyanaconda.network nw = pyanaconda.network.Network()
--- pyanaconda/network.py | 41 ------------------- tests/pyanaconda_test/network_test.py | 70 --------------------------------- 2 files changed, 0 insertions(+), 111 deletions(-)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 2f2f329..59ddcdd 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -512,41 +512,6 @@ class Network: return dev.get('IPV6_DEFAULTGW') return ""
- # Note that the file is written-out only if there is a value - # that has changed. - def writeIfcfgFiles(self): - for device in self.netdevices.values(): - device.writeIfcfgFile() - - # devices == None => set for all - def updateActiveDevices(self, devices=None): - for devname, device in self.netdevices.items(): - if devices and devname not in devices: - device.set(('ONBOOT', 'no')) - else: - device.set(('ONBOOT', 'yes')) - - def getOnbootControlledIfaces(self): - ifaces = [] - for iface, device in self.netdevices.items(): - if (device.get('ONBOOT') == "yes" and - device.get('NM_CONTROLLED') == "yes"): - ifaces.append(iface) - return ifaces - - def writeSSIDifcfgs(self, devssids): - ssids = [] - for ssidlist in devssids.values(): - ssids.extend(ssidlist) - for ssid in ssids: - path = "{0}/ifcfg-{1}".format(netscriptsDir, ssid) - ifcfgfile = open(path, "w") - ifcfgfile.write("NAME={0}\n".format(ssid)+ - "TYPE=Wireless\n"+ - "ESSID={0}\n".format(ssid)+ - "NM_CONTROLLED=yes\n") - ifcfgfile.close() - def writeKS(self, f): devNames = self.netdevices.keys() devNames.sort() @@ -559,12 +524,6 @@ class Network: line = "%s" % kickstartNetworkData(dev, self.hostname) f.write(line)
- def hasWirelessDev(self): - for dev in self.netdevices: - if isys.isWirelessDevice(dev): - return True - return False - def _copyFileToPath(self, file, instPath='', overwrite=False): if not os.path.isfile(file): return False diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py index 26c1b46..16ba066 100644 --- a/tests/pyanaconda_test/network_test.py +++ b/tests/pyanaconda_test/network_test.py @@ -316,13 +316,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(pyanaconda.network.shutil.move.call_args[0], (TMP_FILE, '%s/keys-%s' % (TMP_DIR, self.DEVICE)))
- def network_write_ifcfg_files_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices = {'dev': mock.Mock()} - nw.writeIfcfgFiles() - self.assertTrue(nw.netdevices['dev'].writeIfcfgFile.called) - def network_nm_controlled_devices_1_test(self): import pyanaconda.network nw = pyanaconda.network.Network() @@ -341,49 +334,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(nw.netdevices['dev'].method_calls, [('set', (('NM_CONTROLLED', 'no'),), {})])
- def network_update_active_devices_1_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices = {'dev': mock.Mock()} - nw.updateActiveDevices() - self.assertEqual(nw.netdevices['dev'].method_calls, - [('set', (('ONBOOT', 'yes'),), {})]) - - def network_update_active_devices_2_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices = {'dev': mock.Mock()} - nw.updateActiveDevices(['']) - self.assertEqual(nw.netdevices['dev'].method_calls, - [('set', (('ONBOOT', 'no'),), {})]) - - def network_get_on_boot_controlled_ifaces_1_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices = {'dev': mock.Mock()} - ret = nw.getOnbootControlledIfaces() - self.assertEqual(ret, []) - - def network_get_on_boot_controlled_ifaces_2_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - a = mock.Mock() - a.get.return_value = "yes" - nw.netdevices = {'dev': a} - ret = nw.getOnbootControlledIfaces() - self.assertEqual(ret, ['dev']) - - def network_writeSSIDifcfgs_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices = {'dev': mock.Mock()} - ret = nw.writeSSIDifcfgs({'dev': ['net_essid']}) - self.assertEqual(self.fs['/tmp/etc/sysconfig/network-scripts/ifcfg-net_essid'], - "NAME=net_essid\n" - "TYPE=Wireless\n" - "ESSID=net_essid\n" - "NM_CONTROLLED=yes\n") - def network_write_ks_test(self): import pyanaconda.network TMPFILE = '/tmp/networkKS' @@ -399,26 +349,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(self.fs[TMPFILE], 'network --device eth0 --bootproto dhcp --noipv6\n')
- def network_has_wireless_dev_1_test(self): - import pyanaconda.network - pyanaconda.network.isys = mock.Mock() - pyanaconda.network.isys.isWirelessDevice.return_value = True - - nw = pyanaconda.network.Network() - nw.netdevices = {'dev': ''} - ret = nw.hasWirelessDev() - self.assertTrue(ret) - - def network_has_wireless_dev_2_test(self): - import pyanaconda.network - pyanaconda.network.isys = mock.Mock() - pyanaconda.network.isys.isWirelessDevice.return_value = False - - nw = pyanaconda.network.Network() - nw.netdevices = {'dev': ''} - ret = nw.hasWirelessDev() - self.assertFalse(ret) - def network_copy_config_to_path_test(self): import pyanaconda.network pyanaconda.network.Network._copyFileToPath = mock.Mock()
--- pyanaconda/__init__.py | 2 +- pyanaconda/network.py | 116 +++++++++++++++++--------------- pyanaconda/yuminstall.py | 2 +- tests/pyanaconda_test/network_test.py | 18 ----- 4 files changed, 64 insertions(+), 74 deletions(-)
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py index 4a4be2a..4510a7a 100644 --- a/pyanaconda/__init__.py +++ b/pyanaconda/__init__.py @@ -287,7 +287,7 @@ class Anaconda(object): if not self.ksdata: self.instClass.setNetworkOnbootDefault(self.network) self.network.write() - self.network.copyConfigToPath() + network.copyConfigToPath(ROOT_PATH) self.network.disableNMForStorageDevices(self) self.network.autostartFCoEDevices(self) self.desktop.write() diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 59ddcdd..837e437 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -524,60 +524,6 @@ class Network: line = "%s" % kickstartNetworkData(dev, self.hostname) f.write(line)
- def _copyFileToPath(self, file, instPath='', overwrite=False): - if not os.path.isfile(file): - return False - destfile = os.path.join(instPath, file.lstrip('/')) - if (os.path.isfile(destfile) and not overwrite): - return False - if not os.path.isdir(os.path.dirname(destfile)): - iutil.mkdirChain(os.path.dirname(destfile)) - shutil.copy(file, destfile) - return True - - def _copyIfcfgFiles(self): - files = os.listdir(netscriptsDir) - for cfgFile in files: - if cfgFile.startswith(("ifcfg-","keys-")): - srcfile = os.path.join(netscriptsDir, cfgFile) - self._copyFileToPath(srcfile, ROOT_PATH) - - def copyConfigToPath(self): - if flags.imageInstall: - # for image installs we only want to write out - # /etc/sysconfig/network - destfile = os.path.normpath(ROOT_PATH + networkConfFile) - if not os.path.isdir(os.path.dirname(destfile)): - iutil.mkdirChain(os.path.dirname(destfile)) - shutil.move("/tmp/sysconfig-network", destfile) - return - - # /etc/sysconfig/network-scripts/ifcfg-* - # /etc/sysconfig/network-scripts/keys-* - # we can copy all of them - self._copyIfcfgFiles() - - # /etc/dhcp/dhclient-DEVICE.conf - # TODORV: do we really don't want overwrite on live cd? - for devName, device in self.netdevices.items(): - dhclientfile = os.path.join("/etc/dhcp/dhclient-%s.conf" % devName) - self._copyFileToPath(dhclientfile, ROOT_PATH) - - # /etc/sysconfig/network - self._copyFileToPath(networkConfFile, ROOT_PATH, - overwrite=flags.livecdInstall) - - # /etc/resolv.conf - self._copyFileToPath("/etc/resolv.conf", ROOT_PATH, - overwrite=flags.livecdInstall) - - # /etc/udev/rules.d/70-persistent-net.rules - self._copyFileToPath("/etc/udev/rules.d/70-persistent-net.rules", - ROOT_PATH, overwrite=flags.livecdInstall) - - self._copyFileToPath(ipv6ConfFile, ROOT_PATH, - overwrite=flags.livecdInstall) - def disableNMForStorageDevices(self, anaconda): for devName, device in self.netdevices.items(): if (device.usedByFCoE(anaconda) or @@ -607,6 +553,10 @@ class Network: log.warning("autoconnectFCoEDevices: %s file not found" % device.path)
+ # TODO: + # - do not write ifcfg files + # - separate function for sysconfig/network + # - separate fnc for ipv6 def write(self): ifcfglog.debug("Network.write() called")
@@ -693,6 +643,10 @@ class Network: networkStorageDevice.host_address, self.hostname)
+def getDevices(): + # TODO: filter with existence of ifcfg file? + return isys.getDeviceProperties().keys() + def waitForDevicesActivation(devices): waited_devs_props = {}
@@ -945,3 +899,57 @@ def setHostname(hn): log.info("setting installation environment hostname to %s" % hn) iutil.execWithRedirect("hostname", ["-v", hn ], stdout="/dev/tty5", stderr="/dev/tty5") + +def _copyFileToPath(file, destPath='', overwrite=False): + if not os.path.isfile(file): + return False + destfile = os.path.join(destPath, file.lstrip('/')) + if (os.path.isfile(destfile) and not overwrite): + return False + if not os.path.isdir(os.path.dirname(destfile)): + iutil.mkdirChain(os.path.dirname(destfile)) + shutil.copy(file, destfile) + return True + +def _copyIfcfgFiles(destPath): + files = os.listdir(netscriptsDir) + for cfgFile in files: + if cfgFile.startswith(("ifcfg-","keys-")): + srcfile = os.path.join(netscriptsDir, cfgFile) + _copyFileToPath(srcfile, destPath) + +def copyConfigToPath(destPath): + if flags.imageInstall: + # for image installs we only want to write out + # /etc/sysconfig/network + destfile = os.path.normpath(destPath + networkConfFile) + if not os.path.isdir(os.path.dirname(destfile)): + iutil.mkdirChain(os.path.dirname(destfile)) + shutil.move("/tmp/sysconfig-network", destfile) + return + + # /etc/sysconfig/network-scripts/ifcfg-* + # /etc/sysconfig/network-scripts/keys-* + # we can copy all of them + _copyIfcfgFiles(destPath) + + # /etc/dhcp/dhclient-DEVICE.conf + # TODORV: do we really don't want overwrite on live cd? + for devName in getDevices(): + dhclientfile = os.path.join("/etc/dhcp/dhclient-%s.conf" % devName) + _copyFileToPath(dhclientfile, destPath) + + # /etc/sysconfig/network + _copyFileToPath(networkConfFile, destPath, + overwrite=flags.livecdInstall) + + # /etc/resolv.conf + _copyFileToPath("/etc/resolv.conf", destPath, + overwrite=flags.livecdInstall) + + # /etc/udev/rules.d/70-persistent-net.rules + _copyFileToPath("/etc/udev/rules.d/70-persistent-net.rules", + destPath, overwrite=flags.livecdInstall) + + _copyFileToPath(ipv6ConfFile, destPath, + overwrite=flags.livecdInstall) diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py index 0a3f292..b47f4de 100644 --- a/pyanaconda/yuminstall.py +++ b/pyanaconda/yuminstall.py @@ -1626,7 +1626,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon if not anaconda.ksdata: anaconda.instClass.setNetworkOnbootDefault(anaconda.network) anaconda.network.write() - anaconda.network.copyConfigToPath() + network.copyConfigToPath(ROOT_PATH) anaconda.storage.write() else: # ensure that /etc/mtab is a symlink to /proc/self/mounts diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py index 16ba066..b85bb4f 100644 --- a/tests/pyanaconda_test/network_test.py +++ b/tests/pyanaconda_test/network_test.py @@ -349,24 +349,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(self.fs[TMPFILE], 'network --device eth0 --bootproto dhcp --noipv6\n')
- def network_copy_config_to_path_test(self): - import pyanaconda.network - pyanaconda.network.Network._copyFileToPath = mock.Mock() - pyanaconda.network.Network._copyIfcfgFiles = mock.Mock() - - - nw = pyanaconda.network.Network() - nw.netdevices['dev'] = mock.Mock() - nw.netdevices['dev'].path = self.DEV_FILE - nw.netdevices['dev'].keyfilePath = self.DEV_KEY_FILE - ret = nw.copyConfigToPath() - self.assertEqual(pyanaconda.network.Network._copyFileToPath.call_args_list, - [(('/etc/dhcp/dhclient-dev.conf', '/mnt/sysimage'), {}), - (('/tmp/etc/sysconfig/network', '/mnt/sysimage'), {'overwrite': 0}), - (('/etc/resolv.conf', '/mnt/sysimage'), {'overwrite': 0}), - (('/etc/udev/rules.d/70-persistent-net.rules', '/mnt/sysimage'), {'overwrite': 0})] - ) - def network_disable_nm_for_storage_devices_test(self): import pyanaconda.network pyanaconda.network.NetworkDevice = mock.Mock()
It is used only in kickstart.py in newui --- pyanaconda/iw/network_gui.py | 2 +- pyanaconda/kickstart.py | 4 +- pyanaconda/network.py | 55 +++++++++++++++++++---------------- pyanaconda/textw/netconfig_text.py | 2 +- 4 files changed, 34 insertions(+), 29 deletions(-)
diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py index f1eee76f..cf20c39 100644 --- a/pyanaconda/iw/network_gui.py +++ b/pyanaconda/iw/network_gui.py @@ -155,7 +155,7 @@ def selectInstallNetDeviceDialog(network, devices = None): store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING) combo.set_model(store)
- ksdevice = network.ksdevice + ksdevice = network.get_ksdevice_name() preselected = None
for dev in devices: diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 8238c88..37a37bc 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -662,9 +662,9 @@ class NetworkData(commands.network.F16_NetworkData): devices = self.anaconda.network.netdevices
if not self.device: - if self.anaconda.network.ksdevice: + if "ksdevice" in flags.cmdline: msg = "ksdevice boot parameter" - device = self.anaconda.network.ksdevice + device = network.get_ksdevice_name(flags.cmdline["ksdevice"]) elif network.hasActiveNetDev(): # device activated in stage 1 by network kickstart command msg = "first active device" diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 837e437..c7f11b7 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -444,7 +444,6 @@ class Network: ifcfglog.debug("Network.update() called")
self.netdevices = {} - self.ksdevice = None
if flags.imageInstall: return @@ -470,30 +469,6 @@ class Network:
self.netdevices[iface] = device
- - ksdevice = flags.cmdline.get('ksdevice', None) - if ksdevice: - bootif_mac = None - if ksdevice == 'bootif' and "BOOTIF" in flags.cmdline: - bootif_mac = flags.cmdline["BOOTIF"][3:].replace("-", ":").upper() - # sort for ksdevice=link (to select the same device as in initrd)) - for dev in sorted(self.netdevices): - mac = self.netdevices[dev].get('HWADDR').upper() - if ksdevice == 'link' and isys.getLinkStatus(dev): - self.ksdevice = dev - break - elif ksdevice == 'bootif': - if bootif_mac == mac: - self.ksdevice = dev - break - elif ksdevice == dev: - self.ksdevice = dev - break - elif ':' in ksdevice: - if ksdevice.upper() == mac: - self.ksdevice = dev - break - @property def gateway(self): """GATEWAY - last device in list wins""" @@ -953,3 +928,33 @@ def copyConfigToPath(destPath):
_copyFileToPath(ipv6ConfFile, destPath, overwrite=flags.livecdInstall) + +def get_ksdevice_name(ksspec=""): + + if not ksspec: + ksspec = flags.cmdline.get('ksdevice', "") + ksdevice = ksspec + + bootif_mac = None + if ksdevice == 'bootif' and "BOOTIF" in flags.cmdline: + bootif_mac = flags.cmdline["BOOTIF"][3:].replace("-", ":").upper() + for dev in sorted(getDevices()): + # "eth0" + if ksdevice == dev: + break + # "link" + elif ksdevice == 'link' and isys.getLinkStatus(dev): + ksdevice = dev + break + # "XX:XX:XX:XX:XX:XX" (mac address) + elif ':' in ksdevice: + if ksdevice.upper() == isys.getMacAddress(dev): + ksdevice = dev + break + # "bootif" and BOOTIF==XX:XX:XX:XX:XX:XX + elif ksdevice == 'bootif': + if bootif_mac == isys.getMacAddress(dev): + ksdevice = dev + break + + return ksdevice diff --git a/pyanaconda/textw/netconfig_text.py b/pyanaconda/textw/netconfig_text.py index 40a31cb..6be52f3 100644 --- a/pyanaconda/textw/netconfig_text.py +++ b/pyanaconda/textw/netconfig_text.py @@ -72,7 +72,7 @@ class NetworkConfiguratorText: devnames.sort()
# Preselect device set in kickstart - ksdevice = self.anaconda.ksdevice + ksdevice = network.get_ksdevice_name()
for devname in devnames: hwaddr = self.netdevs[devname].get("HWADDR")
NM is setting hostname and we might be resetting it in kickstart.py. It is stored in ksdata with unfortunate access (iterating over network commands). Hostname handling will need some more work in newui. Here I am just giving another stab to Network() object. --- pyanaconda/iw/lvm_dialog_gui.py | 3 ++- pyanaconda/iw/network_gui.py | 3 +-- pyanaconda/kickstart.py | 3 --- pyanaconda/network.py | 28 +++++++--------------------- pyanaconda/textw/network_text.py | 3 +-- pyanaconda/vnc.py | 2 +- 6 files changed, 12 insertions(+), 30 deletions(-)
diff --git a/pyanaconda/iw/lvm_dialog_gui.py b/pyanaconda/iw/lvm_dialog_gui.py index abc47e8..2097542 100644 --- a/pyanaconda/iw/lvm_dialog_gui.py +++ b/pyanaconda/iw/lvm_dialog_gui.py @@ -32,6 +32,7 @@ from pyanaconda.constants import * from pyanaconda.storage.devices import * from pyanaconda.storage.deviceaction import * from pyanaconda.partIntfHelpers import * +from pyanaconda.network import getHostname
import gettext _ = lambda x: gettext.ldgettext("anaconda", x) @@ -1376,7 +1377,7 @@ class VolumeGroupEditor: if not self.isNew: self.volnameEntry.set_text(self.vg.name) else: - self.volnameEntry.set_text(self.storage.suggestContainerName(hostname=anaconda.network.hostname, + self.volnameEntry.set_text(self.storage.suggestContainerName(hostname=getHostname(), prefix="vg")) else: lbl = createAlignedLabel(_("Volume Group Name:")) diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py index cf20c39..8df2038 100644 --- a/pyanaconda/iw/network_gui.py +++ b/pyanaconda/iw/network_gui.py @@ -40,7 +40,7 @@ class NetworkWindow(InstallWindow): def getScreen(self, anaconda): self.intf = anaconda.intf self.anaconda = anaconda - self.hostname = network.getDefaultHostname(anaconda) + self.hostname = network.getHostname()
# load the UI (self.xml, self.align) = gui.getGladeWidget("network.glade", @@ -95,7 +95,6 @@ class NetworkWindow(InstallWindow): custom_icon="error") self.hostnameError()
- self.anaconda.network.hostname = hostname network.setHostname(hostname) return None
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 37a37bc..4a2cbb7 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -645,7 +645,6 @@ class NetworkData(commands.network.F16_NetworkData): def execute(self): if flags.imageInstall: if self.hostname != "": - self.anaconda.network.hostname = self.hostname network.setHostname(self.hostname)
# Only set hostname @@ -655,7 +654,6 @@ class NetworkData(commands.network.F16_NetworkData): # only set hostname if self.essid: if self.hostname != "": - self.anaconda.network.hostname = self.hostname network.setHostname(self.hostname) return
@@ -708,7 +706,6 @@ class NetworkData(commands.network.F16_NetworkData): break
if self.hostname != "": - self.anaconda.network.hostname = self.hostname network.setHostname(self.hostname) if not dev: # Only set hostname diff --git a/pyanaconda/network.py b/pyanaconda/network.py index c7f11b7..65ef239 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -94,7 +94,7 @@ def sanityCheckHostname(hostname): return None
# Try to determine what the hostname should be for this system -def getDefaultHostname(anaconda): +def getHostname(): resetResolver()
hn = None @@ -114,14 +114,6 @@ def getDefaultHostname(anaconda): hn = hinfo[0] break
- if hn and hn not in ('(none)', 'localhost', 'localhost.localdomain'): - return hn - - try: - hn = anaconda.network.hostname - except: - hn = None - if not hn or hn in ('(none)', 'localhost', 'localhost.localdomain'): hn = socket.gethostname()
@@ -436,8 +428,6 @@ class Network:
def __init__(self):
- self.hostname = socket.gethostname() - self.update()
def update(self): @@ -460,11 +450,6 @@ class Network: else: device.setDefaultConfig()
- # TODORV - the last iface in loop wins, might be ok, - # not worthy of special juggling - if device.get('HOSTNAME'): - self.hostname = device.get('HOSTNAME') - device.description = isys.getNetDevDesc(iface)
self.netdevices[iface] = device @@ -494,9 +479,10 @@ class Network: if len(devNames) == 0: return
+ hostname = getHostname() for devName in devNames: dev = self.netdevices[devName] - line = "%s" % kickstartNetworkData(dev, self.hostname) + line = "%s" % kickstartNetworkData(dev, hostname) f.write(line)
def disableNMForStorageDevices(self, anaconda): @@ -546,9 +532,9 @@ class Network: f.write("NETWORKING=yes\n") f.write("HOSTNAME=")
- # use instclass hostname if set(kickstart) to override - if self.hostname: - f.write(self.hostname + "\n") + hostname = getHostname() + if hostname: + f.write(hostname + "\n") else: f.write("localhost.localdomain\n")
@@ -616,7 +602,7 @@ class Network:
return dracutBootArguments(self.netdevices[nic], networkStorageDevice.host_address, - self.hostname) + getHostname())
def getDevices(): # TODO: filter with existence of ifcfg file? diff --git a/pyanaconda/textw/network_text.py b/pyanaconda/textw/network_text.py index 58eb81e..a33d7f5 100644 --- a/pyanaconda/textw/network_text.py +++ b/pyanaconda/textw/network_text.py @@ -26,8 +26,7 @@ from pyanaconda import network
class HostnameWindow: def __call__(self, screen, anaconda): - hname = network.getDefaultHostname(anaconda) - anaconda.network.hostname = hname + hname = network.getHostname() return INSTALL_OK
# vim:tw=78:ts=4:et:sw=4 diff --git a/pyanaconda/vnc.py b/pyanaconda/vnc.py index a7ccc76..b38f233 100644 --- a/pyanaconda/vnc.py +++ b/pyanaconda/vnc.py @@ -105,7 +105,7 @@ class VncServer: except Exception as e: log.debug("Exception caught trying to get host name of %s: %s" % (ipstr, e)) - self.name = network.getDefaultHostname(self.anaconda) + self.name = network.getHostname() else: if len(hinfo) == 3: self.name = hinfo[0]
--- pyanaconda/iw/network_gui.py | 2 +- pyanaconda/network.py | 4 ---- 2 files changed, 1 insertions(+), 5 deletions(-)
diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py index 8df2038..bdf2ee8 100644 --- a/pyanaconda/iw/network_gui.py +++ b/pyanaconda/iw/network_gui.py @@ -162,7 +162,7 @@ def selectInstallNetDeviceDialog(network, devices = None): if not preselected: preselected = i
- desc = network.netdevices[dev].description + desc = isys.getNetDevDesc(dev) if desc: desc = "%s - %s" %(dev, desc) else: diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 65ef239..2d55b67 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -205,7 +205,6 @@ class NetworkDevice(IfcfgFile):
def __init__(self, dir, iface): IfcfgFile.__init__(self, dir, iface) - self.description = "" if iface.startswith('ctc'): self.info["TYPE"] = "CTC" self.wepkey = "" @@ -391,7 +390,6 @@ class WirelessNetworkDevice(NetworkDevice): self.info = dict() self.iface = iface self.dir = "" - self.description = ""
def clear(self): self.info = dict() @@ -450,8 +448,6 @@ class Network: else: device.setDefaultConfig()
- device.description = isys.getNetDevDesc(iface) - self.netdevices[iface] = device
@property
--- pyanaconda/bootloader.py | 18 ++++-------------- pyanaconda/network.py | 37 +++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 32 deletions(-)
diff --git a/pyanaconda/bootloader.py b/pyanaconda/bootloader.py index 991c8de..5e6485c 100644 --- a/pyanaconda/bootloader.py +++ b/pyanaconda/bootloader.py @@ -28,12 +28,13 @@ import struct
from pyanaconda import iutil from pyanaconda.storage.devicelibs import mdraid -from pyanaconda.isys import sync +from pyanaconda.isys import sync, getMacAddress from pyanaconda.product import productName from pyanaconda.flags import flags from pyanaconda.constants import * from pyanaconda.storage.errors import StorageError from pyanaconda.storage.fcoe import fcoe +import pyanaconda.network
import gettext _ = lambda x: gettext.ldgettext("anaconda", x) @@ -750,14 +751,11 @@ class BootLoader(object): Keyword Arguments:
storage - a pyanaconda.storage.Storage instance - network - a pyanaconda.network.Network instance (for network - storage devices' boot arguments)
All other arguments are expected to have a dracutSetupArgs() method. """ storage = kwargs.pop("storage", None) - network = kwargs.pop("network", None)
# # FIPS @@ -811,15 +809,7 @@ class BootLoader(object): # network storage # XXX this is nothing to be proud of if isinstance(dep, NetworkStorageDevice): - if network is None: - log.error("missing network instance for setup of boot " - "command line for network storage device %s" - % dep.name) - raise BootLoaderError("missing network instance when " - "setting boot args for network " - "storage device") - - setup_args = network.dracutSetupArgs(dep) + setup_args = pyanaconda.network.dracutSetupArgs(dep) self.boot_args.update(setup_args) self.dracut_args.update(setup_args)
@@ -845,7 +835,7 @@ class BootLoader(object): # Dracut needs the explicit ifname= because biosdevname # fails to rename the iface (because of BFS booting from it). for nic, dcb, auto_vlan in fcoe().nics: - hwaddr = network.netdevices[nic].get("HWADDR") + hwaddr = getMacAddress(nic) self.boot_args.add("ifname=%s:%s" % (nic, hwaddr.lower()))
# diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 2d55b67..cf16292 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -582,24 +582,6 @@ class Network: else: return False
- # get a kernel cmdline string for dracut needed for access to host host - def dracutSetupArgs(self, networkStorageDevice): - - if networkStorageDevice.nic == "default": - nic = ifaceForHostIP(networkStorageDevice.host_address) - if not nic: - return "" - else: - nic = networkStorageDevice.nic - - if nic not in self.netdevices.keys(): - log.error('Unknown network interface: %s' % nic) - return "" - - return dracutBootArguments(self.netdevices[nic], - networkStorageDevice.host_address, - getHostname()) - def getDevices(): # TODO: filter with existence of ifcfg file? return isys.getDeviceProperties().keys() @@ -652,6 +634,25 @@ def waitForConnection():
return False
+# get a kernel cmdline string for dracut needed for access to storage host +def dracutSetupArgs(networkStorageDevice): + + if networkStorageDevice.nic == "default": + nic = ifaceForHostIP(networkStorageDevice.host_address) + if not nic: + return "" + else: + nic = networkStorageDevice.nic + + if nic not in getDevices(): + log.error('Unknown network interface: %s' % nic) + return "" + + ifcfg = NetworkDevice(netscriptsDir, nic) + ifcfg.loadIfcfgFile() + return dracutBootArguments(ifcfg, + networkStorageDevice.host_address, + getHostname())
def dracutBootArguments(ifcfg, storage_ipaddr, hostname=None):
This seems not to be used anymore as this happens in newui apply. --- pyanaconda/network.py | 26 +++++++++++++------------- 1 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py index cf16292..9e8a28a 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -468,19 +468,6 @@ class Network: return dev.get('IPV6_DEFAULTGW') return ""
- def writeKS(self, f): - devNames = self.netdevices.keys() - devNames.sort() - - if len(devNames) == 0: - return - - hostname = getHostname() - for devName in devNames: - dev = self.netdevices[devName] - line = "%s" % kickstartNetworkData(dev, hostname) - f.write(line) - def disableNMForStorageDevices(self, anaconda): for devName, device in self.netdevices.items(): if (device.usedByFCoE(anaconda) or @@ -713,6 +700,19 @@ def dracutBootArguments(ifcfg, storage_ipaddr, hostname=None):
return netargs
+def writeKS(f): + devNames = getDevices() + + if len(devNames) == 0: + return + + hostname = getHostname() + for devName in devNames.sort(): + ifcfg = NetworkDevice(netscriptsDir, devName) + ifcfg.loadIfcfgFile() + line = "%s" % kickstartNetworkData(ifcfg, hostname) + f.write(line) + def kickstartNetworkData(ifcfg, hostname=None):
from pyanaconda.kickstart import NetworkData
diff --git a/pyanaconda/network.py b/pyanaconda/network.py index cf16292..9e8a28a 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -468,19 +468,6 @@ class Network: return dev.get('IPV6_DEFAULTGW') return ""
- def writeKS(self, f):
devNames = self.netdevices.keys()devNames.sort()if len(devNames) == 0:returnhostname = getHostname()for devName in devNames:dev = self.netdevices[devName]line = "%s" % kickstartNetworkData(dev, hostname)f.write(line)- def disableNMForStorageDevices(self, anaconda): for devName, device in self.netdevices.items(): if (device.usedByFCoE(anaconda) or
@@ -713,6 +700,19 @@ def dracutBootArguments(ifcfg, storage_ipaddr, hostname=None):
return netargs+def writeKS(f):
- devNames = getDevices()
- if len(devNames) == 0:
return- hostname = getHostname()
- for devName in devNames.sort():
ifcfg = NetworkDevice(netscriptsDir, devName)ifcfg.loadIfcfgFile()line = "%s" % kickstartNetworkData(ifcfg, hostname)f.write(line)def kickstartNetworkData(ifcfg, hostname=None):
from pyanaconda.kickstart import NetworkData
We don't need writeKS methods anymore, so long as ksdata is being set properly. They were previously only there to convert data being stored internally to anaconda into a text format that could be written to anaconda-ks.cfg. But now with using ksdata for everything, we get this almost for free - all we do is call str().
So, you shouldn't need to add a new writeKS here. It won't get called from anywhere anyway.
- Chris
On 07/19/2012 03:58 PM, Chris Lumens wrot
We don't need writeKS methods anymore, so long as ksdata is being set properly. They were previously only there to convert data being stored internally to anaconda into a text format that could be written to anaconda-ks.cfg. But now with using ksdata for everything, we get this almost for free - all we do is call str().
So, you shouldn't need to add a new writeKS here. It won't get called from anywhere anyway.
Yep, that's what I was thinking, I'll just remove the writeKS then.
--- pyanaconda/network.py | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-)
diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 9e8a28a..4fed523 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -538,12 +538,6 @@ class Network:
devices = self.netdevices.values()
- # /etc/sysconfig/network-scripts/ifcfg-* - # /etc/sysconfig/network-scripts/keys-* - for dev in devices: - - dev.writeIfcfgFile() - # /etc/resolv.conf is managed by NM
# disable ipv6
--- 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()
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()
Not sure if this happens in a later patch or not, but you'll want to find another place to put these lines. anaconda.write isn't called from anywhere and I'm in the process of removing the method entirely.
There are a couple different strategies I've been using for this. See how storage does it for one, and doInstall for another.
- Chris
On 07/19/2012 04:03 PM, Chris Lumens wrote:
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()Not sure if this happens in a later patch or not, but you'll want to find another place to put these lines. anaconda.write isn't called from anywhere and I'm in the process of removing the method entirely.
There are a couple different strategies I've been using for this. See how storage does it for one, and doInstall for another.
This is on my list of things to figure out, thanks for hints.
--- pyanaconda/__init__.py | 1 + pyanaconda/network.py | 31 +++++++++++++++++++------------ pyanaconda/yuminstall.py | 1 + 3 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py index db835c4..4763def 100644 --- a/pyanaconda/__init__.py +++ b/pyanaconda/__init__.py @@ -288,6 +288,7 @@ class Anaconda(object): if not self.ksdata: self.instClass.setNetworkOnbootDefault(self.network) self.network.write() + network.disableIPV6() network.copyConfigToPath(ROOT_PATH) network.disableNMForStorageDevices(self.storage) network.autostartFCoEDevices(self.storage) diff --git a/pyanaconda/network.py b/pyanaconda/network.py index ef15463..b26240f 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -490,18 +490,6 @@ class Network:
# /etc/resolv.conf is managed by NM
- # disable ipv6 - if ('noipv6' in flags.cmdline - and not any(dev.get('IPV6INIT') == "yes" for dev in devices)): - if os.path.exists(ipv6ConfFile): - log.warning('Not disabling ipv6, %s exists' % ipv6ConfFile) - else: - log.info('Disabling ipv6 on target system') - f = open(ipv6ConfFile, "w") - f.write("# Anaconda disabling ipv6\n") - f.write("options ipv6 disable=1\n") - f.close() - # 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 @@ -886,6 +874,25 @@ def get_ksdevice_name(ksspec=""):
return ksdevice
+# note that NetworkDevice.get returns "" if key is not found +def get_ifcfg_value(iface, key, root_path=""): + dev = NetworkDevice(os.path.normpath(root_path + netscriptsDir), iface) + dev.loadIfcfgFile() + return dev.get(key) + +# TODO: do it right in sysroot (instead of copying the files later)? +def disableIPV6(): + if ('noipv6' in flags.cmdline + and not any(get_ifcfg_value(dev, 'IPV6INIT') == "yes" + for dev in getDevices())): + if os.path.exists(ipv6ConfFile): + log.warning('Not disabling ipv6, %s exists' % ipv6ConfFile) + else: + log.info('Disabling ipv6 on target system') + f = open(ipv6ConfFile, "w") + f.write("# Anaconda disabling ipv6\n") + f.write("options ipv6 disable=1\n") + f.close()
def disableNMForStorageDevices(storage): for devname in getDevices(): diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py index b47f4de..a80bcbb 100644 --- a/pyanaconda/yuminstall.py +++ b/pyanaconda/yuminstall.py @@ -1626,6 +1626,7 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon if not anaconda.ksdata: anaconda.instClass.setNetworkOnbootDefault(anaconda.network) anaconda.network.write() + network.disableIPV6() network.copyConfigToPath(ROOT_PATH) anaconda.storage.write() else:
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py index db835c4..4763def 100644 --- a/pyanaconda/__init__.py +++ b/pyanaconda/__init__.py @@ -288,6 +288,7 @@ class Anaconda(object): if not self.ksdata: self.instClass.setNetworkOnbootDefault(self.network) self.network.write()
network.disableIPV6() network.copyConfigToPath(ROOT_PATH) network.disableNMForStorageDevices(self.storage) network.autostartFCoEDevices(self.storage)
See previous comment about anaconda.write.
- Chris
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()
This is almost the final step, the object is not used anymore, I am keeping the rest only not to forget to handle what is left: - I need to look at imageInstall - creating default ifcfg files (setDefaultConfig) should go to dracut or some network initialization step
The whole patchset removes anaconda.network object aiming to have all data/configuration in ksdata.
The object was needed for our GUI using nm-c-e. We used to keep list of device configuration objects (basically ifcfg dictionaries) in it so that we could tweak them to be able to use nm-c-e for configuration/activation of devices. Now it seems we can do without the list although we still need to do some modifications of ifcfg files at the end of installation (setting onboot policy, setting values for devices used for storage)
Hopefuly we'll be able to represent all the data stored in network object in ksdata.
Following to the patchset I want to update ksdata with NetworkData objects for all devices and use it to replace network.getDevices(). I have to think where it should happen: - in kickstart.py - or somewhere in pre-gui network initialization (so that it happens also for non-ks cases) where we e.g. activate default device if needed. - or in initialize of standalone spoke - seems to late, we'll need it already for eventual bring-up of network
-----
To sum up what the network.py serves for now:
Some of network utility functions (more of them are in isys): - hostname sanity checking - ip sanity checking - hostname resolution - status of networking - connected? - list of active devices - logging (ifcfg files)
Network configuration: - hostname setting (getting?) - note: storage (lvm, raid) is using hostname for default names - ksdevice resolution (link, MAC address, bootif) - probably we'll be able to remove it, now it is only used for unspecified --device in kickstart network command - write kickstart (currently from ifcfg config) - used by apply method - write dracut arguments (from ifcfg config) - note: depends on storage - modify configuration of target system (ifcfg files) - note: depends on storage - ONBOOT policy (differs on rhel and Fedora) - FCoE - ONBOOT=yes the devices - root on iSCSI - NM_CONTROLLED=no for root on iscsi (there is a NM BZ to fix this) - write /etc/sysconfig/network configuration - this should be reviewed - copy network configuration files to system - ifcfg-<iface> files and wireless key-<iface> files - dhclient-<iface>.conf files (dhcpclass and dhcp timeout which is not supported in noloader) - /etc/sysconfig/network - /etc/resolv.conf - genrated by NM - /etc/udev/rules.d/70-persistent-net.rules (review) - disable ipv6 on target system (noipv6 boot/ks option) --- pyanaconda/__init__.py | 4 ++-- pyanaconda/installclass.py | 2 +- pyanaconda/installclasses/fedora.py | 13 ++++++++----- pyanaconda/iw/advanced_storage.py | 8 ++++---- pyanaconda/iw/network_gui.py | 6 +++--- pyanaconda/kickstart.py | 26 +++++++++++++++++--------- pyanaconda/network.py | 32 +++++++------------------------- pyanaconda/rescue.py | 15 +-------------- pyanaconda/text.py | 4 ++-- pyanaconda/textw/add_drive_text.py | 6 +++--- pyanaconda/textw/netconfig_text.py | 16 ++++++++++------ pyanaconda/vnc.py | 3 +-- pyanaconda/yuminstall.py | 4 ++-- 13 files changed, 61 insertions(+), 78 deletions(-)
diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py index 0b2e93a..18628d2 100644 --- a/pyanaconda/__init__.py +++ b/pyanaconda/__init__.py @@ -285,11 +285,11 @@ class Anaconda(object): self.instLanguage.write()
self.timezone.write() - if not self.ksdata: - self.instClass.setNetworkOnbootDefault(self.network) network.write_sysconfig_network() network.disableIPV6() network.copyConfigToPath(ROOT_PATH) + if not self.ksdata: + self.instClass.setNetworkOnbootDefault() network.disableNMForStorageDevices(self.storage) network.autostartFCoEDevices(self.storage) self.desktop.write() diff --git a/pyanaconda/installclass.py b/pyanaconda/installclass.py index 144df91..cf6fb8d 100644 --- a/pyanaconda/installclass.py +++ b/pyanaconda/installclass.py @@ -217,7 +217,7 @@ class BaseInstallClass(object):
return (all(result.values()), result)
- def setNetworkOnbootDefault(self, network): + def setNetworkOnbootDefault(self): pass
def __init__(self): diff --git a/pyanaconda/installclasses/fedora.py b/pyanaconda/installclasses/fedora.py index bc575ea..e2c1543 100644 --- a/pyanaconda/installclasses/fedora.py +++ b/pyanaconda/installclasses/fedora.py @@ -21,7 +21,7 @@ from pyanaconda.installclass import BaseInstallClass from pyanaconda.constants import * from pyanaconda.product import * from pyanaconda import iutil -from pyanaconda.network import hasActiveNetDev +from pyanaconda import network from pyanaconda import isys
import os, types @@ -122,17 +122,20 @@ class InstallClass(BaseInstallClass): # than two versions ago! return newVer >= oldVer and newVer - oldVer <= 2
- def setNetworkOnbootDefault(self, network): + def setNetworkOnbootDefault(self): # if something's already enabled, we can just leave the config alone - for devName, dev in network.netdevices.items(): - if dev.get('ONBOOT') == 'yes': + for devName in network.getDevices(): + if network.get_ifcfg_value(devName, "ONBOOT", ROOT_PATH) == "yes": return
# the default otherwise: bring up the first wired netdev with link - for devName, dev in network.netdevices.items(): + for devName in network.getDevices(): if (not isys.isWirelessDevice(devName) and isys.getLinkStatus(devName)): + dev = network.NetworkDevice(ROOT_PATH + network.netscriptsDir, devName) + dev.loadIfcfgFile() dev.set(('ONBOOT', 'yes')) + dev.writeIfcfgFile() break
def __init__(self): diff --git a/pyanaconda/iw/advanced_storage.py b/pyanaconda/iw/advanced_storage.py index 1375d7e..c343b9f 100644 --- a/pyanaconda/iw/advanced_storage.py +++ b/pyanaconda/iw/advanced_storage.py @@ -31,6 +31,7 @@ from pyanaconda import network from pyanaconda import partIntfHelpers as pih import pyanaconda.storage.fcoe import pyanaconda.storage.iscsi +from pyanaconda import isys
import logging log = logging.getLogger("anaconda") @@ -337,19 +338,18 @@ def addFcoeDrive(anaconda): store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING) combo.set_model(store)
- netdevs = anaconda.network.netdevices - keys = netdevs.keys() + keys = network.getDevices() keys.sort() selected_interface = None for dev in keys: i = store.append(None) - desc = netdevs[dev].description + desc = isys.getNetDevDesc(dev) if desc: desc = "%s - %s" %(dev, desc) else: desc = "%s" %(dev,)
- mac = netdevs[dev].get("HWADDR") + mac = isys.getMacAddress(dev) if mac: desc = "%s - %s" %(desc, mac)
diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py index bdf2ee8..1fac765 100644 --- a/pyanaconda/iw/network_gui.py +++ b/pyanaconda/iw/network_gui.py @@ -51,7 +51,7 @@ class NetworkWindow(InstallWindow):
self.netconfButton = self.xml.get_widget("netconfButton") self.netconfButton.connect("clicked", self._netconfButton_clicked) - if (len(self.anaconda.network.netdevices) == 0 + if (len(network.getDevices()) == 0 or flags.imageInstall or flags.livecdInstall): self.netconfButton.set_sensitive(False) @@ -129,7 +129,7 @@ def runNMCE(anaconda=None, blocking=True):
def selectInstallNetDeviceDialog(network, devices = None):
- devs = devices or network.netdevices.keys() + devs = devices or network.getDevices() if not devs: return None devs.sort() @@ -168,7 +168,7 @@ def selectInstallNetDeviceDialog(network, devices = None): else: desc = "%s" %(dev,)
- hwaddr = network.netdevices[dev].get("HWADDR") + hwaddr = isys.getMacAddress(dev)
if hwaddr: desc = "%s - %s" %(desc, hwaddr,) diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 4a2cbb7..285f643 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -657,7 +657,7 @@ class NetworkData(commands.network.F16_NetworkData): network.setHostname(self.hostname) return
- devices = self.anaconda.network.netdevices + devices = network.getDevices()
if not self.device: if "ksdevice" in flags.cmdline: @@ -669,7 +669,7 @@ class NetworkData(commands.network.F16_NetworkData): device = network.getActiveNetDevs()[0] else: msg = "first device found" - device = min(devices.keys()) + device = min(devices) log.info("unspecified network --device in kickstart, using %s (%s)" % (device, msg)) else: @@ -695,16 +695,20 @@ class NetworkData(commands.network.F16_NetworkData): # If we were given a network device name, grab the device object. # If we were given a MAC address, resolve that to a device name # and then grab the device object. Otherwise, errors. - dev = None
- if devices.has_key(device): - dev = devices[device] - else: - for (key, val) in devices.iteritems(): - if val.get("HWADDR").lower() == device.lower(): - dev = val + if device not in devices: + for d in devices: + if isys.getMacAddress(d).lower() == device.lower(): + device = d break
+ dev = network.NetworkDevice(ROOT_PATH, device) + try: + dev.loadIfcfgFile() + except IOError as e: + log.info("Can't load ifcfg file %s" % dev.path) + dev = None + if self.hostname != "": network.setHostname(self.hostname) if not dev: @@ -765,6 +769,10 @@ class NetworkData(commands.network.F16_NetworkData): if self.nodefroute: dev.set (("DEFROUTE", "no"))
+ #TODO + # write ifcfg file, carefuly handle ONBOOT value, + # problems - might activate the device!!! + class MultiPath(commands.multipath.FC6_MultiPath): def parse(self, args): raise NotImplementedError("The multipath kickstart command is not currently supported") diff --git a/pyanaconda/network.py b/pyanaconda/network.py index bf94b1d..2cb57b2 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -405,41 +405,23 @@ class Network:
def __init__(self):
- self.update() - - def update(self): - ifcfglog.debug("Network.update() called") - - self.netdevices = {} + ifcfglog.debug("Network object created called")
+ # TODO this may need to be handled in getDevices() if flags.imageInstall: return
+ # TODO this should go away (patch pending), + # default ifcfg files should be created in dracut + # populate self.netdevices devhash = isys.getDeviceProperties(dev=None) for iface in devhash.keys(): - if isys.isWirelessDevice(iface): - device = WirelessNetworkDevice(iface) - else: + if not isys.isWirelessDevice(iface): device = NetworkDevice(netscriptsDir, iface) - if os.access(device.path, os.R_OK): - device.loadIfcfgFile() - else: + if not os.access(device.path, os.R_OK): device.setDefaultConfig()
- self.netdevices[iface] = device - - # 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): - write_sysconfig_network() - if waitForConnection(): - resetResolver() - return True - else: - return False - def getDevices(): # TODO: filter with existence of ifcfg file? return isys.getDeviceProperties().keys() diff --git a/pyanaconda/rescue.py b/pyanaconda/rescue.py index 4a17390..828fcb3 100644 --- a/pyanaconda/rescue.py +++ b/pyanaconda/rescue.py @@ -93,7 +93,7 @@ class RescueInterface(InstallInterfaceBase): return OkCancelWindow(self.screen, title, text)
def enableNetwork(self, anaconda): - if len(anaconda.network.netdevices) == 0: + if len(network.getDevices()) == 0: return False from textw.netconfig_text import NetworkConfiguratorText w = NetworkConfiguratorText(self.screen, anaconda) @@ -172,18 +172,6 @@ def makeResolvConf(instPath): f.write(buf) f.close()
-# -# Write out something useful for networking and start interfaces -# -def startNetworking(network, intf): - # do lo first - if os.system("/usr/sbin/ifconfig lo 127.0.0.1"): - log.error("Error trying to start lo in rescue.py::startNetworking()") - - # start up dhcp interfaces first - if not network.bringUp(): - log.error("Error bringing up network interfaces") - def runShell(screen = None, msg=""): if screen: screen.suspend() @@ -239,7 +227,6 @@ def doRescue(anaconda): "will not be available in rescue mode.")) break
- startNetworking(anaconda.network, anaconda.intf) break else: break diff --git a/pyanaconda/text.py b/pyanaconda/text.py index 1b201c1..020f92a 100644 --- a/pyanaconda/text.py +++ b/pyanaconda/text.py @@ -36,7 +36,7 @@ from localeinfo import expandLangs from flags import flags from textw.constants_text import * from constants import * -from network import hasActiveNetDev +from network import hasActiveNetDev, getDevices from installinterfacebase import InstallInterfaceBase import imp import textw @@ -389,7 +389,7 @@ class InstallInterface(InstallInterfaceBase): return passphrase
def enableNetwork(self): - if len(self.anaconda.network.netdevices) == 0: + if len(getDevices) == 0: return False from textw.netconfig_text import NetworkConfiguratorText w = NetworkConfiguratorText(self.screen, self.anaconda) diff --git a/pyanaconda/textw/add_drive_text.py b/pyanaconda/textw/add_drive_text.py index b28af4f..5c9384d 100644 --- a/pyanaconda/textw/add_drive_text.py +++ b/pyanaconda/textw/add_drive_text.py @@ -24,6 +24,7 @@ from snack import * from constants_text import * from pyanaconda.constants import * import pyanaconda.partIntfHelpers as pih +from pyanaconda import isys
import gettext _ = lambda x: gettext.ldgettext("anaconda", x) @@ -363,8 +364,7 @@ class addDriveDialog(object): return INSTALL_OK
def addFcoeDriveDialog(self, screen): - netdevs = self.anaconda.network.netdevices - devs = netdevs.keys() + devs = network.getDevices() devs.sort()
if not devs: @@ -381,7 +381,7 @@ class addDriveDialog(object):
interfaceList = Listbox(height=len(devs), scroll=1) for dev in devs: - hwaddr = netdevs[dev].get("HWADDR") + hwaddr = isys.getMacAddress(dev) if hwaddr: desc = "%s - %.50s" % (dev, hwaddr) else: diff --git a/pyanaconda/textw/netconfig_text.py b/pyanaconda/textw/netconfig_text.py index 6be52f3..852201e 100644 --- a/pyanaconda/textw/netconfig_text.py +++ b/pyanaconda/textw/netconfig_text.py @@ -45,7 +45,7 @@ class NetworkConfiguratorText: def __init__(self, screen, anaconda): self.screen = screen self.anaconda = anaconda - self.netdevs = self.anaconda.network.netdevices + self.netdevs = network.getDevices()
self._initValues()
@@ -68,14 +68,13 @@ class NetworkConfiguratorText: dev_list = [] selected_devname = None
- devnames = self.netdevs.keys() - devnames.sort() + devnames = self.netdevs.sort()
# Preselect device set in kickstart ksdevice = network.get_ksdevice_name()
for devname in devnames: - hwaddr = self.netdevs[devname].get("HWADDR") + hwaddr = isys.getMacAddress(devname)
if hwaddr: desc = "%s - %.50s" % (devname, hwaddr) @@ -348,7 +347,9 @@ class NetworkConfiguratorText: Returns True in case of success, False if failed. """
- dev = self.netdevs[devname] + dev = network.NetworkDevice(ROOT_PATH, devname) + dev.loadIfcfgFile() + nameservers = ''
if self.ipv4Selected: @@ -395,15 +396,18 @@ class NetworkConfiguratorText: dev.set(('ONBOOT', 'yes'))
w = self.anaconda.intf.waitWindow(_("Configuring Network Interfaces"), _("Waiting for NetworkManager")) - result = self.anaconda.network.bringUp() + dev.writeIfcfgFile() + result = network.waitForConnection() w.pop() if not result: self.anaconda.intf.messageWindow(_("Network Error"), _("There was an error configuring " "network device %s") % dev.iface) dev.set(("ONBOOT", "no")) + dev.writeIfcfgFile() return False
+ network.resetResolver() return True
def _ipv4MethodToggled(self, *args): diff --git a/pyanaconda/vnc.py b/pyanaconda/vnc.py index b38f233..64c2ce1 100644 --- a/pyanaconda/vnc.py +++ b/pyanaconda/vnc.py @@ -80,12 +80,11 @@ class VncServer: # see if we can sniff out network info netinfo = network.Network()
- devices = netinfo.netdevices active_devs = network.getActiveNetDevs()
self.ip = None if active_devs != []: - devname = devices[active_devs[0]].iface + devname = active_devs[0] try: ips = (isys.getIPAddresses(devname, version=4) + isys.getIPAddresses(devname, version=6)) diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py index fd7ba3e..bb98b86 100644 --- a/pyanaconda/yuminstall.py +++ b/pyanaconda/yuminstall.py @@ -1623,11 +1623,11 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon if os.access("/etc/modprobe.d/anaconda.conf", os.R_OK): shutil.copyfile("/etc/modprobe.d/anaconda.conf", ROOT_PATH + "/etc/modprobe.d/anaconda.conf") - if not anaconda.ksdata: - anaconda.instClass.setNetworkOnbootDefault(anaconda.network) network.write_sysconfig_network() network.disableIPV6() network.copyConfigToPath(ROOT_PATH) + if not anaconda.ksdata: + anaconda.instClass.setNetworkOnbootDefault() anaconda.storage.write() else: # ensure that /etc/mtab is a symlink to /proc/self/mounts
This patchset is removing anaconda.network with the goal to use only ksdata to store network configuration.
See [15/15] for details and what will follow.
I want to do also some furher cleanup, review of hostname setting, /etc/sysconfig/network setting etc.
move some methods out of Network object still keeping old ui working --- pyanaconda/gui.py | 4 +- pyanaconda/iw/network_gui.py | 3 +- pyanaconda/kickstart.py | 13 ++- pyanaconda/network.py | 210 +++++++++++++-------------------- pyanaconda/textw/netconfig_text.py | 4 +- tests/pyanaconda_test/network_test.py | 107 ++++------------- 6 files changed, 123 insertions(+), 218 deletions(-)
diff --git a/pyanaconda/gui.py b/pyanaconda/gui.py index d8360a9..308ee86 100755 --- a/pyanaconda/gui.py +++ b/pyanaconda/gui.py @@ -934,7 +934,7 @@ class InstallInterface(InstallInterfaceBase): w = self.anaconda.intf.waitWindow(_("Wireless setup"), _("Scanning access points for wireless devices")) # get available wireless APs - dev_all_ssids = self.anaconda.network.getSSIDs() + dev_all_ssids = network.getSSIDs() w.pop() # select wireless APs dev_ssids = selectSSIDsDialog(dev_all_ssids) or dev_all_ssids @@ -961,7 +961,7 @@ class InstallInterface(InstallInterfaceBase): w = WaitWindow(_("Waiting for NetworkManager"), _("Waiting for NetworkManager to activate " "these devices: %s") % ",".join(waited_devs)) - failed_devs = self.anaconda.network.waitForDevicesActivation(waited_devs) + failed_devs = network.waitForDevicesActivation(waited_devs) w.pop()
if just_setup: diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py index 1521db0..f1c19c0 100644 --- a/pyanaconda/iw/network_gui.py +++ b/pyanaconda/iw/network_gui.py @@ -95,7 +95,8 @@ class NetworkWindow(InstallWindow): custom_icon="error") self.hostnameError()
- self.anaconda.network.setHostname(hostname) + self.anaconda.network.hostname = hostname + network.setHostname(hostname) return None
def NMCEExited(pid, condition, anaconda): diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 8a74713..8238c88 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -645,7 +645,8 @@ class NetworkData(commands.network.F16_NetworkData): def execute(self): if flags.imageInstall: if self.hostname != "": - self.anaconda.network.setHostname(self.hostname) + self.anaconda.network.hostname = self.hostname + network.setHostname(self.hostname)
# Only set hostname return @@ -654,7 +655,8 @@ class NetworkData(commands.network.F16_NetworkData): # only set hostname if self.essid: if self.hostname != "": - self.anaconda.network.setHostname(self.hostname) + self.anaconda.network.hostname = self.hostname + network.setHostname(self.hostname) return
devices = self.anaconda.network.netdevices @@ -706,7 +708,8 @@ class NetworkData(commands.network.F16_NetworkData): break
if self.hostname != "": - self.anaconda.network.setHostname(self.hostname) + self.anaconda.network.hostname = self.hostname + network.setHostname(self.hostname) if not dev: # Only set hostname return @@ -757,10 +760,10 @@ class NetworkData(commands.network.F16_NetworkData): dev.set(("ETHTOOL_OPTS", self.ethtool))
if self.nameserver != "": - self.anaconda.network.setDNS(self.nameserver, dev.iface) + dev.setDNS(self.nameserver)
if self.gateway != "": - self.anaconda.network.setGateway(self.gateway, dev.iface) + dev.setGateway(self.gateway)
if self.nodefroute: dev.set (("DEFROUTE", "no")) diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 859c368..0a5ad61 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -362,6 +362,31 @@ class NetworkDevice(IfcfgFile):
return False
+ def setGateway(self, gw): + if ':' in gw: + self.set(('IPV6_DEFAULTGW', gw)) + else: + self.set(('GATEWAY', gw)) + + def unsetDNS(self): + """Unset all DNS* ifcfg parameters.""" + i = 1 + while True: + if self.get("DNS%d" % i): + self.unset("DNS%d" %i) + else: + break + i += 1 + + def setDNS(self, ns): + dns = ns.split(',') + i = 1 + for addr in dns: + addr = addr.strip() + dnslabel = "DNS%d" % (i,) + self.set((dnslabel, addr)) + i += 1 + class WirelessNetworkDevice(NetworkDevice):
""" @@ -469,11 +494,6 @@ class Network: self.ksdevice = dev break
- - - def getDevice(self, device): - return self.netdevices[device] - def getKSDevice(self): if self.ksdevice is None: return None @@ -483,42 +503,6 @@ class Network: except: return None
- def setHostname(self, hn): - self.hostname = hn - if flags.imageInstall: - log.info("image install -- not setting hostname") - return - - log.info("setting installation environment hostname to %s" % hn) - iutil.execWithRedirect("hostname", ["-v", hn ], - stdout="/dev/tty5", stderr="/dev/tty5") - - def unsetDNS(self, devname): - """Unset all DNS* ifcfg parameters.""" - i = 1 - dev = self.netdevices[devname] - while True: - if dev.get("DNS%d" % i): - dev.unset("DNS%d" %i) - else: - break - i += 1 - - def setDNS(self, ns, device): - dns = ns.split(',') - i = 1 - for addr in dns: - addr = addr.strip() - dnslabel = "DNS%d" % (i,) - self.netdevices[device].set((dnslabel, addr)) - i += 1 - - def setGateway(self, gw, device): - if ':' in gw: - self.netdevices[device].set(('IPV6_DEFAULTGW', gw)) - else: - self.netdevices[device].set(('GATEWAY', gw)) - @property def gateway(self): """GATEWAY - last device in list wins""" @@ -537,29 +521,6 @@ class Network: return dev.get('IPV6_DEFAULTGW') return ""
- def lookupHostname(self): - # can't look things up if they don't exist! - if not self.hostname or self.hostname == "localhost.localdomain": - return None - - if not hasActiveNetDev(): - log.warning("no network devices were available to look up host name") - return None - - try: - (family, socktype, proto, canonname, sockaddr) = \ - socket.getaddrinfo(self.hostname, None, socket.AF_INET)[0] - (ip, port) = sockaddr - except: - try: - (family, socktype, proto, canonname, sockaddr) = \ - socket.getaddrinfo(self.hostname, None, socket.AF_INET6)[0] - (ip, port, flowinfo, scopeid) = sockaddr - except: - return None - - return ip - # Note that the file is written-out only if there is a value # that has changed. def writeIfcfgFiles(self): @@ -595,10 +556,6 @@ class Network: "NM_CONTROLLED=yes\n") ifcfgfile.close()
- - def getSSIDs(self): - return getSSIDs() - def writeKS(self, f): devNames = self.netdevices.keys() devNames.sort() @@ -611,16 +568,6 @@ class Network: line = "%s" % kickstartNetworkData(dev, self.hostname) f.write(line)
- def hasNameServers(self, hash): - if hash.keys() == []: - return False - - for key in hash.keys(): - if key.upper().startswith('DNS'): - return True - - return False - def hasWirelessDev(self): for dev in self.netdevices: if isys.isWirelessDevice(dev): @@ -768,60 +715,12 @@ class Network: f.write("options ipv6 disable=1\n") f.close()
- def waitForDevicesActivation(self, devices): - waited_devs_props = {} - - bus = dbus.SystemBus() - nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) - device_paths = nm.get_dbus_method("GetDevices")() - for device_path in device_paths: - device = bus.get_object(isys.NM_SERVICE, device_path) - device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE) - iface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface")) - if iface in devices: - waited_devs_props[iface] = device_props_iface - - i = 0 - while True: - for dev, device_props_iface in waited_devs_props.items(): - state = device_props_iface.Get(isys.NM_DEVICE_IFACE, "State") - if state == isys.NM_DEVICE_STATE_ACTIVATED: - waited_devs_props.pop(dev) - if len(waited_devs_props) == 0 or i >= CONNECTION_TIMEOUT: - break - i += 1 - time.sleep(1) - - return waited_devs_props.keys() - - # 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 waitForConnection(self): - bus = dbus.SystemBus() - nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) - props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE) - - i = 0 - while i < CONNECTION_TIMEOUT: - state = props.Get(isys.NM_SERVICE, "State") - if nmIsConnected(state): - return True - i += 1 - time.sleep(1) - - state = props.Get(isys.NM_SERVICE, "State") - if nmIsConnected(state): - return True - - return False - # 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() - if self.waitForConnection(): + if waitForConnection(): resetResolver() return True else: @@ -901,6 +800,55 @@ class Network:
return netargs
+def waitForDevicesActivation(devices): + waited_devs_props = {} + + bus = dbus.SystemBus() + nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) + device_paths = nm.get_dbus_method("GetDevices")() + for device_path in device_paths: + device = bus.get_object(isys.NM_SERVICE, device_path) + device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE) + iface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface")) + if iface in devices: + waited_devs_props[iface] = device_props_iface + + i = 0 + while True: + for dev, device_props_iface in waited_devs_props.items(): + state = device_props_iface.Get(isys.NM_DEVICE_IFACE, "State") + if state == isys.NM_DEVICE_STATE_ACTIVATED: + waited_devs_props.pop(dev) + if len(waited_devs_props) == 0 or i >= CONNECTION_TIMEOUT: + break + i += 1 + time.sleep(1) + + return waited_devs_props.keys() + +# 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 waitForConnection(): + bus = dbus.SystemBus() + nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) + props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE) + + i = 0 + while i < CONNECTION_TIMEOUT: + state = props.Get(isys.NM_SERVICE, "State") + if nmIsConnected(state): + return True + i += 1 + time.sleep(1) + + state = props.Get(isys.NM_SERVICE, "State") + if nmIsConnected(state): + return True + + return False + + def kickstartNetworkData(ifcfg, hostname=None):
from pyanaconda.kickstart import NetworkData @@ -1037,3 +985,11 @@ def resetResolver(): isys.resetResolv() urlgrabber.grabber.reset_curl_obj()
+def setHostname(hn): + if flags.imageInstall: + log.info("image install -- not setting hostname") + return + + log.info("setting installation environment hostname to %s" % hn) + iutil.execWithRedirect("hostname", ["-v", hn ], + stdout="/dev/tty5", stderr="/dev/tty5") diff --git a/pyanaconda/textw/netconfig_text.py b/pyanaconda/textw/netconfig_text.py index aabd7d5..ed1fff2 100644 --- a/pyanaconda/textw/netconfig_text.py +++ b/pyanaconda/textw/netconfig_text.py @@ -390,9 +390,9 @@ class NetworkConfiguratorText: else: dev.set(("IPV6INIT", "no"))
- self.anaconda.network.unsetDNS(devname) + self.netdevs[devname].unsetDNS() if nameservers: - self.anaconda.network.setDNS(nameservers, devname) + self.netdevs[devname].setDNS(nameservers)
dev.set(('ONBOOT', 'yes'))
diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py index 561ddab..7ad58cf 100644 --- a/tests/pyanaconda_test/network_test.py +++ b/tests/pyanaconda_test/network_test.py @@ -262,6 +262,28 @@ class NetworkTest(mock.TestCase): self.assertEqual(nd.info, {'KEY': 'other_value'}) self.assertTrue(nd._dirty)
+ def networkdevice_set_gateway_test(self): + import pyanaconda.network + nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE) + nd.setGateway('10.0.0.1') + self.assertEqual(nd.info, {'GATEWAY': '10.0.0.1'}) + self.assertTrue(nd._dirty) + + def networkdevice_set_gateway_ipv6_test(self): + import pyanaconda.network + nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE) + nd.setGateway('fe80::5675:d0ff:feac:4d3f') + self.assertEqual(nd.info, {'IPV6_DEFAULTGW': 'fe80::5675:d0ff:feac:4d3f'}) + self.assertTrue(nd._dirty) + + def networkdevice_set_dns_test(self): + import pyanaconda.network + nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE) + nd.setDNS('10.0.0.1, 10.0.0.2') + self.assertEqual(nd.info, {'DNS1': '10.0.0.1'}) + self.assertEqual(nd.info, {'DNS2': '10.0.0.2'}) + self.assertTrue(nd._dirty) + def networkdevice_keyfile_path_test(self): import pyanaconda.network nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE) @@ -294,14 +316,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(pyanaconda.network.shutil.move.call_args[0], (TMP_FILE, '%s/keys-%s' % (TMP_DIR, self.DEVICE)))
- def network_get_device_test(self): - import pyanaconda.network - - nw = pyanaconda.network.Network() - nw.netdevices['dev'] = 'device' - ret = nw.getDevice('dev') - self.assertEqual(ret, 'device') - def network_get_ks_device_1_test(self): import pyanaconda.network nw = pyanaconda.network.Network() @@ -324,57 +338,6 @@ class NetworkTest(mock.TestCase): ret = nw.getKSDevice() self.assertEqual(ret, 'device')
- def network_set_hostname_test(self): - import pyanaconda.network - pyanaconda.network.iutil.execWithRedirect = mock.Mock() - nw = pyanaconda.network.Network() - nw.setHostname('DESKTOP') - self.assertEqual(nw.hostname, 'DESKTOP') - - def network_set_dns_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices['dev'] = mock.Mock() - nw.setDNS('10.0.0.1, 10.0.0.2', 'dev') - self.assertEqual(nw.netdevices['dev'].method_calls, - [('set', (('DNS1', '10.0.0.1'),), {}), - ('set', (('DNS2', '10.0.0.2'),), {})] - ) - - def network_set_gateway_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices['eth0'] = mock.Mock() - nw.setGateway('10.0.0.1', 'eth0') - self.assertEqual(pyanaconda.network.Network.netdevices['eth0'].method_calls, - [('set', (('GATEWAY', '10.0.0.1'),), {})]) - - def network_lookup_hostname_1_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.hostname = None - ret = nw.lookupHostname() - self.assertEqual(ret, None) - - def network_lookup_hostname_2_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.hostname = 'desktop' - pyanaconda.network.hasActiveNetDev = mock.Mock(return_value=False) - ret = nw.lookupHostname() - self.assertEqual(ret, None) - - def network_lookup_hostname_3_test(self): - import pyanaconda.network - pyanaconda.network.socket.getaddrinfo.return_value = \ - [(0, 0, 0, 0, ('10.1.1.1', 0))] - - nw = pyanaconda.network.Network() - nw.hostname = 'desktop' - pyanaconda.network.hasActiveNetDev = mock.Mock(return_value=True) - ret = nw.lookupHostname() - self.assertEqual(ret, '10.1.1.1') - def network_write_ifcfg_files_test(self): import pyanaconda.network nw = pyanaconda.network.Network() @@ -458,22 +421,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(self.fs[TMPFILE], 'network --device eth0 --bootproto dhcp --noipv6\n')
- def network_has_name_server_1_test(self): - import pyanaconda.network - hash = {'foo':'', 'bar':''} - - nw = pyanaconda.network.Network() - ret = nw.hasNameServers(hash) - self.assertFalse(ret) - - def network_has_name_server_2_test(self): - import pyanaconda.network - hash = {'foo':'', 'bar':'', 'dnsserver':''} - - nw = pyanaconda.network.Network() - ret = nw.hasNameServers(hash) - self.assertTrue(ret) - def network_has_wireless_dev_1_test(self): import pyanaconda.network pyanaconda.network.isys = mock.Mock() @@ -556,8 +503,7 @@ class NetworkTest(mock.TestCase): pyanaconda.network.dbus.Interface().Get.return_value = \ pyanaconda.network.isys.NM_STATE_CONNECTED_GLOBAL
- nw = pyanaconda.network.Network() - ret = nw.waitForConnection() + ret = pyanaconda.network.waitForConnection() self.assertTrue(ret)
def network_wait_for_connection_2_test(self): @@ -568,19 +514,18 @@ class NetworkTest(mock.TestCase): pyanaconda.network.isys.NM_STATE_CONNECTED = self.OK pyanaconda.network.time.sleep = mock.Mock()
- nw = pyanaconda.network.Network() - ret = nw.waitForConnection() + ret = pyanaconda.network.waitForConnection() self.assertFalse(ret)
def network_bring_up_test(self): import pyanaconda.network pyanaconda.network.Network.write = mock.Mock() - pyanaconda.network.Network.waitForConnection = mock.Mock() + pyanaconda.network.waitForConnection = mock.Mock()
nw = pyanaconda.network.Network() nw.bringUp() self.assertTrue(pyanaconda.network.Network.write.called) - self.assertTrue(pyanaconda.network.Network.waitForConnection.called) + self.assertTrue(pyanaconda.network.waitForConnection.called)
def iface_for_host_ip_test(self): import pyanaconda.network
Please ignore this message.
On 07/19/2012 12:25 PM, Radek Vykydal wrote:
move some methods out of Network object still keeping old ui working
pyanaconda/gui.py | 4 +- pyanaconda/iw/network_gui.py | 3 +- pyanaconda/kickstart.py | 13 ++- pyanaconda/network.py | 210 +++++++++++++-------------------- pyanaconda/textw/netconfig_text.py | 4 +- tests/pyanaconda_test/network_test.py | 107 ++++------------- 6 files changed, 123 insertions(+), 218 deletions(-)
diff --git a/pyanaconda/gui.py b/pyanaconda/gui.py index d8360a9..308ee86 100755 --- a/pyanaconda/gui.py +++ b/pyanaconda/gui.py @@ -934,7 +934,7 @@ class InstallInterface(InstallInterfaceBase): w = self.anaconda.intf.waitWindow(_("Wireless setup"), _("Scanning access points for wireless devices")) # get available wireless APs
dev_all_ssids = self.anaconda.network.getSSIDs()
dev_all_ssids = network.getSSIDs() w.pop() # select wireless APs dev_ssids = selectSSIDsDialog(dev_all_ssids) or dev_all_ssids@@ -961,7 +961,7 @@ class InstallInterface(InstallInterfaceBase): w = WaitWindow(_("Waiting for NetworkManager"), _("Waiting for NetworkManager to activate " "these devices: %s") % ",".join(waited_devs))
failed_devs = self.anaconda.network.waitForDevicesActivation(waited_devs)
failed_devs = network.waitForDevicesActivation(waited_devs) w.pop() if just_setup:diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py index 1521db0..f1c19c0 100644 --- a/pyanaconda/iw/network_gui.py +++ b/pyanaconda/iw/network_gui.py @@ -95,7 +95,8 @@ class NetworkWindow(InstallWindow): custom_icon="error") self.hostnameError()
self.anaconda.network.setHostname(hostname)
self.anaconda.network.hostname = hostnamenetwork.setHostname(hostname) return Nonedef NMCEExited(pid, condition, anaconda):
diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 8a74713..8238c88 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -645,7 +645,8 @@ class NetworkData(commands.network.F16_NetworkData): def execute(self): if flags.imageInstall: if self.hostname != "":
self.anaconda.network.setHostname(self.hostname)
self.anaconda.network.hostname = self.hostnamenetwork.setHostname(self.hostname) # Only set hostname return@@ -654,7 +655,8 @@ class NetworkData(commands.network.F16_NetworkData): # only set hostname if self.essid: if self.hostname != "":
self.anaconda.network.setHostname(self.hostname)
self.anaconda.network.hostname = self.hostnamenetwork.setHostname(self.hostname) return devices = self.anaconda.network.netdevices@@ -706,7 +708,8 @@ class NetworkData(commands.network.F16_NetworkData): break
if self.hostname != "":
self.anaconda.network.setHostname(self.hostname)
self.anaconda.network.hostname = self.hostnamenetwork.setHostname(self.hostname) if not dev: # Only set hostname return@@ -757,10 +760,10 @@ class NetworkData(commands.network.F16_NetworkData): dev.set(("ETHTOOL_OPTS", self.ethtool))
if self.nameserver != "":
self.anaconda.network.setDNS(self.nameserver, dev.iface)
dev.setDNS(self.nameserver) if self.gateway != "":
self.anaconda.network.setGateway(self.gateway, dev.iface)
dev.setGateway(self.gateway) if self.nodefroute: dev.set (("DEFROUTE", "no"))diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 859c368..0a5ad61 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -362,6 +362,31 @@ class NetworkDevice(IfcfgFile):
return False
def setGateway(self, gw):
if ':' in gw:self.set(('IPV6_DEFAULTGW', gw))else:self.set(('GATEWAY', gw))def unsetDNS(self):
"""Unset all DNS* ifcfg parameters."""i = 1while True:if self.get("DNS%d" % i):self.unset("DNS%d" %i)else:breaki += 1def setDNS(self, ns):
dns = ns.split(',')i = 1for addr in dns:addr = addr.strip()dnslabel = "DNS%d" % (i,)self.set((dnslabel, addr))i += 1class WirelessNetworkDevice(NetworkDevice):
"""@@ -469,11 +494,6 @@ class Network: self.ksdevice = dev break
- def getDevice(self, device):
return self.netdevices[device]def getKSDevice(self): if self.ksdevice is None: return None@@ -483,42 +503,6 @@ class Network: except: return None
- def setHostname(self, hn):
self.hostname = hnif flags.imageInstall:log.info("image install -- not setting hostname")returnlog.info("setting installation environment hostname to %s" % hn)iutil.execWithRedirect("hostname", ["-v", hn ],stdout="/dev/tty5", stderr="/dev/tty5")- def unsetDNS(self, devname):
"""Unset all DNS* ifcfg parameters."""i = 1dev = self.netdevices[devname]while True:if dev.get("DNS%d" % i):dev.unset("DNS%d" %i)else:breaki += 1- def setDNS(self, ns, device):
dns = ns.split(',')i = 1for addr in dns:addr = addr.strip()dnslabel = "DNS%d" % (i,)self.netdevices[device].set((dnslabel, addr))i += 1- def setGateway(self, gw, device):
if ':' in gw:self.netdevices[device].set(('IPV6_DEFAULTGW', gw))else:self.netdevices[device].set(('GATEWAY', gw))@property def gateway(self): """GATEWAY - last device in list wins"""@@ -537,29 +521,6 @@ class Network: return dev.get('IPV6_DEFAULTGW') return ""
- def lookupHostname(self):
# can't look things up if they don't exist!if not self.hostname or self.hostname == "localhost.localdomain":return Noneif not hasActiveNetDev():log.warning("no network devices were available to look up host name")return Nonetry:(family, socktype, proto, canonname, sockaddr) = \socket.getaddrinfo(self.hostname, None, socket.AF_INET)[0](ip, port) = sockaddrexcept:try:(family, socktype, proto, canonname, sockaddr) = \socket.getaddrinfo(self.hostname, None, socket.AF_INET6)[0](ip, port, flowinfo, scopeid) = sockaddrexcept:return Nonereturn ip# Note that the file is written-out only if there is a value # that has changed. def writeIfcfgFiles(self):@@ -595,10 +556,6 @@ class Network: "NM_CONTROLLED=yes\n") ifcfgfile.close()
- def getSSIDs(self):
return getSSIDs()def writeKS(self, f): devNames = self.netdevices.keys() devNames.sort()@@ -611,16 +568,6 @@ class Network: line = "%s" % kickstartNetworkData(dev, self.hostname) f.write(line)
- def hasNameServers(self, hash):
if hash.keys() == []:return Falsefor key in hash.keys():if key.upper().startswith('DNS'):return Truereturn Falsedef hasWirelessDev(self): for dev in self.netdevices: if isys.isWirelessDevice(dev):@@ -768,60 +715,12 @@ class Network: f.write("options ipv6 disable=1\n") f.close()
- def waitForDevicesActivation(self, devices):
waited_devs_props = {}bus = dbus.SystemBus()nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)device_paths = nm.get_dbus_method("GetDevices")()for device_path in device_paths:device = bus.get_object(isys.NM_SERVICE, device_path)device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)iface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface"))if iface in devices:waited_devs_props[iface] = device_props_ifacei = 0while True:for dev, device_props_iface in waited_devs_props.items():state = device_props_iface.Get(isys.NM_DEVICE_IFACE, "State")if state == isys.NM_DEVICE_STATE_ACTIVATED:waited_devs_props.pop(dev)if len(waited_devs_props) == 0 or i >= CONNECTION_TIMEOUT:breaki += 1time.sleep(1)return waited_devs_props.keys()- # 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 waitForConnection(self):
bus = dbus.SystemBus()nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)i = 0while i < CONNECTION_TIMEOUT:state = props.Get(isys.NM_SERVICE, "State")if nmIsConnected(state):return Truei += 1time.sleep(1)state = props.Get(isys.NM_SERVICE, "State")if nmIsConnected(state):return Truereturn False# 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()if self.waitForConnection():
if waitForConnection(): resetResolver() return True else:@@ -901,6 +800,55 @@ class Network:
return netargs+def waitForDevicesActivation(devices):
- waited_devs_props = {}
- bus = dbus.SystemBus()
- nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
- device_paths = nm.get_dbus_method("GetDevices")()
- for device_path in device_paths:
device = bus.get_object(isys.NM_SERVICE, device_path)device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE)iface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface"))if iface in devices:waited_devs_props[iface] = device_props_iface- i = 0
- while True:
for dev, device_props_iface in waited_devs_props.items():state = device_props_iface.Get(isys.NM_DEVICE_IFACE, "State")if state == isys.NM_DEVICE_STATE_ACTIVATED:waited_devs_props.pop(dev)if len(waited_devs_props) == 0 or i >= CONNECTION_TIMEOUT:breaki += 1time.sleep(1)- return waited_devs_props.keys()
+# 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 waitForConnection():
bus = dbus.SystemBus()
nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH)
props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE)
i = 0
while i < CONNECTION_TIMEOUT:
state = props.Get(isys.NM_SERVICE, "State")if nmIsConnected(state):return Truei += 1time.sleep(1)state = props.Get(isys.NM_SERVICE, "State")
if nmIsConnected(state):
return Truereturn False
def kickstartNetworkData(ifcfg, hostname=None):
from pyanaconda.kickstart import NetworkData@@ -1037,3 +985,11 @@ def resetResolver(): isys.resetResolv() urlgrabber.grabber.reset_curl_obj()
+def setHostname(hn):
- if flags.imageInstall:
log.info("image install -- not setting hostname")return- log.info("setting installation environment hostname to %s" % hn)
- iutil.execWithRedirect("hostname", ["-v", hn ],
stdout="/dev/tty5", stderr="/dev/tty5")diff --git a/pyanaconda/textw/netconfig_text.py b/pyanaconda/textw/netconfig_text.py index aabd7d5..ed1fff2 100644 --- a/pyanaconda/textw/netconfig_text.py +++ b/pyanaconda/textw/netconfig_text.py @@ -390,9 +390,9 @@ class NetworkConfiguratorText: else: dev.set(("IPV6INIT", "no"))
self.anaconda.network.unsetDNS(devname)
self.netdevs[devname].unsetDNS() if nameservers:
self.anaconda.network.setDNS(nameservers, devname)
self.netdevs[devname].setDNS(nameservers) dev.set(('ONBOOT', 'yes'))diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py index 561ddab..7ad58cf 100644 --- a/tests/pyanaconda_test/network_test.py +++ b/tests/pyanaconda_test/network_test.py @@ -262,6 +262,28 @@ class NetworkTest(mock.TestCase): self.assertEqual(nd.info, {'KEY': 'other_value'}) self.assertTrue(nd._dirty)
- def networkdevice_set_gateway_test(self):
import pyanaconda.networknd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE)nd.setGateway('10.0.0.1')self.assertEqual(nd.info, {'GATEWAY': '10.0.0.1'})self.assertTrue(nd._dirty)- def networkdevice_set_gateway_ipv6_test(self):
import pyanaconda.networknd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE)nd.setGateway('fe80::5675:d0ff:feac:4d3f')self.assertEqual(nd.info, {'IPV6_DEFAULTGW': 'fe80::5675:d0ff:feac:4d3f'})self.assertTrue(nd._dirty)- def networkdevice_set_dns_test(self):
import pyanaconda.networknd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE)nd.setDNS('10.0.0.1, 10.0.0.2')self.assertEqual(nd.info, {'DNS1': '10.0.0.1'})self.assertEqual(nd.info, {'DNS2': '10.0.0.2'})self.assertTrue(nd._dirty)def networkdevice_keyfile_path_test(self): import pyanaconda.network nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE)@@ -294,14 +316,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(pyanaconda.network.shutil.move.call_args[0], (TMP_FILE, '%s/keys-%s' % (TMP_DIR, self.DEVICE)))
- def network_get_device_test(self):
import pyanaconda.networknw = pyanaconda.network.Network()nw.netdevices['dev'] = 'device'ret = nw.getDevice('dev')self.assertEqual(ret, 'device')def network_get_ks_device_1_test(self): import pyanaconda.network nw = pyanaconda.network.Network()@@ -324,57 +338,6 @@ class NetworkTest(mock.TestCase): ret = nw.getKSDevice() self.assertEqual(ret, 'device')
- def network_set_hostname_test(self):
import pyanaconda.networkpyanaconda.network.iutil.execWithRedirect = mock.Mock()nw = pyanaconda.network.Network()nw.setHostname('DESKTOP')self.assertEqual(nw.hostname, 'DESKTOP')- def network_set_dns_test(self):
import pyanaconda.networknw = pyanaconda.network.Network()nw.netdevices['dev'] = mock.Mock()nw.setDNS('10.0.0.1, 10.0.0.2', 'dev')self.assertEqual(nw.netdevices['dev'].method_calls,[('set', (('DNS1', '10.0.0.1'),), {}),('set', (('DNS2', '10.0.0.2'),), {})])- def network_set_gateway_test(self):
import pyanaconda.networknw = pyanaconda.network.Network()nw.netdevices['eth0'] = mock.Mock()nw.setGateway('10.0.0.1', 'eth0')self.assertEqual(pyanaconda.network.Network.netdevices['eth0'].method_calls,[('set', (('GATEWAY', '10.0.0.1'),), {})])- def network_lookup_hostname_1_test(self):
import pyanaconda.networknw = pyanaconda.network.Network()nw.hostname = Noneret = nw.lookupHostname()self.assertEqual(ret, None)- def network_lookup_hostname_2_test(self):
import pyanaconda.networknw = pyanaconda.network.Network()nw.hostname = 'desktop'pyanaconda.network.hasActiveNetDev = mock.Mock(return_value=False)ret = nw.lookupHostname()self.assertEqual(ret, None)- def network_lookup_hostname_3_test(self):
import pyanaconda.networkpyanaconda.network.socket.getaddrinfo.return_value = \[(0, 0, 0, 0, ('10.1.1.1', 0))]nw = pyanaconda.network.Network()nw.hostname = 'desktop'pyanaconda.network.hasActiveNetDev = mock.Mock(return_value=True)ret = nw.lookupHostname()self.assertEqual(ret, '10.1.1.1')def network_write_ifcfg_files_test(self): import pyanaconda.network nw = pyanaconda.network.Network()@@ -458,22 +421,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(self.fs[TMPFILE], 'network --device eth0 --bootproto dhcp --noipv6\n')
- def network_has_name_server_1_test(self):
import pyanaconda.networkhash = {'foo':'', 'bar':''}nw = pyanaconda.network.Network()ret = nw.hasNameServers(hash)self.assertFalse(ret)- def network_has_name_server_2_test(self):
import pyanaconda.networkhash = {'foo':'', 'bar':'', 'dnsserver':''}nw = pyanaconda.network.Network()ret = nw.hasNameServers(hash)self.assertTrue(ret)def network_has_wireless_dev_1_test(self): import pyanaconda.network pyanaconda.network.isys = mock.Mock()@@ -556,8 +503,7 @@ class NetworkTest(mock.TestCase): pyanaconda.network.dbus.Interface().Get.return_value = \ pyanaconda.network.isys.NM_STATE_CONNECTED_GLOBAL
nw = pyanaconda.network.Network()ret = nw.waitForConnection()
ret = pyanaconda.network.waitForConnection() self.assertTrue(ret) def network_wait_for_connection_2_test(self):@@ -568,19 +514,18 @@ class NetworkTest(mock.TestCase): pyanaconda.network.isys.NM_STATE_CONNECTED = self.OK pyanaconda.network.time.sleep = mock.Mock()
nw = pyanaconda.network.Network()ret = nw.waitForConnection()
ret = pyanaconda.network.waitForConnection() self.assertFalse(ret) def network_bring_up_test(self): import pyanaconda.network pyanaconda.network.Network.write = mock.Mock()
pyanaconda.network.Network.waitForConnection = mock.Mock()
pyanaconda.network.waitForConnection = mock.Mock() nw = pyanaconda.network.Network() nw.bringUp() self.assertTrue(pyanaconda.network.Network.write.called)
self.assertTrue(pyanaconda.network.Network.waitForConnection.called)
self.assertTrue(pyanaconda.network.waitForConnection.called) def iface_for_host_ip_test(self): import pyanaconda.network
Please ignore this
On 07/19/2012 12:25 PM, Radek Vykydal wrote:
This patchset is removing anaconda.network with the goal to use only ksdata to store network configuration.
See [15/15] for details and what will follow.
I want to do also some furher cleanup, review of hostname setting, /etc/sysconfig/network setting etc.
anaconda-patches mailing list anaconda-patches@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/anaconda-patches
move some methods out of Network object still keeping old ui working --- pyanaconda/gui.py | 4 +- pyanaconda/iw/network_gui.py | 3 +- pyanaconda/kickstart.py | 13 ++- pyanaconda/network.py | 210 +++++++++++++-------------------- pyanaconda/textw/netconfig_text.py | 4 +- tests/pyanaconda_test/network_test.py | 107 ++++------------- 6 files changed, 123 insertions(+), 218 deletions(-)
diff --git a/pyanaconda/gui.py b/pyanaconda/gui.py index d8360a9..308ee86 100755 --- a/pyanaconda/gui.py +++ b/pyanaconda/gui.py @@ -934,7 +934,7 @@ class InstallInterface(InstallInterfaceBase): w = self.anaconda.intf.waitWindow(_("Wireless setup"), _("Scanning access points for wireless devices")) # get available wireless APs - dev_all_ssids = self.anaconda.network.getSSIDs() + dev_all_ssids = network.getSSIDs() w.pop() # select wireless APs dev_ssids = selectSSIDsDialog(dev_all_ssids) or dev_all_ssids @@ -961,7 +961,7 @@ class InstallInterface(InstallInterfaceBase): w = WaitWindow(_("Waiting for NetworkManager"), _("Waiting for NetworkManager to activate " "these devices: %s") % ",".join(waited_devs)) - failed_devs = self.anaconda.network.waitForDevicesActivation(waited_devs) + failed_devs = network.waitForDevicesActivation(waited_devs) w.pop()
if just_setup: diff --git a/pyanaconda/iw/network_gui.py b/pyanaconda/iw/network_gui.py index 1521db0..f1c19c0 100644 --- a/pyanaconda/iw/network_gui.py +++ b/pyanaconda/iw/network_gui.py @@ -95,7 +95,8 @@ class NetworkWindow(InstallWindow): custom_icon="error") self.hostnameError()
- self.anaconda.network.setHostname(hostname) + self.anaconda.network.hostname = hostname + network.setHostname(hostname) return None
def NMCEExited(pid, condition, anaconda): diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py index 8a74713..8238c88 100644 --- a/pyanaconda/kickstart.py +++ b/pyanaconda/kickstart.py @@ -645,7 +645,8 @@ class NetworkData(commands.network.F16_NetworkData): def execute(self): if flags.imageInstall: if self.hostname != "": - self.anaconda.network.setHostname(self.hostname) + self.anaconda.network.hostname = self.hostname + network.setHostname(self.hostname)
# Only set hostname return @@ -654,7 +655,8 @@ class NetworkData(commands.network.F16_NetworkData): # only set hostname if self.essid: if self.hostname != "": - self.anaconda.network.setHostname(self.hostname) + self.anaconda.network.hostname = self.hostname + network.setHostname(self.hostname) return
devices = self.anaconda.network.netdevices @@ -706,7 +708,8 @@ class NetworkData(commands.network.F16_NetworkData): break
if self.hostname != "": - self.anaconda.network.setHostname(self.hostname) + self.anaconda.network.hostname = self.hostname + network.setHostname(self.hostname) if not dev: # Only set hostname return @@ -757,10 +760,10 @@ class NetworkData(commands.network.F16_NetworkData): dev.set(("ETHTOOL_OPTS", self.ethtool))
if self.nameserver != "": - self.anaconda.network.setDNS(self.nameserver, dev.iface) + dev.setDNS(self.nameserver)
if self.gateway != "": - self.anaconda.network.setGateway(self.gateway, dev.iface) + dev.setGateway(self.gateway)
if self.nodefroute: dev.set (("DEFROUTE", "no")) diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 859c368..0a5ad61 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -362,6 +362,31 @@ class NetworkDevice(IfcfgFile):
return False
+ def setGateway(self, gw): + if ':' in gw: + self.set(('IPV6_DEFAULTGW', gw)) + else: + self.set(('GATEWAY', gw)) + + def unsetDNS(self): + """Unset all DNS* ifcfg parameters.""" + i = 1 + while True: + if self.get("DNS%d" % i): + self.unset("DNS%d" %i) + else: + break + i += 1 + + def setDNS(self, ns): + dns = ns.split(',') + i = 1 + for addr in dns: + addr = addr.strip() + dnslabel = "DNS%d" % (i,) + self.set((dnslabel, addr)) + i += 1 + class WirelessNetworkDevice(NetworkDevice):
""" @@ -469,11 +494,6 @@ class Network: self.ksdevice = dev break
- - - def getDevice(self, device): - return self.netdevices[device] - def getKSDevice(self): if self.ksdevice is None: return None @@ -483,42 +503,6 @@ class Network: except: return None
- def setHostname(self, hn): - self.hostname = hn - if flags.imageInstall: - log.info("image install -- not setting hostname") - return - - log.info("setting installation environment hostname to %s" % hn) - iutil.execWithRedirect("hostname", ["-v", hn ], - stdout="/dev/tty5", stderr="/dev/tty5") - - def unsetDNS(self, devname): - """Unset all DNS* ifcfg parameters.""" - i = 1 - dev = self.netdevices[devname] - while True: - if dev.get("DNS%d" % i): - dev.unset("DNS%d" %i) - else: - break - i += 1 - - def setDNS(self, ns, device): - dns = ns.split(',') - i = 1 - for addr in dns: - addr = addr.strip() - dnslabel = "DNS%d" % (i,) - self.netdevices[device].set((dnslabel, addr)) - i += 1 - - def setGateway(self, gw, device): - if ':' in gw: - self.netdevices[device].set(('IPV6_DEFAULTGW', gw)) - else: - self.netdevices[device].set(('GATEWAY', gw)) - @property def gateway(self): """GATEWAY - last device in list wins""" @@ -537,29 +521,6 @@ class Network: return dev.get('IPV6_DEFAULTGW') return ""
- def lookupHostname(self): - # can't look things up if they don't exist! - if not self.hostname or self.hostname == "localhost.localdomain": - return None - - if not hasActiveNetDev(): - log.warning("no network devices were available to look up host name") - return None - - try: - (family, socktype, proto, canonname, sockaddr) = \ - socket.getaddrinfo(self.hostname, None, socket.AF_INET)[0] - (ip, port) = sockaddr - except: - try: - (family, socktype, proto, canonname, sockaddr) = \ - socket.getaddrinfo(self.hostname, None, socket.AF_INET6)[0] - (ip, port, flowinfo, scopeid) = sockaddr - except: - return None - - return ip - # Note that the file is written-out only if there is a value # that has changed. def writeIfcfgFiles(self): @@ -595,10 +556,6 @@ class Network: "NM_CONTROLLED=yes\n") ifcfgfile.close()
- - def getSSIDs(self): - return getSSIDs() - def writeKS(self, f): devNames = self.netdevices.keys() devNames.sort() @@ -611,16 +568,6 @@ class Network: line = "%s" % kickstartNetworkData(dev, self.hostname) f.write(line)
- def hasNameServers(self, hash): - if hash.keys() == []: - return False - - for key in hash.keys(): - if key.upper().startswith('DNS'): - return True - - return False - def hasWirelessDev(self): for dev in self.netdevices: if isys.isWirelessDevice(dev): @@ -768,60 +715,12 @@ class Network: f.write("options ipv6 disable=1\n") f.close()
- def waitForDevicesActivation(self, devices): - waited_devs_props = {} - - bus = dbus.SystemBus() - nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) - device_paths = nm.get_dbus_method("GetDevices")() - for device_path in device_paths: - device = bus.get_object(isys.NM_SERVICE, device_path) - device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE) - iface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface")) - if iface in devices: - waited_devs_props[iface] = device_props_iface - - i = 0 - while True: - for dev, device_props_iface in waited_devs_props.items(): - state = device_props_iface.Get(isys.NM_DEVICE_IFACE, "State") - if state == isys.NM_DEVICE_STATE_ACTIVATED: - waited_devs_props.pop(dev) - if len(waited_devs_props) == 0 or i >= CONNECTION_TIMEOUT: - break - i += 1 - time.sleep(1) - - return waited_devs_props.keys() - - # 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 waitForConnection(self): - bus = dbus.SystemBus() - nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) - props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE) - - i = 0 - while i < CONNECTION_TIMEOUT: - state = props.Get(isys.NM_SERVICE, "State") - if nmIsConnected(state): - return True - i += 1 - time.sleep(1) - - state = props.Get(isys.NM_SERVICE, "State") - if nmIsConnected(state): - return True - - return False - # 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() - if self.waitForConnection(): + if waitForConnection(): resetResolver() return True else: @@ -901,6 +800,55 @@ class Network:
return netargs
+def waitForDevicesActivation(devices): + waited_devs_props = {} + + bus = dbus.SystemBus() + nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) + device_paths = nm.get_dbus_method("GetDevices")() + for device_path in device_paths: + device = bus.get_object(isys.NM_SERVICE, device_path) + device_props_iface = dbus.Interface(device, isys.DBUS_PROPS_IFACE) + iface = str(device_props_iface.Get(isys.NM_DEVICE_IFACE, "Interface")) + if iface in devices: + waited_devs_props[iface] = device_props_iface + + i = 0 + while True: + for dev, device_props_iface in waited_devs_props.items(): + state = device_props_iface.Get(isys.NM_DEVICE_IFACE, "State") + if state == isys.NM_DEVICE_STATE_ACTIVATED: + waited_devs_props.pop(dev) + if len(waited_devs_props) == 0 or i >= CONNECTION_TIMEOUT: + break + i += 1 + time.sleep(1) + + return waited_devs_props.keys() + +# 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 waitForConnection(): + bus = dbus.SystemBus() + nm = bus.get_object(isys.NM_SERVICE, isys.NM_MANAGER_PATH) + props = dbus.Interface(nm, isys.DBUS_PROPS_IFACE) + + i = 0 + while i < CONNECTION_TIMEOUT: + state = props.Get(isys.NM_SERVICE, "State") + if nmIsConnected(state): + return True + i += 1 + time.sleep(1) + + state = props.Get(isys.NM_SERVICE, "State") + if nmIsConnected(state): + return True + + return False + + def kickstartNetworkData(ifcfg, hostname=None):
from pyanaconda.kickstart import NetworkData @@ -1037,3 +985,11 @@ def resetResolver(): isys.resetResolv() urlgrabber.grabber.reset_curl_obj()
+def setHostname(hn): + if flags.imageInstall: + log.info("image install -- not setting hostname") + return + + log.info("setting installation environment hostname to %s" % hn) + iutil.execWithRedirect("hostname", ["-v", hn ], + stdout="/dev/tty5", stderr="/dev/tty5") diff --git a/pyanaconda/textw/netconfig_text.py b/pyanaconda/textw/netconfig_text.py index aabd7d5..ed1fff2 100644 --- a/pyanaconda/textw/netconfig_text.py +++ b/pyanaconda/textw/netconfig_text.py @@ -390,9 +390,9 @@ class NetworkConfiguratorText: else: dev.set(("IPV6INIT", "no"))
- self.anaconda.network.unsetDNS(devname) + self.netdevs[devname].unsetDNS() if nameservers: - self.anaconda.network.setDNS(nameservers, devname) + self.netdevs[devname].setDNS(nameservers)
dev.set(('ONBOOT', 'yes'))
diff --git a/tests/pyanaconda_test/network_test.py b/tests/pyanaconda_test/network_test.py index 561ddab..7ad58cf 100644 --- a/tests/pyanaconda_test/network_test.py +++ b/tests/pyanaconda_test/network_test.py @@ -262,6 +262,28 @@ class NetworkTest(mock.TestCase): self.assertEqual(nd.info, {'KEY': 'other_value'}) self.assertTrue(nd._dirty)
+ def networkdevice_set_gateway_test(self): + import pyanaconda.network + nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE) + nd.setGateway('10.0.0.1') + self.assertEqual(nd.info, {'GATEWAY': '10.0.0.1'}) + self.assertTrue(nd._dirty) + + def networkdevice_set_gateway_ipv6_test(self): + import pyanaconda.network + nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE) + nd.setGateway('fe80::5675:d0ff:feac:4d3f') + self.assertEqual(nd.info, {'IPV6_DEFAULTGW': 'fe80::5675:d0ff:feac:4d3f'}) + self.assertTrue(nd._dirty) + + def networkdevice_set_dns_test(self): + import pyanaconda.network + nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE) + nd.setDNS('10.0.0.1, 10.0.0.2') + self.assertEqual(nd.info, {'DNS1': '10.0.0.1'}) + self.assertEqual(nd.info, {'DNS2': '10.0.0.2'}) + self.assertTrue(nd._dirty) + def networkdevice_keyfile_path_test(self): import pyanaconda.network nd = pyanaconda.network.NetworkDevice(self.NETSCRIPTSDIR, self.DEVICE) @@ -294,14 +316,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(pyanaconda.network.shutil.move.call_args[0], (TMP_FILE, '%s/keys-%s' % (TMP_DIR, self.DEVICE)))
- def network_get_device_test(self): - import pyanaconda.network - - nw = pyanaconda.network.Network() - nw.netdevices['dev'] = 'device' - ret = nw.getDevice('dev') - self.assertEqual(ret, 'device') - def network_get_ks_device_1_test(self): import pyanaconda.network nw = pyanaconda.network.Network() @@ -324,57 +338,6 @@ class NetworkTest(mock.TestCase): ret = nw.getKSDevice() self.assertEqual(ret, 'device')
- def network_set_hostname_test(self): - import pyanaconda.network - pyanaconda.network.iutil.execWithRedirect = mock.Mock() - nw = pyanaconda.network.Network() - nw.setHostname('DESKTOP') - self.assertEqual(nw.hostname, 'DESKTOP') - - def network_set_dns_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices['dev'] = mock.Mock() - nw.setDNS('10.0.0.1, 10.0.0.2', 'dev') - self.assertEqual(nw.netdevices['dev'].method_calls, - [('set', (('DNS1', '10.0.0.1'),), {}), - ('set', (('DNS2', '10.0.0.2'),), {})] - ) - - def network_set_gateway_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.netdevices['eth0'] = mock.Mock() - nw.setGateway('10.0.0.1', 'eth0') - self.assertEqual(pyanaconda.network.Network.netdevices['eth0'].method_calls, - [('set', (('GATEWAY', '10.0.0.1'),), {})]) - - def network_lookup_hostname_1_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.hostname = None - ret = nw.lookupHostname() - self.assertEqual(ret, None) - - def network_lookup_hostname_2_test(self): - import pyanaconda.network - nw = pyanaconda.network.Network() - nw.hostname = 'desktop' - pyanaconda.network.hasActiveNetDev = mock.Mock(return_value=False) - ret = nw.lookupHostname() - self.assertEqual(ret, None) - - def network_lookup_hostname_3_test(self): - import pyanaconda.network - pyanaconda.network.socket.getaddrinfo.return_value = \ - [(0, 0, 0, 0, ('10.1.1.1', 0))] - - nw = pyanaconda.network.Network() - nw.hostname = 'desktop' - pyanaconda.network.hasActiveNetDev = mock.Mock(return_value=True) - ret = nw.lookupHostname() - self.assertEqual(ret, '10.1.1.1') - def network_write_ifcfg_files_test(self): import pyanaconda.network nw = pyanaconda.network.Network() @@ -458,22 +421,6 @@ class NetworkTest(mock.TestCase): self.assertEqual(self.fs[TMPFILE], 'network --device eth0 --bootproto dhcp --noipv6\n')
- def network_has_name_server_1_test(self): - import pyanaconda.network - hash = {'foo':'', 'bar':''} - - nw = pyanaconda.network.Network() - ret = nw.hasNameServers(hash) - self.assertFalse(ret) - - def network_has_name_server_2_test(self): - import pyanaconda.network - hash = {'foo':'', 'bar':'', 'dnsserver':''} - - nw = pyanaconda.network.Network() - ret = nw.hasNameServers(hash) - self.assertTrue(ret) - def network_has_wireless_dev_1_test(self): import pyanaconda.network pyanaconda.network.isys = mock.Mock() @@ -556,8 +503,7 @@ class NetworkTest(mock.TestCase): pyanaconda.network.dbus.Interface().Get.return_value = \ pyanaconda.network.isys.NM_STATE_CONNECTED_GLOBAL
- nw = pyanaconda.network.Network() - ret = nw.waitForConnection() + ret = pyanaconda.network.waitForConnection() self.assertTrue(ret)
def network_wait_for_connection_2_test(self): @@ -568,19 +514,18 @@ class NetworkTest(mock.TestCase): pyanaconda.network.isys.NM_STATE_CONNECTED = self.OK pyanaconda.network.time.sleep = mock.Mock()
- nw = pyanaconda.network.Network() - ret = nw.waitForConnection() + ret = pyanaconda.network.waitForConnection() self.assertFalse(ret)
def network_bring_up_test(self): import pyanaconda.network pyanaconda.network.Network.write = mock.Mock() - pyanaconda.network.Network.waitForConnection = mock.Mock() + pyanaconda.network.waitForConnection = mock.Mock()
nw = pyanaconda.network.Network() nw.bringUp() self.assertTrue(pyanaconda.network.Network.write.called) - self.assertTrue(pyanaconda.network.Network.waitForConnection.called) + self.assertTrue(pyanaconda.network.waitForConnection.called)
def iface_for_host_ip_test(self): import pyanaconda.network
I forgot to send first patch with the set, so I sent it as [0/15] later.
On 07/19/2012 12:02 PM, Radek Vykydal wrote:
This patchset is removing anaconda.network with the goal to use only ksdata to store network configuration.
See [15/15] for details and what will follow.
I want to do also some furher cleanup, review of hostname setting, /etc/sysconfig/network setting etc.
anaconda-patches mailing list anaconda-patches@lists.fedorahosted.org https://fedorahosted.org/mailman/listinfo/anaconda-patches
This patchset is removing anaconda.network with the goal to use only ksdata to store network configuration.
See [15/15] for details and what will follow.
I want to do also some furher cleanup, review of hostname setting, /etc/sysconfig/network setting etc.
I had some minor comments, but overall I think they look pretty good. I'm sure there'll be some bugs but we can sort them out along the way.
Note that you might have some problems due to the fact that I've removed the iw/ directory entirely. Also, I wouldn't have worried about updating yuminstall.py since that's going to go away entirely pretty soon, too. But that's okay.
Thanks for doing this. It's a pretty huge piece of work.
- Chris
anaconda-patches@lists.fedorahosted.org