-
Notifications
You must be signed in to change notification settings - Fork 4k
Tests for chef extension arm commands #2713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ChefExtensionTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using Xunit; | ||
|
||
namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests | ||
{ | ||
public class ChefExtensionTests | ||
{ | ||
public ChefExtensionTests(Xunit.Abstractions.ITestOutputHelper output) | ||
{ | ||
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output)); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void TestSetChefExtensionBasic() | ||
{ | ||
ComputeTestController.NewInstance.RunPsTest("Test-SetChefExtensionBasic"); | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/ChefExtensionTests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# Copyright Microsoft Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ---------------------------------------------------------------------------------- | ||
|
||
|
||
# | ||
# ChefExtensionTests.ps1 | ||
# | ||
|
||
<# | ||
.SYNOPSIS | ||
Test the usage of the Set virtual machine chef extension command | ||
#> | ||
function Test-SetChefExtensionBasic | ||
{ | ||
$rgname = Get-ComputeTestResourceName | ||
$loc = Get-ComputeVMLocation | ||
$TestOutputRoot = [System.AppDomain]::CurrentDomain.BaseDirectory; | ||
|
||
try | ||
{ | ||
############ Create Virtual Machine ############# | ||
# Common | ||
New-AzureRmResourceGroup -Name $rgname -Location $loc -Force; | ||
|
||
# VM Profile & Hardware | ||
$vmsize = 'Standard_A2'; | ||
$vmname = 'vm' + $rgname; | ||
$p = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize; | ||
Assert-AreEqual $p.HardwareProfile.VmSize $vmsize; | ||
|
||
# NRP | ||
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24"; | ||
$vnet = New-AzureRmVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet; | ||
$vnet = Get-AzureRmVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname; | ||
$subnetId = $vnet.Subnets[0].Id; | ||
$pubip = New-AzureRmPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname); | ||
$pubip = Get-AzureRmPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname; | ||
$pubipId = $pubip.Id; | ||
$nic = New-AzureRmNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id; | ||
$nic = Get-AzureRmNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname; | ||
$nicId = $nic.Id; | ||
|
||
$p = Add-AzureRmVMNetworkInterface -VM $p -Id $nicId; | ||
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1; | ||
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Id $nicId; | ||
|
||
# Storage Account | ||
$stoname = 'sto' + $rgname; | ||
$stotype = 'Standard_GRS'; | ||
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype; | ||
Retry-IfException { $global:stoaccount = Get-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname; } | ||
|
||
$osDiskName = 'osDisk'; | ||
$osDiskCaching = 'ReadWrite'; | ||
$osDiskVhdUri = "https://$stoname.blob.core.windows.net/test/os.vhd"; | ||
$dataDiskVhdUri1 = "https://$stoname.blob.core.windows.net/test/data1.vhd"; | ||
|
||
$p = Set-AzureRmVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage; | ||
$p = Add-AzureRmVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty; | ||
|
||
# OS & Image | ||
$user = "localadmin"; | ||
$password = $PLACEHOLDER; | ||
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force; | ||
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword); | ||
$computerName = 'test'; | ||
$vhdContainer = "https://$stoname.blob.core.windows.net/test"; | ||
|
||
$p = Set-AzureRmVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred -ProvisionVMAgent; | ||
$p = Set-AzureRmVMSourceImage -VM $p -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest" | ||
|
||
# Virtual Machine | ||
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $p; | ||
|
||
############ Created Virtual Machine ############# | ||
|
||
############ Test Chef Extension ################# | ||
$version = "1210.12" | ||
$client_rb = "$TestOutputRoot\Templates\client.rb"; | ||
$validationPemFile = "$TestOutputRoot\Templates\tstorgnztn-validator.pem"; | ||
|
||
# Set Chef extension | ||
Set-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname -TypeHandlerVersion $version -ClientRb $client_rb -ValidationPem $validationPemFile -Windows | ||
$extension = Get-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname -Windows | ||
|
||
Assert-NotNull $extension | ||
Assert-AreEqual $extension.Publisher 'Chef.Bootstrap.WindowsAzure' | ||
Assert-AreEqual $extension.ExtensionType 'ChefClient' | ||
Assert-AreEqual $extension.Name 'ChefClient' | ||
|
||
# Test Remove command. | ||
Remove-AzureRmVMChefExtension -ResourceGroupName $rgname -VMName $vmname -Windows | ||
} | ||
finally | ||
{ | ||
# Cleanup | ||
Clean-ResourceGroup $rgname | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markcowl , @shahabhijeet
-- Still facing this error while running the tests:
Basically
Test-SetChefExtensionBasic
is the method we defined in the PS script which is supposed to be called from the C# test script. The method is not being recognized.-- While debugging found that the powershell script is being loaded automatically here: https://github.com/Azure/azure-powershell/blob/dev/src/ResourceManager/Compute/Commands.Compute.Test/Common/ComputeTestController.cs#L146. So we don't have to add the path anywhere.
But
Events
object is null here: https://github.com/Azure/azure-powershell/blob/dev/src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/EnvironmentSetupHelper.cs#L367. After this the error is thrown.-- Tried to run the existing tests too like
AvailabilitySetTests
andDscExtensionTests
, but the error was raised at the same point mentioned above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NimishaS These tests run every day in CI and on people's boxes, so if there is an issue with module loading, it has to be in your local clone of the repo. Please make sure you have updated to the latest, and done a clean rebuild. AFter synicing,
git clean -xdf
then rebuilding from scratch will clean out any artifacts from old builds.