Skip to content

Commit

Permalink
SDK changes for CVM for api-version 2021-11-01 (#25645)
Browse files Browse the repository at this point in the history
* sdk changes for CVM

* save changes for securityType and diskSecurityprofile

Add PMK scenario

* Added recorded file
  • Loading branch information
ms-saypaul authored Jan 14, 2022
1 parent 0128233 commit 11375ec
Show file tree
Hide file tree
Showing 10 changed files with 1,773 additions and 34 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,28 @@ public void TestVMScenarioOperations_TrustedLaunch()
}
}

/// <summary>
/// To record this test case, you need to run it in region which support ConfidentialVM
/// </summary>
[Fact]
[Trait("Name", "TestVMScenarioOperations_ConfidentialVM")]
public void TestVMScenarioOperations_ConfidentialVM()
{
string originalTestLocation = Environment.GetEnvironmentVariable("AZURE_VM_TEST_LOCATION");
try
{
ImageReference image = new ImageReference(publisher: "MICROSOFTWINDOWSSERVER", offer: "WINDOWS-CVM", version: "20348.230.2109130355", sku: "2022-DATACENTER-CVM");
Environment.SetEnvironmentVariable("AZURE_VM_TEST_LOCATION", "northeurope");
VMDiskSecurityProfile diskSecurityProfile = new VMDiskSecurityProfile(securityEncryptionType: "VMGuestStateOnly");
TestVMScenarioOperationsInternal("TestVMScenarioOperations_ConfidentialVM", vmSize: VirtualMachineSizeTypes.StandardDC2asV5, hasManagedDisks: true,
osDiskStorageAccountType: StorageAccountTypes.PremiumLRS, securityType: "ConfidentialVM", imageReference: image, validateListAvailableSize: false, diskSecurityProfile: diskSecurityProfile);
}
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
/// </summary>
Expand Down Expand Up @@ -280,7 +302,7 @@ private void TestVMScenarioOperationsInternal(string methodName, bool hasManaged
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,
string securityType = null, bool isAutomaticPlacementOnDedicatedHostGroupScenario = false, ImageReference imageReference = null, bool validateListAvailableSize = true,
bool associateWithCapacityReservation = false)
bool associateWithCapacityReservation = false, VMDiskSecurityProfile diskSecurityProfile = null)
{
using (MockContext context = MockContext.Start(this.GetType(), methodName))
{
Expand Down Expand Up @@ -330,7 +352,8 @@ 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, securityType: securityType, dedicatedHostGroupReferenceId: dedicatedHostGroupReferenceId,
dedicatedHostGroupName: dedicatedHostGroupName, dedicatedHostName: dedicatedHostName, capacityReservationGroupReferenceId: capacityReservationGroupReferenceId);
dedicatedHostGroupName: dedicatedHostGroupName, dedicatedHostName: dedicatedHostName, capacityReservationGroupReferenceId: capacityReservationGroupReferenceId,
diskSecurityProfile: diskSecurityProfile);

// Instance view is not completely populated just after VM is provisioned. So we wait here for a few minutes to
// allow GA blob to populate.
Expand Down Expand Up @@ -393,12 +416,17 @@ private void TestVMScenarioOperationsInternal(string methodName, bool hasManaged
Helpers.ValidateVirtualMachineSizeListResponse(listVMSizesResponse, hasAZ: zones != null, writeAcceleratorEnabled: writeAcceleratorEnabled, hasDiffDisks: hasDiffDisks);
}

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

if(diskSecurityProfile != null)
{
Assert.Equal("ConfidentialVM", inputVM.SecurityProfile.SecurityType);
}

if(isPpgScenario)
{
ProximityPlacementGroup outProximityPlacementGroup = m_CrpClient.ProximityPlacementGroups.Get(rgName, ppgName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ protected VirtualMachine CreateVM(
string dedicatedHostGroupName = null,
string dedicatedHostName = null,
string userData = null,
string capacityReservationGroupReferenceId = null)
string capacityReservationGroupReferenceId = null,
VMDiskSecurityProfile diskSecurityProfile = null)
{
try
{
Expand Down Expand Up @@ -318,29 +319,21 @@ protected VirtualMachine CreateVM(
};
}

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

if(diskSecurityProfile != null)
{
inputVM.StorageProfile.OsDisk.ManagedDisk = inputVM.StorageProfile.OsDisk.ManagedDisk ?? new ManagedDiskParameters();
inputVM.StorageProfile.OsDisk.ManagedDisk.SecurityProfile = diskSecurityProfile;
}

if (zones != null)
Expand Down
Loading

0 comments on commit 11375ec

Please sign in to comment.