Skip to content

Dev #28

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 9 commits into from
Jun 19, 2015
Merged

Dev #28

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineExtensionTests\TestVirtualMachineExtension.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineNetworkInterfaceTests\TestAddNetworkInterface.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineNetworkInterfaceTests\TestSingleNetworkInterfaceDnsSettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@ public void TestSingleNetworkInterfaceDnsSettings()
{
ComputeTestController.NewInstance.RunPsTest("Test-SingleNetworkInterfaceDnsSettings");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAddNetworkInterface()
{
ComputeTestController.NewInstance.RunPsTest("Test-AddNetworkInterface");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function Test-MultipleNetworkInterface
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[1].Primary true;
Assert-AreNotEqual $p.NetworkProfile.NetworkInterfaces[0].Primary true;

# Storage Account (SA)
# Storage Account (SA)
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
New-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
Expand Down Expand Up @@ -353,3 +353,110 @@ function Test-MultipleNetworkInterface
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Test Virtual Machines with VMAgent and AutoUpdate
#>
function Test-AddNetworkInterface
{
# Setup
$rgname = Get-ComputeTestResourceName

try
{
# Common
$loc = 'westus';
New-AzureResourceGroup -Name $rgname -Location $loc -Force;

# VM Profile & Hardware
$vmsize = 'Standard_A2';
$vmname = 'vm' + $rgname;
$p = New-AzureVMConfig -VMName $vmname -VMSize $vmsize;
Assert-AreEqual $p.HardwareProfile.VirtualMachineSize $vmsize;

# NRP
$subnet = New-AzureVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
$vnet = New-AzureVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -DnsServer "10.1.1.1" -Subnet $subnet;
$vnet = Get-AzureVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
$subnetId = $vnet.Subnets[0].Id;
$pubip = New-AzurePublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
$pubip = Get-AzurePublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
$pubipId = $pubip.Id;
$nic = New-AzureNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
$nicId = $nic.Id;

$nicList = Get-AzureNetworkInterface -ResourceGroupName $rgname;
$nicList[0].Primary = $true;
$p = Add-AzureVMNetworkInterface -VM $p -NetworkInterface $nicList;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are duplicating the codes a bit too much. So, it's hard to see the actual change, :-|

At some point of time, let's clean up the test code....

Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $nicList[0].Id;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Primary $true;

# Storage Account (SA)
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
New-AzureStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
$stoaccount = Get-AzureStorageAccount -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";
$dataDiskVhdUri2 = "https://$stoname.blob.core.windows.net/test/data2.vhd";
$dataDiskVhdUri3 = "https://$stoname.blob.core.windows.net/test/data3.vhd";

$p = Set-AzureVMOSDisk -VM $p -Name $osDiskName -VhdUri $osDiskVhdUri -Caching $osDiskCaching -CreateOption FromImage;

$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 1 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 2 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;

Assert-AreEqual $p.StorageProfile.OSDisk.Caching $osDiskCaching;
Assert-AreEqual $p.StorageProfile.OSDisk.Name $osDiskName;
Assert-AreEqual $p.StorageProfile.OSDisk.VirtualHardDisk.Uri $osDiskVhdUri;
Assert-AreEqual $p.StorageProfile.DataDisks.Count 2;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[0].DiskSizeGB 10;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Lun 1;
Assert-AreEqual $p.StorageProfile.DataDisks[0].VirtualHardDisk.Uri $dataDiskVhdUri1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[1].DiskSizeGB 11;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 2;
Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2;

# OS & Image
$user = "Foo12";
$password = 'BaR@123' + $rgname;
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$computerName = 'test';
$p = Set-AzureVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;

Assert-AreEqual $p.OSProfile.AdminUsername $user;
Assert-AreEqual $p.OSProfile.ComputerName $computerName;
Assert-AreEqual $p.OSProfile.AdminPassword $password;

# Image Reference
$imgRef = Get-DefaultCRPImage;
$p = ($imgRef | Set-AzureVMSourceImage -VM $p);
Assert-NotNull $p.StorageProfile.ImageReference;
Assert-Null $p.StorageProfile.SourceImageId;

# TODO: Remove Data Disks for now
$p.StorageProfile.DataDisks = $null;

# Virtual Machine
# TODO: Still need to do retry for New-AzureVM for SA, even it's returned in Get-.
New-AzureVM -ResourceGroupName $rgname -Location $loc -Name $vmname -VM $p;

$vm1 = Get-AzureVM -Name $vmname -ResourceGroupName $rgname;
Assert-AreEqual $vm1.Name $vmname;
Assert-AreEqual $vm1.NetworkProfile.NetworkInterfaces.Count 1;
Assert-AreEqual $vm1.NetworkProfile.NetworkInterfaces[0].ReferenceUri $nicId;
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,27 @@ function Test-VirtualMachineProfile

# Network
$ipname = 'hpfip' + ((Get-Random) % 10000);
$ipRefUri = "https://test.foo.bar/$ipname";
$ipRefUri1 = "https://test.foo.bar/$ipname";
$nicName = $ipname + 'nic1';
$publicIPName = $ipname + 'name1';

$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri;
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri1;

$ipname = 'hpfip' + ((Get-Random) % 10000);
$ipRefUri2 = "https://test.foo.bar/$ipname";
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;

# Remove all NICs
$p = $p | Remove-AzureVMNetworkInterface;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 0;

$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri1 -Primary;
$p = Add-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;
$p = Remove-AzureVMNetworkInterface -VM $p -Id $ipRefUri2;

Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $ipRefUri1;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Primary $true;

# Storage
$stoname = 'hpfteststo' + ((Get-Random) % 10000);
Expand Down Expand Up @@ -66,6 +79,23 @@ function Test-VirtualMachineProfile
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2;

# Remove all data disks
$p = $p | Remove-AzureVMDataDisk;
Assert-AreEqual $p.StorageProfile.DataDisks.Count 0;

$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk1' -Caching 'ReadOnly' -DiskSizeInGB 10 -Lun 0 -VhdUri $dataDiskVhdUri1 -CreateOption Empty;
$p = Add-AzureVMDataDisk -VM $p -Name 'testDataDisk2' -Caching 'ReadOnly' -DiskSizeInGB 11 -Lun 1 -VhdUri $dataDiskVhdUri2 -CreateOption Empty;

Assert-AreEqual $p.StorageProfile.DataDisks.Count 2;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[0].DiskSizeGB 10;
Assert-AreEqual $p.StorageProfile.DataDisks[0].Lun 0;
Assert-AreEqual $p.StorageProfile.DataDisks[0].VirtualHardDisk.Uri $dataDiskVhdUri1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Caching 'ReadOnly';
Assert-AreEqual $p.StorageProfile.DataDisks[1].DiskSizeGB 11;
Assert-AreEqual $p.StorageProfile.DataDisks[1].Lun 1;
Assert-AreEqual $p.StorageProfile.DataDisks[1].VirtualHardDisk.Uri $dataDiskVhdUri2;

# Windows OS
$user = "Foo12";
$password = 'BaR@000' + ((Get-Random) % 10000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ function Test-VirtualMachine
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $nicId;

# Adding the same Nic but not set it Primary
$p = Add-AzureVMNetworkInterface -VM $p -Id $nicId -Primary;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces.Count 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was already one NIC in the network profile, and now you add another one, why is there still only one NIC?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is adding the same nic ID. I updated the code such that if the same nic is added, it does not add and only update Primary value (if it is changed).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. maybe better to add comments for it.

Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].ReferenceUri $nicId;
Assert-AreEqual $p.NetworkProfile.NetworkInterfaces[0].Primary $true;

# Storage Account (SA)
$stoname = 'sto' + $rgname;
$stotype = 'Standard_GRS';
Expand Down Expand Up @@ -765,7 +771,10 @@ function Test-VirtualMachineCapture
Set-AzureVM -Generalize -ResourceGroupName $rgname -Name $vmname;

$dest = Get-ComputeTestResourceName;
Save-AzureVMImage -ResourceGroupName $rgname -VMName $vmname -DestinationContainerName $dest -VHDNamePrefix 'pslib' -Overwrite;
$templatePath = ".\template.txt";
Save-AzureVMImage -ResourceGroupName $rgname -VMName $vmname -DestinationContainerName $dest -VHDNamePrefix 'pslib' -Overwrite -Path $templatePath;
$template = Get-Content $templatePath;
Assert-True { $template[1].Contains("$schema"); }

# Remove
Remove-AzureVM -ResourceGroupName $rgname -Name $vmname -Force;
Expand Down
Loading