From df06fdbe3dba203ed441ff959ec6ae4a4991894b Mon Sep 17 00:00:00 2001 From: James Falcon Date: Thu, 12 Sep 2024 16:17:56 -0500 Subject: [PATCH] fix: Invalid "seedfrom" in NoCloud system configuration --- cloudinit/sources/DataSourceNoCloud.py | 2 +- tests/unittests/sources/test_nocloud.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py index 23bb2663bf8e..18bf8902de13 100644 --- a/cloudinit/sources/DataSourceNoCloud.py +++ b/cloudinit/sources/DataSourceNoCloud.py @@ -453,7 +453,7 @@ def ds_detect(self): elif ( self.sys_cfg.get("datasource", {}) .get("NoCloud", {}) - .key("seedfrom") + .get("seedfrom") ): LOG.debug( "Machine is configured by system configuration to run on " diff --git a/tests/unittests/sources/test_nocloud.py b/tests/unittests/sources/test_nocloud.py index f05d36c3b7d9..30eb735a350d 100644 --- a/tests/unittests/sources/test_nocloud.py +++ b/tests/unittests/sources/test_nocloud.py @@ -8,7 +8,10 @@ from cloudinit import helpers from cloudinit.sources.DataSourceNoCloud import DataSourceNoCloud as dsNoCloud -from cloudinit.sources.DataSourceNoCloud import parse_cmdline_data +from cloudinit.sources.DataSourceNoCloud import ( + DataSourceNoCloudNet, + parse_cmdline_data, +) from tests.unittests.helpers import mock, populate_dir @@ -87,13 +90,18 @@ def test_nocloud_seed_dir_non_lxd_platform_is_nocloud(self, mocker, paths): assert dsrc.platform_type == "nocloud" assert dsrc.subplatform == "seed-dir (%s)" % seed_dir - def test_nocloud_seedfrom(self, paths): + def test_nocloud_seedfrom(self, paths, caplog): """Check that a seedfrom triggers detection""" - assert dsNoCloud( + ds = DataSourceNoCloudNet( sys_cfg={"datasource": {"NoCloud": {"seedfrom": "somevalue"}}}, distro=None, paths=paths, - ).ds_detect() + ) + assert ds.ds_detect() + assert ( + "Machine is configured by system configuration to run on " + "single datasource DataSourceNoCloudNet" + ) in caplog.text def test_nocloud_user_data_meta_data(self, paths): """Check that meta-data and user-data trigger detection"""