From: Daan De Meyer Date: Wed, 23 Feb 2022 16:23:41 +0000 (+0000) Subject: Rename --network-veth to --netdev (#909) X-Git-Tag: v13~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=309b0573dd8ac41ea92f85d6019f69af9b7d8041;p=thirdparty%2Fmkosi.git Rename --network-veth to --netdev (#909) Co-authored-by: Jörg Behrmann --- diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41df7659e..0ed8f05f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -223,7 +223,7 @@ jobs: [Host] Ssh=yes - NetworkVeth=yes + Netdev=yes EOF mkdir -p mkosi.skeleton/etc/portage diff --git a/NEWS.md b/NEWS.md index 908c4b0d0..8dcf36e10 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,11 +2,12 @@ ## v13 -- The networkd config file installed by mkosi when the --network-veth option is - used (/etc/systemd/network/80-mkosi-network-veth.network in the image) now only matches against network interfaces using the virtio_net driver. +- The `--network-veth` option has been renamed `--netdev`, since it implies usage of a virtual ethernet device, which is not what is done when booting images with qemu where a TUN/TAP device is used. +- The networkd config file installed by mkosi when the `--netdev` option (what used to be `--network-veth`) is + used (formerly `/etc/systemd/network/80-mkosi-network-veth.network` in the image) now only matches against network interfaces using the virtio_net driver. Please make sure you weren't relying on this file to configure any network interfaces other than the tun/tap virtio-net interface created by mkosi when - booting the image in QEMU with the --network-veth option. If you were relying + booting the image in QEMU with the --netdev option. If you were relying on this config file to configure other interfaces, you'll have to re-create it with the correct match and a lower initial number in the filename to make sure networkd will keep configuring your interface, e.g. via the `mkosi.skeleton` or `mkosi.extra` trees or a `mkosi.postinst` script. diff --git a/action/mkosi.default b/action/mkosi.default index 48c057884..8af73cc7b 100644 --- a/action/mkosi.default +++ b/action/mkosi.default @@ -53,4 +53,4 @@ Packages=bzip2 QemuHeadless=yes [Host] -NetworkVeth=yes +Netdev=yes diff --git a/mkosi.md b/mkosi.md index a1d2a00d1..335b48990 100644 --- a/mkosi.md +++ b/mkosi.md @@ -1087,7 +1087,7 @@ a machine ID. : When used with the `qemu` verb, this options sets `qemu`'s `-m` argument which controls the amount of guest's RAM. Defaults to `1G`. -`NetworkVeth=`, `--network-veth` +`Netdev=`, `--netdev` : When used with the boot or qemu verbs, this option creates a virtual ethernet link between the host and the container/VM. The host @@ -1138,7 +1138,7 @@ a machine ID. : When used with the `ssh` verb, `mkosi` will attempt to retry the SSH connection up to given timeout (in seconds) in case it fails. This option is useful mainly in scripted environments where the `qemu` and `ssh` verbs are used in a quick - succession and the veth device might not get enough time to configure itself. + succession and the virtual device might not get enough time to configure itself. ### Commandline-only Options diff --git a/mkosi/__init__.py b/mkosi/__init__.py index eed7c2a99..08c24c95c 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -1746,7 +1746,7 @@ def prepare_tree(args: MkosiArgs, root: Path, do_run_build_script: bool, cached: if args.build_dir is not None: root_home(args, root).joinpath("build").mkdir(0o755) - if args.network_veth and not do_run_build_script: + if args.netdev and not do_run_build_script: root.joinpath("etc/systemd").mkdir(mode=0o755) root.joinpath("etc/systemd/network").mkdir(mode=0o755) @@ -2283,7 +2283,7 @@ def install_fedora(args: MkosiArgs, root: Path, do_run_build_script: bool) -> No configure_dracut(args, packages, root) if do_run_build_script: packages.update(args.build_packages) - if not do_run_build_script and args.network_veth: + if not do_run_build_script and args.netdev: add_packages(args, packages, "systemd-networkd", conditional="systemd") install_packages_dnf(args, root, packages, do_run_build_script) @@ -2366,7 +2366,7 @@ def install_openmandriva(args: MkosiArgs, root: Path, do_run_build_script: bool) add_packages(args, packages, "systemd-boot", "systemd-cryptsetup", conditional="systemd") add_packages(args, packages, "kernel-release-server", "binutils", "dracut", "timezone") configure_dracut(args, packages, root) - if args.network_veth: + if args.netdev: add_packages(args, packages, "systemd-networkd", conditional="systemd") if do_run_build_script: @@ -2601,7 +2601,7 @@ def install_centos(args: MkosiArgs, root: Path, do_run_build_script: bool) -> No packages.update(args.build_packages) if not do_run_build_script and args.distribution == Distribution.centos_epel: - if args.network_veth: + if args.netdev: add_packages(args, packages, "systemd-networkd", conditional="systemd") if epel_release >= 9: add_packages(args, packages, "systemd-boot", conditional="systemd") @@ -2630,7 +2630,7 @@ def install_rocky(args: MkosiArgs, root: Path, do_run_build_script: bool) -> Non if do_run_build_script: packages.update(args.build_packages) - if not do_run_build_script and args.distribution == Distribution.rocky_epel and args.network_veth: + if not do_run_build_script and args.distribution == Distribution.rocky_epel and args.netdev: add_packages(args, packages, "systemd-networkd", conditional="systemd") install_packages_dnf(args, root, packages, do_run_build_script) @@ -2658,7 +2658,7 @@ def install_alma(args: MkosiArgs, root: Path, do_run_build_script: bool) -> None if do_run_build_script: packages.update(args.build_packages) - if not do_run_build_script and args.distribution == Distribution.alma_epel and args.network_veth: + if not do_run_build_script and args.distribution == Distribution.alma_epel and args.netdev: add_packages(args, packages, "systemd-networkd", conditional="systemd") install_packages_dnf(args, root, packages, do_run_build_script) @@ -5579,6 +5579,12 @@ def create_parser() -> ArgumentParserMkosi: group.add_argument("--qemu-mem", help="Configure guest's RAM size", metavar="MEM", default="1G") group.add_argument( "--network-veth", + dest="netdev", + action=BooleanAction, + help=argparse.SUPPRESS, + ) # Compatibility option + group.add_argument( + "--netdev", action=BooleanAction, help="Create a virtual Ethernet link between the host and the container/VM", ) @@ -6800,7 +6806,7 @@ def print_summary(args: MkosiArgs) -> None: MkosiPrinter.info("\nHOST CONFIGURATION:") MkosiPrinter.info(" Extra search paths: " + line_join_list(args.extra_search_paths)) MkosiPrinter.info(" QEMU Headless: " + yes_no(args.qemu_headless)) - MkosiPrinter.info(" Network Veth: " + yes_no(args.network_veth)) + MkosiPrinter.info(" Netdev: " + yes_no(args.netdev)) def reuse_cache_tree( @@ -6910,12 +6916,12 @@ def setup_ssh( return f -def setup_network_veth(args: MkosiArgs, root: Path, do_run_build_script: bool, cached: bool) -> None: - if do_run_build_script or cached or not args.network_veth: +def setup_netdev(args: MkosiArgs, root: Path, do_run_build_script: bool, cached: bool) -> None: + if do_run_build_script or cached or not args.netdev: return - with complete_step("Setting up network veth…"): - network_file = root / "etc/systemd/network/80-mkosi-network-veth.network" + with complete_step("Setting up netdev…"): + network_file = root / "etc/systemd/network/80-mkosi-netdev.network" with open(network_file, "w") as f: # Adapted from https://github.com/systemd/systemd/blob/v247/network/80-container-host0.network f.write( @@ -7042,7 +7048,7 @@ def build_image( set_serial_terminal(args, root, do_run_build_script, cached_tree) set_autologin(args, root, do_run_build_script, cached_tree) sshkey = setup_ssh(args, root, do_run_build_script, for_cache, cached_tree) - setup_network_veth(args, root, do_run_build_script, cached_tree) + setup_netdev(args, root, do_run_build_script, cached_tree) run_postinst_script(args, root, loopdev, do_run_build_script, for_cache) if cleanup: @@ -7363,7 +7369,7 @@ def suppress_stacktrace() -> Iterator[None]: def virt_name(args: MkosiArgs) -> str: name = args.hostname or args.image_id or args.output.with_suffix("").name.partition("_")[0] - # Shorten to 13 characters so we can prefix with ve- or vt- for the network veth ifname which is limited + # Shorten to 13 characters so we can prefix with ve- or vt- for the netdev ifname which is limited # to 16 characters. return name[:13] @@ -7381,15 +7387,15 @@ def ensure_networkd(args: MkosiArgs) -> bool: if args.verb != Verb.ssh: # Some programs will use 'mkosi ssh' with pexpect, so don't print warnings that will break # them. - warn("--network-veth requires systemd-networkd to be running to initialize the host interface " - "of the veth link ('systemctl enable --now systemd-networkd')") + warn("--netdev requires systemd-networkd to be running to initialize the host interface " + "of the virtual link ('systemctl enable --now systemd-networkd')") return False if args.verb == Verb.qemu and not has_networkd_vm_vt(): warn(dedent(r"""\ mkosi didn't find 80-vm-vt.network. This is one of systemd's built-in systemd-networkd config files which configures vt-* interfaces. - mkosi needs this file in order for --network-veth to work properly for QEMU + mkosi needs this file in order for --netdev to work properly for QEMU virtual machines. The file likely cannot be found because the systemd version on the host is too old (< 246) and it isn't included yet. @@ -7440,7 +7446,7 @@ def run_shell_cmdline(args: MkosiArgs) -> List[str]: if is_generated_root(args) or args.verity: cmdline += ["--volatile=overlay"] - if args.network_veth: + if args.netdev: if ensure_networkd(args): cmdline += ["--network-veth"] @@ -7580,7 +7586,7 @@ def run_qemu_cmdline(args: MkosiArgs) -> Iterator[List[str]]: if not args.qemu_headless or (args.qemu_headless and "bios" in args.boot_protocols): cmdline += ["-vga", "virtio"] - if args.network_veth: + if args.netdev: if not ensure_networkd(args): # Fall back to usermode networking if the host doesn't have networkd (eg: Debian) fwd = f",hostfwd=tcp::{args.ssh_port}-:{args.ssh_port}" if args.ssh_port != 22 else "" diff --git a/mkosi/backend.py b/mkosi/backend.py index 710fb93f7..57b37a588 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -475,7 +475,7 @@ class MkosiArgs: password_is_hashed: bool autologin: bool extra_search_paths: List[Path] - network_veth: bool + netdev: bool ephemeral: bool ssh: bool ssh_key: Optional[Path] diff --git a/mkosi/machine.py b/mkosi/machine.py index cd0141c91..8f4351bda 100644 --- a/mkosi/machine.py +++ b/mkosi/machine.py @@ -47,7 +47,7 @@ class Machine: tmp.bootable = True tmp.qemu_headless = True tmp.hostonly_initrd = True - tmp.network_veth = True + tmp.netdev = True tmp.ssh = True elif tmp.verb == Verb.boot: pass diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py index ddb50aa80..1ef6582a8 100644 --- a/tests/test_config_parser.py +++ b/tests/test_config_parser.py @@ -129,7 +129,7 @@ class MkosiConfig: "qemu_headless": False, "qemu_smp": "2", "qemu_mem": "1G", - "network_veth": False, + "netdev": False, "ephemeral": False, "with_unified_kernel_images": True, "hostonly_initrd": False, @@ -367,8 +367,8 @@ class MkosiConfig: self._append_list("extra_search_paths", mk_config_host["ExtraSearchPaths"], job_name, ":") if "QemuHeadless" in mk_config_host: self.reference_config[job_name]["qemu_headless"] = mk_config_host["QemuHeadless"] - if "NetworkVeth" in mk_config_host: - self.reference_config[job_name]["network_veth"] = mk_config_host["NetworkVeth"] + if "Netdev" in mk_config_host: + self.reference_config[job_name]["netdev"] = mk_config_host["Netdev"] if "Ephemeral" in mk_config_host: self.reference_config[job_name]["ephemeral"] = mk_config_host["Ephemeral"] if "Ssh" in mk_config_host: @@ -587,7 +587,7 @@ class MkosiConfigManyParams(MkosiConfigOne): "Host": { "ExtraSearchPaths": "search/here:search/there", "QemuHeadless": True, - "NetworkVeth": True, + "Netdev": True, }, } self._prepare_mkosi_default(directory, mk_config) @@ -653,7 +653,7 @@ class MkosiConfigManyParams(MkosiConfigOne): "Host": { "ExtraSearchPaths": "search/ubu", "QemuHeadless": True, - "NetworkVeth": True, + "Netdev": True, }, } self._prepare_mkosi_default_d(directory, mk_config, 1) @@ -719,7 +719,7 @@ class MkosiConfigManyParams(MkosiConfigOne): "Host": { "ExtraSearchPaths": "search/debi", "QemuHeadless": True, - "NetworkVeth": True, + "Netdev": True, }, } self._prepare_mkosi_default_d(directory, mk_config, 2)