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

Proposed by Scott Moser
Status: Merged
Merged at revision: 13673f8d2b815452aa22f8e3811e04481558a731
Proposed branch: ~smoser/cloud-init:bug/ds-identify-list-none-twice
Merge into: cloud-init:master
Diff against target: 38 lines (+12/-4)
2 files modified
tests/unittests/test_ds_identify.py (+7/-0)
tools/ds-identify (+5/-4)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
cloud-init Commiters Pending
Review via email: mp+324557@code.launchpad.net

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.

Description of the change

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

+1 LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
2index 9e14885..8559e1f 100644
3--- a/tests/unittests/test_ds_identify.py
4+++ b/tests/unittests/test_ds_identify.py
5@@ -210,6 +210,13 @@ class TestDsIdentify(CiTestCase):
6 mydata['files'][cfgpath] = 'datasource_list: ["NoCloud"]\n'
7 self._check_via_dict(mydata, rc=RC_FOUND, dslist=['NoCloud', DS_NONE])
8
9+ def test_configured_list_with_none(self):
10+ """If user set a datasource_list, that should be used."""
11+ mydata = copy.deepcopy(VALID_CFG['GCE'])
12+ cfgpath = 'etc/cloud/cloud.cfg.d/myds.cfg'
13+ mydata['files'][cfgpath] = 'datasource_list: ["Ec2", "None"]\n'
14+ self._check_via_dict(mydata, rc=RC_FOUND, dslist=['Ec2', DS_NONE])
15+
16
17 def blkid_out(disks=None):
18 """Convert a list of disk dictionaries into blkid content."""
19diff --git a/tools/ds-identify b/tools/ds-identify
20index aff26eb..74d2653 100755
21--- a/tools/ds-identify
22+++ b/tools/ds-identify
23@@ -963,10 +963,11 @@ found() {
24 # do not pass an empty line through.
25 shift
26 fi
27- # always write the None datasource last.
28- if [ "$list" != "None" ]; then
29- list="${list:+${list}, }None"
30- fi
31+ # if None is not already in the list, then add it last.
32+ case " $list " in
33+ *\ None,\ *|*\ None\ ) :;;
34+ *) list=${list:+${list}, None};;
35+ esac
36 write_result "datasource_list: [ $list ]" "$@"
37 return
38 }

Subscribers

People subscribed via source and target branches