From c7a8630ca44ffee67509431855a332ae1a7a2214 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Tue, 14 Nov 2017 17:42:15 +0100 Subject: [PATCH] Changes to SqlAGReplica - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed to ServerName and InstanceName respectivly (issue #308). --- CHANGELOG.md | 2 + .../MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 | 50 +++++++-------- .../MSFT_SqlAGReplica.schema.mof | 4 +- .../1-CreateAvailabilityGroupReplica.ps1 | 4 +- .../2-RemoveAvailabilityGroupReplica.ps1 | 4 +- Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 | 64 +++++++++---------- 6 files changed, 65 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a3196f1a..2acf66b1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,8 @@ the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance ([issue #869](https://github.com/PowerShell/xSQLServer/issues/869)). - Changes to xSQLServerAlwaysOnAvailabilityGroupReplica + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)). - Made the resource cluster aware. When ProcessOnlyOnActiveNode is specified, the resource will only determine if a change is needed if the target node is the active host of the SQL Server instance ([issue #870](https://github.com/PowerShell/xSQLServer/issues/870)). diff --git a/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 b/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 index 2117f87b2..71523a112 100644 --- a/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 +++ b/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 @@ -12,10 +12,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER AvailabilityGroupName The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. #> function Get-TargetResource @@ -34,15 +34,15 @@ function Get-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName + $InstanceName ) # Connect to the instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Is this node actively hosting the SQL instance? $isActiveNode = Test-ActiveNode -ServerObject $serverObject @@ -68,8 +68,8 @@ function Get-TargetResource IsActiveNode = $isActiveNode ReadOnlyRoutingConnectionUrl = '' ReadOnlyRoutingList = @() - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName EndpointPort = $endpointPort SQLServerNetName = $serverObject.NetName } @@ -114,10 +114,10 @@ function Get-TargetResource .PARAMETER AvailabilityGroupName The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. .PARAMETER PrimaryReplicaSQLServer @@ -172,11 +172,11 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter()] [String] @@ -236,12 +236,12 @@ function Set-TargetResource Import-SQLPSModule # Connect to the instance - $serverObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName + $serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName # Determine if HADR is enabled on the instance. If not, throw an error if ( -not $serverObject.IsHadrEnabled ) { - throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $SQLInstanceName -ErrorCategory NotImplemented + throw New-TerminatingError -ErrorType HadrNotEnabled -FormatArgs $Ensure, $InstanceName -ErrorCategory NotImplemented } # Get the Availability Group if it exists @@ -288,7 +288,7 @@ function Set-TargetResource $endpoint = $serverObject.Endpoints | Where-Object { $_.EndpointType -eq 'DatabaseMirroring' } if ( -not $endpoint ) { - throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $SQLServer, $SQLInstanceName -ErrorCategory ObjectNotFound + throw New-TerminatingError -ErrorType DatabaseMirroringEndpointNotFound -FormatArgs $ServerName, $InstanceName -ErrorCategory ObjectNotFound } # If a hostname for the endpoint was not specified, define it now. @@ -377,7 +377,7 @@ function Set-TargetResource } else { - throw New-TerminatingError -ErrorType ReplicaNotFound -FormatArgs $Name, $SQLInstanceName -ErrorCategory ResourceUnavailable + throw New-TerminatingError -ErrorType ReplicaNotFound -FormatArgs $Name, $InstanceName -ErrorCategory ResourceUnavailable } } else @@ -437,7 +437,7 @@ function Set-TargetResource } catch { - throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $Name, $SQLInstanceName -ErrorCategory OperationStopped -InnerException $_.Exception + throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $Name, $InstanceName -ErrorCategory OperationStopped -InnerException $_.Exception } # Join the Availability Group Replica to the Availability Group @@ -470,10 +470,10 @@ function Set-TargetResource .PARAMETER AvailabilityGroupName The name of the availability group. - .PARAMETER SQLServer + .PARAMETER ServerName Hostname of the SQL Server to be configured. - .PARAMETER SQLInstanceName + .PARAMETER InstanceName Name of the SQL instance to be configued. .PARAMETER PrimaryReplicaSQLServer @@ -528,11 +528,11 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter()] [String] @@ -590,8 +590,8 @@ function Test-TargetResource ) $getTargetResourceParameters = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer + InstanceName = $InstanceName + ServerName = $ServerName Name = $Name AvailabilityGroupName = $AvailabilityGroupName } @@ -608,7 +608,7 @@ function Test-TargetResource if ( $ProcessOnlyOnActiveNode -and -not $getTargetResourceResult.IsActiveNode ) { # Use localization if the resource has been converted - New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME,$SQLInstanceName ) + New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $InstanceName ) return $result } @@ -631,8 +631,8 @@ function Test-TargetResource $parametersToCheck = @( 'Name', 'AvailabilityGroupName', - 'SQLServer', - 'SQLInstanceName', + 'ServerName', + 'InstanceName', 'Ensure', 'AvailabilityMode', 'BackupPriority', diff --git a/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.schema.mof b/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.schema.mof index 46127e6eb..7f7af3a55 100644 --- a/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.schema.mof +++ b/DSCResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.schema.mof @@ -3,8 +3,8 @@ class MSFT_SqlAGReplica : OMI_BaseResource { [Key, Description("The name of the availability group replica. For named instances this must be in the following format SQLServer\\InstanceName.")] String Name; [Key, Description("The name of the availability group.")] String AvailabilityGroupName; - [Required, Description("Hostname of the SQL Server to be configured.")] String SQLServer; - [Key, Description("Name of the SQL instance to be configured.")] String SQLInstanceName; + [Required, Description("Hostname of the SQL Server to be configured.")] String ServerName; + [Key, Description("Name of the SQL instance to be configured.")] String InstanceName; [Write, Description("Hostname of the SQL Server where the primary replica is expected to be active. If the primary replica is not found here, the resource will attempt to find the host that holds the primary replica and connect to it.")] String PrimaryReplicaSQLServer; [Write, Description("Name of the SQL instance where the primary replica lives.")] String PrimaryReplicaSQLInstanceName; [Write, Description("Specifies if the availability group replica should be present or absent. Default is Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; diff --git a/Examples/Resources/SqlAGReplica/1-CreateAvailabilityGroupReplica.ps1 b/Examples/Resources/SqlAGReplica/1-CreateAvailabilityGroupReplica.ps1 index 8202492c2..088699747 100644 --- a/Examples/Resources/SqlAGReplica/1-CreateAvailabilityGroupReplica.ps1 +++ b/Examples/Resources/SqlAGReplica/1-CreateAvailabilityGroupReplica.ps1 @@ -97,8 +97,8 @@ Configuration Example Ensure = 'Present' Name = $Node.NodeName AvailabilityGroupName = $Node.AvailabilityGroupName - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PrimaryReplicaSQLServer = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName PrimaryReplicaSQLInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName ProcessOnlyOnActiveNode = $Node.ProcessOnlyOnActiveNode diff --git a/Examples/Resources/SqlAGReplica/2-RemoveAvailabilityGroupReplica.ps1 b/Examples/Resources/SqlAGReplica/2-RemoveAvailabilityGroupReplica.ps1 index 8ca68ceed..30428e3a2 100644 --- a/Examples/Resources/SqlAGReplica/2-RemoveAvailabilityGroupReplica.ps1 +++ b/Examples/Resources/SqlAGReplica/2-RemoveAvailabilityGroupReplica.ps1 @@ -90,8 +90,8 @@ Configuration Example Ensure = 'Absent' Name = $Node.NodeName AvailabilityGroupName = $Node.AvailabilityGroupName - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.SQLInstanceName PrimaryReplicaSQLServer = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).NodeName PrimaryReplicaSQLInstanceName = ( $AllNodes | Where-Object { $_.Role -eq 'PrimaryReplica' } ).SQLInstanceName } diff --git a/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 index 65f8a6758..8804d1a70 100644 --- a/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAGReplica.Tests.ps1 @@ -37,21 +37,21 @@ try #region parameter mocks - $mockSqlServer = 'Server1' - $mockSqlInstanceName = 'MSSQLSERVER' + $mockServerName = 'Server1' + $mockInstanceName = 'MSSQLSERVER' $mockPrimaryReplicaSQLServer = 'Server2' $mockPrimaryReplicaSQLInstanceName = 'MSSQLSERVER' $mockAvailabilityGroupName = 'AG_AllServers' - $mockAvailabilityGroupReplicaName = $mockSqlServer + $mockAvailabilityGroupReplicaName = $mockServerName $mockEnsure = 'Present' $mockAvailabilityMode = 'AsynchronousCommit' $mockBackupPriority = 50 $mockConnectionModeInPrimaryRole = 'AllowAllConnections' $mockConnectionModeInSecondaryRole = 'AllowNoConnections' - $mockEndpointHostName = $mockSqlServer + $mockEndpointHostName = $mockServerName $mockFailoverMode = 'Manual' - $mockReadOnlyRoutingConnectionUrl = "TCP://$($mockSqlServer).domain.com:1433" - $mockReadOnlyRoutingList = @($mockSqlServer) + $mockReadOnlyRoutingConnectionUrl = "TCP://$($mockServerName).domain.com:1433" + $mockReadOnlyRoutingList = @($mockServerName) $mockProcessOnlyOnActiveNode = $false #endregion @@ -85,16 +85,16 @@ try $mockAllLoginsAbsent = @{} $mockNtServiceClusSvcPresent = @{ - $mockNtServiceClusSvcName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockSqlServer, $mockNtServiceClusSvcName) ) + $mockNtServiceClusSvcName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockServerName, $mockNtServiceClusSvcName) ) } $mockNtAuthoritySystemPresent = @{ - $mockNtAuthoritySystemName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockSqlServer, $mockNtAuthoritySystemName) ) + $mockNtAuthoritySystemName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockServerName, $mockNtAuthoritySystemName) ) } $mockAllLoginsPresent = @{ - $mockNtServiceClusSvcName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockSqlServer, $mockNtServiceClusSvcName) ) - $mockNtAuthoritySystemName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockSqlServer, $mockNtAuthoritySystemName) ) + $mockNtServiceClusSvcName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockServerName, $mockNtServiceClusSvcName) ) + $mockNtAuthoritySystemName = ( New-Object -TypeName Microsoft.SqlServer.Management.Smo.Login($mockServerName, $mockNtAuthoritySystemName) ) } #endregion @@ -535,8 +535,8 @@ try $getTargetResourceParameters = @{ Name = $mockAvailabilityGroupReplicaName AvailabilityGroupName = $mockAvailabilityGroupName - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName } $mockDatabaseMirroringEndpoint = $true @@ -565,9 +565,9 @@ try $getTargetResourceResult.Name | Should -BeNullOrEmpty $getTargetResourceResult.ReadOnlyRoutingConnectionUrl | Should -BeNullOrEmpty $getTargetResourceResult.ReadOnlyRoutingList | Should -BeNullOrEmpty - $getTargetResourceResult.SQLServer | Should -Be $mockSqlServer - $getTargetResourceResult.SQLInstanceName | Should -Be $mockSqlInstanceName - $getTargetResourceResult.SQLServerNetName | Should -Be $mockSqlServer + $getTargetResourceResult.ServerName | Should -Be $mockServerName + $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName + $getTargetResourceResult.SQLServerNetName | Should -Be $mockServerName Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly } @@ -590,12 +590,12 @@ try $getTargetResourceResult.EndpointPort | Should -Be $mockendpointPort $getTargetResourceResult.Ensure | Should -Be $mockEnsure $getTargetResourceResult.FailoverMode | Should -Be $mockFailoverMode - $getTargetResourceResult.Name | Should -Be $mockSqlServer + $getTargetResourceResult.Name | Should -Be $mockServerName $getTargetResourceResult.ReadOnlyRoutingConnectionUrl | Should -Be $mockReadOnlyRoutingConnectionUrl - $getTargetResourceResult.ReadOnlyRoutingList | Should -Be $mockSqlServer - $getTargetResourceResult.SQLServer | Should -Be $mockSqlServer - $getTargetResourceResult.SQLInstanceName | Should -Be $mockSqlInstanceName - $getTargetResourceResult.SQLServerNetName | Should -Be $mockSqlServer + $getTargetResourceResult.ReadOnlyRoutingList | Should -Be $mockServerName + $getTargetResourceResult.ServerName | Should -Be $mockServerName + $getTargetResourceResult.InstanceName | Should -Be $mockInstanceName + $getTargetResourceResult.SQLServerNetName | Should -Be $mockServerName Assert-MockCalled -CommandName Connect-SQL -Scope It -Times 1 -Exactly } @@ -649,10 +649,10 @@ try BeforeEach { $setTargetResourceParameters = @{ - Name = $mockSqlServer + Name = $mockServerName AvailabilityGroupName = $mockAvailabilityGroupName - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName Ensure = 'Absent' } } @@ -733,10 +733,10 @@ try BeforeEach { $setTargetResourceParameters = @{ - Name = $mockSqlServer + Name = $mockServerName AvailabilityGroupName = $mockAvailabilityGroup2Name - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName PrimaryReplicaSQLServer = $mockPrimaryReplicaSQLServer PrimaryReplicaSQLInstanceName = $mockPrimaryReplicaSQLInstanceName Ensure = $mockEnsure @@ -1072,10 +1072,10 @@ try $mockAlternateEndpointProtocol = $false $setTargetResourceParameters = @{ - Name = $mockSqlServer + Name = $mockServerName AvailabilityGroupName = $mockAvailabilityGroupName - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName PrimaryReplicaSQLServer = $mockPrimaryReplicaSQLServer PrimaryReplicaSQLInstanceName = $mockPrimaryReplicaSQLInstanceName Ensure = $mockEnsure @@ -1274,10 +1274,10 @@ try $mockDatabaseMirroringEndpoint = $true $testTargetResourceParameters = @{ - Name = $mockSqlServer + Name = $mockServerName AvailabilityGroupName = $mockAvailabilityGroupName - SQLServer = $mockSqlServer - SQLInstanceName = $mockSqlInstanceName + ServerName = $mockServerName + InstanceName = $mockInstanceName PrimaryReplicaSQLServer = $mockPrimaryReplicaSQLServer PrimaryReplicaSQLInstanceName = $mockPrimaryReplicaSQLInstanceName Ensure = $mockEnsure