-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from hamistao/add_tpm_tests
Add tests for TPM usage
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/sh | ||
set -eu | ||
|
||
# Install LXD | ||
install_lxd | ||
|
||
# Configure LXD | ||
lxd init --auto | ||
|
||
IMAGE="${TEST_IMG:-ubuntu-minimal-daily:24.04}" | ||
vmName="test-vm" | ||
|
||
# Launch test instance | ||
lxc init "${IMAGE}" "${vmName}" --vm | ||
|
||
echo "==> Try starting a VM with two TPM devices" | ||
lxc config device add "${vmName}" tpm1 tpm | ||
lxc config device add "${vmName}" tpm2 tpm | ||
! lxc start "${vmName}" || false | ||
|
||
echo "==> Starting VM with TPM" | ||
lxc config device remove "${vmName}" tpm2 | ||
lxc start "${vmName}" | ||
waitInstanceReady "${vmName}" | ||
|
||
echo "==> Check if TPM files are present" | ||
lxc exec "${vmName}" -- stat /dev/tpm0 | ||
lxc exec "${vmName}" -- stat /dev/tpmrm0 | ||
|
||
echo "==> Try removing TPM from a running VM" | ||
! lxc config device remove "${vmName}" tpm1 || false | ||
lxc exec "${vmName}" -- stat /dev/tpm0 | ||
lxc exec "${vmName}" -- stat /dev/tpmrm0 | ||
|
||
echo "==> Stopping VM and removing TPM" | ||
lxc stop "${vmName}" --force | ||
lxc config device remove "${vmName}" tpm1 | ||
|
||
echo "==> Check if TPM was indeed removed" | ||
lxc start "${vmName}" | ||
waitInstanceReady "${vmName}" | ||
! lxc exec "${vmName}" -- stat /dev/tpm0 || false | ||
! lxc exec "${vmName}" -- stat /dev/tpmrm0 || false | ||
lxc stop "${vmName}" --force | ||
|
||
# TPM names are included on the swtpm socket path and long socket paths can cause problems if not handled correctly. | ||
echo "==> Test handling TPMs with long names" | ||
longName="tpm-device-with-long-name-for-testing" | ||
lxc config device add "${vmName}" "${longName}" tpm | ||
lxc start "${vmName}" | ||
waitInstanceReady "${vmName}" | ||
lxc exec "${vmName}" -- stat /dev/tpm0 | ||
lxc exec "${vmName}" -- stat /dev/tpmrm0 | ||
lxc delete "${vmName}" --force |