Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/PowerShell/dev' into xSQLServer…
Browse files Browse the repository at this point in the history
…Script
  • Loading branch information
David Reynolds authored and David Reynolds committed Aug 21, 2016
2 parents dba7ab8 + d906654 commit c4cbb31
Show file tree
Hide file tree
Showing 12 changed files with 6,104 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ function Set-TargetResource
"Present"
{
Grant-ServerPerms -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName -AuthorizedUser "NT AUTHORITY\SYSTEM" -SetupCredential $SetupCredential
New-ListenerADObject -AvailabilityGroupNameListener $AvailabilityGroupNameListener -SetupCredential $SetupCredential
New-ListenerADObject -AvailabilityGroupNameListener $AvailabilityGroupNameListener -SetupCredential $SetupCredential -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName

$FailoverCondition = 3
$HealthCheckTimeout = 30000
$ConnectionModeInPrimary ="AllowAllConnections"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Get-TargetResource

$presentIpAddress = $listener.AvailabilityGroupListenerIPAddresses

$dhcp = [bool]( $presentIpAddress | Select-Object -first 1 IsDHCP )
$dhcp = [bool]( $presentIpAddress | Select-Object -First 1 -ExpandProperty IsDHCP )

$ipAddress = @()
foreach( $currentIpAddress in $presentIpAddress ) {
Expand Down Expand Up @@ -169,6 +169,10 @@ function Set-TargetResource
throw New-TerminatingError -ErrorType AvailabilityGroupListenerIPChangeError -FormatArgs @($($IpAddress -join ', '),$($listenerState.IpAddress -join ', ')) -ErrorCategory InvalidOperation
}
}

if( $($PSBoundParameters.ContainsKey('DHCP')) -and $listenerState.DHCP -ne $DHCP ) {
throw New-TerminatingError -ErrorType AvailabilityGroupListenerDHCPChangeError -FormatArgs @( $DHCP, $($listenerState.DHCP) ) -ErrorCategory InvalidOperation
}

