From ca580d97e48a2e377a63053be9931282214ec5f5 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 4 Mar 2023 10:45:57 +0100 Subject: [PATCH 1/3] Updated Assert-SetupActionProperties --- CHANGELOG.md | 9 +++++++++ source/Private/Assert-SetupActionProperties.ps1 | 17 +++++++++++++++++ .../Assert-SetupActionProperties.Tests.ps1 | 16 +++++++++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13e1341e8..0c4c6fa25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,15 @@ 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`. + ## [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/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 @{ From bf6f9f4a1ff5b6d1aaa4bf9e8e641ffff2cde10c Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 4 Mar 2023 10:49:01 +0100 Subject: [PATCH 2/3] Update Invoke-SetupAction --- CHANGELOG.md | 4 ++++ source/Private/Invoke-SetupAction.ps1 | 2 +- tests/Unit/Private/Invoke-SetupAction.Tests.ps1 | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c4c6fa25..3cfe83b91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([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. + ## [16.1.0] - 2023-02-28 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/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' From d8b44651181142f92fc0906931e96ea1ab993660 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sat, 4 Mar 2023 10:49:18 +0100 Subject: [PATCH 3/3] Update Install-SqlDscServer --- CHANGELOG.md | 4 +++- source/Public/Install-SqlDscServer.ps1 | 2 +- tests/Unit/Public/Install-SqlDscServer.Tests.ps1 | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3cfe83b91..cb72a82f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `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 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/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'