dsccommunity / ComputerManagementDsc

DSC resources for for configuration of a Windows computer. These DSC resources allow you to perform computer management tasks, such as renaming the computer, joining a domain and scheduling tasks as well as configuring items such as virtual memory, event logs, time zones and power settings.
https://dsccommunity.org
MIT License
309 stars 82 forks source link

PSResourceRepository: Integration test with `-Default` parameter fails #401

Open nickgw opened 1 year ago

nickgw commented 1 year ago

Problem description

When the PSGallery is not present on the builders, adding it fails with the error "Value may not be null". This has been independently tested and the same configuration works, so it seems it is something isolated to the builders. When PowerShellGet 2.2.5 is loaded the error occurs. Removing PSGet 2.2.5 and importing 1.0.0.1 fixes the issue.

Example pipeline failure here: https://dev.azure.com/dsccommunity/ComputerManagementDsc/_build/results?buildId=6992&view=logs&j=bb95b0b0-86ad-5f35-08c1-35aecf9ab8ed

This is obv low priority since the configuration does work, just not on the builders. It just means we're missing some integration test coverage.

Verbose logs

2022-11-29T16:07:11.9222411Z     Context When using configuration PSResourceRepository_Create_Default_Config
2022-11-29T16:07:12.1209743Z VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = 
2022-11-29T16:07:12.1211373Z SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = 
2022-11-29T16:07:12.1214705Z root/Microsoft/Windows/DesiredStateConfiguration'.
2022-11-29T16:07:12.1416230Z VERBOSE: An LCM method call arrived from computer WIN-STA3E7J6311 with user sid 
2022-11-29T16:07:12.1417625Z S-1-5-21-2690698897-1208728301-426778522-500.
2022-11-29T16:07:12.1418446Z VERBOSE: [WIN-STA3E7J6311]: LCM:  [ Start  Set      ]
2022-11-29T16:07:12.2081315Z VERBOSE: [WIN-STA3E7J6311]: LCM:  [ Start  Resource ]  [[PSResourceRepository]Integration_Test]
2022-11-29T16:07:12.2092695Z VERBOSE: [WIN-STA3E7J6311]: LCM:  [ Start  Test     ]  [[PSResourceRepository]Integration_Test]
2022-11-29T16:07:12.2682693Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Determining the current
2022-11-29T16:07:12.2684735Z  state for resource 'PSResourceRepository' using the key property '{"Name":"PSGallery"}'. (RB0002)
2022-11-29T16:07:12.2859345Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Getting the current 
2022-11-29T16:07:12.2867808Z state for resource 'PSResourceRepository' using the key property '{"Name":"PSGallery"}'. (RB0001)
2022-11-29T16:07:12.2869032Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Return the current 
2022-11-29T16:07:12.2869684Z state of the repository 'PSGallery'.
2022-11-29T16:07:12.2975439Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Suppressed Warning No 
2022-11-29T16:07:12.2978248Z repository with the name 'PSGallery' was found.
2022-11-29T16:07:12.3032636Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] The repository 
2022-11-29T16:07:12.3033830Z 'PSGallery' was not found.
2022-11-29T16:07:12.3694423Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] NOTMATCH: Value (type 
2022-11-29T16:07:12.3704967Z 'InstallationPolicy') for property 'InstallationPolicy' does not match. Current state is '' and desired state is 
2022-11-29T16:07:12.3706137Z 'Untrusted'. (DRC0021)
2022-11-29T16:07:12.3707099Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] NOTMATCH: Value (type 
2022-11-29T16:07:12.3708247Z 'Ensure') for property 'Ensure' does not match. Current state is 'Absent' and desired state is 'Present'. (DRC0021)
2022-11-29T16:07:12.3803132Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] MATCH: Value (type 
2022-11-29T16:07:12.3820979Z 'InstallationPolicy') for property 'InstallationPolicy' does match. Current state is 'Untrusted' and desired state is 
2022-11-29T16:07:12.3822314Z 'Untrusted'. (DRC0020)
2022-11-29T16:07:12.3826531Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] NOTMATCH: Value (type 
2022-11-29T16:07:12.3827840Z 'Ensure') for property 'Ensure' does not match. Current state is 'Absent' and desired state is 'Present'. (DRC0021)
2022-11-29T16:07:12.3829167Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] The current state is 
2022-11-29T16:07:12.3829818Z not the desired state. (RB0004)
2022-11-29T16:07:12.3830777Z VERBOSE: [WIN-STA3E7J6311]: LCM:  [ End    Test     ]  [[PSResourceRepository]Integration_Test]  in 0.1870 seconds.
2022-11-29T16:07:12.3831835Z VERBOSE: [WIN-STA3E7J6311]: LCM:  [ Start  Set      ]  [[PSResourceRepository]Integration_Test]
2022-11-29T16:07:12.4529767Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Setting the desired 
2022-11-29T16:07:12.4531366Z state for resource 'PSResourceRepository' using the key property '{"Name":"PSGallery"}'. (RB0003)
2022-11-29T16:07:12.4770031Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Getting the current 
2022-11-29T16:07:12.4771678Z state for resource 'PSResourceRepository' using the key property '{"Name":"PSGallery"}'. (RB0001)
2022-11-29T16:07:12.4780630Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Return the current 
2022-11-29T16:07:12.4781509Z state of the repository 'PSGallery'.
2022-11-29T16:07:12.4891548Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Suppressed Warning No 
2022-11-29T16:07:12.4894092Z repository with the name 'PSGallery' was found.
2022-11-29T16:07:12.4949762Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] The repository 
2022-11-29T16:07:12.4951517Z 'PSGallery' was not found.
2022-11-29T16:07:12.5300935Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] NOTMATCH: Value (type 
2022-11-29T16:07:12.5302357Z 'InstallationPolicy') for property 'InstallationPolicy' does not match. Current state is '' and desired state is 
2022-11-29T16:07:12.5304750Z 'Untrusted'. (DRC0021)
2022-11-29T16:07:12.5315508Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] NOTMATCH: Value (type 
2022-11-29T16:07:12.5318677Z 'Ensure') for property 'Ensure' does not match. Current state is 'Absent' and desired state is 'Present'. (DRC0021)
2022-11-29T16:07:12.5506527Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] MATCH: Value (type 
2022-11-29T16:07:12.5507516Z 'InstallationPolicy') for property 'InstallationPolicy' does match. Current state is 'Untrusted' and desired state is 
2022-11-29T16:07:12.5508245Z 'Untrusted'. (DRC0020)
2022-11-29T16:07:12.5539901Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] NOTMATCH: Value (type 
2022-11-29T16:07:12.5541256Z 'Ensure') for property 'Ensure' does not match. Current state is 'Absent' and desired state is 'Present'. (DRC0021)
2022-11-29T16:07:12.5557261Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] The property 'Ensure' 
2022-11-29T16:07:12.5558000Z will be set to 'Present'. (RB0006)
2022-11-29T16:07:12.5575267Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Registering default 
2022-11-29T16:07:12.5578038Z repository 'PSGallery' with -Default parameter.
2022-11-29T16:07:13.7582672Z VERBOSE: [WIN-STA3E7J6311]:                            [[PSResourceRepository]Integration_Test] Repository details, 
2022-11-29T16:07:13.7583704Z Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2'; IsTrusted = 'False'; IsRegistered = 'True'.
2022-11-29T16:07:15.0794188Z       [-] Should compile and apply the MOF without throwing 3.11s
2022-11-29T16:07:15.1245751Z         Expected no exception to be thrown, but an exception "Value cannot be null." was thrown from D:\a\1\s\tests\Integration\Classes\PSResourceRepository.integration.tests.ps1:122 char:21
2022-11-29T16:07:15.1258227Z             + ...               Start-DscConfiguration @startDscConfigurationParameters
2022-11-29T16:07:15.1270121Z             +                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
2022-11-29T16:07:15.1281625Z         123:                 } | Should -Not -Throw
2022-11-29T16:07:15.1293625Z         at <ScriptBlock>, D:\a\1\s\tests\Integration\Classes\PSResourceRepository.integration.tests.ps1: line 105

