From d914ed8e573d464c4d21aa41069beb73fd3ce9be Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 2 Mar 2017 21:45:47 -0500 Subject: ds-identify: record not found in cloud.cfg and always add None. On a 'not found' result, was not being written at all. That had the unintended effect of '--force' not working. Now, on a 'not found' result: - if reporting: write the list as found (with just 'None'). - if not reporting: only report that there was nothing found. this means that the warning cloud-init will write about ds-identify failing to find a datasource will be written, but cloud-init will still search its fully configured list. --- tools/ds-identify | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/ds-identify b/tools/ds-identify index fd2a46c8..741cf3ae 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -886,10 +886,23 @@ write_result() { return 0 } +record_notfound() { + # in report mode, report nothing was found. + # if not report mode: only report the negative result. + # reporting an empty list would mean cloud-init would not search + # any datasources. + if [ "$DI_REPORT" = "true" ]; then + found -- + else + local msg="# reporting not found result. notfound=${DI_ON_NOTFOUND}." + local DI_REPORT="true" + found -- "$msg" + fi +} + found() { # found(ds1, [ds2 ...], [-- [extra lines]]) local list="" ds="" - # always we write the None datasource last. while [ $# -ne 0 ]; do if [ "$1" = "--" ]; then shift @@ -902,6 +915,8 @@ found() { # do not pass an empty line through. shift fi + # always write the None datasource last. + list="${list:+${list}, }None" write_result "datasource_list: [ $list ]" "$@" return } @@ -1173,13 +1188,15 @@ _main() { return fi + # record the empty result. + record_notfound case "$DI_ON_NOTFOUND" in $DI_DISABLED) debug 1 "No result. notfound=$DI_DISABLED. returning $ret_dis." return $ret_dis ;; $DI_ENABLED) - debug 1 "notfound=$DI_ENABLED. returning $ret_en" + debug 1 "No result. notfound=$DI_ENABLED. returning $ret_en" return $ret_en;; esac -- cgit v1.2.3