puppetlabs / puppetlabs/puppet-resource_api

Dsc properties are not compared correctly

Open
#308 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Ruby
Stars
27
Forks
42
PR merge metrics
No merged PRs in 30d

Description

Describe the Bug

Somewhere between ruby-pwsh and the resource api, properties are getting lost and compared incorrectly.

for a relatively simple manifest with one dsc resource:

  dsc_virtualmemory { "set_page_file_size_of_24576" :
    dsc_type        => 'customsize',
    dsc_drive       => 'c',
    dsc_initialsize => 24576,
    dsc_maximumsize => 24576,
  }

The following is the truncated output on a verbose run:

Notice: /Stage[main]/Main/Dsc_virtualmemory[set_page_file_size_of_24576]/dsc_initialsize: dsc_initialsize changed  to 24576
Notice: /Stage[main]/Main/Dsc_virtualmemory[set_page_file_size_of_24576]/dsc_maximumsize: dsc_maximumsize changed  to 24576
Notice: dsc_virtualmemory[{:name=>"set_page_file_size_of_24576", :dsc_drive=>"c", :dsc_type=>"customsize"}]: Updating: Finished in 0.933907 seconds

Note that the change lines have a blank where the current value is omitted: dsc_initialsize changed to 24576

I've attached debug runs with and without the powershell to the issue, but this is the relevant part imo:

#PowerShell GET runs
2023-01-05 14:43:22 -0500 Puppet (debug): dsc_virtualmemory: raw data received: {"ResourceId"=>nil, "PsDscRunAsCredential"=>nil, "Type"=>"CustomSize", "InitialSize"=>24576, "ModuleVersion"=>"8.5.0", "SourceInfo"=>nil, "ConfigurationName"=>nil, "Drive"=>"C:\\", "MaximumSize"=>24576, "ModuleName"=>"C:/ProgramData/PuppetLabs/puppet/cache/lib/puppet_x/computermanagementdsc/dsc_resources/ComputerManagementDsc/ComputerManagementDsc.psd1", "DependsOn"=>nil}
2023-01-05 14:43:22 -0500 Puppet (debug): dsc_virtualmemory: Returned to Puppet as {:dsc_drive=>"C:\\", :dsc_initialsize=>24576, :dsc_maximumsize=>24576, :dsc_type=>"CustomSize", :name=>"set_page_file_size_of_24576"}
2023-01-05 14:43:22 -0500 Puppet (debug): Current State: {:name=>"set_page_file_size_of_24576", :dsc_drive=>"c", :dsc_type=>"customsize"}
2023-01-05 14:43:22 -0500 Puppet (debug): dsc_virtualmemory: Canonicalized Resources: [{:name=>"set_page_file_size_of_24576", :dsc_drive=>"c", :dsc_type=>"customsize", :dsc_initialsize=>24576, :dsc_maximumsize=>24576, :validation_mode=>"property"}]
2023-01-05 14:43:22 -0500 /Stage[main]/Main/Dsc_virtualmemory[set_page_file_size_of_24576]/dsc_initialsize (notice): dsc_initialsize changed  to 24576
2023-01-05 14:43:22 -0500 /Stage[main]/Main/Dsc_virtualmemory[set_page_file_size_of_24576]/dsc_maximumsize (notice): dsc_maximumsize changed  to 24576

You can see that the raw data received has the correct data, and that that data is canonicalized correctly:
2023-01-05 14:43:22 -0500 Puppet (debug): dsc_virtualmemory: Canonicalized Resources: [{:name=>"set_page_file_size_of_24576", :dsc_drive=>"c", :dsc_type=>"customsize", :dsc_initialsize=>24576, :dsc_maximumsize=>24576, :validation_mode=>"property"}]

however, the current state has an incomplete list of properties:
2023-01-05 14:43:22 -0500 Puppet (debug): Current State: {:name=>"set_page_file_size_of_24576", :dsc_drive=>"c", :dsc_type=>"customsize"}

causing the resource's set function to run and printing this info:
2023-01-05 14:43:22 -0500 /Stage[main]/Main/Dsc_virtualmemory[set_page_file_size_of_24576]/dsc_initialsize (notice): dsc_initialsize changed to 24576

dsc_initialsize is changed from null to the correct value because the current state is incomplete.

Expected Behavior

I expect the current state to be the complete current state, and in this instance where the resource is in sync, nothing to happen.

Steps to Reproduce

Steps to reproduce the behavior:
On a system where ComputerManagementDsc is available, puppet apply a manifest with the resource at the beginning of the issue.

Environment

  • Version 7.19.0
  • Platform Windows 2019

Additional Context

This applies to a large portion of Dsc resources in Puppet. Flipping validation mode to resource "resolves" the problem, but negates much of the benefit of moving from the old dsc module to the newly released puppet dsc modules.
virtualmemory_debug_nopowershell.log
virtualmemory_debug_powershell.log

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

Start by reproducing the issue with the dsc_virtualmemory manifest and compare the attached PowerShell and no-PowerShell debug logs, especially the raw data, current state, and canonicalized resources. Trace the resource API path that builds current state from the returned DSC properties; done means current state includes dsc_initialsize and dsc_maximumsize and an in-sync resource produces no change notices.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, ruby
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.