← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~smoser/cloud-init:bug/ds-identify-list-none-twice into cloud-init:master

 

Scott Moser has proposed merging ~smoser/cloud-init:bug/ds-identify-list-none-twice into cloud-init:master.

Commit message:
fix tools/ds-identify to not write None twice.

If the user configured:
  datasource_list: ["Ec2", "None"]
then ds-identify would write
  datasource_list: ["Ec2", "None", "None"]
which would break the logic to avoid warning.

Requested reviews:
  cloud-init commiters (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/324557

this is the ds-identify portion of 
 https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/324274

-- 
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:bug/ds-identify-list-none-twice into cloud-init:master.
diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
index 9e14885..8559e1f 100644
--- a/tests/unittests/test_ds_identify.py
+++ b/tests/unittests/test_ds_identify.py
@@ -210,6 +210,13 @@ class TestDsIdentify(CiTestCase):
         mydata['files'][cfgpath] = 'datasource_list: ["NoCloud"]\n'
         self._check_via_dict(mydata, rc=RC_FOUND, dslist=['NoCloud', DS_NONE])
 
+    def test_configured_list_with_none(self):
+        """If user set a datasource_list, that should be used."""
+        mydata = copy.deepcopy(VALID_CFG['GCE'])
+        cfgpath = 'etc/cloud/cloud.cfg.d/myds.cfg'
+        mydata['files'][cfgpath] = 'datasource_list: ["Ec2", "None"]\n'
+        self._check_via_dict(mydata, rc=RC_FOUND, dslist=['Ec2', DS_NONE])
+
 
 def blkid_out(disks=None):
     """Convert a list of disk dictionaries into blkid content."""
diff --git a/tools/ds-identify b/tools/ds-identify
index aff26eb..74d2653 100755
--- a/tools/ds-identify
+++ b/tools/ds-identify
@@ -963,10 +963,11 @@ found() {
         # do not pass an empty line through.
         shift
     fi
-    # always write the None datasource last.
-    if [ "$list" != "None" ]; then
-        list="${list:+${list}, }None"
-    fi
+    # if None is not already in the list, then add it last.
+    case " $list " in
+        *\ None,\ *|*\ None\ ) :;;
+        *) list=${list:+${list}, None};;
+    esac
     write_result "datasource_list: [ $list ]" "$@"
     return
 }

References