Skip to content

Commit

Permalink
ds-identify: exit 2 on disabled state from marker or cmdline
Browse files Browse the repository at this point in the history
The cloud-init-generator no longer checks disabled state of
cloud-init from the kernel command line or marker file in
/etc/cloud/cloud-init.disabled.

This means ds-identify will be called during systemd generator
even in disabled cases.

Given that ds-identify parses the kernel commandline for datasource
discovery, allow it to check whether cloud-init=disabled is present
in kernel command line, KERNEL_CMDLINE or
/etc/cloud/cloud-init.disabled.

Add a new exit code(2) from ds-identify to allow
cloud-init-generator to allow differentation of disabled state due
to environment artifacts versus disabled due to no detected
datasources.

Additionally, factor the minimum operations needed for detecting
if cloud-init is disabled to earlier in ds-identify to allow an early
exit before more costly DMI read operations in collect_info.
There is no need to perform all collect_info in ds-identify when
cloud-init is fully disabled by commandline or
/etc/cloud/cloud-init.disabled.
  • Loading branch information
blackboxsw authored and holmanb committed Sep 26, 2023
1 parent 07965a6 commit 1b5d9b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
8 changes: 6 additions & 2 deletions systemd/cloud-init-generator.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ main() {
ds=$?
debug 1 "ds-identify rc=$ds"

if [ "$ds" = "1" ]; then
debug 1 "cloud-init is enabled but no datasource found, disabling"
if [ "$ds" = "1" -o "$ds" = "2" ]; then
if [ "$ds" = "1" ]; then
debug 1 "cloud-init is enabled but no datasource found, disabling"
else
debug 1 "cloud-init is disabled by kernel commandline or etc_file"
fi
if [ -f "$link_path" ]; then
if rm -f "$link_path"; then
debug 1 "disabled. removed existing $link_path"
Expand Down
4 changes: 4 additions & 0 deletions tests/unittests/test_ds_identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ def write_mock(data):
"ret": 1,
"err": "No dmidecode program. ERROR.",
},
{
"name": "is_disabled",
"ret": 1,
},
{
"name": "get_kenv_field",
"ret": 1,
Expand Down
26 changes: 23 additions & 3 deletions tools/ds-identify
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,23 @@ has_ovf_cdrom() {
return 1
}

is_disabled() {
if [ -f /etc/cloud/cloud-init.disabled ]; then
debug 1 "disabled by marker file /etc/cloud-init.disabled"
return 0
fi
if [ "${KERNEL_CMDLINE:-}" = "cloud-init=disabled" ]; then
debug 1 "disabled by KERNEL_CMDLINE environment variable"
return 0
fi
case "$DI_KERNEL_CMDLINE" in
*cloud-init=disabled*)
debug 1 "disabled by kernel command line cloud-init=disabled"
return 0
esac
return 1
}

dscheck_OVF() {
check_seed_dir ovf ovf-env.xml && return "${DS_FOUND}"

Expand Down Expand Up @@ -1517,10 +1534,7 @@ dscheck_VMware() {
}

collect_info() {
read_uname_info
read_virt
read_pid1_product_name
read_kernel_cmdline
read_config
read_datasource_list
read_dmi_sys_vendor
Expand Down Expand Up @@ -1795,6 +1809,12 @@ _main() {

read_uptime
debug 1 "[up ${_RET}s]" "ds-identify $*"
read_uname_info
read_virt
read_kernel_cmdline
if is_disabled; then
return 2
fi
collect_info

if [ "$DI_LOG" = "stderr" ]; then
Expand Down

0 comments on commit 1b5d9b4

Please sign in to comment.