Skip to content

Commit

Permalink
feat(self-test): add selftest and integration tests
Browse files Browse the repository at this point in the history
Add selftest.py, a standalone script meant to validate a the
functionality of azure-vm-utils when installed in Azure VM.

Add test_images.py, a pytest-based set of tests which tests
marketplace and community images which feature azure-vm-utils
baked in (e.g. debian 13, fedora 41) across a variety of
vm sizes and types.  It also features a test_custom()
to allow for easy testing of any image & vm size combination
via environment TEST_CUSTOM_IMAGES=image1,image2,... and
TEST_CUSTOM_VM_SIZES=size1,size2...  Instructions for usage
added to README.md.

Add python-autoformat and python-lint targets to cmake and
update CI to use linters.

Signed-off-by: Chris Patterson <[email protected]>
  • Loading branch information
cjp256 committed Jan 29, 2025
1 parent d58ab45 commit a19db13
Show file tree
Hide file tree
Showing 8 changed files with 1,289 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ jobs:
- name: Check cppcheck
run: |
make -C build cppcheck
- name: Check python scripts
run: |
python -m venv venv
source venv/bin/activate
pip install -r selftest/test-requirements.txt
make -C build python-lint
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ endif()
include(cmake/cppcheck.cmake)
include(cmake/clangformat.cmake)
include(cmake/doc.cmake)
include(cmake/python.cmake)

include(CTest)
enable_testing()
Expand Down
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,55 @@ DEVNAME=/dev/nvme0n1 azure-nvme-id --udev

Provides helpful symlinks in /dev/disk/azure for local, data, and os disks.

# Testing

## selfcheck

selfcheck is provided to validate the runtime environment of a VM.

With azure-vm-utils installed in a VM on Azure, simply copy the selfcheck.py executable to the target and
execute with sudo.

```
scp selfcheck/selftest.py $ip: && ssh $ip -- sudo ./selftest.py
```

## test_images

To help automate a spread of tests, test_images provides functional testing for a set of pre-existing images,
assuming azure-vm-utils is already installed. It depends on az-cli, ssh, and ssh-keygen to create VMs
and ssh into them to run the tests.

To run tests against marketplace and community images with azure-vm-utils:

```
AZURE_SUBSCRIPTION=<subscription id> \
AZURE_LOCATION=eastus2 \
pytest -v selftest
```

To run tests for custom images and vm sizes, test_custom() is provided and can be configured via environment.
TEST_CUSTOM_IMAGES and TEST_CUSTOM_VM_SIZES are comma-separated so multiple may be tested at a time.

For example:

```
AZURE_SUBSCRIPTION=<subscription id> \
AZURE_LOCATION=eastus2 \
TEST_CUSTOM_IMAGES=/my/image1,/my/image2,... \
TEST_CUSTOM_VM_SIZES=Standard_D2ds_v5,Standard_D2ds_v6,... \
pytest -v -k test_custom
```

For convenience, the default spread of VM sizes can be re-used for custom tests by setting one of the
following that are appropriate for the image(s) under test:

```
TEST_CUSTOM_VM_SIZES=DEFAULT_GEN1_VM_SIZES
TEST_CUSTOM_VM_SIZES=DEFAULT_GEN2_VM_SIZES
TEST_CUSTOM_VM_SIZES=DEFAULT_ARM64_VM_SIZES
```

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand All @@ -57,8 +106,8 @@ contact [[email protected]](mailto:[email protected]) with any additio

## Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
trademarks or logos is subject to and must follow
[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
Any use of third-party trademarks or logos are subject to those third-party's policies.
19 changes: 19 additions & 0 deletions cmake/python.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
file(GLOB PYTHON_SOURCES */*.py)

add_custom_target(
python-autoformat
COMMAND isort ${PYTHON_SOURCES}
COMMAND black ${PYTHON_SOURCES}
COMMAND autoflake -r --in-place --remove-unused-variables --remove-all-unused-imports --ignore-init-module-imports ${PYTHON_SOURCES}
COMMENT "Running autoformatting tools"
)

add_custom_target(
python-lint
COMMAND isort --check-only ${PYTHON_SOURCES}
COMMAND black --check --diff ${PYTHON_SOURCES}
COMMAND mypy --ignore-missing-imports ${PYTHON_SOURCES}
COMMAND flake8 --ignore=W503,E501,E402 ${PYTHON_SOURCES}
COMMAND pylint ${PYTHON_SOURCES}
COMMENT "Running Python lint checks and formatting checks"
)
Empty file added selftest/__init__.py
Empty file.
Loading

0 comments on commit a19db13

Please sign in to comment.