Unit testing an NIC

Testing an NIC involves validating whether it was successfully created, determining whether it is the primary NIC, whether IP forwarding is enabled, whether the IP allocation method matches the provided configuration and the associated subnet on the virtual network and the related IP address. You should pay attention to the syntax used to get the public IP address reference in test cases, using the Get-AzureRmResource cmdlet.

The entire code has been broken into two code listings for easy reading. The entire code listing is available within the chapter-6 - listing9.txt file with the chapter-accompanied code. The first part of it checks for provisioningState, primary NIC, status of IP forwarding, status, and primary NIC IP configuration:

 Context "Network Interface from template deployment" {
It "The NIC Have been provisioned successfully" {
[string]$nic.provisioningState | Should Be "Succeeded"
}

It "Is primary NIC" {
[string]$nic.primary | Should Be true
}

It "IP forwarding is disabled on NIC" {
[int]$nic.enableIPForwarding | Should Be 0
}

It "The NIC IP configuration was provisioned successfully" {
[string]$nic.ipConfigurations[0].properties.provisioningState | Should Be "Succeeded"
}

It "The NIC is the primary Nic" {
[string]$nic.ipConfigurations[0].properties.primary | Should Be true
}

The second part of the code checks for the IP allocation method. It should match the same value that was used in the ARM template while provisioning the NIC. We had used a Dynamic value for the IP allocation method, and the same check is made here. We also check whether the NIC is associated with the provided subnet on the virtual network and also is associated with a valid public IP address resource:

 
It "The IP allocation method used for NIC is dynamic" {
[string]$nic.ipConfigurations[0].properties.privateIPAllocationMethod | Should Be "Dynamic"
}

It "The NIC is associated to appropriate subnet" {
[string]$nic.ipConfigurations[0].properties.subnet.id | should be $([string]$virtualNetwork.subnets[0].id)
}

It "NIC is referencing the appropriate public IP resource" {
[string]$nic.ipConfigurations[0].properties.publicIPAddress.id | should be $(Get-AzureRmResource -ResourceId $([string]$nic.ipConfigurations[0].properties.publicIPAddress.id)).Resourceid
}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.152.157