From e65a41062e53b8e6618fc7696caca301b94eea88 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 4 Mar 2023 14:05:14 +0100 Subject: [PATCH] `Install-SqlDscServer`: Fix `ASSysAdminAccounts` and `SqlSysAdminAccounts` (#1863) - `Assert-SetupActionProperties` - Now throws an exception if the setup action is `Install` and the feature analysis services is specified without the parameter `ASSysAdminAccounts` (issue #1845). - Now throws an exception if the setup action is `Install` and the feature database engine is specified without the parameter `SqlSysAdminAccounts`. - `Invoke-SetupAction` - The parameter `SqlSysAdminAccounts` is no longer mandatory to allow installation where the database engine is not installed. - `Install-SqlDscServer` - The parameter `SqlSysAdminAccounts` is no longer mandatory to allow installation where the database engine is not installed. --- CHANGELOG.md | 15 +++++++++++++++ source/Private/Assert-SetupActionProperties.ps1 | 17 +++++++++++++++++ source/Private/Invoke-SetupAction.ps1 | 2 +- source/Public/Install-SqlDscServer.ps1 | 2 +- .../Assert-SetupActionProperties.Tests.ps1 | 16 +++++++++++++--- tests/Unit/Private/Invoke-SetupAction.Tests.ps1 | 2 +- .../Unit/Public/Install-SqlDscServer.Tests.ps1 | 2 +- 7 files changed, 49 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13e1341e8..cb72a82f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The private function `Import-SQLPSModule` was replaced throughout with the public command `Import-SqlDscPreferredModule` ([issue #1848](https://github.com/dsccommunity/SqlServerDsc/issues/1848)). +### Fixed + +- `Assert-SetupActionProperties` + - Now throws an exception if the setup action is `Install` and the feature + analysis services is specified without the parameter `ASSysAdminAccounts` + ([issue #1845](https://github.com/dsccommunity/SqlServerDsc/issues/1845)). + - Now throws an exception if the setup action is `Install` and the feature + database engine is specified without the parameter `SqlSysAdminAccounts`. +- `Invoke-SetupAction` + - The parameter `SqlSysAdminAccounts` is no longer mandatory to allow + installation where the database engine is not installed. +- `Install-SqlDscServer` + - The parameter `SqlSysAdminAccounts` is no longer mandatory to allow + installation where the database engine is not installed. + ## [16.1.0] - 2023-02-28 ### Removed diff --git a/source/Private/Assert-SetupActionProperties.ps1 b/source/Private/Assert-SetupActionProperties.ps1 index b2d95d6e5..a39445c66 100644 --- a/source/Private/Assert-SetupActionProperties.ps1 +++ b/source/Private/Assert-SetupActionProperties.ps1 @@ -187,4 +187,21 @@ function Assert-SetupActionProperties ) } } + + if ($SetupAction -in ('Install')) + { + if ($Property.ContainsKey('Features') -and $Property.Features -contains 'SQLENGINE') + { + Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @( + 'SqlSysAdminAccounts' + ) + } + + if ($Property.ContainsKey('Features') -and $Property.Features -contains 'AS') + { + Assert-BoundParameter -BoundParameterList $Property -RequiredParameter @( + 'ASSysAdminAccounts' + ) + } + } } diff --git a/source/Private/Invoke-SetupAction.ps1 b/source/Private/Invoke-SetupAction.ps1 index ea797540c..aacfc1732 100644 --- a/source/Private/Invoke-SetupAction.ps1 +++ b/source/Private/Invoke-SetupAction.ps1 @@ -1031,7 +1031,7 @@ function Invoke-SetupAction [System.String] $SqlSvcStartupType, - [Parameter(ParameterSetName = 'Install', Mandatory = $true)] + [Parameter(ParameterSetName = 'Install')] [Parameter(ParameterSetName = 'CompleteImage')] [Parameter(ParameterSetName = 'RebuildDatabase', Mandatory = $true)] [Parameter(ParameterSetName = 'InstallFailoverCluster', Mandatory = $true)] diff --git a/source/Public/Install-SqlDscServer.ps1 b/source/Public/Install-SqlDscServer.ps1 index 03785e2b1..fe724f020 100644 --- a/source/Public/Install-SqlDscServer.ps1 +++ b/source/Public/Install-SqlDscServer.ps1 @@ -854,7 +854,7 @@ function Install-SqlDscServer [System.String] $SqlSvcStartupType, - [Parameter(ParameterSetName = 'Install', Mandatory = $true)] + [Parameter(ParameterSetName = 'Install')] [Parameter(ParameterSetName = 'InstallFailoverCluster', Mandatory = $true)] [Parameter(ParameterSetName = 'InstallRole')] [System.String[]] diff --git a/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 b/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 index 75160d0db..33e33a7e8 100644 --- a/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 +++ b/tests/Unit/Private/Assert-SetupActionProperties.Tests.ps1 @@ -488,8 +488,18 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { MockMissingParameterName = 'RSSvcAccount' MockFeature = 'RS' } + @{ + MockSetupAction = 'Install' + MockFeature = 'AS' + MockMissingParameterName = 'ASSysAdminAccounts' + } + @{ + MockSetupAction = 'Install' + MockFeature = 'SQLENGINE' + MockMissingParameterName = 'SqlSysAdminAccounts' + } ) { - It 'Should not throw an exception' { + It 'Should throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { { Assert-SetupActionProperties -Property @{ @@ -508,7 +518,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { MockSetupAction = 'CompleteFailoverCluster' } ) { - It 'Should not throw an exception' { + It 'Should throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { { Assert-SetupActionProperties -Property @{ @@ -524,7 +534,7 @@ Describe 'Assert-SetupActionProperties' -Tag 'Private' { MockSetupAction = 'AddNode' } ) { - It 'Should not throw an exception' { + It 'Should throw an exception' { InModuleScope -Parameters $_ -ScriptBlock { { Assert-SetupActionProperties -Property @{ diff --git a/tests/Unit/Private/Invoke-SetupAction.Tests.ps1 b/tests/Unit/Private/Invoke-SetupAction.Tests.ps1 index 44a04161d..2729a8315 100644 --- a/tests/Unit/Private/Invoke-SetupAction.Tests.ps1 +++ b/tests/Unit/Private/Invoke-SetupAction.Tests.ps1 @@ -52,7 +52,7 @@ Describe 'Invoke-SetupAction' -Tag 'Private' { @{ MockParameterSetName = 'Install' # cSpell: disable-next - MockExpectedParameters = '-Install -AcceptLicensingTerms -MediaPath -InstanceName -Features -SqlSysAdminAccounts [-SuppressPrivacyStatementNotice] [-IAcknowledgeEntCalLimits] [-Enu] [-UpdateEnabled] [-UpdateSource ] [-InstallSharedDir ] [-InstallSharedWowDir ] [-InstanceDir ] [-InstanceId ] [-PBEngSvcAccount ] [-PBEngSvcPassword ] [-PBEngSvcStartupType ] [-PBDMSSvcAccount ] [-PBDMSSvcPassword ] [-PBDMSSvcStartupType ] [-PBStartPortRange ] [-PBEndPortRange ] [-PBScaleOut] [-ProductKey ] [-AgtSvcAccount ] [-AgtSvcPassword ] [-AgtSvcStartupType ] [-ASBackupDir ] [-ASCollation ] [-ASConfigDir ] [-ASDataDir ] [-ASLogDir ] [-ASTempDir ] [-ASServerMode ] [-ASSvcAccount ] [-ASSvcPassword ] [-ASSvcStartupType ] [-ASSysAdminAccounts ] [-ASProviderMSOLAP] [-BrowserSvcStartupType ] [-EnableRanU] [-InstallSqlDataDir ] [-SqlBackupDir ] [-SecurityMode ] [-SAPwd ] [-SqlCollation ] [-SqlSvcAccount ] [-SqlSvcPassword ] [-SqlSvcStartupType ] [-SqlTempDbDir ] [-SqlTempDbLogDir ] [-SqlTempDbFileCount ] [-SqlTempDbFileSize ] [-SqlTempDbFileGrowth ] [-SqlTempDbLogFileSize ] [-SqlTempDbLogFileGrowth ] [-SqlUserDbDir ] [-SqlSvcInstantFileInit] [-SqlUserDbLogDir ] [-SqlMaxDop ] [-UseSqlRecommendedMemoryLimits] [-SqlMinMemory ] [-SqlMaxMemory ] [-FileStreamLevel ] [-FileStreamShareName ] [-ISSvcAccount ] [-ISSvcPassword ] [-ISSvcStartupType ] [-NpEnabled] [-TcpEnabled] [-RsInstallMode ] [-RSSvcAccount ] [-RSSvcPassword ] [-RSSvcStartupType ] [-MPYCacheDirectory ] [-MRCacheDirectory ] [-SqlInstJava] [-SqlJavaDir ] [-AzureSubscriptionId ] [-AzureResourceGroup ] [-AzureRegion ] [-AzureTenantId ] [-AzureServicePrincipal ] [-AzureServicePrincipalSecret ] [-AzureArcProxy ] [-SkipRules ] [-ProductCoveredBySA] [-Timeout ] [-Force] [-WhatIf] [-Confirm] []' + MockExpectedParameters = '-Install -AcceptLicensingTerms -MediaPath -InstanceName -Features [-SuppressPrivacyStatementNotice] [-IAcknowledgeEntCalLimits] [-Enu] [-UpdateEnabled] [-UpdateSource ] [-InstallSharedDir ] [-InstallSharedWowDir ] [-InstanceDir ] [-InstanceId ] [-PBEngSvcAccount ] [-PBEngSvcPassword ] [-PBEngSvcStartupType ] [-PBDMSSvcAccount ] [-PBDMSSvcPassword ] [-PBDMSSvcStartupType ] [-PBStartPortRange ] [-PBEndPortRange ] [-PBScaleOut] [-ProductKey ] [-AgtSvcAccount ] [-AgtSvcPassword ] [-AgtSvcStartupType ] [-ASBackupDir ] [-ASCollation ] [-ASConfigDir ] [-ASDataDir ] [-ASLogDir ] [-ASTempDir ] [-ASServerMode ] [-ASSvcAccount ] [-ASSvcPassword ] [-ASSvcStartupType ] [-ASSysAdminAccounts ] [-ASProviderMSOLAP] [-BrowserSvcStartupType ] [-EnableRanU] [-InstallSqlDataDir ] [-SqlBackupDir ] [-SecurityMode ] [-SAPwd ] [-SqlCollation ] [-SqlSvcAccount ] [-SqlSvcPassword ] [-SqlSvcStartupType ] [-SqlSysAdminAccounts ] [-SqlTempDbDir ] [-SqlTempDbLogDir ] [-SqlTempDbFileCount ] [-SqlTempDbFileSize ] [-SqlTempDbFileGrowth ] [-SqlTempDbLogFileSize ] [-SqlTempDbLogFileGrowth ] [-SqlUserDbDir ] [-SqlSvcInstantFileInit] [-SqlUserDbLogDir ] [-SqlMaxDop ] [-UseSqlRecommendedMemoryLimits] [-SqlMinMemory ] [-SqlMaxMemory ] [-FileStreamLevel ] [-FileStreamShareName ] [-ISSvcAccount ] [-ISSvcPassword ] [-ISSvcStartupType ] [-NpEnabled] [-TcpEnabled] [-RsInstallMode ] [-RSSvcAccount ] [-RSSvcPassword ] [-RSSvcStartupType ] [-MPYCacheDirectory ] [-MRCacheDirectory ] [-SqlInstJava] [-SqlJavaDir ] [-AzureSubscriptionId ] [-AzureResourceGroup ] [-AzureRegion ] [-AzureTenantId ] [-AzureServicePrincipal ] [-AzureServicePrincipalSecret ] [-AzureArcProxy ] [-SkipRules ] [-ProductCoveredBySA] [-Timeout ] [-Force] [-WhatIf] [-Confirm] []' } @{ MockParameterSetName = 'InstallRole' diff --git a/tests/Unit/Public/Install-SqlDscServer.Tests.ps1 b/tests/Unit/Public/Install-SqlDscServer.Tests.ps1 index 3779a5480..152a4afb5 100644 --- a/tests/Unit/Public/Install-SqlDscServer.Tests.ps1 +++ b/tests/Unit/Public/Install-SqlDscServer.Tests.ps1 @@ -52,7 +52,7 @@ Describe 'Install-SqlDscServer' -Tag 'Public' { @{ MockParameterSetName = 'Install' # cSpell: disable-next - MockExpectedParameters = '-Install -AcceptLicensingTerms -MediaPath -InstanceName -Features -SqlSysAdminAccounts [-SuppressPrivacyStatementNotice] [-IAcknowledgeEntCalLimits] [-Enu] [-UpdateEnabled] [-UpdateSource ] [-InstallSharedDir ] [-InstallSharedWowDir ] [-InstanceDir ] [-InstanceId ] [-PBEngSvcAccount ] [-PBEngSvcPassword ] [-PBEngSvcStartupType ] [-PBDMSSvcAccount ] [-PBDMSSvcPassword ] [-PBDMSSvcStartupType ] [-PBStartPortRange ] [-PBEndPortRange ] [-PBScaleOut] [-ProductKey ] [-AgtSvcAccount ] [-AgtSvcPassword ] [-AgtSvcStartupType ] [-ASBackupDir ] [-ASCollation ] [-ASConfigDir ] [-ASDataDir ] [-ASLogDir ] [-ASTempDir ] [-ASServerMode ] [-ASSvcAccount ] [-ASSvcPassword ] [-ASSvcStartupType ] [-ASSysAdminAccounts ] [-ASProviderMSOLAP] [-BrowserSvcStartupType ] [-EnableRanU] [-InstallSqlDataDir ] [-SqlBackupDir ] [-SecurityMode ] [-SAPwd ] [-SqlCollation ] [-SqlSvcAccount ] [-SqlSvcPassword ] [-SqlSvcStartupType ] [-SqlTempDbDir ] [-SqlTempDbLogDir ] [-SqlTempDbFileCount ] [-SqlTempDbFileSize ] [-SqlTempDbFileGrowth ] [-SqlTempDbLogFileSize ] [-SqlTempDbLogFileGrowth ] [-SqlUserDbDir ] [-SqlSvcInstantFileInit] [-SqlUserDbLogDir ] [-SqlMaxDop ] [-UseSqlRecommendedMemoryLimits] [-SqlMinMemory ] [-SqlMaxMemory ] [-FileStreamLevel ] [-FileStreamShareName ] [-ISSvcAccount ] [-ISSvcPassword ] [-ISSvcStartupType ] [-NpEnabled] [-TcpEnabled] [-RsInstallMode ] [-RSSvcAccount ] [-RSSvcPassword ] [-RSSvcStartupType ] [-MPYCacheDirectory ] [-MRCacheDirectory ] [-SqlInstJava] [-SqlJavaDir ] [-AzureSubscriptionId ] [-AzureResourceGroup ] [-AzureRegion ] [-AzureTenantId ] [-AzureServicePrincipal ] [-AzureServicePrincipalSecret ] [-AzureArcProxy ] [-SkipRules ] [-ProductCoveredBySA] [-Timeout ] [-Force] [-WhatIf] [-Confirm] []' + MockExpectedParameters = '-Install -AcceptLicensingTerms -MediaPath -InstanceName -Features [-SuppressPrivacyStatementNotice] [-IAcknowledgeEntCalLimits] [-Enu] [-UpdateEnabled] [-UpdateSource ] [-InstallSharedDir ] [-InstallSharedWowDir ] [-InstanceDir ] [-InstanceId ] [-PBEngSvcAccount ] [-PBEngSvcPassword ] [-PBEngSvcStartupType ] [-PBDMSSvcAccount ] [-PBDMSSvcPassword ] [-PBDMSSvcStartupType ] [-PBStartPortRange ] [-PBEndPortRange ] [-PBScaleOut] [-ProductKey ] [-AgtSvcAccount ] [-AgtSvcPassword ] [-AgtSvcStartupType ] [-ASBackupDir ] [-ASCollation ] [-ASConfigDir ] [-ASDataDir ] [-ASLogDir ] [-ASTempDir ] [-ASServerMode ] [-ASSvcAccount ] [-ASSvcPassword ] [-ASSvcStartupType ] [-ASSysAdminAccounts ] [-ASProviderMSOLAP] [-BrowserSvcStartupType ] [-EnableRanU] [-InstallSqlDataDir ] [-SqlBackupDir ] [-SecurityMode ] [-SAPwd ] [-SqlCollation ] [-SqlSvcAccount ] [-SqlSvcPassword ] [-SqlSvcStartupType ] [-SqlSysAdminAccounts ] [-SqlTempDbDir ] [-SqlTempDbLogDir ] [-SqlTempDbFileCount ] [-SqlTempDbFileSize ] [-SqlTempDbFileGrowth ] [-SqlTempDbLogFileSize ] [-SqlTempDbLogFileGrowth ] [-SqlUserDbDir ] [-SqlSvcInstantFileInit] [-SqlUserDbLogDir ] [-SqlMaxDop ] [-UseSqlRecommendedMemoryLimits] [-SqlMinMemory ] [-SqlMaxMemory ] [-FileStreamLevel ] [-FileStreamShareName ] [-ISSvcAccount ] [-ISSvcPassword ] [-ISSvcStartupType ] [-NpEnabled] [-TcpEnabled] [-RsInstallMode ] [-RSSvcAccount ] [-RSSvcPassword ] [-RSSvcStartupType ] [-MPYCacheDirectory ] [-MRCacheDirectory ] [-SqlInstJava] [-SqlJavaDir ] [-AzureSubscriptionId ] [-AzureResourceGroup ] [-AzureRegion ] [-AzureTenantId ] [-AzureServicePrincipal ] [-AzureServicePrincipalSecret ] [-AzureArcProxy ] [-SkipRules ] [-ProductCoveredBySA] [-Timeout ] [-Force] [-WhatIf] [-Confirm] []' } @{ MockParameterSetName = 'InstallRole'