From 38cbdee6a28301d5b77ce9525a1da36a90e9b3c0 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Wed, 8 Mar 2023 18:56:29 +0100 Subject: [PATCH] Return failure if any of install_modules fails Add test to verify that install_modules can be skipped and that install_modules returns failure if it fails to update mdev.conf. --- lib/tiny-cloud/init-early | 5 +++-- tests/init-early.test | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/tiny-cloud/init-early b/lib/tiny-cloud/init-early index ca34252..4e71f99 100644 --- a/lib/tiny-cloud/init-early +++ b/lib/tiny-cloud/init-early @@ -27,16 +27,17 @@ has_cloud_hotplugs() { [ -n "$HOTPLUG_MODULES" ]; } install_hotplugs() { skip_action install_hotplugs && return - local result + local result rc=0 for module in $HOTPLUG_MODULES; do result='-' echo -n " $module" if type "mod__$module" | grep -q "is a function"; then - "mod__$module" && result='+' || result='!' + "mod__$module" && result='+' || { result='!'; rc=1; } fi echo -n "($result)" done + return $rc } : "${HOTPLUG_TYPE:=mdev}" diff --git a/tests/init-early.test b/tests/init-early.test index eb22852..8129896 100755 --- a/tests/init-early.test +++ b/tests/init-early.test @@ -8,7 +8,9 @@ export MOCK=echo init_tests \ expand_root \ expand_root_partition \ - expand_root_skip + expand_root_skip \ + install_hotplugs_skip \ + install_hotplugs_fail PROVIDERS="aws azure gcp nocloud oci" @@ -64,3 +66,29 @@ expand_root_skip_body() { done } +install_hotplugs_skip_body() { + fake_bin test-install-hotplugs <<-EOF + #!/bin/sh + SKIP_INIT_ACTIONS=install_hotplugs + . "$srcdir"/lib/tiny-cloud/init-early + install_hotplugs + EOF + for provider in $PROVIDERS; do + CLOUD="$provider" atf_check \ + -o match:'^ SKIPPING$' \ + test-install-hotplugs + done +} + +install_hotplugs_fail_body() { + fake_bin test-install-hotplugs <<-EOF + #!/bin/sh + HOTPLUG_MODULES="vnic_eth_hotplug" + . "$srcdir"/lib/tiny-cloud/init-early + install_hotplugs + EOF + CLOUD=aws atf_check -s not-exit:0 \ + -o match:"^ vnic_eth_hotplug\(!\)$" \ + test-install-hotplugs +} +