Skip to content

Commit 890ba67

Browse files
authored
Merge pull request #10138 from Jyotsna-Anand/jyanand-fix-tests
jyanand-fix-tests
2 parents 20573b6 + 1ece5a6 commit 890ba67

12 files changed

+16947
-11236
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineExtensionTests.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,16 @@ public void TestAzureDiskEncryptionExtensionSinglePassDisableAndRemove()
115115

116116
[Fact]
117117
[Trait(Category.AcceptanceType, Category.CheckIn)]
118-
public void TestAzureDiskEncryptionExtensionSinglePassEnableAndDisableWithNonDefaultParams()
118+
public void TestAzureDiskEncryptionExtensionNonDefaultParams()
119119
{
120-
TestRunner.RunTestScript("Test-AzureDiskEncryptionExtensionSinglePassEnableAndDisableWithNonDefaultParams");
120+
TestRunner.RunTestScript("Test-AzureDiskEncryptionExtensionNonDefaultParams");
121+
}
122+
123+
[Fact]
124+
[Trait(Category.AcceptanceType, Category.CheckIn)]
125+
public void TestAzureDiskEncryptionLnxManagedDisk()
126+
{
127+
TestRunner.RunTestScript("Test-AzureDiskEncryptionLnxManagedDisk");
121128
}
122129

123130
[Fact]

src/Compute/Compute.Test/ScenarioTests/VirtualMachineExtensionTests.ps1

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,8 @@ function Test-VirtualMachineAccessExtension
10181018
# OS & Image
10191019
$user = "Foo12";
10201020
$password = $PLACEHOLDER;
1021-
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
1021+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force; <#[SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Credentials are used only for the duration of test. Resources are deleted at the end of the test.")]#>
1022+
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Credentials are used only for the duration of test. Resources are deleted at the end of the test.")]#>
10221023
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
10231024
$computerName = 'test';
10241025
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
@@ -1254,7 +1255,7 @@ function Test-AzureDiskEncryptionExtensionSinglePassDisableAndRemove
12541255
.SYNOPSIS
12551256
Test the Set-AzVMDiskEncryptionExtension single pass enable and disable scenario with non default parameters
12561257
#>
1257-
function Test-AzureDiskEncryptionExtensionSinglePassEnableAndDisableWithNonDefaultParams
1258+
function Test-AzureDiskEncryptionExtensionNonDefaultParams
12581259
{
12591260
$resourceGroupName = Get-ComputeTestResourceName
12601261
try
@@ -1304,6 +1305,88 @@ function Test-AzureDiskEncryptionExtensionSinglePassEnableAndDisableWithNonDefau
13041305
}
13051306
}
13061307

