Skip to content

SqlRSSetup: Refactor resource into class-based resource #2083

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

Merged
merged 61 commits into from
May 1, 2025

Conversation

johlju
Copy link
Member

@johlju johlju commented Mar 18, 2025

Pull Request (PR) description

  • SqlRSSetup
    • The DSC resource has been refactored into a class-based resource.
      • The parameter SourcePath was replaced with MediaPath.
      • The parameter IAcceptLicensTerms was replaced with a boolean parameter
        AcceptLicensingTerms.
      • The parameter SourceCredential was removed. Because of this, the
        functionality that allowed copying the media from a UNC path using
        those credentials was also removed. If this was something you used,
        please open an issue.
      • The version validation no longer gets the current version from the
        installed package (using Get-Package), but instead from the registry.
      • Prior when install was successful, the resource checked whether there
        were any pending rename operations. Since the install returns 3010
        if a restart is needed it is now assumed that the setup process takes
        care of this. If that is not the case, and this check is needed, then
        open an issue to discuss in what cases this is needed.
      • The Edition option Development was replaced by the value
        Developer.
      • The read-only properties CurrentVersion, ServiceName and ErrorDumpDirectory
        were removed.
      • ConvertTo-SqlDscEditionName to return the edition name of the specified
        edition ID.

This Pull Request (PR) fixes the following issues

Partly handles #1351

Task list

  • Added an entry to the change log under the Unreleased section of the
    file CHANGELOG.md. Entry should say what was changed and how that
    affects users (if applicable), and reference the issue being resolved
    (if applicable).
  • Resource documentation updated in the resource's README.md.
  • Resource parameter descriptions updated in schema.mof.
  • Comment-based help updated, including parameter descriptions.
  • Localization strings updated.
  • Examples updated.
  • Unit tests updated. See DSC Community Testing Guidelines.
  • Integration tests updated (where possible). See DSC Community Testing Guidelines.
  • Code changes adheres to DSC Community Style Guidelines.

This change is Reviewable

