From f146fe71733e72b94fad525b8cc9988b1405e760 Mon Sep 17 00:00:00 2001 From: Brett Holman Date: Wed, 12 Apr 2023 10:44:47 -0600 Subject: NoCloud: Use seedfrom protocol to determine mode (#2107) Historically ds=nocloud-net was a required argument for the user to pass in to tell cloud-init which mode to use. This argument, however, is redundant when a seedfrom argument is passed. Allow the mode to be automatically determined, so that the user need not pass a mode configuration to achieve desired behavior. --- cloudinit/sources/DataSourceNoCloud.py | 19 +++++++++++++++---- .../test_kernel_commandline_match.py | 5 ++++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py index 596a96a7..8d9caa02 100644 --- a/cloudinit/sources/DataSourceNoCloud.py +++ b/cloudinit/sources/DataSourceNoCloud.py @@ -280,12 +280,23 @@ def load_cmdline_data(fill, cmdline=None): ("ds=nocloud-net", sources.DSMODE_NETWORK), ] for idstr, dsmode in pairs: - if parse_cmdline_data(idstr, fill, cmdline): + if not parse_cmdline_data(idstr, fill, cmdline): + continue + if "dsmode" in fill: # if dsmode was explicitly in the command line, then - # prefer it to the dsmode based on the command line id - if "dsmode" not in fill: - fill["dsmode"] = dsmode + # prefer it to the dsmode based on seedfrom type return True + + seedfrom = fill.get("seedfrom") + if seedfrom: + if seedfrom.startswith(("http://", "https://")): + fill["dsmode"] = sources.DSMODE_NETWORK + elif seedfrom.startswith(("file://", "/")): + fill["dsmode"] = sources.DSMODE_LOCAL + else: + fill["dsmode"] = dsmode + + return True return False diff --git a/tests/integration_tests/test_kernel_commandline_match.py b/tests/integration_tests/test_kernel_commandline_match.py index cbbce9ca..f7238f24 100644 --- a/tests/integration_tests/test_kernel_commandline_match.py +++ b/tests/integration_tests/test_kernel_commandline_match.py @@ -49,7 +49,10 @@ def override_kernel_cmdline(ds_str: str, c: IntegrationInstance) -> str: @pytest.mark.parametrize( "ds_str, configured", ( - ("ds=nocloud;s=http://my-url/", "DataSourceNoCloud"), + ( + "ds=nocloud;s=http://my-url/", + "DataSourceNoCloud [seed=None][dsmode=net]", + ), ("ci.ds=openstack", "DataSourceOpenStack"), ), ) -- cgit v1.2.1