diff options
author | Brett Holman <brett.holman@canonical.com> | 2023-04-12 10:44:47 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-12 10:44:47 -0600 |
commit | f146fe71733e72b94fad525b8cc9988b1405e760 (patch) | |
tree | cecd909672cfdcb3b1ee171f8aad5d38ea175926 | |
parent | 24945cad70bb98c12b44b1626cdcd99bc795e2dc (diff) | |
download | cloud-init-git-f146fe71733e72b94fad525b8cc9988b1405e760.tar.gz |
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.
-rw-r--r-- | cloudinit/sources/DataSourceNoCloud.py | 19 | ||||
-rw-r--r-- | tests/integration_tests/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"), ), ) |