Skip to content

Commit

Permalink
Merge pull request #1382 from PowerShell/dev
Browse files Browse the repository at this point in the history
Release of version 13.0.0.0 of SqlServerDsc
  • Loading branch information
kwirkykat authored Jun 26, 2019
2 parents af2cbb0 + b49d73f commit 601107e
Show file tree
Hide file tree
Showing 87 changed files with 4,063 additions and 2,064 deletions.
4 changes: 3 additions & 1 deletion .MetaTestOptIn.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
"Common Tests - New Error-Level Script Analyzer Rules",
"Common Tests - Custom Script Analyzer Rules",
"Common Tests - Validate Markdown Links",
"Common Tests - Relative Path Length"
"Common Tests - Relative Path Length",
"Common Tests - Validate Localization",
"Common Tests - Flagged Script Analyzer Rules"
]
2 changes: 2 additions & 0 deletions Assert-TestEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ $pesterModule = Get-Module $pesterModuleName -ListAvailable -Verbose:$false |
Sort-Object -Property 'Version' -Descending |
Select-Object -First 1

$dependencyMissing = $false

if (-not $pesterModule)
{
<#
Expand Down
75 changes: 75 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,81 @@

## Unreleased

## 13.0.0.0

- Changes to SqlServerDsc
- Added SqlAgentAlert resource.
- Opt-in to the common test 'Common Test - Validation Localization'.
- Opt-in to the common test 'Common Test - Flagged Script Analyzer Rules'
([issue #1101](https://github.com/PowerShell/SqlServerDsc/issues/1101)).
- Removed the helper function `New-TerminatingError`, `New-WarningMessage`
and `New-VerboseMessage` in favor of the the new
[localization helper functions](https://github.com/PowerShell/DscResources/blob/master/StyleGuidelines.md#localization).
- Combine DscResource.LocalizationHelper and DscResource.Common into
SqlServerDsc.Common ([issue #1357](https://github.com/PowerShell/SqlServerDsc/issues/1357)).
- Update Assert-TestEnvironment.ps1 to not error if strict mode is enabled
and there are no missing dependencies ([issue #1368](https://github.com/PowerShell/SqlServerDsc/issues/1368)).
- Changes to SqlServerDsc.Common
- Added StatementTimeout to function 'Connect-SQL' with default 600 seconds (10mins).
- Added StatementTimeout to function 'Invoke-Query' with default 600 seconds (10mins)
([issue #1358](https://github.com/PowerShell/SqlServerDsc/issues/1358)).
- Changes to helper function Connect-SQL
- The function now make it more clear that when using the parameter
`SetupCredential` is impersonates that user, and by default it does
not impersonates a user but uses the credential that the resource
is run as (for example the built-in credential parameter
`PsDscRunAsCredential`). [@kungfu71186](https://github.com/kungfu71186)
- Added parameter alias `-DatabaseCredential` for the parameter
`-SetupCredential`. [@kungfu71186](https://github.com/kungfu71186)
- Changes to SqlAG
- Added en-US localization.
- Changes to SqlAGReplica
- Added en-US localization.
- Improved verbose message output when creating availability group replica,
removing a availability group replica, and joining the availability
group replica to the availability group.
- Changes to SqlAlwaysOnService
- Now outputs the correct verbose message when restarting the service.
- Changes to SqlServerMemory
- Now outputs the correct verbose messages when calculating the dynamic
memory, and when limiting maximum memory.
- Changes to SqlServerRole
- Now outputs the correct verbose message when the members of a role is
not in desired state.
- Changes to SqlAgentOperator
- Fix minor issue that when unable to connect to an instance. Instead
of showing a message saying that connect failed another unrelated
error message could have been shown, because of an error in the code.
- Fix typo in test it block.
- Changes to SqlDatabaseRole
- BREAKING CHANGE: Refactored to enable creation/deletion of the database role
itself as well as management of the role members. *Note that the resource no
longer adds database users.* ([issue #845](https://github.com/PowerShell/SqlServerDsc/issues/845),
[issue #847](https://github.com/PowerShell/SqlServerDsc/issues/847),
[issue #1252](https://github.com/PowerShell/SqlServerDsc/issues/1252),
[issue #1339](https://github.com/PowerShell/SqlServerDsc/issues/1339)).
[Paul Shamus @pshamus](https://github.com/pshamus)
- Changes to SqlSetup
- Add an Action type of 'Upgrade'. This will ask setup to do a version
upgrade where possible ([issue #1368](https://github.com/PowerShell/SqlServerDsc/issues/1368)).
- Fix an error when testing for DQS installation ([issue #1368](https://github.com/PowerShell/SqlServerDsc/issues/1368)).
- Changed the logic of how default value of FailoverClusterGroupName is
set since that was preventing the resource to be able to be debugged
([issue #448](https://github.com/PowerShell/SqlServerDsc/issues/448)).
- Added RSInstallMode parameter ([issue #1163](https://github.com/PowerShell/SqlServerDsc/issues/1163)).
- Changes to SqlWindowsFirewall
- Where a version upgrade has changed paths for a database engine, the
existing firewall rule for that instance will be updated rather than
another one created ([issue #1368](https://github.com/PowerShell/SqlServerDsc/issues/1368)).
Other firewall rules can be fixed to work in the same way later.
- Changes to SqlAGDatabase
- Added new parameter 'ReplaceExisting' with default false.
This allows forced restores when a database already exists on secondary.
- Added StatementTimeout to Invoke-Query to fix Issue#1358
- Fix issue where calling Get would return an error because the database
name list may have been returned as a string instead of as a string array
([issue #1368](https://github.com/PowerShell/SqlServerDsc/issues/1368)).

## 12.5.0.0

- Changes to SqlServerSecureConnection
Expand Down
24 changes: 0 additions & 24 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,30 +339,6 @@ Import-Module -Name (Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) `
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlSetup'
```

#### Old localization helper function

To be able to support localization we have added wrappers for the cmdlets
`Write-Verbose` and `Write-Warning`, and also for creating a terminating error
message.
The localized strings are placed in a file named 'SqlServerDscHelper.strings.psd1'
which are located in each language folder in the root of the module. For English
language strings the folder is ['en-US'](https://github.com/PowerShell/SqlServerDsc/blob/dev/en-US).

##### New-TerminatingError

Throws a localized error message using Throw. The parameter ErrorType takes the
message type for which it will get the localized message string.

##### New-VerboseMessage

Writes a localized verbose message using Write-Verbose. The parameter ErrorType
takes the message type for which it will get the localized message string.

##### New-WarningMessage

Writes a localized warning message using Write-Warning. The parameter ErrorType
takes the message type for which it will get the localized message string.

### Helper functions

Helper functions or wrapper functions that are used by the resource can preferably
Expand Down
80 changes: 62 additions & 18 deletions DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
$script:resourceModulePath = Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent
$script:modulesFolderPath = Join-Path -Path $script:resourceModulePath -ChildPath 'Modules'

$script:localizationModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'DscResource.LocalizationHelper'
Import-Module -Name (Join-Path -Path $script:localizationModulePath -ChildPath 'DscResource.LocalizationHelper.psm1')
$script:resourceHelperModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'SqlServerDsc.Common'
Import-Module -Name (Join-Path -Path $script:resourceHelperModulePath -ChildPath 'SqlServerDsc.Common.psm1')

$script:resourceHelperModulePath = Join-Path -Path $script:modulesFolderPath -ChildPath 'DscResource.Common'
Import-Module -Name (Join-Path -Path $script:resourceHelperModulePath -ChildPath 'DscResource.Common.psm1')
$script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlAG'

<#
.SYNOPSIS
Expand Down Expand Up @@ -39,6 +38,10 @@ function Get-TargetResource
$InstanceName
)

Write-Verbose -Message (
$script:localizedData.GetAvailabilityGroup -f $Name, $InstanceName
)

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

Expand Down Expand Up @@ -246,7 +249,8 @@ function Set-TargetResource
# Determine if HADR is enabled on the instance. If not, throw an error
if ( -not $serverObject.IsHadrEnabled )
{
throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $InstanceName -ErrorCategory NotImplemented
$errorMessage = $script:localizedData.HadrNotEnabled
New-InvalidOperationException -Message $errorMessage
}

# Define current version for check compatibility
Expand All @@ -257,7 +261,7 @@ function Set-TargetResource

switch ($Ensure)
{
Absent
'Absent'
{
# If the AG exists
if ( $availabilityGroup )
Expand All @@ -267,21 +271,27 @@ function Set-TargetResource
{
try
{
Write-Verbose -Message (
$script:localizedData.RemoveAvailabilityGroup -f $Name, $InstanceName
)

Remove-SqlAvailabilityGroup -InputObject $availabilityGroup -ErrorAction Stop
}
catch
{
throw New-TerminatingError -ErrorType RemoveAvailabilityGroupFailed -FormatArgs $availabilityGroup.Name, $InstanceName -ErrorCategory ResourceUnavailable -InnerException $_.Exception
$errorMessage = $script:localizedData.FailedRemoveAvailabilityGroup -f $availabilityGroup.Name, $InstanceName
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
}
else
{
throw New-TerminatingError -ErrorType InstanceNotPrimaryReplica -FormatArgs $InstanceName, $availabilityGroup.Name -ErrorCategory ResourceUnavailable
$errorMessage = $script:localizedData.NotPrimaryReplica -f $serverObject.DomainInstanceName, $availabilityGroup.Name, $availabilityGroup.PrimaryReplicaServerName
New-InvalidOperationException -Message $errorMessage
}
}
}

Present
'Present'
{
# Ensure the appropriate cluster permissions are present
Test-ClusterPermissions -ServerObject $serverObject
Expand All @@ -290,7 +300,8 @@ function Set-TargetResource
$endpoint = $serverObject.Endpoints | Where-Object { $_.EndpointType -eq 'DatabaseMirroring' }
if ( -not $endpoint )
{
throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $ServerName, $InstanceName -ErrorCategory ObjectNotFound
$errorMessage = $script:localizedData.DatabaseMirroringEndpointNotFound -f ('{0}\{1}' -f $ServerName, $InstanceName)
New-ObjectNotFoundException -Message $errorMessage
}

# If the availability group does not exist, create it
Expand Down Expand Up @@ -329,11 +340,16 @@ function Set-TargetResource
# Create the new replica object
try
{
Write-Verbose -Message (
$script:localizedData.CreateAvailabilityGroupReplica -f $newReplicaParams.Name, $Name, $InstanceName
)

$primaryReplica = New-SqlAvailabilityReplica @newReplicaParams -ErrorAction Stop
}
catch
{
throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $newReplicaParams.Name, $InstanceName -ErrorCategory OperationStopped -InnerException $_.Exception
$errorMessage = $script:localizedData.FailedCreateAvailabilityGroupReplica -f $newReplicaParams.Name, $InstanceName
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}

# Set up the parameters for the new availability group
Expand Down Expand Up @@ -368,16 +384,25 @@ function Set-TargetResource
# Create the Availability Group
try
{
Write-Verbose -Message (
$script:localizedData.CreateAvailabilityGroup -f $Name, $InstanceName
)

New-SqlAvailabilityGroup @newAvailabilityGroupParams -ErrorAction Stop
}
catch
{
throw New-TerminatingError -ErrorType CreateAvailabilityGroupFailed -FormatArgs $Name -ErrorCategory OperationStopped -InnerException $_.Exception
$errorMessage = $script:localizedData.FailedCreateAvailabilityGroup -f $Name, $InstanceName
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
}
# Otherwise let's check each of the parameters passed and update the Availability Group accordingly
else
{
Write-Verbose -Message (
$script:localizedData.UpdateAvailabilityGroup -f $Name, $InstanceName
)

# Get the parameters that were submitted to the function
[System.Array] $submittedParameters = $PSBoundParameters.Keys

Expand Down Expand Up @@ -631,10 +656,17 @@ function Test-TargetResource
#>
if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode )
{
New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $InstanceName )
Write-Verbose -Message (
$script:localizedData.NotActiveNode -f $env:COMPUTERNAME, $InstanceName
)

return $result
}

Write-Verbose -Message (
$script:localizedData.TestingConfiguration -f $Name, $InstanceName
)

# Define current version for check compatibility
$sqlMajorVersion = $getTargetResourceResult.Version

Expand Down Expand Up @@ -698,7 +730,9 @@ function Test-TargetResource

if ( $getTargetResourceResult.($parameterName) -ne $parameterValue )
{
New-VerboseMessage -Message "'$($parameterName)' should be '$($parameterValue)' but is '$($getTargetResourceResult.($parameterName))'"
Write-Verbose -Message (
$script:localizedData.ParameterNotInDesiredState -f $parameterName, $parameterValue, $getTargetResourceResult.$parameterName
)

$result = $false
}
Expand All @@ -715,21 +749,30 @@ function Test-TargetResource
# Verify the hostname in the endpoint URL is correct
if ( $EndpointHostName -ne $currentEndpointHostName )
{
New-VerboseMessage -Message "'EndpointHostName' should be '$EndpointHostName' but is '$currentEndpointHostName'"
Write-Verbose -Message (
$script:localizedData.ParameterNotInDesiredState -f 'EndpointHostName', $EndpointHostName, $currentEndpointHostName
)

$result = $false
}

# Verify the protocol in the endpoint URL is correct
if ( 'TCP' -ne $currentEndpointProtocol )
{
New-VerboseMessage -Message "'EndpointProtocol' should be 'TCP' but is '$currentEndpointProtocol'"
Write-Verbose -Message (
$script:localizedData.ParameterNotInDesiredState -f 'EndpointProtocol', 'TCP', $currentEndpointProtocol
)

$result = $false
}

# Verify the port in the endpoint URL is correct
if ( $getTargetResourceResult.EndpointPort -ne $currentEndpointPort )
{
New-VerboseMessage -Message "'EndpointPort' should be '$($getTargetResourceResult.EndpointPort)' but is '$currentEndpointPort'"
Write-Verbose -Message (
$script:localizedData.ParameterNotInDesiredState -f 'EndpointPort', $getTargetResourceResult.EndpointPort, $currentEndpointPort
)

$result = $false
}
}
Expand Down Expand Up @@ -767,7 +810,8 @@ function Update-AvailabilityGroup
}
catch
{
throw New-TerminatingError -ErrorType AlterAvailabilityGroupFailed -FormatArgs $AvailabilityGroup.Name -ErrorCategory OperationStopped -InnerException $_.Exception
$errorMessage = $script:localizedData.FailedAlterAvailabilityGroup -f $AvailabilityGroup.Name
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
finally
{
Expand Down
17 changes: 17 additions & 0 deletions DSCResources/MSFT_SqlAG/en-US/MSFT_SqlAG.strings.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ConvertFrom-StringData @'
GetAvailabilityGroup = Get the current configuration for the availability group '{0}' on the instance '{1}'.
RemoveAvailabilityGroup = Removing the availability group '{0}' on the instance '{1}'.
HadrNotEnabled = Always On Availability Groups is not enabled.
FailedRemoveAvailabilityGroup = Failed to remove the availability group '{0}' from the instance '{1}'.
NotPrimaryReplica = The node '{0}' is not the primary replica for the availability group '{1}'. The primary replica node is '{2}'.
FailedCreateAvailabilityGroup = Failed to create the availability group '{0}' on the instance '{1}'.
FailedCreateAvailabilityGroupReplica = Failed to creating the availability group replica '{0}' on the instance '{1}'.
DatabaseMirroringEndpointNotFound = No database mirroring endpoint was found on '{0}'.
CreateAvailabilityGroupReplica = Creating the availability group replica '{0}' for availability group '{1}' on the instance '{2}'.
CreateAvailabilityGroup = Creating the availability group '{0}' on the instance '{1}'.
UpdateAvailabilityGroup = The availability group '{0}' exist on the instance '{1}'. Updating availability group and availability group replica properties.
NotActiveNode = The node '{0}' is not actively hosting the instance '{1}'. Will always return success for this resource on this node, until this node is actively hosting the instance.
TestingConfiguration = Determines if the configuration for the availability group '{0}' on the instance '{1}' is in desired state.
ParameterNotInDesiredState = Expected the parameter '{0}' to have the value '{1}', but the value is '{2}'.
FailedAlterAvailabilityGroup = Failed to change a property for the availability group '{0}'.
'@
Loading

0 comments on commit 601107e

Please sign in to comment.