Resolves: rhbz#1277975
This will allow to override special default of first network command which is --activate.
The use case is activating a device via boot options (eg for nfs mount of installation image or source) and using another configuration for target system via kickstart (nfs mount and installation could stale in this case if the ip address changes for example).
I was considering also making --activate option support optional arguments (allowing both for --activate for compatibility and --activate=no for this use case) but optparse used in rhel7 pykickstart doesn't allow for nargs=? (zero or one argument) as argparse does. https://www.redhat.com/archives/anaconda-devel-list/2016-May/msg00008.html
--- dracut/parse-kickstart | 3 ++- pyanaconda/network.py | 2 +- pyanaconda/ui/gui/spokes/network.py | 8 +++++++- pyanaconda/ui/tui/spokes/network.py | 7 ++++++- 4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart index 9c36402..08d536a 100755 --- a/dracut/parse-kickstart +++ b/dracut/parse-kickstart @@ -178,7 +178,8 @@ class Network(commands.network.RHEL7_Network, DracutArgsMixin):
# first 'network' line if len(self.network) == 1: - net.activate = True + if not net.noactivate: + net.activate = True # Note that there may be no net.device and no ksdevice if inst.ks=file:/ks.cfg # If that is the case, fall into ksnet_to_dracut with net.device=None and let # it handle things. diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 402456f..b2e9503 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -1203,7 +1203,7 @@ def apply_kickstart(ksdata): # If we have kickstart ifcfg from initramfs if "Generated by parse-kickstart" in f.read(): # and we should activate the device - if i == 0 or network_data.activate: + if (i == 0 and not network_data.noactivate) or network_data.activate: ifcfg = IfcfgFile(ifcfg_path) ifcfg.read() con_uuid = ifcfg.get("UUID") diff --git a/pyanaconda/ui/gui/spokes/network.py b/pyanaconda/ui/gui/spokes/network.py index b48296b..aeea217 100644 --- a/pyanaconda/ui/gui/spokes/network.py +++ b/pyanaconda/ui/gui/spokes/network.py @@ -1636,13 +1636,19 @@ class NetworkStandaloneSpoke(StandaloneSpoke):
def _update_network_data(data, ncb): data.network.network = [] - for dev_cfg in ncb.dev_cfgs: + for i, dev_cfg in enumerate(ncb.dev_cfgs): devname = dev_cfg.get_iface() nd = network.ksdata_from_ifcfg(devname, dev_cfg.con_uuid) if not nd: continue if devname in nm.nm_activated_devices(): nd.activate = True + else: + # First network command defaults to --activate so we must + # use --no-activate explicitly to prevent the default + if i == 0: + nd.noactivate = True + data.network.network.append(nd) hostname = ncb.hostname network.update_hostname_data(data, hostname) diff --git a/pyanaconda/ui/tui/spokes/network.py b/pyanaconda/ui/tui/spokes/network.py index 4b56890..9f1fe6e 100644 --- a/pyanaconda/ui/tui/spokes/network.py +++ b/pyanaconda/ui/tui/spokes/network.py @@ -257,12 +257,17 @@ class NetworkSpoke(FirstbootSpokeMixIn, EditTUISpoke): hostname = self.data.network.hostname
self.data.network.network = [] - for name in nm.nm_devices(): + for i, name in enumarate(nm.nm_devices()): nd = network.ksdata_from_ifcfg(name) if not nd: continue if name in nm.nm_activated_devices(): nd.activate = True + else: + # First network command defaults to --activate so we must + # use --no-activate explicitly to prevent the default + if i == 0: + nd.noactivate = True self.data.network.network.append(nd)
(valid, error) = network.sanityCheckHostname(self.hostname_dialog.value)
Related: rhbz#1277975
This will allow to override special default of first network command which is --activate. --- pykickstart/commands/network.py | 11 ++++++++++- tests/commands/network.py | 7 +++++++ 2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/pykickstart/commands/network.py b/pykickstart/commands/network.py index 4daeece..62aee16 100644 --- a/pykickstart/commands/network.py +++ b/pykickstart/commands/network.py @@ -20,7 +20,7 @@ from pykickstart.base import BaseData, KickstartCommand from pykickstart.constants import BOOTPROTO_BOOTP, BOOTPROTO_DHCP, BOOTPROTO_IBFT, BOOTPROTO_QUERY, BOOTPROTO_STATIC from pykickstart.options import KSOptionParser -from pykickstart.errors import KickstartValueError, formatErrorMsg +from pykickstart.errors import KickstartValueError, formatErrorMsg, KickstartParseError
import gettext import warnings @@ -307,6 +307,7 @@ class RHEL7_NetworkData(F21_NetworkData): F21_NetworkData.__init__(self, *args, **kwargs) self.bridgeslaves = kwargs.get("bridgeslaves", "") self.bridgeopts = kwargs.get("bridgeopts", "") + self.noactivate = kwargs.get("no-activate", False)
def _getArgsAsStr(self): retval = F21_NetworkData._getArgsAsStr(self) @@ -314,6 +315,8 @@ class RHEL7_NetworkData(F21_NetworkData): retval += " --bridgeslaves=%s" % self.bridgeslaves if self.bridgeopts != "": retval += " --bridgeopts=%s" % self.bridgeopts + if self.noactivate: + retval += " --no-activate"
return retval
@@ -639,6 +642,8 @@ class RHEL7_Network(F21_Network): default="") op.add_option("--bridgeopts", dest="bridgeopts", action="store", default="") + op.add_option("--no-activate", dest="noactivate", action="store_true", + default=False) return op
def parse(self, args): @@ -663,4 +668,8 @@ class RHEL7_Network(F21_Network): msg = formatErrorMsg(self.lineno, msg=_("Bad format of --bridgeopts, expecting key=value options separated by ','")) raise KickstartValueError(msg)
+ if retval.activate and retval.noactivate: + error_message = _("Options --activate and --no-activate are mutually exclusive") + raise KickstartParseError(formatErrorMsg(self.lineno, msg=error_message)) + return retval diff --git a/tests/commands/network.py b/tests/commands/network.py index cd150d1..b5cafc4 100644 --- a/tests/commands/network.py +++ b/tests/commands/network.py @@ -152,6 +152,13 @@ class RHEL7_TestCase(F20_TestCase): "--bridgeopts=priority", KickstartValueError)
+ # activating a device + self.assert_parse("network --device eth0 --no-activate") + self.assert_parse("network --device eth0 --activate") + self.assert_parse_error("network --device eth0 --activate --no-activate", + KickstartParseError) + self.assert_parse_error("network --device eth0 --no-activate --activate", + KickstartParseError)
if __name__ == "__main__": unittest.main()
On Mon, 2016-05-30 at 14:33 +0200, Radek Vykydal wrote:
Related: rhbz#1277975
This will allow to override special default of first network command which is --activate.
Would it be possible to have --no-activate just store False into 'opts.activate'? The default could be None if neither --activate nor --no-activate is given.
On 31.5.2016 08:18, Vratislav Podzimek wrote:
On Mon, 2016-05-30 at 14:33 +0200, Radek Vykydal wrote:
Related: rhbz#1277975
This will allow to override special default of first network command which is --activate.
Would it be possible to have --no-activate just store False into 'opts.activate'? The default could be None if neither --activate nor --no-activate is given.
Neat idea, I think it should work. I'll post v2.
On Mon, 2016-05-30 at 14:33 +0200, Radek Vykydal wrote:
Resolves: rhbz#1277975
This will allow to override special default of first network command which is --activate.
The use case is activating a device via boot options (eg for nfs mount of installation image or source) and using another configuration for target system via kickstart (nfs mount and installation could stale in this case if the ip address changes for example).
I was considering also making --activate option support optional arguments (allowing both for --activate for compatibility and --activate=no for this use case) but optparse used in rhel7 pykickstart doesn't allow for nargs=? (zero or one argument) as argparse does. https://www.redhat.com/archives/anaconda-devel-list/2016-May/msg00008.html
dracut/parse-kickstart | 3 ++- pyanaconda/network.py | 2 +- pyanaconda/ui/gui/spokes/network.py | 8 +++++++- pyanaconda/ui/tui/spokes/network.py | 7 ++++++- 4 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/dracut/parse-kickstart b/dracut/parse-kickstart index 9c36402..08d536a 100755 --- a/dracut/parse-kickstart +++ b/dracut/parse-kickstart @@ -178,7 +178,8 @@ class Network(commands.network.RHEL7_Network, DracutArgsMixin): # first 'network' line if len(self.network) == 1: - net.activate = True + if not net.noactivate: + net.activate = True
This should be 'net.activate = not net.noactivate'.
anaconda-patches@lists.fedorahosted.org