From 87e4d5cb45117ee38c8739c55fb2125b614089ab Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 3 May 2020 12:16:48 +0200 Subject: [PATCH] SqlSetup: Added the properties NpEnabled and TcpEnabled (issue #1161) --- CHANGELOG.md | 1 + README.md | 6 ++ .../DSC_SqlSetup/DSC_SqlSetup.psm1 | 70 +++++++++++++++++-- .../DSC_SqlSetup/DSC_SqlSetup.schema.mof | 2 + .../1-InstallDefaultInstanceSingleServer.ps1 | 2 + tests/Integration/DSC_SqlSetup.config.ps1 | 2 + tests/Unit/DSC_SqlSetup.Tests.ps1 | 8 ++- 7 files changed, 83 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7628737a2..69c83fca8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) - SqlSetup - A read only property `IsClustered` was added that can be used to determine if the instance is clustered. + - Added the properties `NpEnabled` and `TcpEnabled` ([issue #1161](https://github.com/dsccommunity/SqlServerDsc/issues/1161)). ### Changed diff --git a/README.md b/README.md index 3874099cec..004039a10c 100644 --- a/README.md +++ b/README.md @@ -2035,6 +2035,12 @@ with different sizes and growths. of each tempdb log file in MB. * **`[UInt32]` SqlTempdbLogFileGrowth** _(Write)_: Specifies the file growth increment of each tempdb data file in MB. +* **`[Boolean]` NpEnabled** _(Write)_: Specifies the state of the Named Pipes + protocol for the SQL Server service. The value $true will enable the Named + Pipes protocol and $false will disabled it. +* **`[Boolean]` TcpEnabled** _(Write)_: Specifies the state of the TCP protocol + for the SQL Server service. The value $true will enable the TCP protocol and + $false will disabled it. * **`[UInt32]` SetupProcessTimeout** _(Write)_: The timeout, in seconds, to wait for the setup process to finish. Default value is 7200 seconds (2 hours). If the setup process does not finish before this time, and error will be thrown. diff --git a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 index 18bc116652..0f18f424ff 100644 --- a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 +++ b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 @@ -605,6 +605,15 @@ function Get-TargetResource .PARAMETER SqlTempdbLogFileGrowth Specifies the file growth increment of each tempdb data file in MB. + .PARAMETER NpEnabled + Specifies the state of the Named Pipes protocol for the SQL Server service. + The value $true will enable the Named Pipes protocol and $false will disabled + it. + + .PARAMETER TcpEnabled + Specifies the state of the TCP protocol for the SQL Server service. The + value $true will enable the TCP protocol and $false will disabled it. + .PARAMETER SetupProcessTimeout The timeout, in seconds, to wait for the setup process to finish. Default value is 7200 seconds (2 hours). If the setup process does not finish before @@ -860,6 +869,14 @@ function Set-TargetResource [System.UInt32] $SqlTempdbLogFileGrowth, + [Parameter()] + [System.Boolean] + $NpEnabled, + + [Parameter()] + [System.Boolean] + $TcpEnabled, + [Parameter()] [System.UInt32] $SetupProcessTimeout = 7200, @@ -1246,6 +1263,30 @@ function Set-TargetResource $setupArguments['SQLSysAdminAccounts'] += $SQLSysAdminAccounts } + if ($PSBoundParameters.ContainsKey('NpEnabled')) + { + if ($NpEnabled) + { + $setupArguments['NPENABLED'] = 1 + } + else + { + $setupArguments['NPENABLED'] = 0 + } + } + + if ($PSBoundParameters.ContainsKey('TcpEnabled')) + { + if ($TcpEnabled) + { + $setupArguments['TCPENABLED'] = 1 + } + else + { + $setupArguments['TCPENABLED'] = 0 + } + } + $argumentVars += @( 'SecurityMode', 'SQLCollation', @@ -1418,18 +1459,14 @@ function Set-TargetResource { if ($argument -eq 'ProductKey') { - $setupArguments += @{ - 'PID' = (Get-Variable -Name $argument -ValueOnly) - } + $setupArguments['PID'] = Get-Variable -Name $argument -ValueOnly } else { # If the argument contains a value, then add the argument to the setup argument list if (Get-Variable -Name $argument -ValueOnly) { - $setupArguments += @{ - $argument = (Get-Variable -Name $argument -ValueOnly) - } + $setupArguments[$argument] = Get-Variable -Name $argument -ValueOnly } } } @@ -1781,6 +1818,19 @@ function Set-TargetResource .PARAMETER SqlTempdbLogFileGrowth Specifies the file growth increment of each tempdb data file in MB. + .PARAMETER NpEnabled + Specifies the state of the Named Pipes protocol for the SQL Server service. + The value $true will enable the Named Pipes protocol and $false will disabled + it. + + Not used in Test-TargetResource. + + .PARAMETER TcpEnabled + Specifies the state of the TCP protocol for the SQL Server service. The + value $true will enable the TCP protocol and $false will disabled it. + + Not used in Test-TargetResource. + .PARAMETER SetupProcessTimeout The timeout, in seconds, to wait for the setup process to finish. Default value is 7200 seconds (2 hours). If the setup process does not finish before @@ -2027,6 +2077,14 @@ function Test-TargetResource [System.UInt32] $SqlTempdbLogFileGrowth, + [Parameter()] + [System.Boolean] + $NpEnabled, + + [Parameter()] + [System.Boolean] + $TcpEnabled, + [Parameter()] [System.UInt32] $SetupProcessTimeout = 7200, diff --git a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof index 55b2807411..a8caa42741 100644 --- a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof +++ b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.schema.mof @@ -62,6 +62,8 @@ class DSC_SqlSetup : OMI_BaseResource [Write, Description("Specifies the file growth increment of each tempdb data file in MB.")] UInt32 SqlTempdbFileGrowth; [Write, Description("Specifies the initial size of each tempdb log file in MB.")] UInt32 SqlTempdbLogFileSize; [Write, Description("Specifies the file growth increment of each tempdb data file in MB.")] UInt32 SqlTempdbLogFileGrowth; + [Write, Description("Specifies the state of the Named Pipes protocol for the SQL Server service. The value $true will enable the Named Pipes protocol and $false will disabled it.")] Boolean NpEnabled; + [Write, Description("Specifies the state of the TCP protocol for the SQL Server service. The value $true will enable the TCP protocol and $false will disabled it.")] Boolean TcpEnabled; [Write, Description("The timeout, in seconds, to wait for the setup process to finish. Default value is 7200 seconds (2 hours). If the setup process does not finish before this time, and error will be thrown.")] UInt32 SetupProcessTimeout; [Write, Description("Feature flags are used to toggle functionality on or off. See the documentation for what additional functionality exist through a feature flag.")] String FeatureFlag[]; [Read, Description("Returns a boolean value of $true if the instance is clustered, otherwise it returns $false.")] Boolean IsClustered; diff --git a/source/Examples/Resources/SqlSetup/1-InstallDefaultInstanceSingleServer.ps1 b/source/Examples/Resources/SqlSetup/1-InstallDefaultInstanceSingleServer.ps1 index 4f5706a3ed..5aad3945c7 100644 --- a/source/Examples/Resources/SqlSetup/1-InstallDefaultInstanceSingleServer.ps1 +++ b/source/Examples/Resources/SqlSetup/1-InstallDefaultInstanceSingleServer.ps1 @@ -79,6 +79,8 @@ Configuration Example ASBackupDir = 'C:\MSOLAP\Backup' ASTempDir = 'C:\MSOLAP\Temp' SourcePath = 'C:\InstallMedia\SQL2016RTM' + NpEnabled = $true + TcpEnabled = $true UpdateEnabled = 'False' ForceReboot = $false diff --git a/tests/Integration/DSC_SqlSetup.config.ps1 b/tests/Integration/DSC_SqlSetup.config.ps1 index 8624199f62..4bd83556a0 100644 --- a/tests/Integration/DSC_SqlSetup.config.ps1 +++ b/tests/Integration/DSC_SqlSetup.config.ps1 @@ -283,6 +283,8 @@ Configuration DSC_SqlSetup_InstallDatabaseEngineNamedInstanceAsSystem_Config SqlTempDbFileGrowth = $Node.SqlTempDbFileGrowth SqlTempDbLogFileSize = $Node.SqlTempDbLogFileSize SqlTempDbLogFileGrowth = $Node.SqlTempDbLogFileGrowth + NpEnabled = $true + TcpEnabled = $true # This must be set if using SYSTEM account to install. SQLSysAdminAccounts = @( diff --git a/tests/Unit/DSC_SqlSetup.Tests.ps1 b/tests/Unit/DSC_SqlSetup.Tests.ps1 index 03f49099c2..465394bf86 100644 --- a/tests/Unit/DSC_SqlSetup.Tests.ps1 +++ b/tests/Unit/DSC_SqlSetup.Tests.ps1 @@ -1728,7 +1728,7 @@ try Assert-VerifiableMock } - Describe "SqlSetup\Set-TargetResource" -Tag 'Set' { + Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' { BeforeAll { #region Setting up TestDrive:\ @@ -2237,6 +2237,8 @@ try SqlTempDbFileGrowth = 128 SqlTempDbLogFileSize = 128 SqlTempDbLogFileGrowth = 128 + NpEnabled = $true + TcpEnabled = $true } if ( $mockSqlMajorVersion -in (13,14) ) @@ -2271,6 +2273,8 @@ try SqlTempDbFileGrowth = 128 SqlTempDbLogFileSize = 128 SqlTempDbLogFileGrowth = 128 + NpEnabled = 1 + TcpEnabled = 1 } { Set-TargetResource @testParameters } | Should -Not -Throw @@ -2282,7 +2286,7 @@ try Assert-MockCalled -CommandName Import-SQLPSModule -Exactly -Times 1 -Scope It } - if( $mockSqlMajorVersion -in (13,14) ) + if ($mockSqlMajorVersion -in (13,14)) { It 'Should throw when feature parameter contains ''SSMS'' when installing SQL Server 2016 and 2017' { $testParameters += @{