Skip to content

Commit

Permalink
NetIPInterface: Fix Parameter Mismatch Issue - Fixes #470 (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
PlagueHO authored Sep 21, 2020
1 parent 8008109 commit c1256af
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 52 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- IPAddress
- Improved integration test structure.

### Fixed

- NetIPInterface
- Fix 'type mismatch for property' issue when setting 'AdvertiseDefaultRoute',
'Advertising', 'AutomaticMetric', 'Dhcp', 'DirectedMacWolPattern', 'EcnMarking',
'ForceArpNdWolPattern', 'Forwarding', 'IgnoreDefaultRoutes', 'ManagedAddressConfiguration',
'NeighborUnreachabilityDetection', 'OtherStatefulConfiguration', 'RouterDiscovery',
'WeakHostReceive' or 'WeakHostSend' - Fixes [Issue #470](https://github.com/dsccommunity/NetworkingDsc/issues/470).

## [8.1.0] - 2020-08-04

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ function Test-TargetResource

$currentState = Get-TargetResource @getTargetResourceParameters

return Test-DscParameterState -CurrentValues $currentState -DesiredValues $PSBoundParameters -Verbose
return Test-DscParameterState -CurrentValues $currentState -DesiredValues $PSBoundParameters -TurnOffTypeChecking
}

<#
Expand Down
90 changes: 74 additions & 16 deletions tests/Integration/DSC_IPAddress.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,82 @@ Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\Co
try
{
Describe 'IPAddress Integration Tests' {
# Configure loopback adapters
New-IntegrationLoopbackAdapter -AdapterName 'NetworkingDscLBA'
New-IntegrationLoopbackAdapter -AdapterName 'NetworkingDscLBA2'

$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).config.ps1"
. $configFile -Verbose -ErrorAction Stop

BeforeAll {
New-IntegrationLoopbackAdapter -AdapterName 'NetworkingDscLBA1'
New-IntegrationLoopbackAdapter -AdapterName 'NetworkingDscLBA2'
}

AfterAll {
Remove-IntegrationLoopbackAdapter -AdapterName 'NetworkingDscLBA1'
Remove-IntegrationLoopbackAdapter -AdapterName 'NetworkingDscLBA2'
}

Describe "$($script:dscResourceName)_Integration" {
Context 'When a single IP address is specified' {
# This is to pass to the Config
$configData = @{
AllNodes = @(
@{
NodeName = 'localhost'
InterfaceAlias = 'NetworkingDscLBA1'
AddressFamily = 'IPv4'
IPAddress = '10.11.12.13/16'
}
)
}

It 'Should compile and apply the MOF without throwing' {
{
& "$($script:dscResourceName)_Config" `
-OutputPath $TestDrive `
-ConfigurationData $configData

Start-DscConfiguration `
-Path $TestDrive `
-ComputerName localhost `
-Wait `
-Verbose `
-Force `
-ErrorAction Stop
} | Should -Not -Throw
}

It 'should be able to call Get-DscConfiguration without throwing' {
{ Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw
}

It 'Should have set the resource and all the parameters should match' {
$current = Get-DscConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq "$($script:dscResourceName)_Config"
}
$current[0].InterfaceAlias | Should -Be $configData.AllNodes[0].InterfaceAlias
$current[0].AddressFamily | Should -Be $configData.AllNodes[0].AddressFamily
$current[0].IPAddress | Should -Be $configData.AllNodes[0].IPAddress
}
}
}

Context 'When a two IP addresses are specified' {
# This is to pass to the Config
$configData = @{
AllNodes = @(
@{
NodeName = 'localhost'
InterfaceAlias = 'NetworkingDscLBA2'
AddressFamily = 'IPv4'
IPAddress = @('10.12.13.14/16', '10.13.14.16/32')
}
)
}

It 'Should compile and apply the MOF without throwing' {
{
& "$($script:dscResourceName)_Config" -OutputPath $TestDrive
& "$($script:dscResourceName)_Config" `
-OutputPath $TestDrive `
-ConfigurationData $configData

Start-DscConfiguration `
-Path $TestDrive `
Expand All @@ -52,22 +117,15 @@ try
$current = Get-DscConfiguration | Where-Object -FilterScript {
$_.ConfigurationName -eq "$($script:dscResourceName)_Config"
}
$current[0].InterfaceAlias | Should -Be $TestIPAddress.InterfaceAlias
$current[0].AddressFamily | Should -Be $TestIPAddress.AddressFamily
$current[0].IPAddress | Should -Be $TestIPAddress.IPAddress
$current[1].InterfaceAlias | Should -Be $TestMultipleIPAddress.InterfaceAlias
$current[1].AddressFamily | Should -Be $TestMultipleIPAddress.AddressFamily
$current[1].IPAddress | Should -Contain $TestMultipleIPAddress.IPAddress[0]
$current[1].IPAddress | Should -Contain $TestMultipleIPAddress.IPAddress[1]
$current[0].InterfaceAlias | Should -Be $configData.AllNodes[0].InterfaceAlias
$current[0].AddressFamily | Should -Be $configData.AllNodes[0].AddressFamily
$current[0].IPAddress | Should -Contain $configData.AllNodes[0].IPAddress[0]
$current[0].IPAddress | Should -Contain $configData.AllNodes[0].IPAddress[1]
}
}
}
}
finally
{
# Remove Loopback Adapter
Remove-IntegrationLoopbackAdapter -AdapterName 'NetworkingDscLBA'
Remove-IntegrationLoopbackAdapter -AdapterName 'NetworkingDscLBA2'

Restore-TestEnvironment -TestEnvironment $script:testEnvironment
}
22 changes: 3 additions & 19 deletions tests/Integration/DSC_IPAddress.config.ps1
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
$TestIPAddress = [PSObject]@{
InterfaceAlias = 'NetworkingDscLBA'
AddressFamily = 'IPv4'
IPAddress = '10.11.12.13/16'
}
$TestMultipleIPAddress = [PSObject]@{
InterfaceAlias = 'NetworkingDscLBA2'
AddressFamily = 'IPv4'
IPAddress = @('10.12.13.14/16','10.13.14.16/32')
}

