Merge ~smoser/cloud-init:bug/1677710-ds-identify-fix-maas-detect into cloud-init:master

Proposed by Scott Moser on 2017-03-30
Status: Merged
Merged at revision: a68e7d50d25e774018588a5312c7698c38ec4de4
Proposed branch: ~smoser/cloud-init:bug/1677710-ds-identify-fix-maas-detect
Merge into: cloud-init:master
Diff against target: 75 lines (+17/-16)
1 file modified
tools/ds-identify (+17/-16)
Reviewer Review Type Date Requested Status
Ryan Harper 2017-03-30 Approve on 2017-03-30
Server Team CI bot continuous-integration Approve on 2017-03-30
Review via email: mp+321482@code.launchpad.net

Commit Message

ds-identify: fix detecting of maas datasource.

The reading of MAAS datasource configuration was simply broken.
it was looking in /etc/cloud/*maas*.cfg rather than
/etc/cloud/cloud.cfg.d/*maas*.cfg.

along side here there is also:
 * doc improvement on check_config
 * remove the path restrictions when searching for values in both
   maas and ovf_vmware_guest_customization. that was done to improve
   performance as check_config's parsing is slow.
 * change to maas to search all config files rather than restricting
   to a subset as it tried before. that was done for
 * better variable names.
    - rename path_cloud_confd to path_etc_cloud
    - PATH_ETC_CLOUD: /etc/cloud
    - PATH_ETC_CI_CFG: /etc/cloud/cloud.cfg
    - PATH_ETC_CI_CFG_D: /etc/cloud/cloud.cfg.d

LP: #1677710

To post a comment you must log in.
Scott Moser (smoser) wrote :

here is my little attempt at getting some speed info on this

$ cat foo.sh
#!/bin/sh
if [ $# -eq 0 ] || [ "$1" = "-h" -o "$1" = "--help" ]; then
    cat <<EOF
Usage: ${0##*/} num [prog [arg [..]]]

run prog with arguments num times.
if no program or args, default is to run:
   check_config datasource_list

  $ time ${0} 10 check_config datasource_list

EOF
exit
fi

. /usr/lib/cloud-init/ds-identify
num=$1
nums=$(seq 1 "$num")
shift
[ $# -eq 0 ] && set -- check_config datasource_list

_RET=""; _RET_fname=""

echo "$num runs of: $*"
for i in $nums; do "$@"; done
ret=$?
echo "returned: $?"
echo "_RET=$_RET"
echo "_RET_fname=${_RET_fname}"

Ryan Harper (raharper) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tools/ds-identify b/tools/ds-identify
2index 54bd999..5d390ef 100755
3--- a/tools/ds-identify
4+++ b/tools/ds-identify
5@@ -70,7 +70,9 @@ PATH_PROC_CMDLINE="${PATH_PROC_CMDLINE:-${PATH_ROOT}/proc/cmdline}"
6 PATH_PROC_1_CMDLINE="${PATH_PROC_1_CMDLINE:-${PATH_ROOT}/proc/1/cmdline}"
7 PATH_PROC_1_ENVIRON="${PATH_PROC_1_ENVIRON:-${PATH_ROOT}/proc/1/environ}"
8 PATH_PROC_UPTIME=${PATH_PROC_UPTIME:-${PATH_ROOT}/proc/uptime}
9-PATH_CLOUD_CONFD="${PATH_CLOUD_CONFD:-${PATH_ROOT}/etc/cloud}"
10+PATH_ETC_CLOUD="${PATH_ETC_CLOUD:-${PATH_ROOT}/etc/cloud}"
11+PATH_ETC_CI_CFG="${PATH_ETC_CI_CFG:-${PATH_ETC_CLOUD}/cloud.cfg}"
12+PATH_ETC_CI_CFG_D="${PATH_ETC_CI_CFG_D:-${PATH_ETC_CI_CFG}.d}"
13 PATH_RUN_CI="${PATH_RUN_CI:-${PATH_RUN}/cloud-init}"
14 PATH_RUN_CI_CFG=${PATH_RUN_CI_CFG:-${PATH_RUN_CI}/cloud.cfg}
15 PATH_RUN_DI_RESULT=${PATH_RUN_DI_RESULT:-${PATH_RUN_CI}/.ds-identify.result}
16@@ -472,15 +474,18 @@ dscheck_CloudSigma() {
17 }
18
19 check_config() {
20- # somewhat hackily read config for 'key' in files matching 'files'
21- # currently does not respect any hierarchy.
22- local key="$1" files="" bp="${PATH_CLOUD_CONFD}/cloud.cfg"
23- if [ $# -eq 1 ]; then
24- files="$bp ${bp}.d/*.cfg"
25+ # check_config(key [,file_globs])
26+ # somewhat hackily read through file_globs for 'key'
27+ # file_globs are expanded via path expansion and
28+ # default to /etc/cloud/cloud.cfg /etc/cloud/cloud.cfg.d/*.cfg
29+ # currently does not respect any hierarchy in searching for key.
30+ local key="$1" files=""
31+ shift
32+ if [ $# -eq 0 ]; then
33+ files="${PATH_ETC_CI_CFG} ${PATH_ETC_CI_CFG_D}/*.cfg"
34 else
35 files="$*"
36 fi
37- shift
38 set +f; set -- $files; set -f;
39 if [ "$1" = "$files" -a ! -f "$1" ]; then
40 return 1
41@@ -520,9 +525,7 @@ dscheck_MAAS() {
42 esac
43
44 # check config files written by maas for installed system.
45- local confd="${PATH_CLOUD_CONFD}"
46- local fnmatch="$confd/*maas*.cfg $confd/*kernel_cmdline*.cfg"
47- if check_config "MAAS" "$fnmatch"; then
48+ if check_config "MAAS"; then
49 return "${DS_FOUND}"
50 fi
51 return ${DS_NOT_FOUND}
52@@ -607,9 +610,7 @@ ovf_vmware_guest_customization() {
53 # (disable_vmware_customization=true). If it is set to false, then
54 # user has requested customization.
55 local key="disable_vmware_customization"
56- local match="" bp="${PATH_CLOUD_CONFD}/cloud.cfg"
57- match="$bp $bp.d/*[Oo][Vv][Ff]*.cfg"
58- if check_config "$key" "$match"; then
59+ if check_config "$key"; then
60 debug 2 "${_RET_fname} set $key to $_RET"
61 case "$_RET" in
62 0|false|False) return 0;;
63@@ -680,9 +681,9 @@ ec2_read_strict_setting() {
64 esac
65
66 # 3. look for the key 'strict_id' (datasource/Ec2/strict_id)
67- local match="" bp="${PATH_CLOUD_CONFD}/cloud.cfg"
68- match="$bp $bp.d/*[Ee][Cc]2*.cfg"
69- if check_config strict_id "$match"; then
70+ # only in cloud.cfg or cloud.cfg.d/EC2.cfg (case insensitive)
71+ local cfg="${PATH_ETC_CI_CFG}" cfg_d="${PATH_ETC_CI_CFG_D}"
72+ if check_config strict_id $cfg "$cfg_d/*[Ee][Cc]2*.cfg"; then
73 debug 2 "${_RET_fname} set strict_id to $_RET"
74 return 0
75 fi

Subscribers

People subscribed via source and target branches

to all changes: