Skip to content

Instantly share code, notes, and snippets.

@trstringer
Last active November 21, 2019 23:22
Show Gist options
  • Save trstringer/15629fe7ceea7d48b20705cd5fb4d0b4 to your computer and use it in GitHub Desktop.
Save trstringer/15629fe7ceea7d48b20705cd5fb4d0b4 to your computer and use it in GitHub Desktop.
#!/bin/bash -i
DEB_PATH="/home/trstringer/dev/cloud-init/cloud-init_19.2-405-g807e6fcd-1~bddeb~16.04.1_all.deb"
FABRIC_NEGOTIATING_LOG_MESSAGE="negotiating with fabric via agent command __builtin__"
validate_image () {
local IMAGE="$1"
local OUTPUT=$(az_vm_create "$IMAGE" "$IMAGE validation")
local VM_NAME=$(echo "$OUTPUT" | head -n 1 | awk '{print $3}')
echo "$(date) - Created $VM_NAME"
echo "$(date) - Installing updated cloud-init deb"
az_vm_deb_install "$VM_NAME" "$DEB_PATH"
echo "$(date) - Validating reboot after cloud-init upgrade"
az_vm_ssh "$VM_NAME" "sudo reboot"
sleep 60
if az_vm_ssh "$VM_NAME" "cat /var/log/cloud-init.log" | grep "$FABRIC_NEGOTIATING_LOG_MESSAGE"; then
echo "$(date) - Success validating $IMAGE used __builtin__ for fabric negotiating"
else
echo "$(date) - FAILURE validating $IMAGE used __builtin__ for fabric negotiating"
exit 1
fi
echo "$(date) - Creating image from $VM_NAME"
az_image_create_from_vm "$VM_NAME"
echo "$(date) - Creating VM from image $VM_NAME"
local OUTPUT=$(az_vm_create "$VM_NAME" "$IMAGE validation vm")
local NEW_VM_NAME=$(echo "$OUTPUT" | head -n 1 | awk '{print $3}')
echo "$(date) - Created $NEW_VM_NAME"
echo "$(date) - Validating agent was used for fabric negotiation"
if az_vm_ssh "$NEW_VM_NAME" "cat /var/log/cloud-init.log" | grep "$FABRIC_NEGOTIATING_LOG_MESSAGE"; then
echo "$(date) - Success validating $IMAGE used __builtin__ for fabric negotiating"
else
echo "$(date) - FAILURE validating $IMAGE used __builtin__ for fabric negotiating"
exit 1
fi
echo "$(date) - Cleaning cloud-init logs"
az_vm_ssh "$NEW_VM_NAME" "sudo cloud-init clean --logs --reboot"
echo "$(date) - Validating reboot uses agent for fabric negotiation"
sleep 60
if az_vm_ssh "$NEW_VM_NAME" "cat /var/log/cloud-init.log" | grep "$FABRIC_NEGOTIATING_LOG_MESSAGE"; then
echo "$(date) - Success validating $IMAGE reboot for fabric negotiation"
else
echo "$(date) - FAILURE validating $IMAGE reboot for fabric negotiation"
exit 1
fi
}
validate_image "canonical:ubuntuserver:16.04.0-LTS:latest"
validate_image "canonical:ubuntuserver:16.04-DAILY-LTS:latest"
@raharper
Copy link

I think one of the paths needs to utilize cloud-init clean --logs; maybe one of your az_vm_create() is doing that. The clean helps produce some of the "first time boot" path that cloud-init takes. Otherwise, this looks fine.

@trstringer
Copy link
Author

Ah good point! I've added the cloud-init clean right before the last validation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment