Skip to content

Commit

Permalink
Merge pull request #1192 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 11.4.0.0 of SqlServerDsc
  • Loading branch information
kwirkykat authored Jul 25, 2018
2 parents 42d4650 + 6d42512 commit 33d2093
Show file tree
Hide file tree
Showing 39 changed files with 1,034 additions and 885 deletions.
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,38 @@

## Unreleased

## 11.4.0.0

- Changes to SqlServerDsc
- Updated helper function Restart-SqlService to have to new optional parameters
`SkipClusterCheck` and `SkipWaitForOnline`. This was to support more aspects
of the resource SqlServerNetwork.
- Updated helper function `Import-SQLPSModule`
- To only import module if the
module does not exist in the session.
- To always import the latest version of 'SqlServer' or 'SQLPS' module, if
more than one version exist on the target node. It will still prefer to
use 'SqlServer' module.
- Updated all the examples and integration tests to not use
`PSDscAllowPlainTextPassword`, so examples using credentials or
passwords by default are secure.
- Changes to SqlAlwaysOnService
- Integration tests was updated to handle new IPv6 addresses on the AppVeyor
build worker ([issue #1155](https://github.com/PowerShell/SqlServerDsc/issues/1155)).
- Changes to SqlServerNetwork
- Refactor SqlServerNetwork to not load assembly from GAC ([issue #1151](https://github.com/PowerShell/SqlServerDsc/issues/1151)).
- The resource now supports restarting the SQL Server service when both
enabling and disabling the protocol.
- Added integration tests for this resource
([issue #751](https://github.com/PowerShell/SqlServerDsc/issues/751)).
- Changes to SqlAG
- Removed excess `Import-SQLPSModule` call.
- Changes to SqlSetup
- Now after a successful install the "SQL PowerShell module" is reevaluated and
forced to be reimported into the session. This is to support that a never
version of SQL Server was installed side-by-side so that SQLPS module should
be used instead.

## 11.3.0.0

- Changes to SqlServerDsc
Expand Down
2 changes: 0 additions & 2 deletions DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ function Set-TargetResource
$ProcessOnlyOnActiveNode
)

Import-SQLPSModule

# Connect to the instance
$serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

Expand Down
175 changes: 91 additions & 84 deletions DSCResources/MSFT_SqlServerNetwork/MSFT_SqlServerNetwork.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,24 @@ function Get-TargetResource
$ProtocolName
)

try
{
$applicationDomainObject = Register-SqlWmiManagement -SQLInstanceName $InstanceName

$managedComputerObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer
Import-SQLPSModule

Write-Verbose -Message ($script:localizedData.GetNetworkProtocol -f $ProtocolName, $InstanceName)
$tcp = $managedComputerObject.ServerInstances[$InstanceName].ServerProtocols[$ProtocolName]
$managedComputerObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer

Write-Verbose -Message $script:localizedData.ReadingNetworkProperties
$returnValue = @{
InstanceName = $InstanceName
ProtocolName = $ProtocolName
IsEnabled = $tcp.IsEnabled
TcpDynamicPort = ($tcp.IPAddresses['IPAll'].IPAddressProperties['TcpDynamicPorts'].Value -ge 0)
TcpPort = $tcp.IPAddresses['IPAll'].IPAddressProperties['TcpPort'].Value
}
Write-Verbose -Message ($script:localizedData.GetNetworkProtocol -f $ProtocolName, $InstanceName)
$tcp = $managedComputerObject.ServerInstances[$InstanceName].ServerProtocols[$ProtocolName]

$returnValue.Keys | ForEach-Object {
Write-Verbose -Message "$_ = $($returnValue[$_])"
}
Write-Verbose -Message $script:localizedData.ReadingNetworkProperties
$returnValue = @{
InstanceName = $InstanceName
ProtocolName = $ProtocolName
IsEnabled = $tcp.IsEnabled
TcpDynamicPort = ($tcp.IPAddresses['IPAll'].IPAddressProperties['TcpDynamicPorts'].Value -ge 0)
TcpPort = $tcp.IPAddresses['IPAll'].IPAddressProperties['TcpPort'].Value
}
finally
{
Unregister-SqlAssemblies -ApplicationDomain $applicationDomainObject

$returnValue.Keys | ForEach-Object {
Write-Verbose -Message "$_ = $($returnValue[$_])"
}

return $returnValue
Expand Down Expand Up @@ -145,90 +138,104 @@ function Set-TargetResource

$getTargetResourceResult = Get-TargetResource -InstanceName $InstanceName -ProtocolName $ProtocolName

try
{
$applicationDomainObject = Register-SqlWmiManagement -SQLInstanceName $InstanceName

$desiredState = @{
InstanceName = $InstanceName
ProtocolName = $ProtocolName
IsEnabled = $IsEnabled
TcpDynamicPort = $TcpDynamicPort
TcpPort = $TcpPort
}
$desiredState = @{
InstanceName = $InstanceName
ProtocolName = $ProtocolName
IsEnabled = $IsEnabled
TcpDynamicPort = $TcpDynamicPort
TcpPort = $TcpPort
}

$isRestartNeeded = $false
$isRestartNeeded = $false

$managedComputerObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer
# Get-TargetResource makes the necessary calls so the type ManagedComputer is available.
$managedComputerObject = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer

Write-Verbose -Message ($script:localizedData.GetNetworkProtocol -f $ProtocolName, $InstanceName)
$tcp = $managedComputerObject.ServerInstances[$InstanceName].ServerProtocols[$ProtocolName]
Write-Verbose -Message ($script:localizedData.GetNetworkProtocol -f $ProtocolName, $InstanceName)
$tcp = $managedComputerObject.ServerInstances[$InstanceName].ServerProtocols[$ProtocolName]

Write-Verbose -Message ($script:localizedData.CheckingProperty -f 'IsEnabled')
if ($desiredState.IsEnabled -ine $getTargetResourceResult.IsEnabled)
{
Write-Verbose -Message ($script:localizedData.UpdatingProperty -f 'IsEnabled', $getTargetResourceResult.IsEnabled, $desiredState.IsEnabled)
$tcp.IsEnabled = $desiredState.IsEnabled
$tcp.Alter()
Write-Verbose -Message ($script:localizedData.CheckingProperty -f 'IsEnabled')
if ($desiredState.IsEnabled -ine $getTargetResourceResult.IsEnabled)
{
Write-Verbose -Message ($script:localizedData.UpdatingProperty -f 'IsEnabled', $getTargetResourceResult.IsEnabled, $desiredState.IsEnabled)
$tcp.IsEnabled = $desiredState.IsEnabled
$tcp.Alter()

$isRestartNeeded = $true
}

$isRestartNeeded = $true
Write-Verbose -Message ($script:localizedData.CheckingProperty -f 'TcpDynamicPort')
if ($desiredState.TcpDynamicPort -ne $getTargetResourceResult.TcpDynamicPort)
{
# Translates the current and desired state to a string for display
$dynamicPortDisplayValueTable = @{
$true = 'enabled'
$false = 'disabled'
}

Write-Verbose -Message ($script:localizedData.CheckingProperty -f 'TcpDynamicPort')
if ($desiredState.TcpDynamicPort -ne $getTargetResourceResult.TcpDynamicPort)
{
# Translates the current and desired state to a string for display
$dynamicPortDisplayValueTable = @{
$true = 'enabled'
$false = 'disabled'
}
# Translates the desired state to a valid value
$desiredDynamicPortValue = @{
$true = '0'
$false = ''
}

# Translates the desired state to a valid value
$desiredDynamicPortValue = @{
$true = '0'
$false = ''
}
$fromTcpDynamicPortDisplayValue = $dynamicPortDisplayValueTable[$getTargetResourceResult.TcpDynamicPort]
$toTcpDynamicPortDisplayValue = $dynamicPortDisplayValueTable[$desiredState.TcpDynamicPort]

$fromTcpDynamicPortDisplayValue = $dynamicPortDisplayValueTable[$getTargetResourceResult.TcpDynamicPort]
$toTcpDynamicPortDisplayValue = $dynamicPortDisplayValueTable[$desiredState.TcpDynamicPort]
Write-Verbose -Message ($script:localizedData.UpdatingProperty -f 'TcpDynamicPorts', $fromTcpDynamicPortDisplayValue, $toTcpDynamicPortDisplayValue)
$tcp.IPAddresses['IPAll'].IPAddressProperties['TcpDynamicPorts'].Value = $desiredDynamicPortValue[$desiredState.TcpDynamicPort]
$tcp.Alter()

Write-Verbose -Message ($script:localizedData.UpdatingProperty -f 'TcpDynamicPorts', $fromTcpDynamicPortDisplayValue, $toTcpDynamicPortDisplayValue)
$tcp.IPAddresses['IPAll'].IPAddressProperties['TcpDynamicPorts'].Value = $desiredDynamicPortValue[$desiredState.TcpDynamicPort]
$tcp.Alter()
$isRestartNeeded = $true
}

$isRestartNeeded = $true
Write-Verbose -Message ($script:localizedData.CheckingProperty -f 'TcpPort')
if ($desiredState.TcpPort -ine $getTargetResourceResult.TcpPort)
{
$fromTcpPort = $getTargetResourceResult.TcpPort
if ($fromTcpPort -eq '')
{
$fromTcpPort = 'none'
}

Write-Verbose -Message ($script:localizedData.CheckingProperty -f 'TcpPort')
if ($desiredState.TcpPort -ine $getTargetResourceResult.TcpPort)
$toTcpPort = $desiredState.TcpPort
if ($toTcpPort -eq '')
{
$fromTcpPort = $getTargetResourceResult.TcpPort
if ($fromTcpPort -eq '')
{
$fromTcpPort = 'none'
}
$toTcpPort = 'none'
}

$toTcpPort = $desiredState.TcpPort
if ($toTcpPort -eq '')
{
$toTcpPort = 'none'
}
Write-Verbose -Message ($script:localizedData.UpdatingProperty -f 'TcpPort', $fromTcpPort, $toTcpPort)
$tcp.IPAddresses['IPAll'].IPAddressProperties['TcpPort'].Value = $desiredState.TcpPort
$tcp.Alter()

Write-Verbose -Message ($script:localizedData.UpdatingProperty -f 'TcpPort', $fromTcpPort, $toTcpPort)
$tcp.IPAddresses['IPAll'].IPAddressProperties['TcpPort'].Value = $desiredState.TcpPort
$tcp.Alter()
$isRestartNeeded = $true
}

$isRestartNeeded = $true
if ($RestartService -and $isRestartNeeded)
{
$restartSqlServiceParameters = @{
SQLServer = $ServerName
SQLInstanceName = $InstanceName
Timeout = $RestartTimeout
}

if ($RestartService -and $isRestartNeeded)
if ($getTargetResourceResult.IsEnabled -eq $false -and $IsEnabled -eq $true)
{
Restart-SqlService -SQLServer $ServerName -SQLInstanceName $InstanceName -Timeout $RestartTimeout
<#
If the protocol was disabled and now being enabled, is not possible
to connect to the instance to evaluate if it is a clustered instance.
This is being tracked in issue #1174.
#>
$restartSqlServiceParameters['SkipClusterCheck'] = $true
}
}
finally
{
Unregister-SqlAssemblies -ApplicationDomain $applicationDomainObject

if ($PSBoundParameters.ContainsKey('IsEnabled') -and $IsEnabled -eq $false)
{
# If the protocol is disabled it is not possible to connect to the instance.
$restartSqlServiceParameters['SkipWaitForOnline'] = $true
}

Restart-SqlService @restartSqlServiceParameters
}
}

Expand Down
25 changes: 24 additions & 1 deletion DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1420,8 +1420,9 @@ function Set-TargetResource
elseif ($processExitCode -ne 0)
{
$setupExitMessageError = ('{0} {1}' -f $setupExitMessage, ($script:localizedData.SetupFailed))

Write-Warning $setupExitMessageError

$setupEndedInError = $true
}
else
{
Expand All @@ -1436,13 +1437,35 @@ function Set-TargetResource
{
Write-Verbose -Message $script:localizedData.Reboot

# Rebooting, so no point in refreshing the session.
$forceReloadPowerShellModule = $false

$global:DSCMachineStatus = 1
}
else
{
Write-Verbose -Message $script:localizedData.SuppressReboot
$forceReloadPowerShellModule = $true
}
}
else
{
$forceReloadPowerShellModule = $true
}

if ((-not $setupEndedInError) -and $forceReloadPowerShellModule)
{
<#
Force reload of SQLPS module in case a newer version of
SQL Server was installed that contains a newer version
of the SQLPS module, although if SqlServer module exist
on the target node, that will be used regardless.
This is to make sure we use the latest SQLPS module that
matches the latest assemblies in GAC, mitigating for example
issue #1151.
#>
Import-SQLPSModule -Force
}

if (-not (Test-TargetResource @PSBoundParameters))
{
Expand Down
15 changes: 2 additions & 13 deletions Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = '*'
InstanceName = 'MSSQLSERVER'

<#
NOTE! THIS IS NOT RECOMMENDED IN PRODUCTION.
This is added so that AppVeyor automatic tests can pass, otherwise
the tests will fail on passwords being in plain text and not being
encrypted. Because it is not possible to have a certificate in
AppVeyor to encrypt the passwords we need to add the parameter
'PSDscAllowPlainTextPassword'.
NOTE! THIS IS NOT RECOMMENDED IN PRODUCTION.
#>
PSDscAllowPlainTextPassword = $true
NodeName = '*'
InstanceName = 'MSSQLSERVER'
},

@{
Expand Down
15 changes: 2 additions & 13 deletions Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@ This example shows how to ensure that the Availability Group 'TestAG' does not e
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = '*'
InstanceName = 'MSSQLSERVER'

<#
NOTE! THIS IS NOT RECOMMENDED IN PRODUCTION.
This is added so that AppVeyor automatic tests can pass, otherwise
the tests will fail on passwords being in plain text and not being
encrypted. Because it is not possible to have a certificate in
AppVeyor to encrypt the passwords we need to add the parameter
'PSDscAllowPlainTextPassword'.
NOTE! THIS IS NOT RECOMMENDED IN PRODUCTION.
#>
PSDscAllowPlainTextPassword = $true
NodeName = '*'
InstanceName = 'MSSQLSERVER'
},

@{
Expand Down
11 changes: 0 additions & 11 deletions Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ $ConfigurationData = @{
BasicAvailabilityGroup = $False
DatabaseHealthTrigger = $True
DtcSupportEnabled = $True

<#
NOTE! THIS IS NOT RECOMMENDED IN PRODUCTION.
This is added so that AppVeyor automatic tests can pass, otherwise
the tests will fail on passwords being in plain text and not being
encrypted. Because it is not possible to have a certificate in
AppVeyor to encrypt the passwords we need to add the parameter
'PSDscAllowPlainTextPassword'.
NOTE! THIS IS NOT RECOMMENDED IN PRODUCTION.
#>
PSDscAllowPlainTextPassword = $true
},

@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,9 @@
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = '*'
SQLInstanceName = 'MSSQLSERVER'
AvailabilityGroupName = 'TestAG'
<#
NOTE! THIS IS NOT RECOMMENDED IN PRODUCTION.
This is added so that AppVeyor automatic tests can pass, otherwise
the tests will fail on passwords being in plain text and not being
encrypted. Because it is not possible to have a certificate in
AppVeyor to encrypt the passwords we need to add the parameter
'PSDscAllowPlainTextPassword'.
NOTE! THIS IS NOT RECOMMENDED IN PRODUCTION.
#>
PSDscAllowPlainTextPassword = $true
NodeName = '*'
SQLInstanceName = 'MSSQLSERVER'
AvailabilityGroupName = 'TestAG'
},

@{
Expand Down
Loading

0 comments on commit 33d2093

Please sign in to comment.