Skip to content

Commit 02ab411

Browse files
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
2 parents bfb5796 + 0e1387b commit 02ab411

File tree

102 files changed

+89248
-53113
lines changed

Some content is hidden

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

102 files changed

+89248
-53113
lines changed

setup-powershellget/Setup/ShortcutStartup.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ For a list of all Azure RM cmdlets type 'help azurerm'.
5959
6060
To start using Azure RM login via Login-AzureRmAccount cmdlet.
6161
To switch between subscriptions use Set-AzureRmContext.
62+
For more details, see http://aka.ms/azps-getting-started.
6263
6364
To use Azure Service Management cmdlets please execute the following cmdlet:
6465
Install-Module Azure

src/ResourceManager/ApiManagement/Commands.ApiManagement.Test/ScenarioTests/Common.ps1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ Gets all locations for a provider
5050
#>
5151
function Get-ProviderLocations($provider)
5252
{
53-
$location = Get-AzureRmLocation | where {$_.Name -eq $provider}
54-
$location.Locations
53+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
54+
{
55+
$namespace = $provider.Split("/")[0]
56+
if($provider.Contains("/"))
57+
{
58+
$type = $provider.Substring($namespace.Length + 1)
59+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
60+
61+
if ($location -eq $null)
62+
{
63+
return @("Central US", "East US")
64+
} else
65+
{
66+
return $location.Locations[0]
67+
}
68+
}
69+
70+
return @("Central US", "East US")
71+
}
72+
73+
return @("Central US", "East US")
5574
}

src/ResourceManager/ApiManagement/Commands.SMAPI.Test/ScenarioTests/Common.ps1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ Gets all locations for a provider
5050
#>
5151
function Get-ProviderLocations($provider)
5252
{
53-
$location = Get-AzureRmLocation | where {$_.Name -eq $provider}
54-
$location.Locations
53+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
54+
{
55+
$namespace = $provider.Split("/")[0]
56+
if($provider.Contains("/"))
57+
{
58+
$type = $provider.Substring($namespace.Length + 1)
59+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
60+
61+
if ($location -eq $null)
62+
{
63+
return @("West US", "East US")
64+
} else
65+
{
66+
return $location.Locations[0]
67+
}
68+
}
69+
70+
return @("West US", "East US")
71+
}
72+
73+
return @("West US", "East US")
5574
}

src/ResourceManager/AzureBatch/Commands.Batch.Test/ScenarioTests/Common.ps1

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,27 @@ Gets the location for the Batch account provider. Default to West US if none fou
3636
#>
3737
function Get-BatchAccountProviderLocation($index)
3838
{
39-
$location = Get-AzureRmLocation | where {$_.Name -eq "Microsoft.Batch/batchAccounts"}
40-
if ($location -eq $null)
39+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
4140
{
42-
"West US"
43-
}
44-
else
45-
{
46-
if ($index -eq $null)
47-
{
48-
$location.Locations[0]
49-
}
50-
else
51-
{
52-
$location.Locations[$index]
41+
$namespace = $provider.Split("/")[0]
42+
if($provider.Contains("/"))
43+
{
44+
$type = $provider.Substring($namespace.Length + 1)
45+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
46+
47+
if ($location -eq $null)
48+
{
49+
return "West US"
50+
} else
51+
{
52+
return $location.Locations[0]
53+
}
5354
}
54-
}
55+
56+
return "West US"
57+
}
58+
59+
return "WestUS"
5560
}
5661

