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

Added New parameter ProductCoveredbySA that is introduced in SQL 2022 #2044

Merged
merged 50 commits into from
Sep 29, 2024

Conversation

sara921-spec
Copy link
Contributor

@sara921-spec sara921-spec commented Aug 27, 2024

This Pull Request (PR) fixes the following issues

Pull Request (PR) description

  • 'ProductCoveredbySA'
    • Added new parameter ProductCoveredbySA which is introduced in SQL 2022.

Adding parameter ProductCoveredbySA (introduced in sql 2022) into DSC_SqlSetup
Specifies the license coverage for SQL Server. True indicates it's covered under Software Assurance or SQL Server
subscription.
False, or omitting the parameter, indicates it's covered under a SQL Server license.
Default value is False.

This Pull Request (PR) fixes the following issues

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.

Reviewable

@sara921-spec sara921-spec requested a review from a team as a code owner August 27, 2024 10:03
Copy link

codecov bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94%. Comparing base (3c30929) to head (7de6c99).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #2044   +/-   ##
====================================
  Coverage    94%     94%           
====================================
  Files        94      94           
  Lines      7922    7930    +8     
====================================
+ Hits       7492    7500    +8     
  Misses      430     430           
Flag Coverage Δ
unit 94% <100%> (+<1%) ⬆️
Files with missing lines Coverage Δ
source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 98% <100%> (+<1%) ⬆️

@sara921-spec sara921-spec requested a review from johlju as a code owner August 27, 2024 11:40
Copy link
Member

@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.

Thank you for sending this in.

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @sara921-spec)

a discussion (no related file):
Please also update the schema: https://github.com/dsccommunity/SqlServerDsc/blob/main/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof



source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 line 1319 at r2 (raw file):

        {
            $setupArguments['ProductCoveredBySA'] = $false
        }

I think we can skip this? Omitting the parameter from the arguments is the same as saying /PRODUCTCOVEREDBYSA=False. It will also simplify the unit test cases needed.

Code quote:

        else
        {
            $setupArguments['ProductCoveredBySA'] = $false
        }

@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 Aug 27, 2024
Copy link
Member

@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, 3 unresolved discussions (waiting on @sara921-spec)


CHANGELOG.md line 11 at r2 (raw file):

- 'ProductCoveredbySA'
 - Added new parameter ProductCoveredbySA which in introduced in SQL 2022.

Suggest changing to the below. Use SqlSetup and make sure second entry is indented with 2 spaces for the list to render correctly.

Suggestion:

- SqlSetup
  - Added new parameter ProductCoveredbySA which in introduced in SQL 2022.

@johlju
Copy link
Member

johlju commented Aug 28, 2024

Happy to take a look, but might take a few days before I have time. 😊

Copy link
Member

@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.

Reviewed 1 of 4 files at r3, all commit messages.
Reviewable status: 1 of 4 files reviewed, 2 unresolved discussions (waiting on @sara921-spec)


source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 line 325 at r3 (raw file):

        {
           # Grab the value of ProductCoveredBySA from the registry based on the instance
           $getTargetResourceReturnValue.ProductCoveredBySA = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL$($SqlVersion).$($InstanceName)\Setup\IsProductCoveredBySA"

Instead of Get-ItemProperty, try using the helper function Get-RegistryPropertyValue: https://github.com/dsccommunity/SqlServerDsc/blob/3c3092976409645d74f58707331f66ffe1967127/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1#L18C10-L18C35

But you probably have to test that it actually can get the value in a real environment using the helper function. 🤔 .

Code quote:

Get-ItemProperty

@johlju
Copy link
Member

johlju commented Aug 29, 2024

If the above command (in the review comment) is able to get the value, then it will should resolve the error in the tests. If the command does not work, then you need to handle the error being thrown another way. 🙂

@sara921-spec
Copy link
Contributor Author

If the above command (in the review comment) is able to get the value, then it will should resolve the error in the tests. If the command does not work, then you need to handle the error being thrown another way. 🙂

@johlju This update to use "Get-RegistryPropertyValue" as suggested worked to pass the HKLM path errors, we have only 2 check failures now.

error - 'Conn' is not a valid value for setting 'FEATURES'.

@johlju
Copy link
Member

johlju commented Aug 30, 2024

The Feature CONN and some other features are not available in SQL Server 2022. I see you have enabled SQL Server 2022 (major version '16') for a bunch of tests which is good because that is really needed, but that is why it is failing. You need to make sure the correct values are passed to *-TargetResource and then evaluated the correct values where returned when the major version is 16. For example not calling the *-TargetResource with 'CONN' features parameter.

@sara921-spec
Copy link
Contributor Author

sara921-spec commented Sep 3, 2024

Hi @johlju What are the available features for 2022 or how to get that? any idea?

#1566

Seems "RS" is not valid too

Error: Context When installing a default instance for major version 16
Context When installing all features
##[error] [-] Should set the system in the desired state when feature is SQLENGINE 59ms (54ms|5ms)
##[error] Expected no exception to be thrown, but an exception "System.InvalidOperationException: 'Rs' is not a valid value for setting 'FEATURES'. Refer to SQL Help for more information." was thrown from D:\a\1\s\output\builtModule\SqlServerDsc\17.0.0\Modules\DscResource.Common\0.17.2\DscResource.Common.psm1:3755 char:9

@dan-hughes
Copy link

Just the last few bits left and I can pass it off to someone with merge rights :-).

