-
Notifications
You must be signed in to change notification settings - Fork 9
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
Compare-DscParameterState: Reverse check fails in a certain circumstance #65
Comments
I found a clue.
To establish the difference between But when you use It's like than you write : Compare-DscParameterState -CurrentValue $nameServers -DesiredValues [Microsoft.Management.Infrastructure.CimInstance[]]@() -TurnOffTypeChecking In Test-DscParameterState, the default value is $true. We might add -IncludeInDesiredState parameter, and another test if the result of Compare-DscParameterState is null. |
A resource could pass an empty array, for example for a property I think a good start is to build tests that should pass but fail with the current implementation so we make sure to support all (known) scenarios. |
When testing your example (to remember what actually was not happening) I saw that there seem to be and issue with types (as well?). 🤔 This does not return anything (using just an array without specifying the type): Compare-DscParameterState -CurrentValues @{
IsSingleInstance = 'Yes'
NameServer = @()
} -DesiredValues @{
NameServers = [Microsoft.Management.Infrastructure.CimInstance[]] @(
New-CimInstance -ClassName 'MSFT_KeyValuePair' -Namespace 'root/microsoft/Windows/DesiredStateConfiguration' -Property @{
Key = 'B.ROOT-SERVERS.NET.'
Value = '199.9.14.201'
} -ClientOnly
)
IsSingleInstance = 'Yes'
Verbose = $true
} -TurnOffTypeChecking -ReverseCheck When specifying the type (same as in DesiredState) it actually returns something, not sure it is correct though, since actual type is returned as Compare-DscParameterState -CurrentValues @{
IsSingleInstance = 'Yes'
NameServer = [Microsoft.Management.Infrastructure.CimInstance[]]@()
} -DesiredValues @{
NameServers = [Microsoft.Management.Infrastructure.CimInstance[]] @(
New-CimInstance -ClassName 'MSFT_KeyValuePair' -Namespace 'root/microsoft/Windows/DesiredStateConfiguration' -Property @{
Key = 'B.ROOT-SERVERS.NET.'
Value = '199.9.14.201'
} -ClientOnly
)
IsSingleInstance = 'Yes'
Verbose = $true
} -TurnOffTypeChecking -ReverseCheck # $a contains the result from the second call above.
C:\source\DscResource.Common [main ≡]> $a
Name Value
---- -----
Property NameServer
InDesiredState False
ExpectedType System.Collections.Hashtable
ActualType {Name}
C:\source\DscResource.Common [main ≡]> $a.ActualType
Name Value
---- -----
Name Unknown |
Agree ! A member can be empty or null, but not the object passed to To resolve and test this, I changed the line 510 of if ($InDesiredStateTable.InDesiredState)
{
if ($desiredValue.Keys.Count -eq 0 -and $currentValue.Keys.Count -ne 0)
{
Write-Verbose -Message ($script:localizedData.NoMatchKeyMessage -f $desiredType.FullName, $key, $($currentValue.Keys -join ', '))
$InDesiredStateTable.InDesiredState = $false
}
else{
$InDesiredStateTable.InDesiredState = Test-DscParameterState @param
}
}
else
{
$null = Test-DscParameterState @param
}
continue I need to do more tests, but that seems to be good. I think you have an error in your command. In
Yes because there is a conversion to hashtable in the function. But there is nothing to convert... |
Great catch! Correcting that and then running the following does not return the expected resulting hashtable. But the following do return the expected resulting hashtable if adding the your proposed change, Compare-DscParameterState -CurrentValues @{
IsSingleInstance = 'Yes'
NameServers = [Microsoft.Management.Infrastructure.CimInstance[]]@()
} -DesiredValues @{
NameServers = [Microsoft.Management.Infrastructure.CimInstance[]] @(
New-CimInstance -ClassName 'MSFT_KeyValuePair' -Namespace 'root/microsoft/Windows/DesiredStateConfiguration' -Property @{
Key = 'B.ROOT-SERVERS.NET.'
Value = '199.9.14.201'
} -ClientOnly
)
IsSingleInstance = 'Yes'
Verbose = $true
} -TurnOffTypeChecking -ReverseCheck @NicolasBn Suggest adding the snippet above to a unit test which will fail without your change, then add another test to cover the other lines not covered by the snippet above (the verbose message). @NicolasBn Awesome work! |
Agree. Can't see a scenario where either would ever be null, so think it safe to assume we must always provide a value. This is also already assumed by the current functionality since those two parameters are mandatory (not allowing |
I already did all this, but I found another bugs :
I cill correct all of this in my next PR.
Thank you :) |
Looking forward to it. I think Compare-DscParameterState should not recursively call Test-DscParameterState. If it should recursively call something it should recursively call itself ( |
…er with an empty hashtable or CimInstance property is passed in DesriedValues - fixes issue dsccommunity#65
Hum, That depend the need. Here, |
Details of the scenario you tried and the problem that is occurring
Details about the problem can be found in the issue dsccommunity/DnsServerDsc#121.
Steps to reproduce the problem
This does not return the expected output.
Expected behavior
Should return an hashtable with the expected metdata,
Current behavior
Returns
$null
.Suggested solution to the issue
The problem is the parameter
ReverseCheck
that assignes$null
for the variable$returnValue
which then is returned by the command.After 3 hours of debugging I was no closer to solution.
The operating system the target node is running
Windows 10
Version and build of PowerShell the target node is running
Version of the module that was used
0.10.1
The text was updated successfully, but these errors were encountered: