Skip to content

Latest commit

 

History

History

testinit

README.md

Azure-Init - Testinit Project

Testinit provides isolated provisioning tests and systemd-based E2E tests. Both use shared mock Azure Instance Metadata Service (IMDS) and WireServer handlers.

Warning

Running the ./start-all.sh script will modify your local machine due to how systemd in Docker works! Whenever possible, do not run this system on your personal machine as it completes the full provisioning run found in azure-init. This may affect your local hostname, ssh keys, users, or more. Exercise caution running this system locally!

Overview

This project consists of:

  • Isolated Tests: The real Cargo-built agent running with stubbed OS commands in disposable, unprivileged containers
  • Provisioning Agent: A systemd-based service running the azure-init binary in a privileged container
  • Testing Server: A mock Azure service providing IMDS and WireServer endpoints

Systemd Architecture

The setup creates two Docker networks with Azure-like IP addresses:

  • imds-network (169.254.0.0/16) - For IMDS communication
  • wireserver-network (168.63.0.0/16) - For WireServer communication

Prerequisites

  • Docker and Docker Compose
  • WSL2 or Linux environment
  • Python 3, Rust, and libudev development headers for isolated tests

Isolated Provisioning Tests

The Cargo test runs the real agent with stubbed OS commands and shared mock services, without the privileged Compose setup. From the repository root on Ubuntu:

python3 -B -m unittest discover -s testinit/testing-server -p 'test_*.py' -v
. /etc/os-release
docker build --build-arg "BASE_IMAGE=ubuntu:${VERSION_ID}" \
  -f testinit/Dockerfile.isolated -t azure-init-main-tests:local testinit
cargo test --locked --all-features --package azure-init --test testinit \
  -- --ignored agent_provisioning_in_container

This Docker-dependent test is ignored by default. The coverage workflow runs it and uploads combined coverage to Codecov.

Systemd E2E Quick Start

Starting Services

Run the start script to launch both services:

./start-all.sh

This will:

  1. Start the testing server container first (creates networks with Azure IP addresses)
  2. Wait for the testing server to be ready
  3. Start the provisioning agent

Selecting Images

The start-all.sh script also accepts an optional base image parameter for the Azure-init container.

./start-all.sh debian:12

Without a base container image argument, start-all defaults to Ubuntu 24.04. The list of currently tested images can be found in the e2e testing workflow.

Stopping Services

Stop all services and clean up:

./stop-all.sh

This will:

  1. Stop the provisioning agent container
  2. Stop the testing server container
  3. Remove orphaned containers
  4. Clean up Docker networks

Service Details

Provisioning Agent

  • Container: azureinit-provisioning-agent
  • Image: Built from local Dockerfile
  • Service: systemd-based azure-init.service
  • Privileges: Runs with privileged: true for systemd support
  • Binary Location: In the container, located at /usr/bin/azure-init

Testing Server

  • Container: azure-testing-server
  • Endpoints:
    • IMDS: http://169.254.169.254/metadata/instance
    • WireServer: http://168.63.129.16
  • Port: 80 (mapped to host)

Monitoring and Debugging

View Logs

Provisioning Agent:

docker compose logs -f provisioning-agent

Testing Server:

cd testing-server
docker compose logs -f testing-server

Development

Building

The systemd Dockerfile builds the repository source with cargo build and installs azure-init.service. The isolated Dockerfile contains only the fixture runtime and shared mock handlers; its agent binary is mounted by the Cargo test.