diff --git a/CHANGELOG.md b/CHANGELOG.md index d38879739..e64197761 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ - Fixed unit tests for Get-TargetResource to ensure correctly testing return values ([issue #849](https://github.com/PowerShell/xSQLServer/issues/849)) - Changes to xSQLServerAlwaysOnAvailabilityGroup + - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed + to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)). - Refactored the unit tests to allow them to be more user friendly and to test additional SQLServer variations. - Each test will utilize the Import-SQLModuleStub to ensure the correct diff --git a/DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1 b/DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1 index e5154e69f..e11edd953 100644 --- a/DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1 +++ b/DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1 @@ -9,10 +9,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare .PARAMETER Name 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 configured. #> function Get-TargetResource @@ -27,15 +27,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 # Define current version for check compatibility $sqlMajorVersion = $serverObject.Version.Major @@ -56,8 +56,8 @@ function Get-TargetResource # Create the return object. Default ensure to Absent. $alwaysOnAvailabilityGroupResource = @{ Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName Ensure = 'Absent' IsActiveNode = $isActiveNode } @@ -98,10 +98,10 @@ function Get-TargetResource .PARAMETER Name 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 configured. .PARAMETER Ensure @@ -155,11 +155,11 @@ function Set-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -235,12 +235,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 } # Define current version for check compatibility @@ -265,12 +265,12 @@ function Set-TargetResource } catch { - throw New-TerminatingError -ErrorType RemoveAvailabilityGroupFailed -FormatArgs $availabilityGroup.Name, $SQLInstanceName -ErrorCategory ResourceUnavailable -InnerException $_.Exception + throw New-TerminatingError -ErrorType RemoveAvailabilityGroupFailed -FormatArgs $availabilityGroup.Name, $InstanceName -ErrorCategory ResourceUnavailable -InnerException $_.Exception } } else { - throw New-TerminatingError -ErrorType InstanceNotPrimaryReplica -FormatArgs $SQLInstanceName, $availabilityGroup.Name -ErrorCategory ResourceUnavailable + throw New-TerminatingError -ErrorType InstanceNotPrimaryReplica -FormatArgs $InstanceName, $availabilityGroup.Name -ErrorCategory ResourceUnavailable } } } @@ -284,7 +284,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 ( -not $EndpointHostName ) @@ -327,7 +327,7 @@ function Set-TargetResource } catch { - throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $newReplicaParams.Name, $SQLInstanceName -ErrorCategory OperationStopped -InnerException $_.Exception + throw New-TerminatingError -ErrorType CreateAvailabilityGroupReplicaFailed -FormatArgs $newReplicaParams.Name, $InstanceName -ErrorCategory OperationStopped -InnerException $_.Exception } # Set up the parameters for the new availability group @@ -477,10 +477,10 @@ function Set-TargetResource .PARAMETER Name 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 configured. .PARAMETER Ensure @@ -534,11 +534,11 @@ function Test-TargetResource [Parameter(Mandatory = $true)] [String] - $SQLServer, + $ServerName, [Parameter(Mandatory = $true)] [String] - $SQLInstanceName, + $InstanceName, [Parameter()] [ValidateSet('Present', 'Absent')] @@ -606,8 +606,8 @@ function Test-TargetResource ) $getTargetResourceParameters = @{ - SQLInstanceName = $SQLInstanceName - SQLServer = $SQLServer + InstanceName = $InstanceName + ServerName = $ServerName Name = $Name } @@ -622,7 +622,7 @@ 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,$SQLInstanceName ) + New-VerboseMessage -Message ( 'The node "{0}" is not actively hosting the instance "{1}". Exiting the test.' -f $env:COMPUTERNAME, $InstanceName ) return $result } @@ -647,8 +647,8 @@ function Test-TargetResource { $parametersToCheck = @( 'Name', - 'SQLServer', - 'SQLInstanceName', + 'ServerName', + 'InstanceName', 'Ensure', 'AutomatedBackupPreference', 'AvailabilityMode', diff --git a/DSCResources/MSFT_SqlAG/MSFT_SqlAG.schema.mof b/DSCResources/MSFT_SqlAG/MSFT_SqlAG.schema.mof index 487516fd8..c5304af6c 100644 --- a/DSCResources/MSFT_SqlAG/MSFT_SqlAG.schema.mof +++ b/DSCResources/MSFT_SqlAG/MSFT_SqlAG.schema.mof @@ -2,8 +2,8 @@ class MSFT_SqlAG : OMI_BaseResource { [Key, Description("The name of the availability group.")] String Name; - [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("Specifies if the availability group should be present or absent. Default is Present."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; [Write, Description("Specifies the automated backup preference for the availability group. Default is None"), ValueMap{"Primary","SecondaryOnly","Secondary","None"}, Values{"Primary","SecondaryOnly","Secondary","None"}] String AutomatedBackupPreference; [Write, Description("Specifies the replica availability mode. Default is 'AsynchronousCommit'."), ValueMap{"AsynchronousCommit","SynchronousCommit"}, Values{"AsynchronousCommit","SynchronousCommit"}] String AvailabilityMode; diff --git a/Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1 b/Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1 index 7565b18aa..8392b66b6 100644 --- a/Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1 +++ b/Examples/Resources/SqlAG/1-CreateAvailabilityGroup.ps1 @@ -6,8 +6,8 @@ $ConfigurationData = @{ AllNodes = @( @{ - NodeName = '*' - SQLInstanceName = 'MSSQLSERVER' + NodeName = '*' + InstanceName = 'MSSQLSERVER' }, @{ @@ -34,8 +34,8 @@ Configuration Example Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SysAdminAccount } @@ -45,7 +45,7 @@ Configuration Example DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' NodeName = $Node.NodeName - InstanceName = $Node.SqlInstanceName + InstanceName = $Node.InstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' PsDscRunAsCredential = $SysAdminAccount @@ -57,8 +57,8 @@ Configuration Example EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SysAdminAccount } @@ -69,8 +69,8 @@ Configuration Example { Ensure = 'Present' Name = 'TestAG' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName + InstanceName = $Node.InstanceName + ServerName = $Node.NodeName DependsOn = '[SqlServerEndpoint]HADREndpoint', '[SqlServerPermission]AddNTServiceClusSvcPermissions' PsDscRunAsCredential = $SysAdminAccount } diff --git a/Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1 b/Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1 index 8637df955..d41c2352a 100644 --- a/Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1 +++ b/Examples/Resources/SqlAG/2-RemoveAvailabilityGroup.ps1 @@ -6,8 +6,8 @@ This example shows how to ensure that the Availability Group 'TestAG' does not e $ConfigurationData = @{ AllNodes = @( @{ - NodeName = '*' - SQLInstanceName = 'MSSQLSERVER' + NodeName = '*' + InstanceName = 'MSSQLSERVER' }, @{ @@ -35,8 +35,8 @@ Configuration Example { Ensure = 'Absent' Name = 'TestAG' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName + InstanceName = $Node.InstanceName + ServerName = $Node.NodeName PsDscRunAsCredential = $SysAdminAccount } } diff --git a/Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1 b/Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1 index 01f7c504e..397b4f85b 100644 --- a/Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1 +++ b/Examples/Resources/SqlAG/3-CreateAvailabilityGroupDetailed.ps1 @@ -12,7 +12,7 @@ $ConfigurationData = @{ AllNodes = @( @{ NodeName = '*' - SQLInstanceName = 'MSSQLSERVER' + InstanceName = 'MSSQLSERVER' ProcessOnlyOnActiveNode = $true AutomatedBackupPreference = 'Primary' @@ -29,8 +29,8 @@ $ConfigurationData = @{ }, @{ - NodeName = 'SP23-VM-SQL1' - Role = 'PrimaryReplica' + NodeName = 'SP23-VM-SQL1' + Role = 'PrimaryReplica' } ) } @@ -52,8 +52,8 @@ Configuration Example Ensure = 'Present' Name = 'NT SERVICE\ClusSvc' LoginType = 'WindowsUser' - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SysAdminAccount } @@ -63,7 +63,7 @@ Configuration Example DependsOn = '[SqlServerLogin]AddNTServiceClusSvc' Ensure = 'Present' NodeName = $Node.NodeName - InstanceName = $Node.SqlInstanceName + InstanceName = $Node.InstanceName Principal = 'NT SERVICE\ClusSvc' Permission = 'AlterAnyAvailabilityGroup', 'ViewServerState' PsDscRunAsCredential = $SysAdminAccount @@ -75,8 +75,8 @@ Configuration Example EndPointName = 'HADR' Ensure = 'Present' Port = 5022 - SQLServer = $Node.NodeName - SQLInstanceName = $Node.SQLInstanceName + ServerName = $Node.NodeName + InstanceName = $Node.InstanceName PsDscRunAsCredential = $SysAdminAccount } @@ -87,8 +87,8 @@ Configuration Example { Ensure = 'Present' Name = 'TestAG' - SQLInstanceName = $Node.SQLInstanceName - SQLServer = $Node.NodeName + InstanceName = $Node.InstanceName + ServerName = $Node.NodeName ProcessOnlyOnActiveNode = $Node.ProcessOnlyOnActiveNode AutomatedBackupPreference = $Node.AutomatedBackupPreference diff --git a/README.md b/README.md index 656a51e53..d134ea7f9 100644 --- a/README.md +++ b/README.md @@ -212,8 +212,8 @@ It will also manage the Availability Group replica on the specified node. #### Parameters * **`[String]` Name** _(Key)_: The name of the availability group. -* **`[String]` SQLServer** _(Required)_: Hostname of the SQL Server to be configured. -* **`[String]` SQLInstanceName** _(Key)_: Name of the SQL instance to be configured. +* **`[String]` ServerName** _(Required)_: Hostname of the SQL Server to be configured. +* **`[String]` InstanceName** _(Key)_: Name of the SQL instance to be configured. * **`[String]` Ensure** _(Write)_: Specifies if the availability group should be present or absent. Default is Present. { *Present* | Absent } * **`[String]` AutomatedBackupPreference** _(Write)_: Specifies the automated backup diff --git a/Tests/Unit/MSFT_SqlAG.Tests.ps1 b/Tests/Unit/MSFT_SqlAG.Tests.ps1 index d0eb895b0..c8db71a47 100644 --- a/Tests/Unit/MSFT_SqlAG.Tests.ps1 +++ b/Tests/Unit/MSFT_SqlAG.Tests.ps1 @@ -48,8 +48,8 @@ try RemoveAvailabilityGroupFailed = 'AvailabilityGroup3' } - # Define the values that could be passed into the SQLServer parameter - $mockSqlServerParameters = @{ + # Define the values that could be passed into the ServerName parameter + $mockServerNameParameters = @{ Server1 = @{ FQDN = 'Server1.contoso.com' #IP = '192.168.1.1' @@ -63,8 +63,8 @@ try } } - # Define the values that could be passed into the SQLInstanceName parameter - $mockSqlInstanceNameParameters = @( + # Define the values that could be passed into the InstanceName parameter + $mockInstanceNameParameters = @( 'MSSQLSERVER', 'NamedInstance' ) @@ -166,7 +166,7 @@ try ( Get-Command -Name Test-TargetResource ).Parameters.Values | Where-Object -FilterScript { ( # Ignore these specific parameters. These get tested enough. - @('Ensure', 'Name', 'SQLServer', 'SQLInstanceName', 'DtcSupportEnabled', 'ProcessOnlyOnActiveNode') -notcontains $_.Name + @('Ensure', 'Name', 'ServerName', 'InstanceName', 'DtcSupportEnabled', 'ProcessOnlyOnActiveNode') -notcontains $_.Name ) -and ( # Ignore the CmdletBinding parameters $_.Attributes.TypeId.Name -notcontains 'AliasAttribute' @@ -189,38 +189,38 @@ try foreach ( $majorVersionToTest in $majorVersionsToTest ) { - foreach ( $mockSqlServer in $mockSqlServerParameters.GetEnumerator() ) + foreach ( $mockServerName in $mockServerNameParameters.GetEnumerator() ) { # Determine with SQL Server mock will be used - $mockSqlServerToBeUsed = $mockSqlServer.Key + $mockServerNameToBeUsed = $mockServerName.Key - foreach ( $mockSqlServerParameter in $mockSqlServer.Value.Values ) + foreach ( $mockServerNameParameter in $mockServerName.Value.Values ) { - foreach ( $mockSqlInstanceNameParameter in $mockSqlInstanceNameParameters ) + foreach ( $mockInstanceNameParameter in $mockInstanceNameParameters ) { # Build the domain instance name - if ( $mockSqlInstanceNameParameter -eq 'MSSQLSERVER' ) + if ( $mockInstanceNameParameter -eq 'MSSQLSERVER' ) { - $domainInstanceNameProperty = $mockSqlServerParameter + $domainInstanceNameProperty = $mockServerNameParameter } else { - $domainInstanceNameProperty = '{0}\{1}' -f $mockSqlServerParameter,$mockSqlInstanceNameParameter + $domainInstanceNameProperty = '{0}\{1}' -f $mockServerNameParameter,$mockInstanceNameParameter } - if ( $mockSqlServerToBeUsed -eq 'Server1' ) + if ( $mockServerNameToBeUsed -eq 'Server1' ) { $getTargetResourceAbsentTestCases += @{ Name = $mockNameParameters.AbsentAvailabilityGroup - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } $getTargetResourcePresentTestCases += @{ Name = $mockNameParameters.PresentAvailabilityGroup - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } @@ -230,8 +230,8 @@ try ErrorResult = $createAvailabilityGroupFailureToTest.Value Ensure = 'Present' Name = $createAvailabilityGroupFailureToTest.Key - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } } @@ -240,8 +240,8 @@ try Ensure = 'Present' Name = $mockNameParameters.AbsentAvailabilityGroup Result = 'DatabaseMirroringEndpointNotFound' - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } @@ -249,21 +249,21 @@ try Ensure = 'Present' Name = $mockNameParameters.AbsentAvailabilityGroup Result = 'HadrNotEnabled' - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } $setTargetResourceRemoveAvailabilityGroupTestCases += @{ Ensure = 'Absent' Name = $mockNameParameters.PresentAvailabilityGroup - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } } - switch ( $mockSqlServerToBeUsed ) + switch ( $mockServerNameToBeUsed ) { 'Server1' { @@ -282,8 +282,8 @@ try ErrorResult = $setTargetResourceRemoveAvailabilityGroupErrorTestCaseErrorResult Ensure = 'Absent' Name = $setTargetResourceRemoveAvailabilityGroupErrorTestCaseName - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } @@ -293,8 +293,8 @@ try Ensure = 'Present' Name = $mockNameParameters.PresentAvailabilityGroup ProcessOnlyOnActiveNode = $processOnlyOnActiveNode - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } } @@ -306,8 +306,8 @@ try Ensure = $ensureCaseToTest Name = $mockNameParameters.AbsentAvailabilityGroup Result = ( $ensureCaseToTest -eq 'Absent' ) - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } @@ -315,8 +315,8 @@ try Ensure = $ensureCaseToTest Name = $mockNameParameters.PresentAvailabilityGroup Result = ( $ensureCaseToTest -eq 'Present' ) - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } } @@ -371,7 +371,7 @@ try } } - if ( $mockSqlServerToBeUsed -eq 'Server1' ) + if ( $mockServerNameToBeUsed -eq 'Server1' ) { $setTargetResourceCreateAvailabilityGroupWithParameterTestCases += @{ DomainInstanceName = $domainInstanceNameProperty @@ -379,8 +379,8 @@ try Name = $mockNameParameters.AbsentAvailabilityGroup ParameterName = $resourceParameter.Key ParameterValue = $testCaseParameterValue - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } } @@ -391,8 +391,8 @@ try ParameterName = $resourceParameter.Key ParameterValue = $testCaseParameterValue Result = $false - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } @@ -402,8 +402,8 @@ try ParameterName = $resourceParameter.Key ParameterValue = $testCaseParameterValue Result = $false - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } } @@ -430,8 +430,8 @@ try EndpointPropertyValue = $endpointPropertyValue Ensure = 'Present' Name = $mockNameParameters.PresentAvailabilityGroup - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } @@ -441,8 +441,8 @@ try Ensure = 'Present' Name = $mockNameParameters.PresentAvailabilityGroup Result = $false - SQLServer = $mockSqlServerParameter - SQLInstanceName = $mockSqlInstanceNameParameter + ServerName = $mockServerNameParameter + InstanceName = $mockInstanceNameParameter Version = $majorVersionToTest } } @@ -479,16 +479,16 @@ try # If this mock function is called from the Get-PrimaryReplicaServerObject command mock if ( [string]::IsNullOrEmpty($SQLServer) -and [string]::IsNullOrEmpty($SQLInstanceName) -and $AvailabilityGroup -and $ServerObject ) { - $SQLServer,$SQLInstanceName = $AvailabilityGroup.PrimaryReplicaServerName.Split('\') + $SQLServer,$InstanceName = $AvailabilityGroup.PrimaryReplicaServerName.Split('\') } # Determine which SQL Server mock data we will use - $mockSqlServer = ( $mockSqlServerParameters.GetEnumerator() | Where-Object -FilterScript { $_.Value.Values -contains $SQLServer } ).Name - if ( [string]::IsNullOrEmpty($mockSqlServer) ) + $mockServerName = ( $mockServerNameParameters.GetEnumerator() | Where-Object -FilterScript { $_.Value.Values -contains $SQLServer } ).Name + if ( [string]::IsNullOrEmpty($mockServerName) ) { - $mockSqlServer = $SQLServer + $mockServerName = $SQLServer } - $mockCurrentServerObjectProperties = $mockServerObjectProperies.$mockSqlServer + $mockCurrentServerObjectProperties = $mockServerObjectProperies.$mockServerName # Build the domain instance name if ( ( $SQLInstanceName -eq 'MSSQLSERVER' ) -or [string]::IsNullOrEmpty($SQLInstanceName) ) @@ -688,12 +688,12 @@ try Context 'When the Availability Group is Absent' { - It 'Should not return an Availability Group when Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $getTargetResourceAbsentTestCases { + It 'Should not return an Availability Group when Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $getTargetResourceAbsentTestCases { param ( $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -702,8 +702,8 @@ try $getTargetResourceParameters = @{ Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } $result = Get-TargetResource @getTargetResourceParameters @@ -715,12 +715,12 @@ try } Context 'When the Availability Group is Present' { - It 'Should return the correct Availability Group properties when Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $getTargetResourcePresentTestCases { + It 'Should return the correct Availability Group properties when Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $getTargetResourcePresentTestCases { param ( $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -729,27 +729,27 @@ try $getTargetResourceParameters = @{ Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } # Determine which SQL Server mock data will be used - $mockSqlServer = ( $mockSqlServerParameters.GetEnumerator() | Where-Object -FilterScript { $_.Value.Values -contains $SQLServer } ).Name + $mockServerName = ( $mockServerNameParameters.GetEnumerator() | Where-Object -FilterScript { $_.Value.Values -contains $ServerName } ).Name $result = Get-TargetResource @getTargetResourceParameters $result.Name | Should -Be $Name - $result.SQLServer | Should -Be $SQLServer - $result.SQLInstanceName | Should -Be $SQLInstanceName + $result.ServerName | Should -Be $ServerName + $result.InstanceName | Should -Be $InstanceName $result.Ensure | Should -Be 'Present' $result.AutomatedBackupPreference | Should -Be $mockAvailabilityGroupProperties.AutomatedBackupPreference - $result.AvailabilityMode | Should -Be $mockAvailabilityGroupReplicaProperties.$mockSqlServer.AvailabilityMode - $result.BackupPriority | Should -Be $mockAvailabilityGroupReplicaProperties.$mockSqlServer.BackupPriority - $result.ConnectionModeInPrimaryRole | Should -Be $mockAvailabilityGroupReplicaProperties.$mockSqlServer.ConnectionModeInPrimaryRole - $result.ConnectionModeInSecondaryRole | Should -Be $mockAvailabilityGroupReplicaProperties.$mockSqlServer.ConnectionModeInSecondaryRole - $result.EndpointURL | Should -Be "$($mockAvailabilityGroupReplicaProperties.$mockSqlServer.EndpointProtocol)://$($mockAvailabilityGroupReplicaProperties.$mockSqlServer.EndpointHostName):$($mockAvailabilityGroupReplicaProperties.$mockSqlServer.EndpointPort)" + $result.AvailabilityMode | Should -Be $mockAvailabilityGroupReplicaProperties.$mockServerName.AvailabilityMode + $result.BackupPriority | Should -Be $mockAvailabilityGroupReplicaProperties.$mockServerName.BackupPriority + $result.ConnectionModeInPrimaryRole | Should -Be $mockAvailabilityGroupReplicaProperties.$mockServerName.ConnectionModeInPrimaryRole + $result.ConnectionModeInSecondaryRole | Should -Be $mockAvailabilityGroupReplicaProperties.$mockServerName.ConnectionModeInSecondaryRole + $result.EndpointURL | Should -Be "$($mockAvailabilityGroupReplicaProperties.$mockServerName.EndpointProtocol)://$($mockAvailabilityGroupReplicaProperties.$mockServerName.EndpointHostName):$($mockAvailabilityGroupReplicaProperties.$mockServerName.EndpointPort)" $result.FailureConditionLevel | Should -Be $mockAvailabilityGroupProperties.FailureConditionLevel - $result.FailoverMode | Should -Be $mockAvailabilityGroupReplicaProperties.$mockSqlServer.FailoverMode + $result.FailoverMode | Should -Be $mockAvailabilityGroupReplicaProperties.$mockServerName.FailoverMode $result.HealthCheckTimeout | Should -Be $mockAvailabilityGroupProperties.HealthCheckTimeout if ( $Version -ge 13 ) @@ -794,7 +794,7 @@ try } Context 'When the Availability Group is Absent and the desired state is Present and a parameter is supplied' { - It 'Should create the availability group "" with the parameter "" set to "" when Ensure is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceCreateAvailabilityGroupWithParameterTestCases { + It 'Should create the availability group "" with the parameter "" set to "" when Ensure is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceCreateAvailabilityGroupWithParameterTestCases { param ( $DomainInstanceName, @@ -802,8 +802,8 @@ try $Name, $ParameterName, $ParameterValue, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -813,8 +813,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName $ParameterName = $ParameterValue } @@ -839,14 +839,14 @@ try } Context 'When the Availability Group is Absent, the desired state is Present, and creating the Availability Group fails' { - It 'Should throw "" when creating the availability group "" fails, Ensure is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceCreateAvailabilityGroupFailedTestCases { + It 'Should throw "" when creating the availability group "" fails, Ensure is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceCreateAvailabilityGroupFailedTestCases { param ( $ErrorResult, $Ensure, $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -869,8 +869,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Throw "$($ErrorResult)" @@ -894,7 +894,7 @@ try } Context 'When the Availability Group is Present and a value is passed to a parameter' { - It 'Should set "" to "" when Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourcePropertyIncorrectTestCases { + It 'Should set "" to "" when Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourcePropertyIncorrectTestCases { param ( $Ensure, @@ -902,8 +902,8 @@ try $ParameterName, $ParameterValue, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -913,8 +913,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName $ParameterName = $ParameterValue } @@ -951,13 +951,13 @@ try } Context 'When the Availability Group is Present and the desired state is Absent' { - It 'Should remove the Availability Group "" when Ensure is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceRemoveAvailabilityGroupTestCases { + It 'Should remove the Availability Group "" when Ensure is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceRemoveAvailabilityGroupTestCases { param ( $Ensure, $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -967,8 +967,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw @@ -992,14 +992,14 @@ try } Context 'When the Availability Group is Present and throws an error when removal is attempted' { - It 'Should throw "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceRemoveAvailabilityGroupErrorTestCases { + It 'Should throw "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceRemoveAvailabilityGroupErrorTestCases { param ( $ErrorResult, $Ensure, $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1022,8 +1022,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Throw "$($ErrorResult)" @@ -1055,14 +1055,14 @@ try $mockIsHadrEnabled = $false } - It 'Should throw "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceHadrDisabledTestCases { + It 'Should throw "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceHadrDisabledTestCases { param ( $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1072,8 +1072,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Throw $Result @@ -1105,14 +1105,14 @@ try $mockIsDatabaseMirroringEndpointPresent = $false } - It 'Should throw "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceEndpointMissingTestCases { + It 'Should throw "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourceEndpointMissingTestCases { param ( $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1122,8 +1122,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Throw $Result @@ -1159,15 +1159,15 @@ try $mockAvailabilityGroupReplicaPropertiesServer2Original = $mockAvailabilityGroupReplicaProperties.Server2.Clone() } - It 'Should set "" to "" when Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $setTargetResourcesEndpointUrlTestCases { + It 'Should set "" to "" when Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $setTargetResourcesEndpointUrlTestCases { param ( $EndpointPropertyName, $EndpointPropertyValue, $Ensure, $Name, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1180,8 +1180,8 @@ try $setTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } { Set-TargetResource @setTargetResourceParameters } | Should -Not -Throw @@ -1214,14 +1214,14 @@ try } Context 'When the Availability Group is Absent' { - It 'Should be "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceAbsentTestCases { + It 'Should be "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceAbsentTestCases { param ( $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1231,8 +1231,8 @@ try $testTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } Test-TargetResource @testTargetResourceParameters | Should -Be $Result @@ -1243,14 +1243,14 @@ try } Context 'When the Availability Group is Present and the default parameters are passed' { - It 'Should be "" when Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourcePresentTestCases { + It 'Should be "" when Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourcePresentTestCases { param ( $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1260,8 +1260,8 @@ try $testTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } Test-TargetResource @testTargetResourceParameters | Should -Be $Result @@ -1272,7 +1272,7 @@ try } Context 'When the Availability Group is Present and a value is passed to a parameter' { - It 'Should be "" when "" is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourcePropertyIncorrectTestCases { + It 'Should be "" when "" is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourcePropertyIncorrectTestCases { param ( $Ensure, @@ -1280,8 +1280,8 @@ try $ParameterName, $ParameterValue, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1291,8 +1291,8 @@ try $testTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName $ParameterName = $ParameterValue } @@ -1316,7 +1316,7 @@ try $mockAvailabilityGroupReplicaPropertiesServer2Original = $mockAvailabilityGroupReplicaProperties.Server2.Clone() } - It 'Should be "" when "" is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceEndpointIncorrectTestCases { + It 'Should be "" when "" is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceEndpointIncorrectTestCases { param ( $EndpointPropertyName, @@ -1324,8 +1324,8 @@ try $Ensure, $Name, $Result, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1338,8 +1338,8 @@ try $testTargetResourceParameters = @{ Ensure = $Ensure Name = $Name - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } Test-TargetResource @testTargetResourceParameters | Should -Be $Result @@ -1359,14 +1359,14 @@ try $mockProcessOnlyOnActiveNode = $false } - It 'Should be "true" when ProcessOnlyOnActiveNode is "", Ensure is "", Name is "", SQLServer is "", SQLInstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceProcessOnlyOnActiveNodeTestCases { + It 'Should be "true" when ProcessOnlyOnActiveNode is "", Ensure is "", Name is "", ServerName is "", InstanceName is "", and the SQL version is ""' -TestCases $testTargetResourceProcessOnlyOnActiveNodeTestCases { param ( $Ensure, $Name, $ProcessOnlyOnActiveNode, - $SQLServer, - $SQLInstanceName, + $ServerName, + $InstanceName, $Version ) @@ -1377,8 +1377,8 @@ try Ensure = $Ensure Name = $Name ProcessOnlyOnActiveNode = $ProcessOnlyOnActiveNode - SQLServer = $SQLServer - SQLInstanceName = $SQLInstanceName + ServerName = $ServerName + InstanceName = $InstanceName } Test-TargetResource @testTargetResourceParameters | Should Be $true