configuration DSC_IPAddress_Config {
Import-DscResource -ModuleName NetworkingDsc

node localhost {
IPAddress Integration_Test {
InterfaceAlias = $TestIPAddress.InterfaceAlias
AddressFamily = $TestIPAddress.AddressFamily
IPAddress = $TestIPAddress.IPAddress
}
IPAddress Integration_Test2 {
InterfaceAlias = $TestMultipleIPAddress.InterfaceAlias
AddressFamily = $TestMultipleIPAddress.AddressFamily
IPAddress = $TestMultipleIPAddress.IPAddress
InterfaceAlias = $Node.InterfaceAlias
AddressFamily = $Node.AddressFamily
IPAddress = $Node.IPAddress
}
}
}
32 changes: 16 additions & 16 deletions tests/Unit/DSC_NetIPInterface.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,119 +46,119 @@ try
$testParameterList = @(
@{
Name = 'AdvertiseDefaultRoute'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.AdvertiseDefaultRoute]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $AdvertiseDefaultRoute -eq 'Disabled'
}
},
@{
Name = 'Advertising'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.Advertising]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $Advertising -eq 'Disabled'
}
},
@{
Name = 'AutomaticMetric'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.AutomaticMetric]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $AutomaticMetric -eq 'Disabled'
}
},
@{
Name = 'Dhcp'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.Dhcp]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $Dhcp -eq 'Disabled'
}
},
@{
Name = 'DirectedMacWolPattern'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.DirectedMacWolPattern]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $DirectedMacWolPattern -eq 'Disabled'
}
},
@{
Name = 'EcnMarking'
MockedValue = 'AppDecide'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.EcnMarking]::AppDecide
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $EcnMarking -eq 'Disabled'
}
},
@{
Name = 'ForceArpNdWolPattern'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.ForceArpNdWolPattern]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $ForceArpNdWolPattern -eq 'Disabled'
}
},
@{
Name = 'Forwarding'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.Forwarding]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $Forwarding -eq 'Disabled'
}
},
@{
Name = 'IgnoreDefaultRoutes'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.IgnoreDefaultRoutes]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $IgnoreDefaultRoutes -eq 'Disabled'
}
},
@{
Name = 'ManagedAddressConfiguration'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.ManagedAddressConfiguration]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $ManagedAddressConfiguration -eq 'Disabled'
}
},
@{
Name = 'NeighborUnreachabilityDetection'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.NeighborUnreachabilityDetection]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $NeighborUnreachabilityDetection -eq 'Disabled'
}
},
@{
Name = 'OtherStatefulConfiguration'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.OtherStatefulConfiguration]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $OtherStatefulConfiguration -eq 'Disabled'
}
},
@{
Name = 'RouterDiscovery'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.RouterDiscovery]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $RouterDiscovery -eq 'Disabled'
}
},
@{
Name = 'WeakHostReceive'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.WeakHostReceive]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $WeakHostReceive -eq 'Disabled'
}
},
@{
Name = 'WeakHostSend'
MockedValue = 'Enabled'
MockedValue = [Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetIPInterface.WeakHostSend]::Enabled
TestValue = 'Disabled'
ParameterFilter = {
$InterfaceAlias -eq 'Ethernet' -and $AddressFamily -eq 'IPv4' -and $WeakHostSend -eq 'Disabled'
Expand Down Expand Up @@ -370,7 +370,7 @@ try
}
}
}
} #end InModuleScope $DSCResourceName
}
}
finally
{
Expand Down

0 comments on commit c1256af

Please sign in to comment.