Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trusted Launch Test #18562

Merged
merged 18 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Compute.Tests;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,27 @@ public void TestVMScenarioOperations_EncryptionAtHost()
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
}
}

/// <summary>
/// To record this test case, you need to run it in region which support Encryption at host
/// </summary>
[Fact]
[Trait("Name", "TestVMScenarioOperations_TrustedLaunch")]
public void TestVMScenarioOperations_TrustedLaunch()
{
string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");
try
{
ImageReference image = new ImageReference(publisher: "MicrosoftWindowsServer", offer: "windowsserver-gen2preview-preview", version: "18363.592.2001092016", sku: "windows10-tvm");
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "eastus2euap");
TestVMScenarioOperationsInternal("TestVMScenarioOperations_TrustedLaunch", vmSize: VirtualMachineSizeTypes.StandardD2sV3, hasManagedDisks: true,
osDiskStorageAccountType: StorageAccountTypes.StandardSSDLRS, securityType: "TrustedLaunch", imageReference: image, validateListAvailableSize: false);
}
finally
{
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", originalTestLocation);
}
}

/// <summary>
/// To record this test case, you need to run it in region which support DiskEncryptionSet resource for the Disks
Expand Down Expand Up @@ -241,7 +262,7 @@ public void TestVMScenarioOperations_PpgScenario()
private void TestVMScenarioOperationsInternal(string methodName, bool hasManagedDisks = false, IList<string> zones = null, string vmSize = "Standard_A1_v2",
string osDiskStorageAccountType = "Standard_LRS", string dataDiskStorageAccountType = "Standard_LRS", bool? writeAcceleratorEnabled = null,
bool hasDiffDisks = false, bool callUpdateVM = false, bool isPpgScenario = false, string diskEncryptionSetId = null, bool? encryptionAtHostEnabled = null,
bool isAutomaticPlacementOnDedicatedHostGroupScenario = false, ImageReference imageReference = null, bool validateListAvailableSize = true)
string securityType = null, bool isAutomaticPlacementOnDedicatedHostGroupScenario = false, ImageReference imageReference = null, bool validateListAvailableSize = true)
{
using (MockContext context = MockContext.Start(this.GetType(), methodName))
{
Expand Down Expand Up @@ -280,7 +301,7 @@ private void TestVMScenarioOperationsInternal(string methodName, bool hasManaged

CreateVM(rgName, asName, storageAccountName, imageRef, out inputVM, hasManagedDisks: hasManagedDisks,hasDiffDisks: hasDiffDisks, vmSize: vmSize, osDiskStorageAccountType: osDiskStorageAccountType,
dataDiskStorageAccountType: dataDiskStorageAccountType, writeAcceleratorEnabled: writeAcceleratorEnabled, zones: zones, ppgName: ppgName,
diskEncryptionSetId: diskEncryptionSetId, encryptionAtHostEnabled: encryptionAtHostEnabled, dedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId,
diskEncryptionSetId: diskEncryptionSetId, encryptionAtHostEnabled: encryptionAtHostEnabled, securityType: securityType, dedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId,
dedicatedHostGroupName: dedicatedHostGroupName, dedicatedHostName: dedicatedHostName);

// Instance view is not completely populated just after VM is provisioned. So we wait here for a few minutes to
Expand Down Expand Up @@ -326,6 +347,12 @@ private void TestVMScenarioOperationsInternal(string methodName, bool hasManaged
listVMSizesResponse = m_CrpClient.AvailabilitySets.ListAvailableSizes(rgName, asName);
Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks);
}

if(securityType != null && securityType.Equals("TrustedLaunch"))
{
Assert.True(inputVM.SecurityProfile.UefiSettings.VTpmEnabled);
Assert.True(inputVM.SecurityProfile.UefiSettings.SecureBootEnabled);
}

if(isPpgScenario)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ protected VirtualMachine CreateVM(
string ppgName = null,
string diskEncryptionSetId = null,
bool? encryptionAtHostEnabled = null,
string securityType = null,
string dedicatedHostGroupReferenceId = null,
string dedicatedHostGroupName = null,
string dedicatedHostName = null)
Expand Down Expand Up @@ -296,6 +297,30 @@ protected VirtualMachine CreateVM(
EncryptionAtHost = encryptionAtHostEnabled.Value
};
}

if (securityType != null && securityType.Equals("TrustedLaunch"))
{
if(inputVM.SecurityProfile != null)
{
inputVM.SecurityProfile.UefiSettings = new UefiSettings
{
VTpmEnabled = true,
SecureBootEnabled = true
};
}
else
{
inputVM.SecurityProfile = new SecurityProfile
{
UefiSettings = new UefiSettings
{
VTpmEnabled = true,
SecureBootEnabled = true
}
};
}

}

if (zones != null)
{
Expand Down
Loading