diff --git a/cloudinit/sources/DataSourceNoCloud.py b/cloudinit/sources/DataSourceNoCloud.py index 23bb2663bf8..18bf8902de1 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 927ae9e98b8..a401c6292ed 100644 --- a/tests/unittests/sources/test_nocloud.py +++ b/tests/unittests/sources/test_nocloud.py @@ -7,7 +7,10 @@ import yaml 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 @@ -86,13 +89,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"""