vmware / dscr-for-vmware

The Repository contains Microsoft PowerShell Desired State Configuration (DSC) Resources for managing VC and ESXi settings.
Other
139 stars 41 forks source link

[Improvement] Add verbose messages when test fails #264

Closed danielboth closed 4 years ago

danielboth commented 4 years ago

When a DSC resource is not in desired state, the test method should show clearly (in verbose mode) what is not in desired state, by showing both current and desired values.

For example when running with the following configuration:

VMHostNtpSettings BaseNtpSettings {
            Server = $vCenterFqdn
            Name = $esxiHostName
            Credential = $Credential
            NtpServer = @(
                'ntp1.domain.com' 
                'ntp2.domain.com' 
            )
            NtpServicePolicy = 'On'
        }

I'm only getting these verbose messages when the DSC resource is out of desired state.

VERBOSE: [LOCALHOST]: LCM:  [ Start  Resource ]  [[VMHostNtpSettings]BaseNtpSettings]
VERBOSE: [LOCALHOST]: LCM:  [ Start  Test     ]  [[VMHostNtpSettings]BaseNtpSettings]
VERBOSE: [LOCALHOST]:                            [[VMHostNtpSettings]BaseNtpSettings] 3/29/2020 11:35:43 PM Disconnect-VIServer Finished execution
VERBOSE: [LOCALHOST]: LCM:  [ End    Test     ]  [[VMHostNtpSettings]BaseNtpSettings] False in 1.0480 seconds.
VERBOSE: [LOCALHOST]: LCM:  [ End    Resource ]  [[VMHostNtpSettings]BaseNtpSettings]

Not useful, as I don't have any idea now what's wrong, are the NTP servers configured incorrectly, or is the service not configured properly. Instead I would like to read

VERBOSE: [LOCALHOST]: LCM:  [ Start  Resource ]  [[VMHostNtpSettings]BaseNtpSettings]
VERBOSE: [LOCALHOST]: LCM:  [ Start  Test     ]  [[VMHostNtpSettings]BaseNtpSettings]
VERBOSE: [LOCALHOST]:                            [[VMHostNtpSettings]BaseNtpSettings] Setting NtpServicePolicy: Current setting [ Off ] does not match desired setting [ On ]
VERBOSE: [LOCALHOST]: LCM:  [ End    Test     ]  [[VMHostNtpSettings]BaseNtpSettings] False in 1.0480 seconds.
VERBOSE: [LOCALHOST]: LCM:  [ End    Resource ]  [[VMHostNtpSettings]BaseNtpSettings]

That way, it becomes also clear what executing Set will actually change when executed in production.

I'm using VMware.vSphereDsc version 2.1.0.58

SimeonGerginov commented 4 years ago

Good observation! I also think that more information from the Test() output will be helpful. We will start working on applying this feature to all existing DSC Resources that we have in the VMware.vSphereDSC module.

SimeonGerginov commented 4 years ago

The verbose message output when the Test() method fails was added via PR #268. You can run one of the Configurations in the repository to see the new format.