mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-10-28 11:25:21 +01:00
nuageinit: apply meta-data if user-data is a script
Tested by: [email protected] Sponsored by: OVHcloud Pull Request: https://github.com/freebsd/freebsd-src/pull/2446
This commit is contained in:
1 parent
262fa4695d
commit
de0a279c8b
2 files changed
+30
-15
No files matched your search
+14
-12
@@ -1173,18 +1173,8 @@ end
|
||||
local metadata = load_metadata(citype)
|
||||
local line, obj = load_userdata()
|
||||
|
||||
-- No user-data
|
||||
if line == nil then
|
||||
local calls_table = {
|
||||
sethostname,
|
||||
create_default_user,
|
||||
}
|
||||
|
||||
for i = 1, #calls_table do
|
||||
calls_table[i](obj, metadata)
|
||||
end
|
||||
-- YAML user-data
|
||||
elseif line == "#cloud-config" then
|
||||
if line == "#cloud-config" then
|
||||
local pre_network_calls = {
|
||||
ca_certs,
|
||||
mounts,
|
||||
@@ -1231,7 +1221,19 @@ elseif line == "#cloud-config" then
|
||||
calls_table[i](obj, metadata)
|
||||
end
|
||||
end
|
||||
elseif line:sub(1, 2) == "#!" then
|
||||
-- No YAML user-data
|
||||
else
|
||||
local calls_table = {
|
||||
sethostname,
|
||||
create_default_user,
|
||||
}
|
||||
|
||||
for i = 1, #calls_table do
|
||||
calls_table[i](obj, metadata)
|
||||
end
|
||||
end
|
||||
|
||||
if line ~= nil and line:sub(1, 2) == "#!" then
|
||||
-- delay for execution at rc.local time --
|
||||
nuage.chmod(root .. "/var/cache/nuageinit/user_data", "0755")
|
||||
end
|
||||
@@ -92,23 +92,36 @@ EOF
|
||||
nocloud_userdata_script_body()
|
||||
{
|
||||
mkdir -p media/nuageinit
|
||||
printf "instance-id: iid-local01\n" > "${PWD}"/media/nuageinit/meta-data
|
||||
setup_test_adduser
|
||||
cat > media/nuageinit/meta-data << EOF
|
||||
instance-id: iid-local01
|
||||
hostname: myhost
|
||||
EOF
|
||||
# ensure this is an invalid when parsed with the yaml parser
|
||||
printf "#!/bin/sh\n: ${test:-yes}\necho $test\n" > "${PWD}"/media/nuageinit/user-data
|
||||
chmod 644 "${PWD}"/media/nuageinit/user-data
|
||||
atf_check -s exit:0 /usr/libexec/nuageinit "${PWD}"/media/nuageinit nocloud
|
||||
atf_check test -x var/cache/nuageinit/user_data
|
||||
atf_check -o inline:"#!/bin/sh\n: ${test:-yes}\necho $test\n" cat var/cache/nuageinit/user_data
|
||||
# ensure meta-data is applied, regardless of what is in user-data
|
||||
atf_check -o inline:"hostname='myhost'\n" cat etc/rc.conf.d/hostname
|
||||
}
|
||||
|
||||
nocloud_user_data_script_body()
|
||||
{
|
||||
mkdir -p media/nuageinit
|
||||
printf "instance-id: iid-local01\n" > "${PWD}"/media/nuageinit/meta-data
|
||||
setup_test_adduser
|
||||
cat > media/nuageinit/meta-data << EOF
|
||||
instance-id: iid-local01
|
||||
hostname: myhost
|
||||
EOF
|
||||
printf "#!/bin/sh\necho yeah\n" > "${PWD}"/media/nuageinit/user_data
|
||||
chmod 755 "${PWD}"/media/nuageinit/user_data
|
||||
chmod 644 "${PWD}"/media/nuageinit/user_data
|
||||
atf_check -s exit:0 /usr/libexec/nuageinit "${PWD}"/media/nuageinit nocloud
|
||||
atf_check test -x var/cache/nuageinit/user_data
|
||||
atf_check -o inline:"#!/bin/sh\necho yeah\n" cat var/cache/nuageinit/user_data
|
||||
# ensure meta-data is applied, regardless of what is in user-data
|
||||
atf_check -o inline:"hostname='myhost'\n" cat etc/rc.conf.d/hostname
|
||||
}
|
||||
|
||||
nocloud_userdata_cloudconfig_users_head()
|
||||
|
||||
Reference in new issue
Block a user