PowerShell / PowerShell/DSC

Improve synthetic diff array for test operations

Open
#1,660 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Enhancement Needs Triage
Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

Summary of the new feature / enhancement

As a system administrator using DSC to manage my infrastructure,
I want the differingProperties and changedProperties fields of results to accurately reflect configurable properties of the resource without substantial noise,
So that I can quickly review result data.

Currently, the synthetic diff array of property names for DSC resource testoperations has no handling for read-only and write-only properties. This problem is most clearly raised for the transitional PowerShell script resources, where you get results like this:

desiredState:
  input:
    configFilePath: ~/foo/bar/config.toml
    settings:
      foo: bar
  getScript: |
    param($data)

    function Get-Config {
      [CmdletBinding(DefaultParameterSetName = 'ByPath')]
      param(
        [Parameter(Mandatory, ParameterSetName = 'ByPath')]
        [string]$Path,
        [Parameter(Mandatory, ParameterSetName = 'DefaultConfig')]
        [switch]$Default
      )

      # Elided for brevity
    }

    if ([string]::IsNullOrEmpty($data.configFilePath)) {
      Write-Warning "No config file path provided. Using default configuration."
      Get-Config -Default
    } else {
      Get-Config -Path $data.configFilePath
    }
  testScript: |
    param($data)

    function Get-Config {
      [CmdletBinding(DefaultParameterSetName = 'ByPath')]
      param(
        [Parameter(Mandatory, ParameterSetName = 'ByPath')]
        [string]$Path,
        [Parameter(Mandatory, ParameterSetName = 'DefaultConfig')]
        [switch]$Default
      )
      # Elided for brevity
    }

    function Test-Config {
      [CmdletBinding()]
      param(
        [Parameter(Mandatory)]
        [pscustomobject]$actual,
        [Parameter(Mandatory)]
        [pscustomobject]$desired
      )
      # Elided for brevity
    }

    if ($null -eq $data.settings) {
      throw "Unable to test configuration without specific settings"
    }
    if ($data.settings -isnot [System.Management.Automation.PSCustomObject]) {
      throw "Unable to test configuration; settings input data must be an object but was [$($data.settings.GetType().FullName)]"
    }

    $actualState = if ([string]::IsNullOrEmpty($data.configFilePath)) {
      Write-Warning "No config file path provided. Using default configuration."
      Get-Config -Default
    } else {
      Get-Config -Path $data.configFilePath
    }

    Test-Config -Actual $actualState -Desired $data.settings

actualState
  _inDesiredState: false
inDesiredState: false
differingProperties:
  - input
  - getScript
  - testScript
  - output

Not only is the result object difficult to read, but the actualState tells the user almost nothing (the _inDesiredState field is hoisted to the top level of the result), but the differing properties field is useless - input and *Script properties are write-only, so the resource will never return them, and output/_inDesiredState are read-only, so the user should never supply them.

The result is a substantial amount of noise with very little information for the user. The only way to more clearly indicate result granularity is for a resource to emit trace messages about how the instance is out-of-state.

Proposed technical implementation details (optional)

While I don't have a concrete proposal, this issue made me think of two approaches that could help with this problem:

  1. Introduce special handling for read-only/write-only properties in result data - we probably shouldn't include them in the differingProperties array, because they'll never match both actual and desired state.
  2. Define a helper keyword for resource schema properties like x-dsc-hideFromDesiredState to specifically filter out properties that add a lot of noise to the result object.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name implementation files or tests. Start by locating the synthetic diff generation and resource schema handling for DSC test operations, then compare how read-only and write-only properties are represented. Done should mean result diffs no longer report properties that cannot be supplied or returned, with coverage for transitional PowerShell script resources.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, rust
Domain
devops
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.