From 0ae47288d1e840fa4db2a95a0f3d9cf04fe1e576 Mon Sep 17 00:00:00 2001 From: James Falcon Date: Tue, 26 Mar 2024 15:55:50 -0500 Subject: [PATCH] fix: Always use single datasource if specified (#5098) This change may require a user to add `None` to the `datasource_list` defined in `/etc/cloud/cloud.cfg[.d]` if they have a customized datasource_list and want the DataSourceNone fallback behavior. ds-identify would automatically append "None" to the datasource_list if a single entry was provided in /etc/cloud/cloud.cfg[.d]. This wasn't a problem in the past as the python code would detect a single datasource along with None as an indication to automatically use that datasource. Since the python code no longer does that, we should ensure that one specified datasource results in one specified datasource after ds-identify has run. Fixes GH-5091 --- tests/unittests/test_ds_identify.py | 2 +- tools/ds-identify | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py index 1be00e46425..105825b698e 100644 --- a/tests/unittests/test_ds_identify.py +++ b/tests/unittests/test_ds_identify.py @@ -622,7 +622,7 @@ def test_single_entry_defines_datasource(self): mydata = copy.deepcopy(VALID_CFG["Ec2-hvm"]) cfgpath = "etc/cloud/cloud.cfg.d/myds.cfg" mydata["files"][cfgpath] = 'datasource_list: ["NoCloud"]\n' - self._check_via_dict(mydata, rc=RC_FOUND, dslist=["NoCloud", DS_NONE]) + self._check_via_dict(mydata, rc=RC_FOUND, dslist=["NoCloud"]) def test_configured_list_with_none(self): """When datasource_list already contains None, None is not added. diff --git a/tools/ds-identify b/tools/ds-identify index 741742c7f72..8f8e56198b2 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -1999,7 +1999,11 @@ _main() { # if there is only a single entry in $DI_DSLIST if [ $# -eq 1 ] || [ $# -eq 2 -a "$2" = "None" ] ; then debug 1 "single entry in datasource_list ($DI_DSLIST) use that." - found "$@" + if [ $# -eq 1 ]; then + write_result "datasource_list: [ $1 ]" + else + found "$@" + fi return fi