5762
<#

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@
6666
<Reference Include="Microsoft.Azure.Management.Authorization">
6767
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.1.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
6868
</Reference>
69-
<Reference Include="Microsoft.Azure.Management.Compute, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
70-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.8.2.0\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
69+
<Reference Include="Microsoft.Azure.Management.Compute, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
70+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Compute.9.0.0\lib\net40\Microsoft.Azure.Management.Compute.dll</HintPath>
7171
<Private>True</Private>
7272
</Reference>
7373
<Reference Include="Microsoft.Azure.Management.Network, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -157,6 +157,7 @@
157157
<Compile Include="ScenarioTests\AddVhdTests.cs" />
158158
<Compile Include="ScenarioTests\ComputeCloudExceptionTests.cs" />
159159
<Compile Include="ScenarioTests\DscExtensionTests.cs" />
160+
<Compile Include="ScenarioTests\VirtualMachineBootDiagnosticsTests.cs" />
160161
<Compile Include="ScenarioTests\VMDynamicTests.cs" />
161162
<Compile Include="ScenarioTests\VirtualMachineProfileTests.cs" />
162163
<Compile Include="ScenarioTests\AvailabilitySetTests.cs" />
@@ -223,6 +224,9 @@
223224
<None Include="ScenarioTests\Generated\VirtualMachineDynamicTest3.ps1">
224225
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
225226
</None>
227+
<None Include="ScenarioTests\VirtualMachineBootDiagnosticsTests.ps1">
228+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
229+
</None>
226230
<None Include="ScenarioTests\VMDynamicTests.ps1">
227231
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
228232
</None>
@@ -258,6 +262,18 @@
258262
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.DscExtensionTests\TestGetAzureRmVMDscExtension.json">
259263
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
260264
</None>
265+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineBootDiagnosticsTests\TestLinuxVirtualMachineBootDiagnostics.json">
266+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
267+
</None>
268+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineBootDiagnosticsTests\TestVirtualMachineBootDiagnostics.json">
269+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
270+
</None>
271+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineBootDiagnosticsTests\TestVirtualMachineBootDiagnosticsPremium.json">
272+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
273+
</None>
274+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineBootDiagnosticsTests\TestVirtualMachineBootDiagnosticsSet.json">
275+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
276+
</None>
261277
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\TestVirtualMachineAccessExtension.json">
262278
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
263279
</None>

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AddVhdTests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ function Test-AddVhd
6464

6565
$destBlobHandle = GetBlobHandle $vhdDestUri $storageKey.Key1;
6666
Assert-True {VerifyMD5hash $destBlobHandle $testItem.md5hash};
67+
68+
$vhdDownloadPath = $vhdLocalPath + "-download.vhd";
69+
70+
$vhdDownloadContext = Save-AzureRmVhd -ResourceGroupName $rgname -SourceUri $vhdDestUri -LocalFilePath $vhdDownloadPath;
71+
Write-Output ("Source :" +$vhdDownloadContext.Source);
72+
Write-Output ("LocalFilePath :" +$vhdDownloadContext.LocalFilePath);
73+
Assert-AreEqual $vhdDestUri $vhdDownloadContext.Source;
74+
Assert-AreEqual $vhdDownloadPath $vhdDownloadContext.LocalFilePath;
75+
76+
$vhdDownloadContext = Save-AzureRmVhd -ResourceGroupName $rgname -SourceUri $vhdDestUri -LocalFilePath $vhdDownloadPath -Overwrite;
77+
Assert-AreEqual $vhdDestUri $vhdDownloadContext.Source;
78+
Assert-AreEqual $vhdDownloadPath $vhdDownloadContext.LocalFilePath;
6779
}
6880
}
6981
finally

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ComputeTestCommon.ps1

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -398,28 +398,27 @@ function Get-SasUri
398398
# Get a Location according to resource provider.
399399
function Get-ResourceProviderLocation
400400
{
401-
param ([string] $name, [string] $default = "westus", [bool] $canonical = $true)
402-
403-
$loc = Get-AzureRmLocation | where { $_.Name.Equals($name) };
404-
405-
if ($loc -eq $null)
406-
{
407-
throw 'There is no available locations with given parameters';
408-
}
409-
410-
if ($loc.LocationsString.ToLowerInvariant().Replace(" ", "").Contains($default.ToLowerInvariant().Replace(" ","")))
401+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
411402
{
412-
return $default;
403+
$namespace = $provider.Split("/")[0]
404+
if($provider.Contains("/"))
405+
{
406+
$type = $provider.Substring($namespace.Length + 1)
407+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
408+
409+
if ($location -eq $null)
410+
{
411+
return "West US"
412+
} else
413+
{
414+
return $location.Locations[0]
415+
}
416+
}
417+
418+
return "West US"
413419
}
414420

415-
if ($canonical)
416-
{
417-
return $loc.Locations[0].ToLowerInvariant().Replace(" ", "");
418-
}
419-
else
420-
{
421-
return $loc.Locations[0];
422-
}
421+
return "WestUS"
423422
}
424423

