Skip to content

Commit

Permalink
Changes to SqlServerEndpoint
Browse files Browse the repository at this point in the history
  - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
    to ServerName and InstanceName respectivly (issue dsccommunity#308).
  • Loading branch information
johlju committed Dec 1, 2017
1 parent 91ea216 commit d6513cc
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
- Changes to SqlServerPermission
- BREAKING CHANGE: Parameter NodeName has been renamed to ServerName
([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).
- Changes to SqlServerEndpoint
- BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).

## 8.2.0.0

Expand Down
50 changes: 25 additions & 25 deletions DSCResources/MSFT_SqlServerEndpoint/MSFT_SqlServerEndpoint.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare
.PARAMETER EndpointName
The name of the endpoint.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
#>
function Get-TargetResource
Expand All @@ -26,26 +26,26 @@ function Get-TargetResource

[Parameter()]
[System.String]
$SQLServer = $env:COMPUTERNAME,
$ServerName = $env:COMPUTERNAME,

[Parameter(Mandatory = $true)]
[System.String]
$SQLInstanceName
$InstanceName
)

$getTargetResourceReturnValues = @{
SQLServer = $SQLServer
SQLInstanceName = $SQLInstanceName
Ensure = 'Absent'
EndpointName = ''
Port = ''
IpAddress = ''
ServerName = $ServerName
InstanceName = $InstanceName
Ensure = 'Absent'
EndpointName = ''
Port = ''
IpAddress = ''
}

$sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName
if ($sqlServerObject)
{
Write-Verbose -Message ('Connected to {0}\{1}' -f $SQLServer, $SQLInstanceName)
Write-Verbose -Message ('Connected to {0}\{1}' -f $ServerName, $InstanceName)

$endpointObject = $sqlServerObject.Endpoints[$EndpointName]
if ($endpointObject.Name -eq $EndpointName)
Expand Down Expand Up @@ -73,7 +73,7 @@ function Get-TargetResource
else
{
throw New-TerminatingError -ErrorType NotConnectedToInstance `
-FormatArgs @($SQLServer, $SQLInstanceName) `
-FormatArgs @($ServerName, $InstanceName) `
-ErrorCategory InvalidOperation
}

Expand All @@ -93,10 +93,10 @@ function Get-TargetResource
.PARAMETER Port
The network port the endpoint is listening on. Default value is 5022.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
.PARAMETER IpAddress
Expand All @@ -122,20 +122,20 @@ function Set-TargetResource

[Parameter()]
[System.String]
$SQLServer = $env:COMPUTERNAME,
$ServerName = $env:COMPUTERNAME,

[Parameter(Mandatory = $true)]
[System.String]
$SQLInstanceName,
$InstanceName,

[Parameter()]
[System.String]
$IpAddress = '0.0.0.0'
)

$getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -ServerName $ServerName -InstanceName $InstanceName

$sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName
if ($sqlServerObject)
{
if ($Ensure -eq 'Present' -and $getTargetResourceResult.Ensure -eq 'Absent')
Expand Down Expand Up @@ -196,7 +196,7 @@ function Set-TargetResource
else
{
throw New-TerminatingError -ErrorType NotConnectedToInstance `
-FormatArgs @($SQLServer, $SQLInstanceName) `
-FormatArgs @($ServerName, $InstanceName) `
-ErrorCategory InvalidOperation
}
}
Expand All @@ -214,10 +214,10 @@ function Set-TargetResource
.PARAMETER Port
The network port the endpoint is listening on. Default value is 5022.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
.PARAMETER IpAddress
Expand All @@ -244,18 +244,18 @@ function Test-TargetResource

[Parameter()]
[System.String]
$SQLServer = $env:COMPUTERNAME,
$ServerName = $env:COMPUTERNAME,

[Parameter(Mandatory = $true)]
[System.String]
$SQLInstanceName,
$InstanceName,

[Parameter()]
[System.String]
$IpAddress = '0.0.0.0'
)

$getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$getTargetResourceResult = Get-TargetResource -EndpointName $EndpointName -ServerName $ServerName -InstanceName $InstanceName
if ($getTargetResourceResult.Ensure -eq $Ensure)
{
$result = $true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class MSFT_SqlServerEndpoint : OMI_BaseResource
[Key, Description("The name of the endpoint.")] String EndpointName;
[Write, Description("If the endpoint should be present or absent. Default values is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Write, Description("The network port the endpoint is listening on. Default value is 5022.")] Uint16 Port;
[Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String SQLServer;
[Key, Description("The name of the SQL instance to be configured.")] String SQLInstanceName;
[Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String ServerName;
[Key, Description("The name of the SQL instance to be configured.")] String InstanceName;
[Write, Description("The network IP address the endpoint is listening on. Default the endpoint will listen on any valid IP address.")] String IpAddress;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Configuration Example
SqlServerEndpoint SQLConfigureEndpoint-Instance1
{
EndpointName = 'HADR'
SQLInstanceName = 'INST1'
InstanceName = 'INST1'

PsDscRunAsCredential = $SysAdminAccount
}

SqlServerEndpoint SQLConfigureEndpoint-Instances2
{
EndpointName = 'HADR'
SQLInstanceName = 'INST2'
InstanceName = 'INST2'

PsDscRunAsCredential = $SysAdminAccount
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ Configuration Example
Port = 9001
IpAddress = '192.168.0.20'

SQLServer = 'server1.company.local'
SQLInstanceName = 'INST1'
ServerName = 'server1.company.local'
InstanceName = 'INST1'

PsDscRunAsCredential = $SysAdminAccount
}
Expand Down
14 changes: 7 additions & 7 deletions Tests/Unit/MSFT_SqlServerEndpoint.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ try
Invoke-TestSetup

InModuleScope $script:DSCResourceName {
$mockNodeName = 'localhost'
$mockServerName = 'localhost'
$mockInstanceName = 'INSTANCE1'
$mockPrincipal = 'COMPANY\SqlServiceAcct'
$mockOtherPrincipal = 'COMPANY\OtherAcct'
Expand Down Expand Up @@ -136,8 +136,8 @@ try
}

$defaultParameters = @{
SQLInstanceName = $mockInstanceName
SQLServer = $mockNodeName
InstanceName = $mockInstanceName
ServerName = $mockServerName
EndpointName = $mockEndpointName
}

Expand All @@ -159,8 +159,8 @@ try

It 'Should return the same values as passed as parameters' {
$result = Get-TargetResource @testParameters
$result.SQLServer | Should -Be $testParameters.SQLServer
$result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName
$result.ServerName | Should -Be $testParameters.ServerName
$result.InstanceName | Should -Be $testParameters.InstanceName
}

It 'Should not return any values in the properties for the endpoint' {
Expand All @@ -187,8 +187,8 @@ try

It 'Should return the same values as passed as parameters' {
$result = Get-TargetResource @testParameters
$result.SQLServer | Should -Be $testParameters.SQLServer
$result.SQLInstanceName | Should -Be $testParameters.SQLInstanceName
$result.ServerName | Should -Be $testParameters.ServerName
$result.InstanceName | Should -Be $testParameters.InstanceName
$result.EndpointName | Should -Be $testParameters.EndpointName
$result.Port | Should -Be $mockEndpointListenerPort
$result.IpAddress | Should -Be $mockEndpointListenerIpAddress
Expand Down

0 comments on commit d6513cc

Please sign in to comment.