Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cloud-init.postinst for maas preseed provisioning #5686

Merged
merged 3 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
cloud-init (24.4~3+really24.3.1-0ubuntu2) oracular; urgency=medium
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would 24.4~4 make more sense here as this is devel?

Copy link
Collaborator Author

@blackboxsw blackboxsw Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering the same, but this is an ubuntu downstream packaging change just beyond the 24.4~3+really24.3.1 and into the development release still, so I'd think we would follow the ubuntu-specific version bump in devel series.


* d/cloud-init.postinst: fix MAAS preseed provisioning by replacing
handle_preseed_maas and handle_preseed_local_cloud_config functions
which were removed in commit cf13fd126 (GH-5685)

-- Chad Smith <chad.smith@canonical.com> Tue, 10 Sep 2024 13:41:14 -0600

cloud-init (24.4~3+really24.3.1-0ubuntu1) oracular; urgency=medium

* d/cloud-init.lintian-overrides:
Expand Down
80 changes: 80 additions & 0 deletions debian/cloud-init.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,80 @@ with open(fname, "w") as fp:
fp.write(yaml.dump(cfg))' "$@"
}

handle_preseed_maas() {
local cfg_file="/etc/cloud/cloud.cfg.d/90_dpkg_maas.cfg"
local md_url="" creds_all="" c_key="" t_key="" t_sec="" c_sec="";

db_get "cloud-init/maas-metadata-url" && md_url="$RET" || :
db_get "cloud-init/maas-metadata-credentials" && creds_all="$RET" || :

# nothing to do
[ -n "$md_url" -o -n "$creds_all" ] || return 0

# change a url query string format into : delimited
if [ -n "$creds_all" -a "${creds_all#*&}" != "${creds_all}" ]; then
# the command here ends up looking like:
# python3 -c '...' 'oauth_consumer_key=v1&oauth_token_key=v2...' \
# oauth_consumer_key oauth_token_key oauth_token_secret
creds_all=$(python3 -c 'from six.moves.urllib.parse import parse_qs;
import sys;
keys = parse_qs(sys.argv[1])
for k in sys.argv[2:]:
sys.stdout.write("%s:" % keys.get(k,[""])[0])' "$creds_all" \
oauth_consumer_key oauth_token_key oauth_token_secret
)
fi

# now, if non-empty creds_all is: consumer_key:token_key:token_secret
if [ -n "$creds_all" ]; then
OIFS="$IFS"; IFS=:; set -- $creds_all; IFS="$OIFS"
c_key=$1; t_key=$2; t_sec=$3
fi

if [ "$md_url" = "_" -a "${c_key}:${t_key}:${t_sec}" = "_:_:_" ]; then
# if all these values were '_', the delete value, just delete the file.
rm -f "$cfg_file"
else
local header="# written by cloud-init debian package per preseed entries
# cloud-init/{maas-metadata-url,/maas-metadata-credentials}"

local pair="" k="" v="" pload="" orig_umask=""
for pair in "metadata_url:$md_url" "consumer_key:${c_key}" \
"token_key:${t_key}" "token_secret:$t_sec"; do
k=${pair%%:*}
v=${pair#${k}:}
[ -n "$v" ] && pload="${pload} $k: \"$v\","
done

# '_' would indicate "delete", otherwise, existing entries are left
orig_umask=$(umask)
umask 066
: >> "$cfg_file" && chmod 600 "$cfg_file"
update_cfg "$cfg_file" "$header" "datasource: { MAAS: { ${pload%,} } }" _
umask ${orig_umask}
fi

# now clear the database of the values, as they've been consumed
db_unregister "cloud-init/maas-metadata-url" || :
db_unregister "cloud-init/maas-metadata-credentials" || :
}

handle_preseed_local_cloud_config() {
local ccfg="" debconf_name="cloud-init/local-cloud-config"
local cfg_file="/etc/cloud/cloud.cfg.d/90_dpkg_local_cloud_config.cfg"
local header="# written by cloud-init debian package per preseed entry
# $debconf_name"

db_get "${debconf_name}" && ccfg="$RET" || :

if [ "$ccfg" = "_" ]; then
rm -f "$cfg_file"
elif [ -n "$ccfg" ]; then
{ echo "$header"; echo "$ccfg"; } > "$cfg_file"
fi
db_unregister "${debconf_name}" || :
}

fix_1336855() {
### Begin fix for LP: 1336855
# fix issue where cloud-init misidentifies the location of grub and
Expand Down Expand Up @@ -191,6 +265,12 @@ datasource_list: [ $values ]
EOF
fi

# if there are maas settings pre-seeded apply them
handle_preseed_maas

# if there is generic cloud-config preseed, apply them
handle_preseed_local_cloud_config

# fix issue where cloud-init misidentifies the location of grub
fix_1336855

Expand Down
Loading