mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2025-12-14 19:02:45 +03:00
Refactor imds tests and add tests for azure, gcp and oci
This commit is contained in:
parent
0f40c146f2
commit
b63ffb71d0
@ -82,6 +82,7 @@ host="${url#http*://}"
|
||||
host="${host%%/*}"
|
||||
path="${url#http*://$host}"
|
||||
path="${path#${WGET_STRIP_PREFIX:-/}}"
|
||||
path="${path%\?*}"
|
||||
|
||||
if [ -z "$WGETCONTENT" ]; then
|
||||
(
|
||||
|
||||
124
tests/imds.test
124
tests/imds.test
@ -4,50 +4,115 @@
|
||||
. $(atf_get_srcdir)/test_env.sh
|
||||
|
||||
export PREFIX="$srcdir"
|
||||
PROVIDERS="alpine aws azure gcp nocloud"
|
||||
|
||||
init_tests \
|
||||
imds_help \
|
||||
imds_space \
|
||||
imds_aws_hostname \
|
||||
imds_aws_local_hostname \
|
||||
imds_aws_ssh_keys \
|
||||
imds_nocloud_cmdline_local_hostname \
|
||||
imds_nocloud_cidata_hostname \
|
||||
imds_nocloud_cidata_local_hostname
|
||||
\
|
||||
imds_hostname_alpine \
|
||||
imds_hostname_aws \
|
||||
imds_hostname_azure \
|
||||
imds_hostname_gcp \
|
||||
imds_hostname_nocloud \
|
||||
imds_hostname_oci \
|
||||
\
|
||||
imds_local_hostname_alpine \
|
||||
imds_local_hostname_aws \
|
||||
imds_local_hostname_azure \
|
||||
imds_local_hostname_gcp \
|
||||
imds_local_hostname_nocloud \
|
||||
imds_local_hostname_oci \
|
||||
\
|
||||
imds_ssh_keys_alpine \
|
||||
imds_ssh_keys_aws \
|
||||
imds_ssh_keys_azure \
|
||||
imds_ssh_keys_gcp \
|
||||
imds_ssh_keys_nocloud \
|
||||
imds_ssh_keys_oci \
|
||||
\
|
||||
imds_nocloud_cmdline_local_hostname
|
||||
|
||||
imds_help_body() {
|
||||
atf_check -o match:"Usage: imds" imds -h
|
||||
}
|
||||
|
||||
imds_space_body() {
|
||||
CLOUD=nocloud atf_check -o match:'^ $' imds +s
|
||||
CLOUD=nocloud atf_check -o match:'^\t$' imds +t
|
||||
CLOUD=nocloud atf_check -o match:'^$' imds +n
|
||||
for provider in $PROVIDERS; do
|
||||
CLOUD="$provider" atf_check -o match:'^ $' imds +s
|
||||
CLOUD="$provider" atf_check -o match:'^\t$' imds +t
|
||||
CLOUD="$provider" atf_check -o match:'^$' imds +n
|
||||
done
|
||||
}
|
||||
|
||||
imds_aws_hostname_body() {
|
||||
fake_metadata_aws <<-EOF
|
||||
check_hostname() {
|
||||
fake_metadata "$1" <<-EOF
|
||||
# nocloud, alpine, aws
|
||||
hostname: myhostname
|
||||
# azure
|
||||
compute:
|
||||
name: myhostname
|
||||
# gcp, oci
|
||||
instance:
|
||||
hostname: myhostname
|
||||
EOF
|
||||
CLOUD=aws atf_check -o match:"myhostname" imds @hostname
|
||||
CLOUD="$1" atf_check -o match:"myhostname" imds @hostname
|
||||
}
|
||||
imds_hostname_alpine_body() { check_hostname alpine; }
|
||||
imds_hostname_aws_body() { check_hostname aws; }
|
||||
imds_hostname_azure_body() { check_hostname azure; }
|
||||
imds_hostname_gcp_body() { check_hostname gcp; }
|
||||
imds_hostname_nocloud_body() { check_hostname nocloud; }
|
||||
imds_hostname_oci_body() { check_hostname oci; }
|
||||
|
||||
imds_aws_local_hostname_body() {
|
||||
fake_metadata_aws <<-EOF
|
||||
check_local_hostname() {
|
||||
fake_metadata "$1" <<-EOF
|
||||
# nocloud, alpine, aws
|
||||
local-hostname: myhostname
|
||||
# azure
|
||||
compute:
|
||||
name: myhostname
|
||||
# gcp, oci
|
||||
instance:
|
||||
hostname: myhostname
|
||||
EOF
|
||||
CLOUD=aws atf_check -o match:"myhostname" imds @local-hostname
|
||||
CLOUD="$1" atf_check -o match:"myhostname" imds @local-hostname
|
||||
}
|
||||
imds_local_hostname_alpine_body() { check_local_hostname alpine; }
|
||||
imds_local_hostname_aws_body() { check_local_hostname aws; }
|
||||
imds_local_hostname_azure_body() { check_local_hostname azure; }
|
||||
imds_local_hostname_gcp_body() { check_local_hostname gcp; }
|
||||
imds_local_hostname_nocloud_body() { check_local_hostname nocloud; }
|
||||
imds_local_hostname_oci_body() { check_local_hostname oci; }
|
||||
|
||||
imds_aws_ssh_keys_body() {
|
||||
fake_metadata_aws <<-EOF
|
||||
check_ssh_keys() {
|
||||
local key="ssh-ed25519 keydata"
|
||||
fake_metadata "$1" <<-EOF
|
||||
# aws, alpine, nocloud
|
||||
public-keys:
|
||||
0=testuser:
|
||||
0:
|
||||
openssh-key: ssh-ed25519 keydata
|
||||
openssh-key: $key
|
||||
# azure
|
||||
compute:
|
||||
publicKeys:
|
||||
- keyData: $key
|
||||
# gcp
|
||||
instance:
|
||||
attributes:
|
||||
ssh-keys: user1:$key
|
||||
# oci
|
||||
metadata:
|
||||
ssh_authorized_keys: $key
|
||||
EOF
|
||||
CLOUD=aws atf_check -o match:"ssh-ed25519 keydata" imds @ssh-keys
|
||||
CLOUD="$1" atf_check -o match:"$key" imds @ssh-keys
|
||||
}
|
||||
imds_ssh_keys_alpine_body() { check_ssh_keys alpine; }
|
||||
imds_ssh_keys_aws_body() { check_ssh_keys aws; }
|
||||
imds_ssh_keys_azure_body() { check_ssh_keys azure; }
|
||||
imds_ssh_keys_gcp_body() { check_ssh_keys gcp; }
|
||||
imds_ssh_keys_nocloud_body() { check_ssh_keys nocloud; }
|
||||
imds_ssh_keys_oci_body() { check_ssh_keys oci; }
|
||||
|
||||
imds_nocloud_cmdline_local_hostname_body() {
|
||||
atf_require_prog yx
|
||||
@ -59,24 +124,3 @@ imds_nocloud_cmdline_local_hostname_body() {
|
||||
imds @local-hostname
|
||||
done
|
||||
}
|
||||
|
||||
imds_nocloud_cidata_hostname_body() {
|
||||
atf_require_prog yx
|
||||
fake_metadata_nocloud <<-EOF
|
||||
hostname: myhostname
|
||||
EOF
|
||||
CLOUD=nocloud atf_check \
|
||||
-o match:'^myhostname$' \
|
||||
imds @hostname
|
||||
}
|
||||
|
||||
imds_nocloud_cidata_local_hostname_body() {
|
||||
atf_require_prog yx
|
||||
fake_metadata_nocloud <<-EOF
|
||||
local-hostname: my-local-hostname
|
||||
EOF
|
||||
|
||||
CLOUD=nocloud atf_check \
|
||||
-o match:'^my-local-hostname$' \
|
||||
imds @local-hostname
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ init_tests \
|
||||
enable_sshd \
|
||||
create_default_user
|
||||
|
||||
PROVIDERS="aws azure gcp nocloud oci"
|
||||
PROVIDERS="alpine aws azure gcp nocloud oci"
|
||||
|
||||
expand_root_body() {
|
||||
mkdir proc
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
export PREFIX="$srcdir"
|
||||
export MOCK=echo
|
||||
lib="$srcdir"/lib/tiny-cloud/init
|
||||
PROVIDERS="aws azure gcp nocloud oci"
|
||||
PROVIDERS="alpine aws azure gcp nocloud oci"
|
||||
|
||||
init_tests \
|
||||
userdata_type \
|
||||
|
||||
@ -68,6 +68,32 @@ fake_metadata_aws() {
|
||||
export WGET_STRIP_PREFIX="/latest/meta-data"
|
||||
}
|
||||
|
||||
fake_metadata_azure() {
|
||||
cat > "169.254.169.254.yaml"
|
||||
export WGET_STRIP_PREFIX="/metadata/instance"
|
||||
}
|
||||
|
||||
fake_metadata_gcp() {
|
||||
cat > "169.254.169.254.yaml"
|
||||
export WGET_STRIP_PREFIX="/computeMetadata/v1"
|
||||
}
|
||||
|
||||
fake_metadata_oci() {
|
||||
cat > "169.254.169.254.yaml"
|
||||
export WGET_STRIP_PREFIX="/opc/v2"
|
||||
}
|
||||
|
||||
fake_metadata() {
|
||||
case "${1:-$CLOUD}" in
|
||||
alpine|nocloud) fake_metadata_nocloud;;
|
||||
aws) fake_metadata_aws;;
|
||||
azure) fake_metadata_azure;;
|
||||
gcp) fake_metadata_gcp;;
|
||||
oci) fake_metadata_oci;;
|
||||
*) echo "TODO: fake_metadata_$CLOUD" >&2;;
|
||||
esac
|
||||
}
|
||||
|
||||
fake_interfaces() {
|
||||
local n=1
|
||||
for i; do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user