No use splatting
Code snippet:

$getRegistryPropertyParams = @{
   Path = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL$($SqlVersion).$($InstanceName)\Setup"
   Name = 'IsProductCoveredBySA'
}

@dan-hughes Does it not needed to be passed like below? I mean for ($getTargetResourceReturnValue?) or that line is not needed? Thought we need that gettargetrespurcereturnvalue

$getTargetResourceReturnValue.ProductCoveredBySA = Get-RegistryPropertyValue @getRegistryPropertyParams

You are correct that is how you pass a splat to a command. The last commit you made looks to be good.

@dan-hughes
Copy link

@sara921-spec, run a format on the module file and commit again, it should fix the HQRM test.

@sara921-spec

This comment was marked as resolved.

@dan-hughes
Copy link

@dan-hughes It actually looked for single quotes as mentioned here https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#correct-format-for-hashtables-or-objects).,

I believe we are looking good now! do u see any other updates required?

The path string was not the issue, it was the formatting. I've just cloned your repo and opened it in VSCode.

image

If I put your double quotes back so the string has the correct values in and format it it looks like this.

image

@sara921-spec
Copy link
Contributor Author

sara921-spec commented Sep 24, 2024

@dan-hughes does it looks good now?

@dan-hughes
Copy link

@sara921-spec, I'll look at this over the weekend.

Copy link

@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.

Unit Tests:
ContextBlock 'When SQL Server version is and the system is not in the desired state for default instance'

  • It needs to add the check that the value is false.

source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 Outdated Show resolved Hide resolved
source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 Outdated Show resolved Hide resolved
source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 Outdated Show resolved Hide resolved
source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 Outdated Show resolved Hide resolved
tests/Unit/DSC_SqlSetup.Tests.ps1 Outdated Show resolved Hide resolved
tests/Unit/DSC_SqlSetup.Tests.ps1 Outdated Show resolved Hide resolved
tests/Unit/DSC_SqlSetup.Tests.ps1 Outdated Show resolved Hide resolved
tests/Unit/DSC_SqlSetup.Tests.ps1 Outdated Show resolved Hide resolved
@sara921-spec
Copy link
Contributor Author

Unit Tests: ContextBlock 'When SQL Server version is and the system is not in the desired state for default instance'

  • It needs to add the check that the value is false.

@dan-hughes False for the parameter productcoveredbysa? In the past johan had the below thought (or am I not reading your request correctly?)

image

@dan-hughes
Copy link

Unit Tests: ContextBlock 'When SQL Server version is and the system is not in the desired state for default instance'

  • It needs to add the check that the value is false.

@dan-hughes False for the parameter productcoveredbysa? In the past johan had the below thought (or am I not reading your request correctly?)

image

Apologies for not being clear,

It was more of adding the $result.ProductCoveredBySA | Should -BeFalse check here for the as the resource should return the default value for the type.

It looks like you have resolved all the other issues so once this is done and it builds it's good to go.

@dan-hughes
Copy link

I'm not sure where I got that Context block title from though as I've just searched and cannot find it!

@@ -2707,6 +2823,52 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' {
}
}

Context 'When installing the database engine and ProductcoveredBySA is true' {

Choose a reason for hiding this comment

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

I'm not in front of a big enough screen to look at the whole test file, but this test looks to be a copy + paste of the test added at line 2484. Is this supposed to be here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, line 2826 is the actual test, I don't know how 2484 got there, I should have misplaced it somehow. let me remove it

Copy link
Contributor Author

@sara921-spec sara921-spec Sep 29, 2024

Choose a reason for hiding this comment

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

@dan-hughes all set I guess -:)

@johlju
Copy link
Member

johlju commented Sep 29, 2024

@sara921-spec awesome work on this, thank you! Also big thanks to @dan-hughes for the review! 🙇‍♂️

@johlju johlju merged commit dd56306 into dsccommunity:main Sep 29, 2024
43 of 44 checks passed
@johlju johlju removed 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 Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New parameter productcoveredbysa : Command proposal
4 participants