Skip to content

Commit 66952b3

Browse files
authored
Merge branch 'master' into release-2020-12-08-v2
2 parents c68f695 + 033e0eb commit 66952b3

File tree

78 files changed

+4532
-2699
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+4532
-2699
lines changed

src/Accounts/Authentication.Test/AuthenticationFactoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public void CanAuthenticateUsingMSIDefault()
172172
PowerShellTokenCacheProvider factory = new InMemoryTokenCacheProvider();
173173
AzureSession.Instance.RegisterComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, () => factory);
174174
var msalAccessTokenAcquirerFactory = new MsalAccessTokenAcquirerFactory();
175-
AzureSession.Instance.RegisterComponent(nameof(MsalAccessTokenAcquirerFactory), () => msalAccessTokenAcquirerFactory);
175+
AzureSession.Instance.RegisterComponent(nameof(MsalAccessTokenAcquirerFactory), () => msalAccessTokenAcquirerFactory, true);
176176

177177
string expectedAccessToken = Guid.NewGuid().ToString();
178178
_output.WriteLine("Expected access token for default URI: {0}", expectedAccessToken);

src/Automation/Automation/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed issue that parameters of `Start-AzAutomationRunbook` cannot convert PSObject wrapped string to JSON string [#13240]
2122

2223
## Version 1.4.0
2324
* Added `-RunOn` parameters to `Set-AzAutomationWebhook` to specify a Hybrid Worker Group

src/Automation/Automation/Common/PowershellJsonConverter.cs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ public static string Serialize(object inputObject)
3131
{
3232
return null;
3333
}
34-
34+
while(inputObject is PSObject && ((PSObject)inputObject).BaseObject != null)
35+
{
36+
inputObject = ((PSObject)inputObject).BaseObject;
37+
}
38+
if(inputObject is string)
39+
{
40+
inputObject = ((string)inputObject).Trim();
41+
}
3542
return JsonConvert.SerializeObject(inputObject);
3643
}
3744

@@ -51,42 +58,5 @@ public static PSObject Deserialize(string json)
5158
return json;
5259
}
5360
}
54-
55-
/// <summary>
56-
/// Invokes a powershell script using the same runspace as the caller.
57-
/// </summary>
58-
/// <param name="scriptName">script name</param>
59-
/// <param name="parameters">parameters for the script</param>
60-
/// <returns></returns>
61-
private static Collection<PSObject> InvokeScript(string scriptName, Hashtable parameters)
62-
{
63-
using (var powerShell = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace))
64-
{
65-
powerShell.AddCommand(scriptName);
66-
foreach (DictionaryEntry parameter in parameters)
67-
{
68-
powerShell.AddParameter(parameter.Key.ToString(), parameter.Value);
69-
}
70-
71-
72-
var result = powerShell.Invoke();
73-
74-
//Error handling
75-
if (powerShell.HadErrors)
76-
{
77-
StringBuilder errorStringBuilder = new StringBuilder();
78-
foreach (var error in powerShell.Streams.Error)
79-
{
80-
errorStringBuilder.AppendLine(error.InvocationInfo.MyCommand.Name + " : " + error.Exception.Message);
81-
errorStringBuilder.AppendLine(error.InvocationInfo.PositionMessage);
82-
}
83-
84-
throw new AzureAutomationOperationException(string.Format(CultureInfo.CurrentCulture,
85-
Resources.PowershellJsonDecrypterFailed, errorStringBuilder.ToString()));
86-
}
87-
88-
return result;
89-
}
90-
}
9161
}
9262
}

src/Billing/Billing/help/Get-AzBillingInvoice.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Get invoices by billing account name and include download url for each invoice i
7979