if( $listenerState.Port -ne $Port -or -not $ipAddressEqual ) {
New-VerboseMessage -Message "Listener differ in configuration."
Expand All @@ -193,7 +197,7 @@ function Set-TargetResource
$newIpAddress = @()

foreach( $currentIpAddress in $IpAddress ) {
if( -not $listenerState.IpAddress -contains $currentIpAddress ) {
if( -not ( $listenerState.IpAddress -contains $currentIpAddress ) ) {
$newIpAddress += $currentIpAddress
}
}
Expand Down Expand Up @@ -274,9 +278,21 @@ function Test-TargetResource
}

[System.Boolean] $result = $false
if( ( $Ensure -eq "" -or ( $Ensure -ne "" -and $listenerState.Ensure -eq $Ensure) ) -and ($Port -eq "" -or $listenerState.Port -eq $Port) -and $ipAddressEqual ) {
$result = $true
if( $listenerState.Ensure -eq $Ensure) {
if( $Ensure -eq 'Absent' ) {
$result = $true
}
}

if( -not $($PSBoundParameters.ContainsKey('Ensure')) -or $Ensure -eq "Present" ) {
if( ( $Port -eq "" -or $listenerState.Port -eq $Port) -and
$ipAddressEqual -and
( -not $($PSBoundParameters.ContainsKey('DHCP')) -or $listenerState.DHCP -eq $DHCP ) )
{
$result = $true
}
}

} else {
throw New-TerminatingError -ErrorType UnexpectedErrorFromGet -ErrorCategory InvalidResult
}
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,20 @@ Please check out common DSC Resources [contributing guidelines](https://github.c

### Unreleased
* Added resources
- xSQLServerReplication
- xSQLServerScript
* Added tests for resources
- xSQLServerPermission
- xSQLServerEndpointState
- xSQLServerEndpointPermission
- xSQLServerAvailabilityGroupListener
* Fixes in xSQLServerAvailabilityGroupListener
- In one case the Get-method did not report that DHCP was configured.
- Now the resource will throw 'Not supported' when IP is changed between Static and DHCP.
- Fixed an issue where sometimes the listener wasn't removed.
- Fixed the issue when trying to add a static IP to a listener was ignored.
* Fixes in xSQLAOGroupEnsure
- Added parameters to New-ListenerADObject to allow usage of a named instance.

### 1.8.0.0

Expand All @@ -345,7 +358,6 @@ Please check out common DSC Resources [contributing guidelines](https://github.c
- xSQLServerEndpointState
- xSQLServerEndpointPermission
- xSQLServerAvailabilityGroupListener
- xSQLServerReplication
* xSQLServerHelper
- added functions
- Import-SQLPSModule
Expand Down
49 changes: 33 additions & 16 deletions Tests/Unit/Stubs/SMO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,33 @@

namespace Microsoft.SqlServer.Management.Smo
{
public class Globals
{
// Static property that is switched on or off by tests if data should be mocked (true) or not (false).
public static bool GenerateMockData = false;
}

// Typename: Microsoft.SqlServer.Management.Smo.ObjectPermissionSet
// BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase
// Used by:
// xSQLServerEndpointPermission.Tests.ps1
public class ObjectPermissionSet
{
public ObjectPermissionSet(){}

public ObjectPermissionSet(
bool connect )
{
this.Connect = connect;
}

public bool Connect = false;
}

// TypeName: Microsoft.SqlServer.Management.Smo.ServerPermissionSet
// BaseType: Microsoft.SqlServer.Management.Smo.PermissionSetBase
// Used by:
// xSQLServerPermission
// xSQLServerPermission.Tests.ps1
public class ServerPermissionSet
{
public ServerPermissionSet(){}
Expand All @@ -32,7 +55,7 @@ public ServerPermissionSet(
// TypeName: Microsoft.SqlServer.Management.Smo.ServerPermissionInfo
// BaseType: Microsoft.SqlServer.Management.Smo.PermissionInfo
// Used by:
// xSQLServerPermission
// xSQLServerPermission.Tests.ps1
public class ServerPermissionInfo
{
public ServerPermissionInfo()
Expand All @@ -54,33 +77,23 @@ public ServerPermissionInfo(
// TypeName: Microsoft.SqlServer.Management.Smo.Server
// BaseType: Microsoft.SqlServer.Management.Smo.SqlSmoObject
// Used by:
// xSQLServerPermission
// xSQLServerPermission.Tests.ps1
public class Server
{
private bool _generateMockData = false;

public string MockGranteeName;

public string Name;
public string DisplayName;
public string InstanceName;
public bool IsHadrEnabled = false;

public Server()
{
_generateMockData = false;
}

public Server( bool generateMockData )
{
this._generateMockData = generateMockData;
}
public Server(){}

public Microsoft.SqlServer.Management.Smo.ServerPermissionInfo[] EnumServerPermissions( string principal, Microsoft.SqlServer.Management.Smo.ServerPermissionSet permissionSetQuery )
{
List<Microsoft.SqlServer.Management.Smo.ServerPermissionInfo> listOfServerPermissionInfo = new List<Microsoft.SqlServer.Management.Smo.ServerPermissionInfo>();

if( this._generateMockData ) {
if( Globals.GenerateMockData ) {
Microsoft.SqlServer.Management.Smo.ServerPermissionSet[] permissionSet = {
new Microsoft.SqlServer.Management.Smo.ServerPermissionSet( true, false, false, false ),
new Microsoft.SqlServer.Management.Smo.ServerPermissionSet( false, true, false, false ),
Expand Down Expand Up @@ -108,7 +121,11 @@ public void Grant( Microsoft.SqlServer.Management.Smo.ServerPermissionSet permis

public void Revoke( Microsoft.SqlServer.Management.Smo.ServerPermissionSet permission, string granteeName )
{

if( granteeName != this.MockGranteeName )
{
string errorMessage = "Expected to get granteeName == '" + this.MockGranteeName + "'. But got '" + granteeName + "'";
throw new System.ArgumentException(errorMessage, "granteeName");
}
}
}
}
Loading

0 comments on commit c4cbb31

Please sign in to comment.