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

Change import type resource to a group type resource #500

Merged
merged 6 commits into from
Jul 25, 2024

Conversation

SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Jul 24, 2024

PR Summary

The main problem with test and any import type resource is that the engine uses the user input/doc as the expected state. In this case, it's a pointer to a config file and an optional parameters file. So expected and desired would never match.

The change here is that an import kind of resource is no longer just a resource that the engine resolves, but is a type of group resource which is expected to resolve the configuration file to an actual configuration and execute the requested operation.

dsc here is used to implement the include resource which has a hidden as_include switch to tell itself it needs to resolve the configuration then act the same as a group resource. The validate operation now checks that the properties match an import configuration schema. Removed all the previous code where the engine perform the resolving import kind of resources and have test check if import kind, then just use the returned output (which is in the correct format already as a group resource) instead of trying to figure out expected/actual.

PR Context

Fixes incomplete functionality of include resource for test operation as the expected state was a redirection pointer than the resolved expected state.

Example output from test:

metadata:
  Microsoft.DSC:
    version: 3.0.0
    operation: Test
    executionType: Actual
    startDatetime: 2024-07-24T20:44:14.049535-07:00
    endDatetime: 2024-07-24T20:44:14.352636-07:00
    duration: PT0.303101S
    securityContext: Restricted
results:
- metadata:
    Microsoft.DSC:
      duration: PT0.181454S
  name: get os info
  type: Microsoft.DSC/Include
  result:
  - metadata:
      Microsoft.DSC:
        duration: PT0.069375S
    name: os
    type: Microsoft/OSInfo
    result:
      desiredState:
        family: macOS
      actualState:
        $id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
        family: macOS
        version: 14.5.0
        bitness: '64'
        architecture: arm64
      inDesiredState: true
      differingProperties: []
  - metadata:
      Microsoft.DSC:
        duration: PT0.018143S
    name: another os instance
    type: Microsoft/OSInfo
    result:
      desiredState:
        family: macOS
      actualState:
        $id: https://developer.microsoft.com/json-schemas/dsc/os_info/20230303/Microsoft.Dsc.OS_Info.schema.json
        family: macOS
        version: 14.5.0
        bitness: '64'
        architecture: arm64
      inDesiredState: true
      differingProperties: []
  - metadata:
      Microsoft.DSC:
        duration: PT0.032894S
    name: path
    type: Test/Echo
    result:
      desiredState:
        output: /Users/steve/repos/DSC/bin/debug:/usr/local/microsoft/powershell/7-preview:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/steve/.cargo/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Applications/iTerm.app/Contents/Resources/utilities:/Users/steve/.dotnet/tools
      actualState:
        output: /Users/steve/repos/DSC/bin/debug:/usr/local/microsoft/powershell/7-preview:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/steve/.cargo/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Applications/iTerm.app/Contents/Resources/utilities:/Users/steve/.dotnet/tools
      inDesiredState: true
      differingProperties: []
messages: []
hadErrors: false

$out.hadErrors | Should -Be $false
}

It 'Test with include works' {
$includeYaml = Join-Path $PSScriptRoot ../../dsc/examples/include.dsc.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there is no value in using Join-Path when one of its arguments already contains the forward slash separators.

Copy link
Member Author

@SteveL-MSFT SteveL-MSFT Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that Join-Path isn't required here

@SteveL-MSFT SteveL-MSFT added this pull request to the merge queue Jul 25, 2024
Merged via the queue into PowerShell:main with commit 79bb481 Jul 25, 2024
4 checks passed
@SteveL-MSFT SteveL-MSFT deleted the include-group branch July 25, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants