End-to-end tests validate the integration of azure-init in a real Azure VM environment. These tests verify that azure-init can properly provision Linux VMs according to Azure metadata.
Before running end-to-end tests, ensure you have:
- Azure CLI installed and configured
- An active Azure subscription (set as
SUBSCRIPTION_IDenvironment variable) - SSH keys set up (default:
~/.ssh/id_rsaand~/.ssh/id_rsa.pub) - jq installed for JSON parsing
- Appropriate Azure permissions to create resource groups, VMs, and Shared Image Gallery resources
There are two ways to run end-to-end tests for azure-init, both of which involve creating resources in your Azure cloud subscription:
- Direct VM Testing (Simplest) - Creates a VM using a standard Ubuntu image and runs the
functional_testsbinary directly. - SIG Image Testing (Advanced) - Creates a custom SIG image with azure-init pre-installed and enabled via a systemd service, then allocates a VM with that image.
For most users, the Direct VM Testing approach is recommended as it's simpler and faster. However, SIG testing should be done later on to ensure proper provisioning flow.
This approach works by:
- Building the
functional_testsbinary in a compatible environment - Creating a temporary VM in your Azure subscription using a standard Ubuntu image
- Copying the functional tests binary to the VM via SSH
- Running the tests on the VM to validate functionality
- Automatically deleting the VM and resource group after testing
The entire process happens in your Azure cloud subscription, but the test is controlled from your local machine. This approach is faster because it skips the image creation process, but it may not test the actual VM provisioning with azure-init since the agent is not pre-installed in the standard image.
To run e2e tests using the direct approach, use the following command from the repository root:
export SUBSCRIPTION_ID=$(az account show --query id -o tsv)
make e2e-testThis command will:
- Build the functional tests binary
- Create a new VM in your Azure subscription using a standard Ubuntu image
- Copy the functional tests binary to the VM
- Run the tests on the VM
- Automatically clean up resources when done
You can customize the VM creation with environment variables:
RG="mytest-azinit" LOCATION="westus2" VM_SIZE="Standard_D2s_v3" make e2e-testWhen running end-to-end tests, an important consideration is the binary compatibility between your build environment (where the functional_tests binary is compiled) and the target environment (the Azure VM where the tests will run).
Understanding the Issue
The functional_tests binary is:
- Built on your local system
- Copied to an Azure VM via SSH
- Executed on the VM to test azure-init functionality
If your build environment has newer libraries (especially glibc) than the target VM, you may encounter compatibility errors like:
./functional_tests: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_X.XX' not found
This occurs because your local build is dynamically linked against a newer version of glibc than what's available on the standard Ubuntu VM image in Azure. Be sure to build azure-init in the same environment as the target OS.
-
Build Process:
- The
functional_testsbinary is built in your chosen environment - This binary must be compatible with the target Azure VM environment
- The
-
VM Creation:
- The
functional_tests.shscript creates a resource group and VM in Azure - It uses standard Azure CLI commands to provision the VM
- The VM is created with your SSH public key for authentication
- The
-
Test Execution:
- The compatible binary is copied to the VM using SCP
- The script runs the binary on the VM with sudo permissions
- The binary tests core azure-init provisioning functionality like user creation and SSH key setup
-
Cleanup:
- The script automatically deletes the resource group to clean up all resources
The functional tests verify that azure-init correctly:
- Processes Azure VM metadata from the IMDS endpoint
- Sets up user accounts as specified in the provisioning data
- Configures SSH keys for secure access
- Sets the hostname according to Azure VM specifications
- Handles password configuration properly
-
Azure CLI Not Authenticated
- Run
az loginbefore running tests
- Run
-
Missing SUBSCRIPTION_ID
- Export your subscription ID:
export SUBSCRIPTION_ID=$(az account show --query id -o tsv)
- Export your subscription ID:
-
SSH Key Issues
- If you don't have SSH keys, the script will generate them
- To use custom keys, set
PATH_TO_PUBLIC_SSH_KEYandPATH_TO_PRIVATE_SSH_KEY
-
VM Creation Failures
- Check your quota limits in the Azure region you're using
- Verify you have permissions to create VMs with the specified size
-
Binary Compatibility Errors
- If you see
version GLIBC_X.XX not founderrors, it means your build environment has a newer glibc than the target VM - Options to resolve:
- Build on a matching OS version (same as the target VM)
- Configure static linking in your Rust build
- If you see
-
Image Creation Failures
- Check the resource group (default:
testgalleryazinitrg) for error details - If the image fails to create, the resource group is preserved for debugging
- Check the resource group (default:
For more advanced testing scenarios, you can create a custom Shared Image Gallery (SIG) image with azure-init pre-installed.
Those internal to Microsoft should also review the internal testing documentation.
This approach provides a more complete end-to-end test because:
- It creates a custom VM image with azure-init pre-installed and properly configured
- The VM provisioning process actually uses azure-init during boot
- It allows testing of the full provisioning flow from VM creation to user setup
This approach is more thorough but takes significantly longer (30+ minutes for image creation) as it involves:
- Creating a base VM
- Installing azure-init on that VM
- Generalizing the VM
- Capturing it as a SIG image
- Creating a second VM from that image
- Running tests on the second VM
All of these steps happen in your Azure cloud subscription, controlled from your local machine.
Azure Shared Image Gallery is a service that helps you build structure and organization around your custom VM images. In our testing, we can use SIG to create a custom VM image with azure-init pre-installed, allowing us to test the provisioning process in a controlled environment.
The SIG is created only within your own Azure subscription and is not publicly accessible.
To create an Azure SIG image for end-to-end testing:
demo/image_creation.shThis script:
- Creates an Azure resource group and storage account
- Deploys a virtual machine with a base image
- Installs and configures azure-init on the VM
- Generalizes the VM and captures it as a SIG image
- Publishes the SIG image for testing
You can customize the image creation with environment variables:
RG="mytest-azinit" LOCATION="westeurope" VM_SIZE="Standard_D2ds_v5" BASE_IMAGE="Canonical:0001-com-ubuntu-server-jammy:22_04-lts-gen2:latest" demo/image_creation.shNote: The BASE_IMAGE should be a Debian derivative like Ubuntu.
When the build host OS differs from the target host OS, the functional_test binary might not run due to package version mismatches (e.g., glibc).
After creating your SIG image, run the tests with:
VM_IMAGE="$(az sig image-definition list --resource-group testgalleryazinitrg --gallery-name testgalleryazinit | jq -r .[].id)" make e2e-testThis will allocate a VM of your given image type (with Azure-init installed) and later run the functional_test binary after provisioning.
When testing is done, clean up the SIG resource group:
az group delete --resource-group testgalleryazinitrgThis helps to avoid your subscription getting charged for resources you no longer use.
For more granular control over testing, you can set these environment variables:
SUBSCRIPTION_ID: Your Azure subscription IDRG: Resource group name (default:e2etest-azinit-<timestamp>)LOCATION: Azure region (default:eastus)VM_NAME: Base name for test VMsVM_SIZE: VM size (default:Standard_D2lds_v5)VM_ADMIN_USERNAME: Admin username (default:azureuser)VM_IMAGE: Image to use (URN or image ID)VM_SECURITY_TYPE: Security type (default:TrustedLaunch)
| Feature | Direct VM Testing | SIG Image Testing |
|---|---|---|
| Speed | Faster (5-10 minutes) | Slower (30+ minutes) |
| Completeness | Tests functionality only | Tests full provisioning flow |
| Resources Created | Single VM | Multiple VMs + SIG resources |
| Costs | Lower Azure costs | Higher Azure costs |
| Complexity | Simple, one command | Multiple steps |
| Tests Azure-init Integration | No (uses existing VM) | Yes (tests VM with azure-init) |