Skip to content

Commit

Permalink
Assert-SetupActionProperties: Use commands from DscResource.Common (#…
Browse files Browse the repository at this point in the history
…1828)

- SqlServerDsc
  - Removed `Test-ServiceAccountRequirePassword` from private functions (issue #1794)
    - Replaced by `Test-AccountRequirePassword` that was added to _DscResource.Common_
      public functions ([issue #93](dsccommunity/DscResource.Common#93)).
  - Removed `Assert-RequiredCommandParameter` from private functions (issue #1796).
    - Replaced by `Assert-BoundParameter` (part of _DscResource.Common_)
      that had a new parameter set added ([issue #92](dsccommunity/DscResource.Common#92)).
  • Loading branch information
johlju authored Jan 2, 2023
1 parent 31abc0a commit 2408ab5
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 366 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@
},
"powershell.pester.useLegacyCodeLens": false,
"pester.testFilePath": [
"[tT]ests/[qQ][aA]/*.[tT]ests.[pP][sS]1",
"[tT]ests/[uU]nit/**/*.[tT]ests.[pP][sS]1",
"[tT]ests/[uU]nit/*.[tT]ests.[pP][sS]1"
],
"pester.runTestsInNewProcess": false,
"pester.runTestsInNewProcess": true,
"pester.pesterModulePath": "./output/RequiredModules/Pester",
"powershell.pester.codeLens": true,
"pester.suppressCodeLensNotice": true
Expand Down
19 changes: 15 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- SqlServerDsc
- Removed `Assert-ElevatedUser` from private functions - [Issue #1797](https://github.com/dsccommunity/SqlServerDsc/issues/1797)
- `Assert-ElevatedUser` added to _DscResource.Common_ public functions - [Issue #82](https://github.com/dsccommunity/DscResource.Common/issues/82)
- Removed `Test-IsNumericType` from private functions - [Issue #1795](https://github.com/dsccommunity/SqlServerDsc/issues/1795)
- `Test-IsNumericType` added to _DscResource.Common_ public functions - [Issue #87](https://github.com/dsccommunity/DscResource.Common/issues/87)
- `Assert-ElevatedUser` added to _DscResource.Common_ public functions
([issue #82](https://github.com/dsccommunity/DscResource.Common/issues/82)).
- Removed `Test-IsNumericType` from private functions ([issue #1795](https://github.com/dsccommunity/SqlServerDsc/issues/1795)).
- `Test-IsNumericType` added to _DscResource.Common_ public functions
([issue #87](https://github.com/dsccommunity/DscResource.Common/issues/87)).
- Removed `Test-ServiceAccountRequirePassword` from private functions ([issue #1794](https://github.com/dsccommunity/SqlServerDsc/issues/1794)
- Replaced by `Test-AccountRequirePassword` that was added to _DscResource.Common_
public functions ([issue #93](https://github.com/dsccommunity/DscResource.Common/issues/93)).
- Removed `Assert-RequiredCommandParameter` from private functions ([issue #1796](https://github.com/dsccommunity/SqlServerDsc/issues/1796)).
- Replaced by `Assert-BoundParameter` (part of _DscResource.Common_)
that had a new parameter set added ([issue #92](https://github.com/dsccommunity/DscResource.Common/issues/92)).

### Added

- SqlServerDsc
- The following private functions were added to the module (see comment-based
help for more information):
- `Assert-RequiredCommandParameter`
- `Assert-SetupActionProperties`
- `Invoke-SetupAction`
- The following public functions were added to the module (see comment-based
Expand Down Expand Up @@ -60,6 +67,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update to build module in separate folder under `output`.
- Moved the build step of the pipeline to a Windows build worker when
running in Azure DevOps.
- Settings for the _Visual Studio Code_ extension _Pester Tests_ was changed
to be able to run all unit tests, and all tests run by the extension
are now run in a separate process to be able to handle changes in
class-based resources.
- `Install-SqlServerDsc`
- No longer throws an exception when parameter `AgtSvcAccount` is not specified.
- SqlAgReplica
Expand Down
93 changes: 0 additions & 93 deletions source/Private/Assert-RequiredCommandParameter.ps1

This file was deleted.

26 changes: 13 additions & 13 deletions source/Private/Assert-SetupActionProperties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ function Assert-SetupActionProperties
$assertParameters = @('PBStartPortRange', 'PBEndPortRange')

$assertRequiredCommandParameterParameters = @{
BoundParameter = $Property
BoundParameterList = $Property
RequiredParameter = $assertParameters
IfParameterPresent = $assertParameters
}

Assert-RequiredCommandParameter @assertRequiredCommandParameterParameters
Assert-BoundParameter @assertRequiredCommandParameterParameters

# The parameter UseSqlRecommendedMemoryLimits is mutually exclusive to SqlMinMemory and SqlMaxMemory.
Assert-BoundParameter -BoundParameterList $Property -MutuallyExclusiveList1 @(
Expand All @@ -60,7 +60,7 @@ function Assert-SetupActionProperties
# If Role is set to SPI_AS_NewFarm then the specific parameters are required.
if ($Property.ContainsKey('Role') -and $Property.Role -eq 'SPI_AS_NewFarm')
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @(
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @(
'FarmAccount'
'FarmPassword'
'Passphrase'
Expand All @@ -71,13 +71,13 @@ function Assert-SetupActionProperties
# If the parameter SecurityMode is set to 'SQL' then the parameter SAPwd is required.
if ($Property.ContainsKey('SecurityMode') -and $Property.SecurityMode -eq 'SQL')
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @('SAPwd')
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @('SAPwd')
}

# If the parameter FileStreamLevel is set and is greater or equal to 2 then the parameter FileStreamShareName is required.
if ($Property.ContainsKey('FileStreamLevel') -and $Property.FileStreamLevel -ge 2)
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @('FileStreamShareName')
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @('FileStreamShareName')
}

# If a *SvcAccount is specified then the accompanying *SvcPassword must be set unless it is a (global) managed service account, virtual account, or a built-in account.
Expand All @@ -97,19 +97,19 @@ function Assert-SetupActionProperties
if ($currentAccountProperty -in $Property.Keys)
{
# If not (global) managed service account, virtual account, or a built-in account.
if ((Test-ServiceAccountRequirePassword -Name $Property.$currentAccountProperty))
if ((Test-AccountRequirePassword -Name $Property.$currentAccountProperty))
{
$assertPropertyName = $currentAccountProperty -replace 'Account', 'Password'

Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter $assertPropertyName
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter $assertPropertyName
}
}
}

# If feature AzureExtension is specified then the all the Azure* parameters must be set (except AzureArcProxy).
if ($Property.ContainsKey('Features') -and $Property.Features -contains 'AZUREEXTENSION') # cSpell: disable-line
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @(
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @(
'AzureSubscriptionId'
'AzureResourceGroup'
'AzureRegion'
Expand All @@ -125,7 +125,7 @@ function Assert-SetupActionProperties
{
if ($Property.ContainsKey('Features') -and $Property.Features -contains 'SQLENGINE')
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @('AgtSvcAccount')
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @('AgtSvcAccount')
}
}

Expand All @@ -134,24 +134,24 @@ function Assert-SetupActionProperties
# The parameter ASSvcAccount is mandatory if feature AS is installed and setup action is InstallFailoverCluster, PrepareFailoverCluster, or AddNode.
if ($Property.ContainsKey('Features') -and $Property.Features -contains 'AS')
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @('ASSvcAccount')
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @('ASSvcAccount')
}

# The parameter SqlSvcAccount is mandatory if feature SQLENGINE is installed and setup action is InstallFailoverCluster, PrepareFailoverCluster, or AddNode.
if ($Property.ContainsKey('Features') -and $Property.Features -contains 'SQLENGINE')
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @('SqlSvcAccount')
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @('SqlSvcAccount')
}

# The parameter ISSvcAccount is mandatory if feature IS is installed and setup action is InstallFailoverCluster, PrepareFailoverCluster, or AddNode.
if ($Property.ContainsKey('Features') -and $Property.Features -contains 'IS')
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @('ISSvcAccount')
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @('ISSvcAccount')
}

if ($Property.ContainsKey('Features') -and $Property.Features -contains 'RS')
{
Assert-RequiredCommandParameter -BoundParameter $Property -RequiredParameter @('RSSvcAccount')
Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @('RSSvcAccount')
}
}

Expand Down
58 changes: 0 additions & 58 deletions source/Private/Test-ServiceAccountRequirePassword.ps1

This file was deleted.

4 changes: 0 additions & 4 deletions source/en-US/SqlServerDsc.strings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ ConvertFrom-StringData @'
Server_MediaPathNotFound = The specified media path does not exist or does not contain 'setup.exe'.
Server_ConfigurationFileNotFound = The specified configuration file was not found.
## Assert-RequiredCommandParameter
RequiredCommandParameter_SpecificParametersMustAllBeSet = The parameters '{0}' must all be specified.
RequiredCommandParameter_SpecificParametersMustAllBeSetWhenParameterExist = The parameters '{0}' must all be specified if either parameter '{1}' is specified.
## Assert-SetupActionProperties
InstallSqlServerProperties_ASServerModeInvalidValue = The value for ASServerMode is not valid for the setup action {0}.
InstallSqlServerProperties_RsInstallModeInvalidValue = The only valid value for RsInstallMode is 'FilesOnlyMode' when using setup action {0}.
Expand Down
Loading

0 comments on commit 2408ab5

Please sign in to comment.