8080
### Example 7
8181
```
82-
PS C:\> Get-AzBillingInvoice Get-AzBillingInvoice -Name 0000000000 -BillingAccountName 00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000_0000-00-00 -GenerateDownloadUrl
82+
PS C:\> Get-AzBillingInvoice -Name 0000000000 -BillingAccountName 00000000-0000-0000-0000-000000000000:00000000-0000-0000-0000-000000000000_0000-00-00 -GenerateDownloadUrl
8383
```
8484

8585
Get specific invoice by invoice name and billing account name and include download url for each invoice in the result.

src/Compute/Compute.Test/ScenarioTests/DiskRPTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,12 @@ public void TestGetDiskEncryptionSetAssociatedResource()
107107
{
108108
TestRunner.RunTestScript("Test-GetDiskEncryptionSetAssociatedResource");
109109
}
110+
111+
[Fact]
112+
[Trait(Category.AcceptanceType, Category.CheckIn)]
113+
public void TestSnapshotDuplicateCreationFails()
114+
{
115+
TestRunner.RunTestScript("Test-SnapshotDuplicateCreationFails");
116+
}
110117
}
111118
}

src/Compute/Compute.Test/ScenarioTests/DiskRPTests.ps1

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ function Test-Snapshot
246246
$snapshotconfig.EncryptionSettingsCollection.Enabled = $false;
247247
$snapshotconfig.EncryptionSettingsCollection.EncryptionSettings = $null;
248248
$snapshotconfig.CreationData.ImageReference = $null;
249-
$job = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname -Snapshot $snapshotconfig -AsJob;
249+
$job = Update-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname -Snapshot $snapshotconfig -AsJob;
250250
$result = $job | Wait-Job;
251251
Assert-AreEqual "Completed" $result.State;
252252

@@ -619,7 +619,7 @@ function Test-SnapshotEncrypt
619619
Assert-AreEqual 0 $snapshotconfig.CreationData.ImageReference.Lun;
620620

621621
$snapshotconfig.CreationData.ImageReference = $null;
622-
$job = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname -Snapshot $snapshotconfig -AsJob;
622+
$job = Update-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname -Snapshot $snapshotconfig -AsJob;
623623
$result = $job | Wait-Job;
624624
Assert-AreEqual "Completed" $result.State;
625625

@@ -1336,4 +1336,42 @@ function Test-DiskConfigTierSectorSizeReadOnly
13361336
# Cleanup
13371337
Clean-ResourceGroup $rgname
13381338
}
1339+
}
1340+
1341+
<#
1342+
.SYNOPSIS
1343+
Test the New-AzSnapshot cmdlet throws an error when attempting to create a snapshot with
1344+
the same name in the same resource group.
1345+
#>
1346+
function Test-SnapshotDuplicateCreationFails
1347+
{
1348+
# Setup
1349+
$rgname = Get-ComputeTestResourceName;
1350+
$loc = Get-ComputeVMLocation;
1351+
1352+
try
1353+
{
1354+
# Common
1355+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
1356+
$snapshotName = "test1";
1357+
1358+
$snapshotconfig = New-AzSnapshotConfig -Location $loc -DiskSizeGB 5 -AccountType Standard_LRS -OsType Windows -CreateOption Empty;
1359+
1360+
$snapshot = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotName -Snapshot $snapshotconfig;
1361+
Assert-NotNull $snapshot;
1362+
1363+
# Assert duplicate snapshot fails to create.
1364+
Assert-ThrowsContains { $snapshot2 = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotName -Snapshot $snapshotconfig; } "Please use Update-AzSnapshot to update an existing Snapshot.";
1365+
1366+
# Assert update snapshot succeeds.
1367+
$snapshotconfig2 = New-AzSnapshotUpdateConfig -DiskSizeGB 10 -AccountType Standard_LRS -OsType Windows;
1368+
$job = Update-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotName -SnapshotUpdate $snapshotconfig2 -AsJob;
1369+
$result = $job | Wait-Job;
1370+
Assert-AreEqual "Completed" $result.State;
1371+
}
1372+
finally
1373+
{
1374+
# Cleanup
1375+
Clean-ResourceGroup $rgname
1376+
}
13391377
}