@johlju johlju requested a review from a team as a code owner March 18, 2025 18:15
@johlju johlju added the waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. label Mar 18, 2025
#>
if ($this.ForceRestart -or ($exitCode -eq 3010 -and -not $this.SuppressRestart))
{
$global:DSCMachineStatus = 1

Check warning

Code scanning / PSScriptAnalyzer

Found global variable 'global:DSCMachineStatus'. Warning

Found global variable 'global:DSCMachineStatus'.
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

{
$errorMessage = $script:localizedData.Get_FileProductVersion_GetFileProductVersionError -f $Path, $_.Exception.Message

Write-Error -Message $errorMessage -ErrorAction 'Stop'

Check warning

Code scanning / PSScriptAnalyzer

Write-Error is used to create a terminating error. throw or $pscmdlet.ThrowTerminatingError should be used. Warning

Write-Error is used to create a terminating error. throw or $pscmdlet.ThrowTerminatingError should be used.
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@johlju
Copy link
Member Author

johlju commented Mar 18, 2025

Stuff left to do:

  • Add unit tests for SqlRSSetup
  • Add integration tests for Power BI Report Server
  • Move any needed docs from the removed README.md to the new resource's comment-based help
  • Make sure to support EditionUpgrade in the Test() method, see issue SqlRSSetup: Will always make an edition upgrade #1311
  • Try to remove the newly added env: in azure-pipelines. It should not be needed. 🤔
  • Strings like Evaluating SQL Reporting Services setup for instance 'PBIRS' should be corrected to indicate PowerBI Report Server when instance is PBIRS.

Copy link

codecov bot commented Mar 18, 2025

Codecov Report

Attention: Patch coverage is 92.98246% with 12 lines in your changes missing coverage. Please review.

Project coverage is 94%. Comparing base (f9eda7b) to head (90868af).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
source/Classes/020.SqlRSSetup.ps1 91% 12 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #2083   +/-   ##
====================================
- Coverage    94%     94%   -1%     
====================================
  Files       105     107    +2     
  Lines      8114    8104   -10     
====================================
- Hits       7689    7667   -22     
- Misses      425     437   +12     
Flag Coverage Δ
unit 94% <92%> (-1%) ⬇️
Files with missing lines Coverage Δ
source/Private/Get-FileProductVersion.ps1 100% <100%> (ø)
source/Public/ConvertTo-SqlDscEditionName.ps1 100% <100%> (ø)
source/Classes/020.SqlRSSetup.ps1 91% <91%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@johlju johlju force-pushed the f/refactor-SqlRSSetup branch from 0a1f8c9 to e1ffe69 Compare March 19, 2025 20:41
@@ -21,7 +21,7 @@
SqlRSSetup 'InstallDefaultInstance'
{
InstanceName = 'SSRS'
IAcceptLicenseTerms = 'Yes'
AcceptLicenseTerms = $true

Check failure

Code scanning / PSScriptAnalyzer

The member 'IAcceptLicenseTerms' is not valid. Valid members are 'AcceptLicensingTerms', 'Action', 'DependsOn', 'Edition', 'EditionUpgrade', 'ForceRestart', 'InstallFolder', 'InstanceName', 'LogPath', 'MediaPath', 'ProductKey', 'PsDscRunAsCredential', 'SuppressRestart', 'Timeout', 'VersionUpgrade'. Error

The member 'IAcceptLicenseTerms' is not valid. Valid members are
'AcceptLicensingTerms', 'Action', 'DependsOn', 'Edition', 'EditionUpgrade', 'ForceRestart', 'InstallFolder', 'InstanceName', 'LogPath', 'MediaPath', 'ProductKey', 'PsDscRunAsCredential', 'SuppressRestart', 'Timeout', 'VersionUpgrade'.
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -25,7 +25,7 @@
Action = 'Uninstall'

# This needs to be set to although it is not used during uninstall.
IAcceptLicenseTerms = 'Yes'
AcceptLicenseTerms = $true

Check failure

Code scanning / PSScriptAnalyzer

The member 'IAcceptLicenseTerms' is not valid. Valid members are 'AcceptLicensingTerms', 'Action', 'DependsOn', 'Edition', 'EditionUpgrade', 'ForceRestart', 'InstallFolder', 'InstanceName', 'LogPath', 'MediaPath', 'ProductKey', 'PsDscRunAsCredential', 'SuppressRestart', 'Timeout', 'VersionUpgrade'. Error

The member 'IAcceptLicenseTerms' is not valid. Valid members are
'AcceptLicensingTerms', 'Action', 'DependsOn', 'Edition', 'EditionUpgrade', 'ForceRestart', 'InstallFolder', 'InstanceName', 'LogPath', 'MediaPath', 'ProductKey', 'PsDscRunAsCredential', 'SuppressRestart', 'Timeout', 'VersionUpgrade'.
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@johlju johlju force-pushed the f/refactor-SqlRSSetup branch 3 times, most recently from b0607da to 68b6ea0 Compare April 6, 2025 18:51
@johlju johlju added needs review The pull request needs a code review. and removed waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. labels Apr 8, 2025
@johlju johlju force-pushed the f/refactor-SqlRSSetup branch from bfe2417 to 90868af Compare April 8, 2025 11:27
Copy link
Contributor

@dan-hughes dan-hughes left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 25 files at r1, 3 of 7 files at r2, 2 of 26 files at r3, 35 of 36 files at r4, all commit messages.
Reviewable status: 45 of 46 files reviewed, 19 unresolved discussions (waiting on @Github-advanced-security[bot] and @johlju)


tests/Integration/Resources/DSC_SqlRSSetup.config.ps1 line 22 at r4 (raw file):

                InstanceName         = if (Test-ContinuousIntegrationTaskCategory -Category 'Integration_PowerBI')
                {
                    'PBIRS' # cSpell:ignore PBIRS

Add this spelling to the settings.json?

Code quote:

# cSpell:ignore PBIRS

source/en-US/SqlRSSetup.strings.psd1 line 0 at r4 (raw file):
Do these need a string code e.g. SRSET0001?


source/Private/Get-FileProductVersion.ps1 line 0 at r4 (raw file):
Seems generic enough to be a candidate for moving to DscResource.Common?


tests/Unit/Public/ConvertTo-SqlDscEditionName.Tests.ps1 line 13 at r4 (raw file):

            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null

Again, redirecting error stream 2.


tests/Unit/Public/ConvertTo-SqlDscEditionName.Tests.ps1 line 52 at r4 (raw file):

    Context 'When converting a known EditionId' {
        BeforeAll {
            $mockLocalizedConvertingEditionId = InModuleScope -ScriptBlock {

Is the variable used anywhere?

Also, no Set-StrictMode.


tests/Unit/Private/Get-FileProductVersion.Tests.ps1 line 13 at r4 (raw file):

            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null

Error stream.


.vscode/analyzersettings.psd1 line 36 at r4 (raw file):

        'PSUseCmdletCorrectly'
        'PSUseOutputTypeCorrectly'
        #'PSAvoidGlobalVars'

Should this be re-enabled and a local supress statement used?


source/Public/ConvertTo-SqlDscEditionName.ps1 line 82 at r4 (raw file):

            EditionName = 'Unknown'
        }
    }

Could this be a switch statement? $mappingID is not used anywhere else.

Code quote:

    if ($EditionIdMap.ContainsKey($mappingID))
    {
        $editionInfo = $EditionIdMap[$mappingID]

        $resultObject = [PSCustomObject]@{
            EditionId = $Id
            Edition = $editionInfo.Edition
            EditionName = $editionInfo.EditionName
        }

        return $resultObject
    }
    else
    {
        Write-Debug -Message ($script:localizedData.ConvertTo_EditionName_UnknownEditionId -f $Id)

        return [PSCustomObject]@{
            EditionId = $Id
            Edition = 'Unknown'
            EditionName = 'Unknown'
        }
    }

tests/Unit/Classes/SqlRSSetup.Tests.ps1 line 0 at r4 (raw file):
Missing Set-StrictMode -Version 1.0 in all InModuleScope blocks


tests/Unit/Classes/SqlRSSetup.Tests.ps1 line 19 at r4 (raw file):

            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 2>&1 4>&1 5>&1 6>&1 > $null

This should be 3 I believe.

Code quote:

2

tests/Unit/Classes/SqlRSSetup.Tests.ps1 line 1041 at r4 (raw file):

        It 'Should throw the correct error message' {
            InModuleScope -ScriptBlock {
                $mockExpectedErrorMessage = ($script:mockSqlRSSetupInstance.localizedData.InstanceName_Invalid -f 'INSTANCE') + ' (Parameter ''InstanceName'')'

Does Get-InvalidArgumentRecord not work?


tests/Unit/Classes/SqlRSSetup.Tests.ps1 line 1070 at r4 (raw file):

            It 'Should throw the correct error message' {
                InModuleScope -ScriptBlock {
                    $mockExpectedErrorMessage = $script:mockSqlRSSetupInstance.localizedData.AcceptLicensingTerms_Required + ' (Parameter ''AcceptLicensingTerms'')'

And here?


source/Classes/020.SqlRSSetup.ps1 line 173 at r4 (raw file):

    [ValidateSet('Install', 'Repair', 'Uninstall')]
    [System.String]
    $Action

Can this use an Enum? It can be reused in other install resources?

Code quote:

    [DscProperty(Mandatory)]
    [ValidateSet('Install', 'Repair', 'Uninstall')]
    [System.String]
    $Action

source/Classes/020.SqlRSSetup.ps1 line 194 at r4 (raw file):

    [ValidateSet('Developer', 'Evaluation', 'ExpressAdvanced')]
    [System.String]
    $Edition

Same here too.

Code quote:

    [DscProperty()]
    [ValidateSet('Developer', 'Evaluation', 'ExpressAdvanced')]
    [System.String]
    $Edition

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 40 of 46 files reviewed, 19 unresolved discussions (waiting on @dan-hughes)


.vscode/analyzersettings.psd1 line 36 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Should this be re-enabled and a local supress statement used?

I tried, but I could not find a way to make a local suppress statement for it, do you have a suggestion how to make one?


source/Classes/020.SqlRSSetup.ps1 line 173 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Can this use an Enum? It can be reused in other install resources?

Done. The enum should probably be reused in the public commands as well, but have to be another PR to fix that.


source/Classes/020.SqlRSSetup.ps1 line 194 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Same here too.

Done. Not sure if it would benefit anything as it would be ReportServerEdition and would only be used in this resource. Bu

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 39 of 48 files reviewed, 19 unresolved discussions (waiting on @dan-hughes)


source/Classes/020.SqlRSSetup.ps1 line 194 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

Done. Not sure if it would benefit anything as it would be ReportServerEdition and would only be used in this resource. Bu

Forgot to write the last sentence. :) But if it would be used by commands as well, then there is a benefit, assuming we can resolve the commands in another PR.

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 39 of 48 files reviewed, 18 unresolved discussions (waiting on @dan-hughes)


tests/Unit/Classes/SqlRSSetup.Tests.ps1 line 19 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

This should be 3 I believe.

Done.


tests/Unit/Classes/SqlRSSetup.Tests.ps1 line 1041 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Does Get-InvalidArgumentRecord not work?

Done. Yes, forgot about that command.


tests/Unit/Classes/SqlRSSetup.Tests.ps1 line 1070 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

And here?

Done. Fixed throughout.


tests/Unit/Classes/SqlRSSetup.Tests.ps1 line at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Missing Set-StrictMode -Version 1.0 in all InModuleScope blocks

Done. Fix in all InModuleScope inside It-block.


tests/Unit/Public/ConvertTo-SqlDscEditionName.Tests.ps1 line 13 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Again, redirecting error stream 2.

Done.


tests/Unit/Public/ConvertTo-SqlDscEditionName.Tests.ps1 line 52 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Is the variable used anywhere?

Also, no Set-StrictMode.

Done. Removed unnecessary lines. Public command - testing actually exported command, so no InModuleScope to run Set-StrictMode in.


source/Private/Get-FileProductVersion.ps1 line at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Seems generic enough to be a candidate for moving to DscResource.Common?

Done. Moved and removed here.


tests/Unit/Private/Get-FileProductVersion.Tests.ps1 line 13 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Error stream.

Done. Test removed, moved command to DscResource.Common.

{
$errorMessage = $script:localizedData.Get_FileProductVersion_GetFileProductVersionError -f $Path, $_.Exception.Message

Write-Error -Message $errorMessage -ErrorAction 'Stop'
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Dismissed @dan-hughes from a discussion.
Reviewable status: 38 of 48 files reviewed, 17 unresolved discussions (waiting on @dan-hughes)


source/en-US/SqlRSSetup.strings.psd1 line at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Do these need a string code e.g. SRSET0001?

Done.


source/Public/ConvertTo-SqlDscEditionName.ps1 line 82 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Could this be a switch statement? $mappingID is not used anywhere else.

Do you mean to also remove $EditionIdMap and move each object to be returned in switch-block?


tests/Integration/Resources/DSC_SqlRSSetup.config.ps1 line 22 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Add this spelling to the settings.json?

Done.

#>
if ($this.ForceRestart -or ($exitCode -eq 3010 -and -not $this.SuppressRestart))
{
$global:DSCMachineStatus = 1
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -21,7 +21,7 @@
SqlRSSetup 'InstallDefaultInstance'
{
InstanceName = 'SSRS'
IAcceptLicenseTerms = 'Yes'
AcceptLicenseTerms = $true
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -25,7 +25,7 @@
Action = 'Uninstall'

# This needs to be set to although it is not used during uninstall.
IAcceptLicenseTerms = 'Yes'
AcceptLicenseTerms = $true
Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@johlju
Copy link
Member Author

johlju commented Apr 30, 2025

@dan-hughes I have finally had the time to handle the review comments, I hope I fixed most but need input on a couple, when you have time 🙂

Copy link
Contributor

@dan-hughes dan-hughes left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 8 files at r5, 7 of 7 files at r6, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @johlju)


.vscode/analyzersettings.psd1 line 36 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

I tried, but I could not find a way to make a local suppress statement for it, do you have a suggestion how to make one?

I'm assuming you can do what is done in test files and add [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]?

It just seemed a little overkill disabling the check across the whole module.


source/Public/ConvertTo-SqlDscEditionName.ps1 line 82 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

Do you mean to also remove $EditionIdMap and move each object to be returned in switch-block?

Yes. Something like this:

$resultObject = [PSCustomObject]@{
        EditionId = $Id
        Edition = ''
        EditionName = ''
    }

    Write-Debug -Message ($script:localizedData.ConvertTo_EditionName_ConvertingEditionId -f $Id)

    switch ($Id) {
        2176971986 { 
            $resultObject.Edition = 'Developer'
            $resultObject.EditionName = 'SQL Server Developer Edition'
        }
        2017617798 {
            $resultObject.Edition = 'Developer'
            $resultObject.EditionName = 'Power BI Report Server - Developer'
        }
        1369084056 { 
            $resultObject.Edition = 'Evaluation'
            $resultObject.EditionName = 'Power BI Report Server - Evaluation'
        }
        default {
            Write-Debug -Message ($script:localizedData.ConvertTo_EditionName_UnknownEditionId -f $Id)
            $resultObject.Edition = 'Unknown'
            $resultObject.EditionName = 'Unknown'
        }
    }

    return $resultObject

Are the strings localized?

@johlju johlju force-pushed the f/refactor-SqlRSSetup branch from a15d5cd to 5e6e619 Compare April 30, 2025 17:22
Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 46 of 49 files reviewed, 6 unresolved discussions (waiting on @dan-hughes)


.vscode/analyzersettings.psd1 line 36 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

I'm assuming you can do what is done in test files and add [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')]?

It just seemed a little overkill disabling the check across the whole module.

I can't make it work as it is normally put above a param (), and I can't add that to a class script file as the param () will be added to the built module. I tried to add it in different places in a class to see that it worked but couldn't get anything to work. Not sure if the SuppressMessageAttribute is supported for classes. 🤔

So, I disable the rule as that was the only workaround I could think of. It was not my desire, and rather would like to find another solution if possible.


source/Public/ConvertTo-SqlDscEditionName.ps1 line 82 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Yes. Something like this:

$resultObject = [PSCustomObject]@{
        EditionId = $Id
        Edition = ''
        EditionName = ''
    }

    Write-Debug -Message ($script:localizedData.ConvertTo_EditionName_ConvertingEditionId -f $Id)

    switch ($Id) {
        2176971986 { 
            $resultObject.Edition = 'Developer'
            $resultObject.EditionName = 'SQL Server Developer Edition'
        }
        2017617798 {
            $resultObject.Edition = 'Developer'
            $resultObject.EditionName = 'Power BI Report Server - Developer'
        }
        1369084056 { 
            $resultObject.Edition = 'Evaluation'
            $resultObject.EditionName = 'Power BI Report Server - Evaluation'
        }
        default {
            Write-Debug -Message ($script:localizedData.ConvertTo_EditionName_UnknownEditionId -f $Id)
            $resultObject.Edition = 'Unknown'
            $resultObject.EditionName = 'Unknown'
        }
    }

    return $resultObject

Are the strings localized?

Got you, will fix tomorrow. Hmm, they should probably be localized, guessing a Spanish SQL Server actually have Spanish names returned. 🤔 Fixing that too.

Copy link
Contributor

@dan-hughes dan-hughes left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r7, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @johlju)


.vscode/analyzersettings.psd1 line 36 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

I can't make it work as it is normally put above a param (), and I can't add that to a class script file as the param () will be added to the built module. I tried to add it in different places in a class to see that it worked but couldn't get anything to work. Not sure if the SuppressMessageAttribute is supported for classes. 🤔

So, I disable the rule as that was the only workaround I could think of. It was not my desire, and rather would like to find another solution if possible.

Leave it and create an issue for it? I'll have a play about with it next week.

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @dan-hughes)


.vscode/analyzersettings.psd1 line 36 at r4 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Leave it and create an issue for it? I'll have a play about with it next week.

Done. It did work using Set-Variable to set the global variable, which the rule ignored. But then I remembered we have a function Set‑DscMachineRebootRequired in DscResource.Common, so changed to that.


source/Classes/020.SqlRSSetup.ps1 line 191 at r7 (raw file):

    [DscProperty()]
    [ReportServerEdition]
    $Edition

Having an enum here really complicates things as it is optional. Get-DscProperty will return it as a property that are set even if it is not as it will be set to the default value 0 if not set. Assert-BoundParameters will always see Edition being set as it defaults to 0.

I will revert this to ValidateSet() - having an enum is not worth the extra code needed... for now. I think more work need to be done to handle enums this way. 🤔

Code quote:

    [ReportServerEdition]
    $Edition

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 46 of 49 files reviewed, 7 unresolved discussions (waiting on @dan-hughes)


source/Public/ConvertTo-SqlDscEditionName.ps1 line 82 at r4 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

Got you, will fix tomorrow. Hmm, they should probably be localized, guessing a Spanish SQL Server actually have Spanish names returned. 🤔 Fixing that too.

Done.

@dan-hughes
Copy link
Contributor

source/Classes/020.SqlRSSetup.ps1 line 191 at r7 (raw file):

    [DscProperty()]
    [ReportServerEdition]
    $Edition

Having an enum here really complicates things as it is optional. Get-DscProperty will return it as a property that are set even if it is not as it will be set to the default value 0 if not set. Assert-BoundParameters will always see Edition being set as it defaults to 0.

I will revert this to ValidateSet() - having an enum is not worth the extra code needed... for now. I think more work need to be done to handle enums this way. 🤔

Code quote:

    [ReportServerEdition]
    $Edition

It shouldn't do. You have enabled the feature flag which removes any Enum's with a zero value in GetDesiredState before being passed into AssertProperties.

@johlju
Copy link
Member Author

johlju commented May 1, 2025

@dan-hughes now all review comments should be resolved. I hade to revert the enum on the optional parameter, see comment. Not sure how to solve commands in DscResource.Base other than passing in a new parameter that switches behavior. 🤔 Anyway, I think that work is out of scope for this PR. 🙂

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 44 of 49 files reviewed, 7 unresolved discussions (waiting on @dan-hughes)


source/Classes/020.SqlRSSetup.ps1 line 191 at r7 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

It shouldn't do. You have enabled the feature flag which removes any Enum's with a zero value in GetDesiredState before being passed into AssertProperties.

Correct, checked now an Assert-BoundParameters should work in AssertProperties().

So it is only this line that does not work for this particular resource as it is getting the settings from the current instance to send to the public command.

$commandParameters = $this |
Get-DscProperty @getDscPropertyParameters

For that to work I would have to remove the Edition parameter if set to 0 after the call to Edition. I just don't see the benefit of having all the extra code just to have an enum 🤔

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 44 of 49 files reviewed, 7 unresolved discussions (waiting on @dan-hughes)


source/Classes/020.SqlRSSetup.ps1 line 191 at r7 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

Correct, checked now an Assert-BoundParameters should work in AssertProperties().

So it is only this line that does not work for this particular resource as it is getting the settings from the current instance to send to the public command.

$commandParameters = $this |
Get-DscProperty @getDscPropertyParameters

For that to work I would have to remove the Edition parameter if set to 0 after the call to Edition. I just don't see the benefit of having all the extra code just to have an enum 🤔

I meant to say... after the call to Get-dscProperty. 🙂

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 44 of 49 files reviewed, 7 unresolved discussions (waiting on @dan-hughes)


source/Classes/020.SqlRSSetup.ps1 line 191 at r7 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

I meant to say... after the call to Get-dscProperty. 🙂

We could extend Get-DscProperty with a switch parameter -IgnoreZeroEnumValue. But rather not do it for this PR. 🙂

Copy link
Contributor

@dan-hughes dan-hughes left a comment

Choose a reason for hiding this comment

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

Reviewed 5 of 5 files at r8, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @johlju)


source/Classes/020.SqlRSSetup.ps1 line 191 at r7 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

We could extend Get-DscProperty with a switch parameter -IgnoreZeroEnumValue. But rather not do it for this PR. 🙂

Move private function Clear-ZeroedEnumPropertyValue from .Base into .Common or just make it public as an option?


source/Classes/020.SqlRSSetup.ps1 line 237 at r8 (raw file):

        )

        $this.FeatureOptionalEnums = $true

This can now be removed as no optional Enums.

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @johlju)


source/Classes/020.SqlRSSetup.ps1 line 191 at r7 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

Move private function Clear-ZeroedEnumPropertyValue from .Base into .Common or just make it public?

Since .Base imports DscResource.Common, we could move it to DscResource.Common 🤔 If we make it public in Base then we need to import that as well in each modules prefix.ps1. 🤔 Best option might be moving it to Common. 🤔

Also added the issue: dsccommunity/DscResource.Common#150

Copy link
Member Author

@johlju johlju left a comment

Choose a reason for hiding this comment

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

Reviewable status: 48 of 49 files reviewed, 5 unresolved discussions (waiting on @dan-hughes)


source/Classes/020.SqlRSSetup.ps1 line 237 at r8 (raw file):

Previously, dan-hughes (Daniel Hughes) wrote…

This can now be removed as no optional Enums.

Done.

Copy link
Contributor

@dan-hughes dan-hughes left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r9, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @johlju)

@johlju
Copy link
Member Author

johlju commented May 1, 2025

Added issue #2101 to track re-adding the enum in the future. 🙂

@johlju johlju merged commit 603095d into dsccommunity:main May 1, 2025
58 of 59 checks passed
@johlju johlju deleted the f/refactor-SqlRSSetup branch May 1, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review The pull request needs a code review.
Projects
None yet
2 participants