Skip to content

Commit af2ba48

Browse files
committed
Merge branch 'master' of https://github.com/Azure/azure-powershell into march
# Conflicts: # src/Compute/Compute/ChangeLog.md
2 parents 04ef688 + 54e1a7c commit af2ba48

File tree

5 files changed

+6264
-2
lines changed

5 files changed

+6264
-2
lines changed

src/Compute/Compute.Test/ScenarioTests/GalleryTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,12 @@ public void TestGallery()
3030
{
3131
TestRunner.RunTestScript("Test-Gallery");
3232
}
33+
34+
[Fact]
35+
[Trait(Category.AcceptanceType, Category.CheckIn)]
36+
public void TestGalleryCrossTenant()
37+
{
38+
TestRunner.RunTestScript("Test-GalleryCrossTenant");
39+
}
3340
}
3441
}

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

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function Test-Gallery
195195
-PurchasePlanPublisher $purchasePlanPublisher;
196196

197197
$wildcardNameQuery = ($galleryImageName -replace ".$") + "*"
198-
$galleryImageDefinitionList = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $wildcardNameQuery;
198+
$galleryImageDefinitionList = Get-AzGalleryImageDefinition -ResourceGroupName $rgname -GalleryName $galleryName -Name $wildcardNameQuery;
199199
$definition = $galleryImageDefinitionList | ? {$_.Name -eq $galleryImageName};
200200
Verify-GalleryImageDefinition $definition $rgname $galleryImageName $loc $description1 `
201201
$eula $privacyStatementUri $releaseNoteUri `
@@ -344,3 +344,61 @@ function Test-Gallery
344344
Clean-ResourceGroup $rgname
345345
}
346346
}
347+
348+
<#
349+
.SYNOPSIS
350+
Testing creating VM with a shared gallery image from a different subscription.
351+
#>
352+
function Test-GalleryCrossTenant
353+
{
354+
# Setup
355+
# In order to record this test, please use another subscription to create a gallery image and share the image to the test subscription. And then set the gallery image id here.
356+
$imageId = "/subscriptions/97f78232-382b-46a7-8a72-964d692c4f3f/resourceGroups/xwRg/providers/Microsoft.Compute/galleries/galleryForCirrus/images/xwGalleryImageForCirrusWindows/versions/1.0.0";
357+
358+
$rgname = Get-ComputeTestResourceName;
359+
360+
try
361+
{
362+
# Common
363+
$loc = Get-ComputeVMLocation;
364+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
365+
366+
# Create a VM first
367+
$vmsize = 'Standard_D2_v2';
368+
$vmname = 'vm' + $rgname;
369+
$p = New-AzVMConfig -VMName $vmname -VMSize $vmsize;
370+
371+
# NRP
372+
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
373+
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
374+
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
375+
$subnetId = $vnet.Subnets[0].Id;
376+
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
377+
$pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
378+
$nic = New-AzNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
379+
$nic = Get-AzNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
380+
$nicId = $nic.Id;
381+
$p = Add-AzVMNetworkInterface -VM $p -Id $nicId -Primary;
382+
383+
# OS & Image
384+
$user = "Foo12";
385+
$password = $PLACEHOLDER;
386+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
387+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
388+
$computerName = 'test';
389+
$p = Set-AzVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;
390+
391+
$p = Set-AzVMSourceImage -VM $p -Id $imageId;
392+
393+
# Virtual Machine
394+
New-AzVM -ResourceGroupName $rgname -Location $loc -VM $p;
395+
396+
$vm = Get-AzVM -ResourceGroupName $rgname -Name $vmname;
397+
Assert-AreEqual $imageId $vm.StorageProfile.ImageReference.Id;
398+
}
399+
finally
400+
{
401+
# Cleanup
402+
Clean-ResourceGroup $rgname
403+
}
404+
}

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.GalleryTests/TestGalleryCrossTenant.json

Lines changed: 6176 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
@@ -20,6 +20,7 @@
2020
-->
2121
## Upcoming Release
2222
* Add HyperVGeneration parameter to New-AzDiskConfig and New-AzSnapshotConfig
23+
* Allow VM creation with galley image from other tenants.
2324

2425
## Version 1.6.0
2526
* Fix issue with path resolution in Get-AzVmBootDiagnosticsData

src/Compute/Compute/VirtualMachine/Operation/NewAzureVMCommand.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,10 +488,30 @@ public void DefaultExecuteCmdlet()
488488
Zones = this.Zone ?? this.VM.Zones,
489489
};
490490

491+
Dictionary<string, List<string>> auxAuthHeader = null;
492+
if (!string.IsNullOrEmpty(parameters.StorageProfile?.ImageReference?.Id))
493+
{
494+
var resourceId = ResourceId.TryParse(parameters.StorageProfile.ImageReference.Id);
495+
496+
if (string.Equals(ComputeStrategy.Namespace, resourceId?.ResourceType?.Namespace, StringComparison.OrdinalIgnoreCase)
497+
&& string.Equals("galleries", resourceId?.ResourceType?.Provider, StringComparison.OrdinalIgnoreCase)
498+
&& !string.Equals(this.ComputeClient?.ComputeManagementClient?.SubscriptionId, resourceId?.SubscriptionId, StringComparison.OrdinalIgnoreCase))
499+
{
500+
List<string> resourceIds = new List<string>();
501+
resourceIds.Add(parameters.StorageProfile.ImageReference.Id);
502+
var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds);
503+
if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0)
504+
{
505+
auxAuthHeader = new Dictionary<string, List<string>>(auxHeaderDictionary);
506+
}
507+
}
508+
}
509+
491510
var result = this.VirtualMachineClient.CreateOrUpdateWithHttpMessagesAsync(
492511
this.ResourceGroupName,
493512
this.VM.Name,
494-
parameters).GetAwaiter().GetResult();
513+
parameters,
514+
auxAuthHeader).GetAwaiter().GetResult();
495515
var psResult = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(result);
496516

497517
if (!(this.DisableBginfoExtension.IsPresent || IsLinuxOs()))

0 commit comments

Comments
 (0)