Skip to content
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

DnsServerDsc: Resources errors on test if DNS is not installed #45

Open
GoateePFE opened this issue Feb 9, 2017 · 10 comments
Open

DnsServerDsc: Resources errors on test if DNS is not installed #45

GoateePFE opened this issue Feb 9, 2017 · 10 comments
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.

Comments

@GoateePFE
Copy link
Contributor

xDNSServerForwarder (as well as other resource in the module) need error handling logic to gracefully return FALSE on the Test function when DNS is not installed. This is particularly needed when DSC is used to audit a server config without applying.

@Persistent13
Copy link

@GoateePFE I'd be willing to add this functionality.
What do you believe the best way to do this would be?

I'm not sure how to best handle the error.
I'm thinking to update the get function to return an empty IPAddresses array, test should then not throw an error.

@GoateePFE
Copy link
Contributor Author

@Persistent13 That should do it for now.

Long term we should probably add a function to the root of the resource module to check for the presence of the DNS server role and warn if it is not installed. Then all resources could reference that.

Function Test-DNSServerRole {
[CmdletBinding()]
Param()
If ((Get-WindowsFeature DNS).Installed) {
Write-Verbose "DNS server role installed."
Return $true
} Else {
Write-Verbose "DNS server role NOT installed."
Return $false
}
}

Easy enough.

@iainbrighton
Copy link
Contributor

iainbrighton commented Apr 27, 2017 via email

@johlju johlju added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels May 7, 2018
@johlju
Copy link
Member

johlju commented May 7, 2018

Label this as help wanted to that someone in the community can run with this.

@1800Zeta
Copy link
Contributor

1800Zeta commented Jun 17, 2019

https://github.com/PowerShell/xDnsServer/blob/dev/DSCResources/Helper.psm1

This Helper Module includes
Internal function to assert if the role specific module is installed or not
function Assert-Module

So just need to ensure that the others include and use it

@rchristman89
Copy link

Assert-Module will still error out on Get if the module isn't installed. I think Assert-Module still needs to be added to all of the resources in xDnsServer.

For not erroring out on Get we could do a try catch:

try
    {
        Assert-Module -ModuleName 'DNS'
    }
catch
{
    Write-Warning -Message 'DNS module is not installed and this resource will not work properly.'
    return @{
         Ensure = 'Absent'
         Prop    = $null
    }
}

@rchristman89
Copy link

Most of the resources in XDnsServer do require it. So I was thinking it needed to be added to those.

This was specifically opened to not error out in Get, is that something we can support?

@johlju
Copy link
Member

johlju commented Apr 12, 2020

Yes to both. For all the resource; Get-TargetResource should be able to return the result without throwing an error. It should always return the correct hashtable (all the properties in the schema), either with the actual current values or with null values for those properties it cannot fetch. Key properties should always be set to the configuration values and if there is an Ensure property it should be set to Absent if the Key values does not exist in the current state.

@rchristman89
Copy link

Awesome. I will look at doing that.

@johlju johlju changed the title xDNSServerForwarder errors on test if DNS is not installed. Add error handling. xDnsServer: Resources errors on test if DNS is not installed. Add error handling. Feb 25, 2021
@johlju johlju changed the title xDnsServer: Resources errors on test if DNS is not installed. Add error handling. xDnsServer: Resources errors on test if DNS is not installed Feb 25, 2021
@johlju johlju changed the title xDnsServer: Resources errors on test if DNS is not installed DnsServerDsc: Resources errors on test if DNS is not installed Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

6 participants