425424
function Get-ComputeVMLocation
@@ -466,3 +465,18 @@ function Get-ComputePublisherLocation
466465
{
467466
Get-ResourceProviderLocation "Microsoft.Compute/locations/publishers";
468467
}
468+
469+
function Get-SubscriptionIdFromResourceGroup
470+
{
471+
param ([string] $rgname)
472+
473+
$rg = Get-AzureRmResourceGroup -ResourceGroupName $rgname;
474+
475+
$rgid = $rg.ResourceId;
476+
477+
# ResouceId is a form of "/subscriptions/<subId>/resourceGroups/<resourgGroupName>"
478+
# So return the second part to get subscription Id
479+
$first = $rgid.IndexOf('/', 1);
480+
$last = $rgid.IndexOf('/', $first + 1);
481+
return $rgid.Substring($first + 1, $last - $first - 1);
482+
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/DscExtensionTests.ps1

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ function Test-GetAzureRmVMDscExtension
113113
#helper methods for ARM
114114
function Get-DefaultResourceGroupLocation
115115
{
116-
$location = Get-AzureRmLocation | where {$_.Name -eq "Microsoft.Resources/resourceGroups"}
117-
return $location.Locations[0]
116+
if ([Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::Mode -ne [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
117+
{
118+
$namespace = "Microsoft.Resources"
119+
$type = "resourceGroups"
120+
$location = Get-AzureRmResourceProvider -ProviderNamespace $namespace | where {$_.ResourceTypes[0].ResourceTypeName -eq $type}
121+
122+
if ($location -eq $null)
123+
{
124+
return "West US"
125+
} else
126+
{
127+
return $location.Locations[0]
128+
}
129+
}
130+
131+
return "West US"
118132
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/Generated/VirtualMachineDynamicTest1.ps1

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
# code is regenerated.
1919

2020

21+
$global:ps_test_tag_name = 'crptestps6050'
22+
23+
2124
function get_vm_config_object
2225
{
2326
param ([string] $rgname, [string] $vmsize)
2427

2528
$st = Write-Verbose "Creating VM Config Object - Start";
2629

27-
$vmname = 'vm' + $rgname;
30+
$vmname = $rgname + 'vm';
2831
$p = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize;
2932

3033
$st = Write-Verbose "Creating VM Config Object - End";
@@ -39,12 +42,13 @@ function get_created_storage_account_name
3942

4043
$st = Write-Verbose "Creating and getting storage account for '${loc}' and '${rgname}' - Start";
4144

42-
$stoname = 'sto' + $rgname;
45+
$stoname = $rgname + 'sto';
4346
$stotype = 'Standard_GRS';
4447

4548
$st = Write-Verbose "Creating and getting storage account for '${loc}' and '${rgname}' - '${stotype}' & '${stoname}'";
4649

4750
$st = New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
51+
$st = Set-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Tags (Get-ComputeTestTag $global:ps_test_tag_name);
4852
$st = Get-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname;
4953

5054
$st = Write-Verbose "Creating and getting storage account for '${loc}' and '${rgname}' - End";
@@ -59,14 +63,14 @@ function create_and_setup_nic_ids
5963

6064
$st = Write-Verbose "Creating and getting NICs for '${loc}' and '${rgname}' - Start";
6165

62-
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
63-
$vnet = New-AzureRmVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -DnsServer "10.1.1.1" -Subnet $subnet;
64-
$vnet = Get-AzureRmVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
66+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name ($rgname + 'subnet') -AddressPrefix "10.0.0.0/24";
67+
$vnet = New-AzureRmVirtualNetwork -Force -Name ($rgname + 'vnet') -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -DnsServer "10.1.1.1" -Subnet $subnet -Tag (Get-ComputeTestTag $global:ps_test_tag_name);
68+
$vnet = Get-AzureRmVirtualNetwork -Name ($rgname + 'vnet') -ResourceGroupName $rgname;
6569
$subnetId = $vnet.Subnets[0].Id;
6670
$nic_ids = @($null) * 1;
67-
$nic0 = New-AzureRmNetworkInterface -Force -Name ('nic0' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId;
71+
$nic0 = New-AzureRmNetworkInterface -Force -Name ($rgname + 'nic0') -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -Tag (Get-ComputeTestTag $global:ps_test_tag_name);
6872
$nic_ids[0] = $nic0.Id;
69-
$vmconfig = Add-AzureRmVMNetworkInterface -VM $vmconfig -Id $nic0.Id -Primary;
73+
$vmconfig = Add-AzureRmVMNetworkInterface -VM $vmconfig -Id $nic0.Id;
7074
$st = Write-Verbose "Creating and getting NICs for '${loc}' and '${rgname}' - End";
7175

7276
return $nic_ids;
@@ -81,10 +85,10 @@ function create_and_setup_vm_config_object
8185
$vmconfig = get_vm_config_object $rgname $vmsize
8286

8387
$user = "Foo12";
84-
$password = "BaR#123" + $rgname;
88+
$password = $rgname + "BaR#123";
8589
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
8690
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
87-
$computerName = "cn" + $rgname;
91+
$computerName = $rgname + "cn";
8892
$vmconfig = Set-AzureRmVMOperatingSystem -VM $vmconfig -Windows -ComputerName $computerName -Credential $cred;
8993

9094
$st = Write-Verbose "Creating and setting up the VM config object for '${loc}', '${rgname}' and '${vmsize}' - End";
@@ -118,20 +122,20 @@ function setup_image_and_disks
118122
}
119123

120124

121-
function ps_vm_dynamic_test_func_1_pstestrg592
125+
function ps_vm_dynamic_test_func_1_crptestps5352
122126
{
123127
# Setup
124-
$rgname = 'pstestrg592';
128+
$rgname = 'crptestps5352';
125129

126130
try
127131
{
128-
$loc = 'Japan East';
129-
$vmsize = 'Standard_A2';
132+
$loc = 'East US 2';
133+
$vmsize = 'Standard_A1';
130134

131-
$st = Write-Verbose "Running Test ps_vm_dynamic_test_func_1_pstestrg592 - Start ${rgname}, ${loc} & ${vmsize}";
135+
$st = Write-Verbose "Running Test ps_vm_dynamic_test_func_1_crptestps5352 - Start ${rgname}, ${loc} & ${vmsize}";
132136

133-
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_pstestrg592 - Creating Resource Group';
134-
$st = New-AzureRmResourceGroup -Location $loc -Name $rgname -Force;
137+
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_crptestps5352 - Creating Resource Group';
138+
$st = New-AzureRmResourceGroup -Location $loc -Name $rgname -Tag (Get-ComputeTestTag $global:ps_test_tag_name) -Force;
135139

136140
$vmconfig = create_and_setup_vm_config_object $loc $rgname $vmsize;
137141

@@ -145,20 +149,21 @@ function ps_vm_dynamic_test_func_1_pstestrg592
145149
$st = setup_image_and_disks $loc $rgname $stoname $vmconfig;
146150

147151
# Virtual Machine
148-
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_pstestrg592 - Creating VM';
152+
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_crptestps5352 - Creating VM';
149153

150-
$vmname = 'vm' + $rgname;
151-
$st = New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $vmconfig;
154+
$vmname = $rgname + 'vm';
155+
156+
$st = New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $vmconfig -Tags (Get-ComputeTestTag $global:ps_test_tag_name);
152157

153158
# Get VM
154-
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_pstestrg592 - Getting VM';
159+
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_crptestps5352 - Getting VM';
155160
$vm1 = Get-AzureRmVM -Name $vmname -ResourceGroupName $rgname;
156161

157162
# Remove
158-
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_pstestrg592 - Removing VM';
163+
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_crptestps5352 - Removing VM';
159164
$st = Remove-AzureRmVM -Name $vmname -ResourceGroupName $rgname -Force;
160165

161-
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_pstestrg592 - End';
166+
$st = Write-Verbose 'Running Test ps_vm_dynamic_test_func_1_crptestps5352 - End';
162167
}
163168
finally
164169
{

0 commit comments

Comments
 (0)