mirror of
https://github.com/token2/snapd.git
synced 2026-03-13 11:15:47 -07:00
Accordingly to the task definition in spread project: https://github.com/snapcore/spread/blob/master/spread/project.go#L332
84 lines
2.7 KiB
YAML
84 lines
2.7 KiB
YAML
summary: Ensure that cloud-init integration works
|
|
|
|
details: |
|
|
snapd picks up basic cloud information from the host and makes it available
|
|
to the snaps. Run the test on a live backend which sets instance data
|
|
properly.
|
|
|
|
# GCE backend sets instance data
|
|
backends: [google]
|
|
|
|
prepare: |
|
|
if ! command -v jq; then
|
|
snap install --devmode jq
|
|
fi
|
|
|
|
execute: |
|
|
if [[ ! -e /run/cloud-init/instance-data.json ]]; then
|
|
echo "cloud-init instance data is required to execute the test"
|
|
|
|
if os.query is-ubuntu && not os.query is-trusty; then
|
|
# we expect the test to run on all Ubuntu images excluding 14.04
|
|
echo "the test expected to run on $SPREAD_SYSTEM"
|
|
exit 1
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
get_conf() {
|
|
# we could use cloud-init query <key>, but that requires cloud-init 18.4+
|
|
# which is not available in all images we use
|
|
local kname="$1"
|
|
if jq -r '.v1 | keys[]' < /run/cloud-init/instance-data.json | grep -q _; then
|
|
kname=${kname/-/_}
|
|
else
|
|
kname=${kname/_/-}
|
|
fi
|
|
|
|
jq -r ".[\"v1\"][\"$kname\"]" < /run/cloud-init/instance-data.json
|
|
}
|
|
# GCE sets the following in Ubuntu images:
|
|
# {
|
|
# ...
|
|
# "v1": {
|
|
# "availability-zone": "us-east1-b",
|
|
# "availability_zone": "us-east1-b",
|
|
# "cloud-name": "gce",
|
|
# "cloud_name": "gce",
|
|
# "region": "us-east1"
|
|
# ...
|
|
# }
|
|
# }
|
|
|
|
# keys can be queried only using underscore names
|
|
cloud_name=$(get_conf cloud_name)
|
|
test -n "$cloud_name"
|
|
# this shouldn't happen under GCE
|
|
if [[ "$cloud_name" == "nocloud" || "$cloud_name" == "none" ]]; then
|
|
echo "not a cloud instance, config should be empty"
|
|
|
|
nocloud=$(snap get core -d | jq -r '.cloud')
|
|
test "$nocloud" = null
|
|
exit 0
|
|
fi
|
|
|
|
snap_cloud_name=$(snap get core cloud.name)
|
|
test "$cloud_name" = "$snap_cloud_name"
|
|
|
|
cloud_avzone=$(get_conf availability_zone)
|
|
snap_cloud_avzone=$(snap get core cloud.availability-zone)
|
|
test "$cloud_avzone" = "$snap_cloud_avzone"
|
|
|
|
cloud_region=$(get_conf region)
|
|
snap_cloud_region=$(snap get core cloud.region)
|
|
test "$cloud_region" = "$snap_cloud_region"
|
|
|
|
if os.query is-core; then
|
|
# TODO: is there a race here with snapd restricting cloud-init and us
|
|
# checking that it was restricted?
|
|
echo "Test that cloud-init restrict file was written"
|
|
test -f /etc/cloud/cloud.cfg.d/zzzz_snapd.cfg
|
|
echo "Test that cloud-init restrict file does NOT have manual_cache_clean set"
|
|
NOMATCH "manual_cache_clean: true" < /etc/cloud/cloud.cfg.d/zzzz_snapd.cfg
|
|
fi
|