Created
January 27, 2021 18:25
-
-
Save trstringer/6695950ec629a5231646653f299ca2ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -i | |
# First create a VM and install the updated cloud-init from my build. Ensure | |
# that we are able to utilize the "desired" IMDS api version 2020-09-01. | |
RESOURCE_NAME=$(resource_name) | |
echo "$(date) - Using resource name $RESOURCE_NAME" | |
az_vm_create_default | |
az_vm_deb_install "$RESOURCE_NAME" ~/dev/cloud-init/cloud-init_all.deb | |
OLD_RESOURCE_NAME=$RESOURCE_NAME | |
RESOURCE_NAME=$(resource_name) | |
az_vm_create_from_vm "$OLD_RESOURCE_NAME" | |
if az_vm_ssh "$RESOURCE_NAME" "grep 'Falling back to IMDS api-version' /var/log/cloud-init.log"; then | |
echo "$(date) Failed: api-version not found" | |
exit 1 | |
else | |
echo "$(date) api-version found successfully" | |
fi | |
# For the second test, modify the source code directly so that the desired | |
# IMDS api-version is impossible to be used (a future date). This test | |
# should verify that we fall back to the minimum api-version for IMDS. | |
echo "$(date) Modifying to impossible IMDS version for wanted" | |
az_vm_ssh "$RESOURCE_NAME" "sudo sed -i 's/2020-09-01/2022-09-01/g' /usr/lib/python3/dist-packages/cloudinit/sources/DataSourceAzure.py" | |
az_vm_ssh "$RESOURCE_NAME" "sudo cloud-init clean --logs" | |
OLD_RESOURCE_NAME=$RESOURCE_NAME | |
RESOURCE_NAME=$(resource_name) | |
az_vm_create_from_vm "$OLD_RESOURCE_NAME" | |
if ! az_vm_ssh "$RESOURCE_NAME" "grep 'Falling back to IMDS api-version' /var/log/cloud-init.log"; then | |
echo "$(date) Failed: no fall back for IMDS version" | |
exit 1 | |
else | |
echo "$(date) Success for fall back IMDS version" | |
fi | |
echo "$(date) - All tests succeded" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment