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

JeaRoleCapabilities Test always reeturns $false #19

Closed
raandree opened this issue Dec 28, 2018 · 7 comments

Comments

@raandree
Copy link

commented Dec 28, 2018

I am trying to create a Role Capabilities with the JeaRoleCapabilities resource. The resource's test method seems to return $false even if the Role Capabilities file exist with the requires settings. Can you repro this as well or is it me doing something wrong? I have put already a bit of time into this and should have a fix available soon if it is an issue with the code.

configuration JeaConfig1
{
    Import-DscResource -ModuleName JeaDsc

    node 'localhost'
    {

        JeaRoleCapabilities DscDiagnosticsRead
        {
            Path = 'C:\Program Files\WindowsPowerShell\Modules\JeaDsc\RoleCapabilities\DscDiagnosticsRead.psrc'
            VisibleCmdlets = "@{ Name = 'Get-DscLocalConfigurationManager'; Parameters = @{ Name = '*' } }"
            FunctionDefinitions = "@{ Name = 'Test'; ScriptBlock = { Test-DscConfiguration -Detailed } }", "@{ Name = 'GD'; ScriptBlock = { Get-Date } }"
            VisibleFunctions = 'GD', 'Test'
        }
    }
}

JeaConfig1 -OutputPath c:\JeaTest
Start-DscConfiguration -Path C:\JeaTest -Verbose -Wait -Force
localhost.mof                                                                                                                        
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/
Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer RAANDREE0 with user sid S-1-5-21-3110595715-3530629690-4267244086-1001.
VERBOSE: [RAANDREE0]: LCM:  [ Start  Set      ]
VERBOSE: [RAANDREE0]: LCM:  [ Start  Resource ]  [[JeaRoleCapabilities]DscDiagnosticsRead]
VERBOSE: [RAANDREE0]: LCM:  [ Start  Test     ]  [[JeaRoleCapabilities]DscDiagnosticsRead]
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsRead] Validating Path: C:\Program Files\WindowsPowerShell\Modules\JeaDsc\RoleCapabilities\DscDiagn
osticsRead.psrc
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsRead] Checking file extension is psrc for: C:\Program Files\WindowsPowerShell\Modules\JeaDsc\RoleC
apabilities\DscDiagnosticsRead.psrc
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsRead] Checking parent forlder is RoleCapabilities for: C:\Program Files\WindowsPowerShell\Modules\
JeaDsc\RoleCapabilities\DscDiagnosticsRead.psrc
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsRead] Checking Folder is in PSModulePath is psrc for: C:\Program Files\WindowsPowerShell\Modules\J
eaDsc\RoleCapabilities\DscDiagnosticsRead.psrc
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsRead] Path is a valid psrc path. Returning true.
VERBOSE: [RAANDREE0]: LCM:  [ End    Test     ]  [[JeaRoleCapabilities]DscDiagnosticsRead]  in 0.0330 seconds.
VERBOSE: [RAANDREE0]: LCM:  [ Start  Set      ]  [[JeaRoleCapabilities]DscDiagnosticsRead]
VERBOSE: [RAANDREE0]: LCM:  [ End    Set      ]  [[JeaRoleCapabilities]DscDiagnosticsRead]  in 0.0410 seconds.
VERBOSE: [RAANDREE0]: LCM:  [ End    Resource ]  [[JeaRoleCapabilities]DscDiagnosticsRead]
VERBOSE: [RAANDREE0]: LCM:  [ End    Set      ]
VERBOSE: [RAANDREE0]: LCM:  [ End    Set      ]    in  0.2200 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 0.315 seconds
@ChrisLGardner

This comment has been minimized.

Copy link
Owner

commented Dec 29, 2018

@ChrisLGardner ChrisLGardner added the bug label Dec 30, 2018
@raandree

This comment has been minimized.

Copy link
Author

commented Dec 30, 2018

The problem seem to be that New-PSRoleCapabilityFile slightly changes the format of scriptblocks. Hence the comparison always returns $false.

If you can repro this with the code provided in my initial post, I will polish my changes and create a new PR.

@ChrisLGardner

This comment has been minimized.

Copy link
Owner

commented Dec 30, 2018

I'm seeing that same behaviour in my tests too. I'll do some debugging and see what I come up with but if you've got a PR then that would be great.

@ChrisLGardner

This comment has been minimized.

Copy link
Owner

commented Dec 30, 2018

So it definitely looks like the way the comparison is being done is the problem.

@ChrisLGardner

This comment has been minimized.

Copy link
Owner

commented Feb 16, 2019

This should now be fixed in master as I've started using the same approach as the session configuration and convert it to JSON and compare the strings. I'll get a release out to the gallery soon.

@ChrisLGardner

This comment has been minimized.

Copy link
Owner

commented Apr 27, 2019

This should be in 0.6.0 and above. 0.6.1 includes a small bug fix so I'd recommend that one or newer.

@raandree

This comment has been minimized.

Copy link
Author

commented May 15, 2019

Sorry, but does not seem to work. I am using version 0.6.4 and a config based on your DemoConfig.ps1.

configuration Test1
{
    Import-DscResource -Module JeaDsc

    JeaRoleCapabilities DscDiagnosticsCapability
    {
        Path = 'C:\Program Files\WindowsPowerShell\Modules\JeaDsc\RoleCapabilities\DscDiagnostics.psrc'
        VisibleCmdlets = "@{ Name = 'Restart-Service'; Parameters = @{ Name = 'Name'; ValidateSet = 'w32time' } }"
        #FunctionDefinitions = "@{ Name = 'Test'; ScriptBlock = { Get-Date } }"
    }
    
    JeaSessionConfiguration Endpoint
    {
        EndpointName = "DscDiagnostics"
        RoleDefinitions = "@{ 'G1' = @{ RoleCapabilities = 'DscDiagnostics' } }"
        TranscriptDirectory = 'C:\ProgramData\Jea\DscDiagnostics'        
        DependsOn = '[JeaRoleCapabilities]DscDiagnosticsCapability'
    }
}

Test1 -OutputPath d:\dsc
Start-DscConfiguration -Path d:\dsc -Wait -Verbose -Force

The resource [JeaRoleCapabilities]DscDiagnosticsCapability is never in the desired state as the VisibleCmdlets hashtable seems to be converted into a string.

VERBOSE: [RAANDREE0]: LCM:  [ Start  Test     ]  [[JeaRoleCapabilities]DscDiagnosticsCapability]
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsCapability] Validating Path: C:\Program Files\WindowsPowerShell\Modules\JeaDsc\RoleCapabilities\Ds
cDiagnostics.psrc
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsCapability] Checking file extension is psrc for: C:\Program Files\WindowsPowerShell\Modules\JeaDsc
\RoleCapabilities\DscDiagnostics.psrc
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsCapability] Checking parent forlder is RoleCapabilities for: C:\Program Files\WindowsPowerShell\Mo
dules\JeaDsc\RoleCapabilities\DscDiagnostics.psrc
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsCapability] Checking Folder is in PSModulePath is psrc for: C:\Program Files\WindowsPowerShell\Mod
ules\JeaDsc\RoleCapabilities\DscDiagnostics.psrc
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsCapability] Path is a valid psrc path. Returning true.
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsCapability] Existing Configuration: {
    "Path":  "C:\\Program Files\\WindowsPowerShell\\Modules\\JeaDsc\\RoleCapabilities\\DscDiagnostics.psrc",
    "VisibleCmdlets":  [
                           "System.Collections.Hashtable"
                       ]
}
VERBOSE: [RAANDREE0]:                            [[JeaRoleCapabilities]DscDiagnosticsCapability] New COnfiguration: {
    "Path":  "C:\\Program Files\\WindowsPowerShell\\Modules\\JeaDsc\\RoleCapabilities\\DscDiagnostics.psrc",
    "VisibleCmdlets":  [
                           "@{ Name = \u0027Restart-Service\u0027; Parameters = @{ Name = \u0027Name\u0027; ValidateSet = \u0027w32time\u0027 } }"
                       ]
}
VERBOSE: [RAANDREE0]: LCM:  [ End    Test     ]  [[JeaRoleCapabilities]DscDiagnosticsCapability]  in 0.3180 seconds.
VERBOSE: [RAANDREE0]: LCM:  [ Start  Set      ]  [[JeaRoleCapabilities]DscDiagnosticsCapability]
VERBOSE: [RAANDREE0]: LCM:  [ End    Set      ]  [[JeaRoleCapabilities]DscDiagnosticsCapability]  in 0.0720 seconds.
VERBOSE: [RAANDREE0]: LCM:  [ End    Resource ]  [[JeaRoleCapabilities]DscDiagnosticsCapability]

If VisibleCmdlets is just a string array and not a hashtable as a string (like in #25), things work as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.