1308+
<#
1309+
.SYNOPSIS
1310+
Test the Set-AzVMDiskEncryptionExtension single pass enable for Linux managed disk VMs
1311+
#>
1312+
function Test-AzureDiskEncryptionLnxManagedDisk
1313+
{
1314+
$testMode = Get-ComputeTestMode
1315+
$rgname = Get-ComputeTestResourceName
1316+
try
1317+
{
1318+
# create virtual machine
1319+
$loc = Get-ComputeVMLocation;
1320+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
1321+
# VM Profile & Hardware
1322+
$vmsize = 'Standard_D2S_V3';
1323+
$vmname = 'vm' + $rgname;
1324+
$imagePublisher = "RedHat";
1325+
$imageOffer = "RHEL";
1326+
$imageSku = "7.5";
1327+
$p = New-AzVMConfig -VMName $vmname -VMSize $vmsize;
1328+
Assert-AreEqual $p.HardwareProfile.VmSize $vmsize;
1329+
1330+
# NRP
1331+
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
1332+
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
1333+
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
1334+
$subnetId = $vnet.Subnets[0].Id;
1335+
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
1336+
$pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
1337+
$pubipId = $pubip.Id;
1338+
$nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
1339+
$nic = Get-AzNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
1340+
$nicId = $nic.Id;
1341+
1342+
$p = Add-AzVMNetworkInterface -VM $p -Id $nicId;
1343+
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
1344+
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Id $nicId;
1345+
1346+
# Storage Account (SA)
1347+
$stoname = 'sto' + $rgname;
1348+
$stotype = 'Standard_GRS';
1349+
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
1350+
Retry-IfException { $global:stoaccount = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname; }
1351+
$stokey = (Get-AzStorageAccountKey -ResourceGroupName $rgname -Name $stoname)[0].Value;
1352+
1353+
$osDiskName = 'linuxOsDisk';
1354+
$osDiskCaching = 'ReadWrite';
1355+
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/linuxos.vhd";
1356+
$p = Set-AzVMOSDisk -VM $p -Name $osDiskName -Caching $osDiskCaching -CreateOption FromImage -Linux;
1357+
Assert-AreEqual $p.StorageProfile.OSDisk.Caching $osDiskCaching;
1358+
Assert-AreEqual $p.StorageProfile.OSDisk.Name $osDiskName;
1359+
# OS & Image
1360+
$user = "Foo12";
1361+
$password = $PLACEHOLDER;
1362+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force; <#[SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Credentials are used only for the duration of test. Resources are deleted at the end of the test.")]#>
1363+
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Credentials are used only for the duration of test. Resources are deleted at the end of the test.")]#>
1364+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
1365+
$computerName = 'test';
1366+
$vhdContainer = "https://$stoname.blob.core.windows.net/test";
1367+
1368+
$p = Set-AzVMOperatingSystem -VM $p -Linux -ComputerName $computerName -Credential $cred;
1369+
$p = Set-AzVMSourceImage -VM $p -PublisherName $imagePublisher -Offer $imageOffer -Skus $imageSku -Version "latest"
1370+
Assert-AreEqual $p.OSProfile.AdminUsername $user;
1371+
Assert-AreEqual $p.OSProfile.ComputerName $computerName;
1372+
Assert-AreEqual $p.OSProfile.AdminPassword $password;
1373+
Assert-AreEqual $p.StorageProfile.ImageReference.Offer $imageOffer;
1374+
Assert-AreEqual $p.StorageProfile.ImageReference.Publisher $imagePublisher;
1375+
Assert-AreEqual $p.StorageProfile.ImageReference.Sku $imageSku;
1376+
1377+
# Virtual Machine
1378+
New-AzVM -ResourceGroupName $rgname -Location $loc -VM $p;
1379+
$kv = Create-KeyVault $rgname $loc;
1380+
# Enable single pass encryption without -skipVmBackup on Linux VM managed disk and verify exception is thrown
1381+
Assert-ThrowsContains { Set-AzVMDiskEncryptionExtension -ResourceGroupName $rgname -VMName $vmname -DiskEncryptionKeyVaultUrl $kv.DiskEncryptionKeyVaultUrl -DiskEncryptionKeyVaultId $kv.DiskEncryptionKeyVaultId -VolumeType "OS" -Force; } `
1382+
"skipVmBackup parameter is a required parameter for encrypting Linux VMs with managed disks"; #>
1383+
}
1384+
finally
1385+
{
1386+
Clean-ResourceGroup($rgname)
1387+
}
1388+
}
1389+
13071390
<#
13081391
.SYNOPSIS
13091392
Test AzureDiskEncryption extension
@@ -1601,7 +1684,8 @@ function Test-VirtualMachineBginfoExtension
16011684
# OS & Image
16021685
$user = "Foo12";
16031686
$password = $PLACEHOLDER;
1604-
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
1687+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force; <#[SuppressMessage("Microsoft.Security", "CS001:SecretInline", Justification="Credentials are used only for the duration of test. Resources are deleted at the end of the test.")]#>
1688+
<#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Credentials are used only for the duration of test. Resources are deleted at the end of the test.")]#>
16051689
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
16061690
$computerName = 'test';
16071691
$vhdContainer = "https://$stoname.blob.core.windows.net/test";

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests/TestAzureDiskEncryptionExtensionNonDefaultParams.json

Lines changed: 5984 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests/TestAzureDiskEncryptionExtensionSinglePass.json

Lines changed: 2133 additions & 3110 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests/TestAzureDiskEncryptionExtensionSinglePassDisableAndRemove.json

Lines changed: 2612 additions & 2719 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests/TestAzureDiskEncryptionExtensionSinglePassEnableAndDisableWithNonDefaultParams.json

Lines changed: 0 additions & 5400 deletions
This file was deleted.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests/TestAzureDiskEncryptionLnxManagedDisk.json

Lines changed: 6081 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
## Upcoming Release
2222
* Add Priority, EvictionPolicy, and MaxPrice parameters to New-AzVM and New-AzVmss cmdlets
2323
* Fix warning message and help document for Add-AzVMAdditionalUnattendContent and Add-AzVMSshPublicKey cmdlets
24+
* Fix -skipVmBackup exception for Linux VMs with managed disks for Set-AzVMDiskEncryptionExtension.
2425

2526
## Version 2.6.0
2627
* Add UploadSizeInBytes parameter tp New-AzDiskConfig

src/Compute/Compute/Extension/AzureDiskEncryption/SetAzureDiskEncryptionExtension.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
2020
using Microsoft.Azure.Management.Compute;
2121
using Microsoft.Azure.Management.Compute.Models;
22+
using Microsoft.Azure.Commands.Compute.Properties;
2223
using Microsoft.Rest.Azure;
2324
using System;
2425
using System.Collections;
@@ -541,9 +542,22 @@ public override void ExecuteCmdlet()
541542

542543
currentOSType = virtualMachineResponse.StorageProfile.OsDisk.OsType;
543544

545+
var vmParameters = (this.ComputeClient.ComputeManagementClient.VirtualMachines.Get(
546+
this.ResourceGroupName, VMName));
547+
544548
if (OperatingSystemTypes.Linux.Equals(currentOSType) && !SkipVmBackup)
545549
{
546-
CreateVMBackupForLinx();
550+
if (vmParameters.StorageProfile.OsDisk.ManagedDisk != null)
551+
{
552+
ThrowTerminatingError(new ErrorRecord(new ArgumentException(string.Format(CultureInfo.CurrentUICulture, Resources.EnableDiskEncryptionMissingSkipVmBackup)),
553+
"InvalidArgument",
554+
ErrorCategory.InvalidArgument,
555+
null));
556+
}
557+
else
558+
{
559+
CreateVMBackupForLinx();
560+
}
547561
}
548562

549563
VirtualMachineExtension parameters = GetVmExtensionParameters(virtualMachineResponse);

src/Compute/Compute/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compute/Compute/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ The file needs to be a PowerShell script (.ps1 or .psm1) or a ZIP archive (.zip)
597597
<data name="NoSubscriptionInContext" xml:space="preserve">
598598
<value>No subscription found in the context. Please ensure that the credentials you provided are authorized to access an Azure subscription, then run Connect-AzAccount to login.</value>
599599
</data>
600+
<data name="EnableDiskEncryptionMissingSkipVmBackup" xml:space="preserve">
601+
<value>-skipVmBackup parameter is a required parameter for encrypting Linux VMs with managed disks. For more information, see https://docs.microsoft.com/azure/security/azure-security-disk-encryption-linux. </value>
602+
</data>
600603
<data name="LinuxConfigurationSpecified" xml:space="preserve">
601604
<value>Linux configuration is already specified. This cmdlet requires a Windows configuration.</value>
602605
</data>

tools/SecurityTools/CredScanSuppressions.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,19 @@
870870
"_justification": "Legitimate test session record - the resources are being deleted after the test run in Record mode."
871871
},
872872
{
873-
"file": "src\\Compute\\Compute.Test\\SessionRecords\\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\\TestAzureDiskEncryptionExtensionSinglePassEnableAndDisableWithNonDefaultParams.json",
873+
"file": "src\\Compute\\Compute.Test\\SessionRecords\\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\\TestAzureDiskEncryptionExtensionNonDefaultParams.json",
874+
"_justification": "Generated test resource group, deleted after test execution"
875+
},
876+
{
877+
"file": "src\\Compute\\Compute.Test\\SessionRecords\\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\\TestAzureDiskEncryptionExtensionSinglePass.json",
878+
"_justification": "Generated test resource group, deleted after test execution"
879+
},
880+
{
881+
"file": "src\\Compute\\Compute.Test\\SessionRecords\\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\\TestAzureDiskEncryptionExtensionSinglePassDisableAndRemove.json",
882+
"_justification": "Generated test resource group, deleted after test execution"
883+
},
884+
{
885+
"file": "src\\Compute\\Compute.Test\\SessionRecords\\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\\TestAzureDiskEncryptionLnxManagedDisk.json",
874886
"_justification": "Generated test resource group, deleted after test execution"
875887
}
876888
]

0 commit comments

Comments
 (0)