DSC configuration

$ConfigurationData = @{
    AllNodes    = , @{
        NodeName        = 'localhost'
        CertificateFile = $Null
    }
    NonNodeData = @{
         PSResourceRepository_Create_Default_Config = @{
             Name    = 'PSGallery'
             Ensure  = 'Present'
             Default = $true
         }
    }
}

configuration PSResourceRepository_Create_Default_Config
{
    Import-DscResource -ModuleName 'ComputerManagementDsc'

    node $AllNodes.NodeName
    {
        PSResourceRepository 'Integration_Test'
        {
            Name    = $ConfigurationData.NonNodeData.PSResourceRepository_Create_Default_Config.Name
            Ensure  = $ConfigurationData.NonNodeData.PSResourceRepository_Create_Default_Config.Ensure
            Default = $ConfigurationData.NonNodeData.PSResourceRepository_Create_Default_Config.Default
        }
    }
}

Suggested solution

Check the build process for the builders themselves.

Operating system the target node is running

The issue occurs on both Windows 2019 and 2022 runners

PowerShell version and build the target node is running

PS C:\Windows\system32> Get-Module packagemanagement

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4.8.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-Pack...

PS C:\Windows\system32> Get-Module powershellget

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     2.2.5      PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCap...

ComputerManagementDsc version

Unreleased 8.6.0