src/Compute/Compute.Test/ScenarioTests/GalleryTests.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,16 +673,15 @@ function Test-GalleryImageVersionDiskImage
673673

674674
$snapshotname1 = 'ossnapshot' + $rgname;
675675
$snapshotconfig = New-AzSnapshotConfig -Location $loc -DiskSizeGB 5 -AccountType Standard_LRS -OsType Windows -CreateOption Empty -HyperVGeneration "V1";
676-
$snapshot1 = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname1 -Snapshot $snapshotconfig
676+
$snapshot1 = Update-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname1 -Snapshot $snapshotconfig
677677

678678
$snapshotname2 = 'data1snapshot' + $rgname;
679679
$snapshotconfig = New-AzSnapshotConfig -Location $loc -DiskSizeGB 5 -AccountType Standard_LRS -OsType Windows -CreateOption Empty -HyperVGeneration "V1";
680-
$snapshot2 = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname2 -Snapshot $snapshotconfig
680+
$snapshot2 = Update-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname2 -Snapshot $snapshotconfig
681681

682682
$snapshotname3 = 'data2snapshot' + $rgname;
683683
$snapshotconfig = New-AzSnapshotConfig -Location $loc -DiskSizeGB 5 -AccountType Standard_LRS -OsType Windows -CreateOption Empty -HyperVGeneration "V1";
684-
$snapshot3 = New-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname3 -Snapshot $snapshotconfig
685-
684+
$snapshot3 = Update-AzSnapshot -ResourceGroupName $rgname -SnapshotName $snapshotname3 -Snapshot $snapshotconfig
686685

687686
$targetRegions = @(@{Name='South Central US';ReplicaCount=1;StorageAccountType='Standard_LRS'},@{Name='East US';ReplicaCount=2},@{Name='Central US'});
688687
$tag = @{test1 = "testval1"; test2 = "testval2" };

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3612,7 +3612,7 @@ function Test-VirtualMachineManagedDisk
36123612
# Create OS snapshot from the VM
36133613
$snapshotConfig = New-AzSnapshotConfig -SourceUri $vm.Storageprofile.OsDisk.ManagedDisk.Id -Location $loc -CreateOption Copy;
36143614
$snapshotname = "ossnapshot";
3615-
New-AzSnapshot -Snapshot $snapshotConfig -SnapshotName $snapshotname -ResourceGroupName $rgname;
3615+
Update-AzSnapshot -Snapshot $snapshotConfig -SnapshotName $snapshotname -ResourceGroupName $rgname;
36163616
$snapshot = Get-AzSnapshot -SnapshotName $snapshotname -ResourceGroupName $rgname;
36173617

36183618
Assert-NotNull $snapshot.Id;

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DiskRPTests/TestSnapshot.json

Lines changed: 484 additions & 520 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DiskRPTests/TestSnapshotConfigDiskAccessNetworkPolicy.json

Lines changed: 310 additions & 538 deletions
Large diffs are not rendered by default.

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DiskRPTests/TestSnapshotDuplicateCreationFails.json

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

src/Compute/Compute/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
## Version 4.7.0
2525
* Edited Get-AzVm to filter by `-Name` prior to checking for throttling due to too many resources.
2626
* New cmdlet `Start-AzVmssRollingExtensionUpgrade`.
27+
* Edited `New-AzSnapshot` cmdlet to check for existing snapshot with the same name in the same resource group.
28+
- Throws an error if a duplicate snapshot exists.
2729

2830
## Version 4.6.0
2931
* Added `-VmssId` parameter to `New-AzVm`

src/Compute/Compute/Generated/Snapshot/SnapshotCreateOrUpdateMethod.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ public override void ExecuteCmdlet()
4141
base.ExecuteCmdlet();
4242
ExecuteClientAction(() =>
4343
{
44+
Snapshot existingResource;
45+
try
46+
{
47+
existingResource = SnapshotsClient.Get(this.ResourceGroupName, this.SnapshotName);
48+
}
49+
catch
50+
{
51+
existingResource = null;
52+
}
53+
54+
if (existingResource != null)
55+
{
56+
throw new Exception(string.Format("A Snapshot with name '{0}' in resource group '{1}' already exists. Please use Update-AzSnapshot to update an existing Snapshot.", this.SnapshotName, this.ResourceGroupName));
57+
}
58+
4459
if (ShouldProcess(this.SnapshotName, VerbsCommon.New))
4560
{
4661
string resourceGroupName = this.ResourceGroupName;

src/Security/Security.Test/ScenarioTests/DeviceSecurityGroupsTests.ps1

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,97 +18,66 @@ Get device security groups by the IoT hub resource Id
1818
#>
1919
function Get-AzureRmDeviceSecurityGroup-ResourceIdScope
2020
{
21-
$RuleType = "ActiveConnectionsNotInAllowedRange"
22-
$TimeWindowSize = New-TimeSpan -Minutes 5
23-
$TimeWindowRule = New-AzDeviceSecurityGroupTimeWindowRuleObject -Type $RuleType -Enabled $true -MaxThreshold 30 -MinThreshold 0 -TimeWindowSize $TimeWindowSize
24-
$TimeWindowRules = @($TimeWindowRule);
25-
26-
$HubResourceId = "/subscriptions/075423e9-7d33-4166-8bdf-3920b04e3735/resourceGroups/MichalResourceGroup/providers/Microsoft.Devices/IotHubs/MichalDemoHub"
21+
$HubResourceId = "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/resourceGroups/IOT-ResourceGroup-CUS/providers/Microsoft.Devices/IotHubs/SDK-IotHub-CUS"
2722
$Name = "samplesecuritygroup"
28-
Set-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId -TimeWindowRule $TimeWindowRules
29-
30-
$groups = Get-AzDeviceSecurityGroup -HubResourceId $HubResourceId
23+
Set-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId
24+
$groups = Get-AzDeviceSecurityGroup -HubResourceId $HubResourceId
3125
Validate-Groups $groups
3226
}
33-
3427
<#
3528
.SYNOPSIS
3629
Get device security group by its name
3730
#>
3831
function Get-AzureRmDeviceSecurityGroup-ResourceIdLevelResource
3932
{
40-
41-
$RuleType = "ActiveConnectionsNotInAllowedRange"
42-
$TimeWindowSize = New-TimeSpan -Minutes 5
43-
$TimeWindowRule = New-AzDeviceSecurityGroupTimeWindowRuleObject -Type $RuleType -Enabled $true -MaxThreshold 30 -MinThreshold 0 -TimeWindowSize $TimeWindowSize
44-
$TimeWindowRules = @($TimeWindowRule);
45-
46-
$HubResourceId = "/subscriptions/075423e9-7d33-4166-8bdf-3920b04e3735/resourceGroups/MichalResourceGroup/providers/Microsoft.Devices/IotHubs/MichalDemoHub"
33+
$HubResourceId = "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/resourceGroups/IOT-ResourceGroup-CUS/providers/Microsoft.Devices/IotHubs/SDK-IotHub-CUS"
4734
$Name = "samplesecuritygroup"
48-
Set-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId -TimeWindowRule $TimeWindowRules
49-
50-
$group = Get-AzDeviceSecurityGroup -HubResourceId $HubResourceId -Name $Name
35+
Set-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId
36+
$group = Get-AzDeviceSecurityGroup -HubResourceId $HubResourceId -Name $Name
5137
Validate-Group $group
5238
}
53-
5439
<#
5540
.SYNOPSIS
5641
Set device security group
5742
#>
5843
function Set-AzureRmDeviceSecurityGroup-ResourceIdLevelResource
5944
{
60-
$RuleType = "ActiveConnectionsNotInAllowedRange"
61-
$TimeWindowSize = New-TimeSpan -Minutes 5
62-
$TimeWindowRule = New-AzDeviceSecurityGroupTimeWindowRuleObject -Type $RuleType -Enabled $true -MaxThreshold 30 -MinThreshold 0 -TimeWindowSize $TimeWindowSize
63-
$TimeWindowRules = @($TimeWindowRule);
64-
65-
$HubResourceId = "/subscriptions/075423e9-7d33-4166-8bdf-3920b04e3735/resourceGroups/MichalResourceGroup/providers/Microsoft.Devices/IotHubs/MichalDemoHub"
45+
$HubResourceId = "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/resourceGroups/IOT-ResourceGroup-CUS/providers/Microsoft.Devices/IotHubs/SDK-IotHub-CUS"
6646
$Name = "samplesecuritygroup"
67-
$group = Set-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId -TimeWindowRule $TimeWindowRules
47+
$group = Set-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId
6848
Validate-Group $group
6949
}
70-
7150
<#
7251
.SYNOPSIS
7352
Delete device security group
7453
#>
7554
function Remove-AzureRmDeviceSecurityGroup-ResourceIdLevelResource
7655
{
77-
$RuleType = "ActiveConnectionsNotInAllowedRange"
78-
$TimeWindowSize = New-TimeSpan -Minutes 5
79-
$TimeWindowRule = New-AzDeviceSecurityGroupTimeWindowRuleObject -Type $RuleType -Enabled $true -MaxThreshold 30 -MinThreshold 0 -TimeWindowSize $TimeWindowSize
80-
$TimeWindowRules = @($TimeWindowRule);
81-
82-
$HubResourceId = "/subscriptions/075423e9-7d33-4166-8bdf-3920b04e3735/resourceGroups/MichalResourceGroup/providers/Microsoft.Devices/IotHubs/MichalDemoHub"
56+
$HubResourceId = "/subscriptions/487bb485-b5b0-471e-9c0d-10717612f869/resourceGroups/IOT-ResourceGroup-CUS/providers/Microsoft.Devices/IotHubs/SDK-IotHub-CUS"
8357
$Name = "samplesecuritygroup"
84-
$group = Set-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId -TimeWindowRule $TimeWindowRules
58+
$group = Set-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId
8559
Remove-AzDeviceSecurityGroup -Name $Name -HubResourceId $HubResourceId
8660
Validate-Group $group
8761
}
88-
8962
<#
9063
.SYNOPSIS
9164
Validates a list of iot security solutions
9265
#>
9366
function Validate-Groups
9467
{
9568
param($groups)
96-
97-
Assert-True { $groups.Count -gt 0 }
98-
69+
Assert-True { $groups.Count -gt 0 }
9970
Foreach($group in $groups)
10071
{
10172
Validate-Group $group
10273
}
10374
}
104-
10575
<#
10676
.SYNOPSIS
10777
Validates a single contact
10878
#>
10979
function Validate-Group
11080
{
11181
param($group)
112-
11382
Assert-NotNull $group
11483
}

src/Security/Security.Test/ScenarioTests/SecurityAlertTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Get security alerts on a resource group and its resources
2828
#>
2929
function Get-AzureRmSecurityAlert-ResourceGroupScope
3030
{
31-
$rgName = Get-TestResourceGroupName
31+
$rgName = "Sample-RG"
3232

3333
$alerts = Get-AzSecurityAlert -ResourceGroupName $rgName
3434
Validate-Alerts $alerts
@@ -166,5 +166,5 @@ function Validate-AlertActivity
166166
param($alert)
167167

168168
Assert-NotNull $alert
169-
Assert-True { $alert.State -eq "Active" }
169+
Assert-True { $alert.Status -eq "Active" }
170170
}

0 commit comments

Comments
 (0)