Skip to content

Commit 6c8c917

Browse files
committed
Fix Set-AzurePlatformVMImage for OS Images
1 parent 6483748 commit 6c8c917

File tree

2 files changed

+72
-7
lines changed

2 files changed

+72
-7
lines changed

src/ServiceManagement/Compute/Commands.ServiceManagement.PlatformImageRepository/ImagePublishing/SetAzurePlatformVMImage.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,23 @@ private void ProcessReplicateImageParameterSet()
153153
ValidateTargetLocations();
154154
return this.ComputeClient.VirtualMachineOSImages.Replicate(this.ImageName, new Management.Compute.Models.VirtualMachineOSImageReplicateParameters
155155
{
156-
TargetLocations = this.ReplicaLocations == null ? null : this.ReplicaLocations.ToList()
156+
TargetLocations = this.ReplicaLocations == null ? null : this.ReplicaLocations.ToList(),
157+
ComputeImageAttributes = new ComputeImageAttributes
158+
{
159+
Offer = this.ComputeImageConfig.Offer,
160+
Sku = this.ComputeImageConfig.Sku,
161+
Version = this.ComputeImageConfig.Version
162+
},
163+
MarketplaceImageAttributes = this.MarketplaceImageConfig == null ? null : new MarketplaceImageAttributes
164+
{
165+
Plan = new Plan
166+
{
167+
Name = this.MarketplaceImageConfig.PlanName,
168+
Product = this.MarketplaceImageConfig.Product,
169+
Publisher = this.MarketplaceImageConfig.Publisher
170+
},
171+
PublisherId = this.MarketplaceImageConfig.PublisherId
172+
}
157173
});
158174
});
159175
}

src/ServiceManagement/Compute/Commands.ServiceManagement.Test/FunctionalTests/FunctionalTest.cs

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,18 +1747,19 @@ public void AzurePlatformVMImageNegativeTest()
17471747
{
17481748
StartTest(MethodBase.GetCurrentMethod().Name, testStartTime);
17491749

1750-
var imgName = Utilities.GetUniqueShortName("img");
1751-
1752-
try
1753-
{
1754-
var scripts = new string[]
1750+
Func<string, string[]> getScripts = img => new string[]
17551751
{
17561752
"Import-Module '.\\" + Utilities.AzurePowershellModuleServiceManagementPirModule + "';",
17571753
"$c1 = New-AzurePlatformComputeImageConfig -Offer test -Sku test -Version test;",
17581754
"$c2 = New-AzurePlatformMarketplaceImageConfig -PlanName test -Product test -Publisher test -PublisherId test;",
1759-
"Set-AzurePlatformVMImage -ImageName " + imgName + " -ReplicaLocations 'West US' -ComputeImageConfig $c1 -MarketplaceImageConfig $c2;"
1755+
"Set-AzurePlatformVMImage -ImageName " + img + " -ReplicaLocations 'West US' -ComputeImageConfig $c1 -MarketplaceImageConfig $c2;"
17601756
};
17611757

1758+
var imgName = Utilities.GetUniqueShortName("img");
1759+
1760+
try
1761+
{
1762+
var scripts = getScripts(imgName);
17621763
vmPowershellCmdlets.RunPSScript(string.Join(System.Environment.NewLine, scripts), true);
17631764
}
17641765
catch (Exception e)
@@ -1775,6 +1776,54 @@ public void AzurePlatformVMImageNegativeTest()
17751776
Assert.Fail("Exception occurred: {0}", e.ToString());
17761777
}
17771778
}
1779+
1780+
// OS Image
1781+
var osImages = vmPowershellCmdlets.GetAzureVMImage();
1782+
imgName = osImages.First().ImageName;
1783+
1784+
try
1785+
{
1786+
var scripts = getScripts(imgName);
1787+
vmPowershellCmdlets.RunPSScript(string.Join(System.Environment.NewLine, scripts), true);
1788+
}
1789+
catch (Exception e)
1790+
{
1791+
var expectedMsg = "ForbiddenError: This operation is not allowed for this subscription.";
1792+
if (e.InnerException != null && e.InnerException.Message != null && e.InnerException.Message.Contains(expectedMsg))
1793+
{
1794+
pass = true;
1795+
Console.WriteLine(e.InnerException.ToString());
1796+
}
1797+
else
1798+
{
1799+
pass = false;
1800+
Assert.Fail("Exception occurred: {0}", e.ToString());
1801+
}
1802+
}
1803+
1804+
// VM Image
1805+
var vmImages = vmPowershellCmdlets.GetAzureVMImageReturningVMImages();
1806+
imgName = vmImages.First().ImageName;
1807+
1808+
try
1809+
{
1810+
var scripts = getScripts(imgName);
1811+
vmPowershellCmdlets.RunPSScript(string.Join(System.Environment.NewLine, scripts), true);
1812+
}
1813+
catch (Exception e)
1814+
{
1815+
var expectedMsg = "ForbiddenError: This operation is not allowed for this subscription.";
1816+
if (e.InnerException != null && e.InnerException.Message != null && e.InnerException.Message.Contains(expectedMsg))
1817+
{
1818+
pass = true;
1819+
Console.WriteLine(e.InnerException.ToString());
1820+
}
1821+
else
1822+
{
1823+
pass = false;
1824+
Assert.Fail("Exception occurred: {0}", e.ToString());
1825+
}
1826+
}
17781827
}
17791828
}
17801829
}

0 commit comments

Comments
 (0)