Skip to content

Commit

Permalink
Changes to SqlServerEndpointState
Browse files Browse the repository at this point in the history
  - BREAKING CHANGE: Parameter NodeName has been renamed to ServerName
    (issue dsccommunity#308).
  • Loading branch information
johlju committed Dec 1, 2017
1 parent 30ae6fa commit 85945a2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 37 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
- Changes to SqlServerEndpointPermission
- BREAKING CHANGE: Parameter NodeName has been renamed to ServerName
([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).
- Changes to SqlServerEndpointState
- BREAKING CHANGE: Parameter NodeName has been renamed to ServerName
([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).
- Changes to SqlServerLogin
- BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare
.PARAMETER InstanceName
The name of the SQL instance to be configured.
.PARAMETER NodeName
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER Name
Expand All @@ -26,7 +26,7 @@ function Get-TargetResource

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

[Parameter(Mandatory = $true)]
[System.String]
Expand All @@ -37,7 +37,7 @@ function Get-TargetResource

try
{
$sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName
$sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

$endpointObject = $sqlServerObject.Endpoints[$Name]
if ($null -ne $endpointObject)
Expand All @@ -56,7 +56,7 @@ function Get-TargetResource

return @{
InstanceName = [System.String] $InstanceName
NodeName = [System.String] $NodeName
ServerName = [System.String] $ServerName
Name = [System.String] $Name
State = [System.String] $currentState
}
Expand All @@ -69,7 +69,7 @@ function Get-TargetResource
.PARAMETER InstanceName
The name of the SQL instance to be configured.
.PARAMETER NodeName
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER Name
Expand All @@ -89,7 +89,7 @@ function Set-TargetResource

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

[Parameter(Mandatory = $true)]
[System.String]
Expand All @@ -103,7 +103,7 @@ function Set-TargetResource

$parameters = @{
InstanceName = [System.String] $InstanceName
NodeName = [System.String] $NodeName
ServerName = [System.String] $ServerName
Name = [System.String] $Name
}

Expand All @@ -114,7 +114,7 @@ function Set-TargetResource
{
New-VerboseMessage -Message ('Changing state of endpoint ''{0}''' -f $Name)

$sqlServerObject = Connect-SQL -SQLServer $NodeName -SQLInstanceName $InstanceName
$sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

$endpointObject = $sqlServerObject.Endpoints[$Name]

Expand Down Expand Up @@ -143,7 +143,7 @@ function Set-TargetResource
.PARAMETER InstanceName
The name of the SQL instance to be configured.
.PARAMETER NodeName
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER Name
Expand All @@ -164,7 +164,7 @@ function Test-TargetResource

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

[Parameter(Mandatory = $true)]
[System.String]
Expand All @@ -178,7 +178,7 @@ function Test-TargetResource

$parameters = @{
InstanceName = $InstanceName
NodeName = $NodeName
ServerName = $ServerName
Name = $Name
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class MSFT_SqlServerEndpointState : OMI_BaseResource
{
[Key, Description("The name of the SQL instance to be configured.")] String InstanceName;
[Write, Description("The host name of the SQL Server to be configured. Default value is $env:COMPUTERNAME.")] String NodeName;
[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 endpoint.")] String Name;
[Write, Description("The state of the endpoint. Valid states are Started, Stopped or Disabled. Default value is 'Started'."), ValueMap{"Started","Stopped","Disabled"}, Values{"Started","Stopped","Disabled"}] String State;
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Configuration Example
# Start the DefaultMirrorEndpoint in the default instance
SqlServerEndpointState StartEndpoint1
{
NodeName = 'SQLNODE01.company.local'
ServerName = 'SQLNODE01.company.local'
InstanceName = 'MSSQLSERVER'
Name = 'DefaultMirrorEndpoint'
State = 'Started'
Expand All @@ -39,7 +39,7 @@ Configuration Example
# Start the HADR in the default instance
SqlServerEndpointState StartEndpoint2
{
NodeName = 'SQLNODE01.company.local'
ServerName = 'SQLNODE01.company.local'
InstanceName = 'MSSQLSERVER'
Name = 'HADR'
State = 'Started'
Expand All @@ -50,7 +50,7 @@ Configuration Example
# Start the DefaultMirrorEndpoint in the named instance INSTANCE1
SqlServerEndpointState StartEndpoint3
{
NodeName = 'SQLNODE01.company.local'
ServerName = 'SQLNODE01.company.local'
InstanceName = 'INSTANCE1'
Name = 'DefaultMirrorEndpoint'
State = 'Started'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Configuration Example
{
SqlServerEndpointState StopEndpoint
{
NodeName = 'SQLNODE01.company.local'
ServerName = 'SQLNODE01.company.local'
InstanceName = 'MSSQLSERVER'
Name = 'DefaultMirrorEndpoint'
State = 'Stopped'
Expand Down
44 changes: 23 additions & 21 deletions Tests/Unit/MSFT_SqlServerEndpointState.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
$script:DSCModuleName = 'SqlServerDsc'
$script:DSCResourceName = 'MSFT_SqlServerEndpointState'
$script:DSCModuleName = 'SqlServerDsc'
$script:DSCResourceName = 'MSFT_SqlServerEndpointState'

#region HEADER

# Unit Test Template Version: 1.2.0
$script:moduleRoot = Split-Path -Parent (Split-Path -Parent $PSScriptRoot)
if ( (-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests'))) -or `
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
(-not (Test-Path -Path (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1'))) )
{
& git @('clone','https://github.com/PowerShell/DscResource.Tests.git',(Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
& git @('clone', 'https://github.com/PowerShell/DscResource.Tests.git', (Join-Path -Path $script:moduleRoot -ChildPath '\DSCResource.Tests\'))
}

Import-Module (Join-Path -Path $script:moduleRoot -ChildPath 'DSCResource.Tests\TestHelper.psm1') -Force
Expand All @@ -20,12 +20,14 @@ $TestEnvironment = Initialize-TestEnvironment `

#endregion HEADER

function Invoke-TestSetup {
function Invoke-TestSetup
{
# Loading stub cmdlets
Import-Module -Name ( Join-Path -Path ( Join-Path -Path $PSScriptRoot -ChildPath Stubs ) -ChildPath SQLPSStub.psm1 ) -Force -Global
}

function Invoke-TestCleanup {
function Invoke-TestCleanup
{
Restore-TestEnvironment -TestEnvironment $TestEnvironment
}

Expand All @@ -49,21 +51,21 @@ try
$mockConnectSql = {
return New-Object Object |
Add-Member -MemberType ScriptProperty -Name 'Endpoints' {
return @(
@{
# TypeName: Microsoft.SqlServer.Management.Smo.Endpoint
$mockDynamicEndpointName = New-Object Object |
Add-Member -MemberType NoteProperty -Name 'Name' -Value $mockDynamicEndpointName -PassThru |
Add-Member -MemberType NoteProperty -Name 'EndpointState' -Value $mockDynamicEndpointState -PassThru -Force
}
)
} -PassThru -Force
return @(
@{
# TypeName: Microsoft.SqlServer.Management.Smo.Endpoint
$mockDynamicEndpointName = New-Object Object |
Add-Member -MemberType NoteProperty -Name 'Name' -Value $mockDynamicEndpointName -PassThru |
Add-Member -MemberType NoteProperty -Name 'EndpointState' -Value $mockDynamicEndpointState -PassThru -Force
}
)
} -PassThru -Force
}

$defaultParameters = @{
InstanceName = $mockInstanceName
NodeName = $mockNodeName
Name = $mockEndpointName
ServerName = $mockNodeName
Name = $mockEndpointName
}

#endregion Pester Test Initialization
Expand All @@ -88,7 +90,7 @@ try

It 'Should return the same values as passed as parameters' {
$result = Get-TargetResource @testParameters
$result.NodeName | Should -Be $testParameters.NodeName
$result.ServerName | Should -Be $testParameters.ServerName
$result.InstanceName | Should -Be $testParameters.InstanceName
$result.Name | Should -Be $testParameters.Name
}
Expand All @@ -109,7 +111,7 @@ try

It 'Should return the same values as passed as parameters' {
$result = Get-TargetResource @testParameters
$result.NodeName | Should -Be $testParameters.NodeName
$result.ServerName | Should -Be $testParameters.ServerName
$result.InstanceName | Should -Be $testParameters.InstanceName
$result.Name | Should -Be $testParameters.Name
}
Expand Down Expand Up @@ -144,7 +146,7 @@ try

It 'Should return the same values as passed as parameters' {
$result = Get-TargetResource @testParameters
$result.NodeName | Should -Be $testParameters.NodeName
$result.ServerName | Should -Be $testParameters.ServerName
$result.InstanceName | Should -Be $testParameters.InstanceName
$result.Name | Should -Be $testParameters.Name
}
Expand All @@ -165,7 +167,7 @@ try

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

0 comments on commit 85945a2

Please sign in to comment.