Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADReplicationSiteLink: Add Integration tests, add setting 'options' #509

Merged
merged 32 commits into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
419c4a4
Checking in to switch dev machines
1800Zeta Sep 12, 2019
8dc90e7
Add description attribute to test-resource with unit tests
1800Zeta Sep 13, 2019
e4b255d
Add Description to Set-TargetResource
1800Zeta Sep 13, 2019
dbb48d0
Update test to increase codecov
1800Zeta Sep 13, 2019
de1cbba
Added Integration Testing
1800Zeta Sep 13, 2019
f1fd66d
Update Help Text and a small tidy up
1800Zeta Sep 13, 2019
55b0c3d
Update CHANGELOG.md
1800Zeta Sep 13, 2019
ee8dbe9
Update MSFT_ADReplicationSite.Tests.ps1
1800Zeta Sep 13, 2019
07933f2
Updates based on review
1800Zeta Sep 16, 2019
823a1c5
Set RenameDefaultFirstSiteName to false by default
1800Zeta Sep 16, 2019
ff0629a
Update CHANGELOG.md
1800Zeta Sep 16, 2019
bc5dd69
Feedback request Pt2
1800Zeta Sep 18, 2019
83b8971
Remove extra parentheses as requested
1800Zeta Sep 18, 2019
1ce3e66
Added Integration Tests
1800Zeta Sep 18, 2019
0e6e7ab
Adding abilty to configure the Options on a sitelink
1800Zeta Sep 20, 2019
3808372
Complete with options being set and unit and integration tests
1800Zeta Sep 20, 2019
9905c6c
Remove a debug pause from integration test
1800Zeta Sep 20, 2019
8223ca3
Merge remote-tracking branch 'upstream/dev' into ADReplicationSiteLink
1800Zeta Sep 24, 2019
a174ea5
Adding some polish
1800Zeta Sep 25, 2019
1986c03
Update MSFT_ADReplicationSiteLink.psm1
1800Zeta Sep 25, 2019
8102a0e
Merge remote-tracking branch 'upstream/dev' into ADReplicationSiteLink
1800Zeta Sep 27, 2019
7ac926f
Update MSFT_ADReplicationSiteLink.tests.ps1
1800Zeta Sep 27, 2019
f90cebb
Update MSFT_ADReplicationSiteLink.tests.ps1
1800Zeta Sep 27, 2019
6d99e80
Merge remote-tracking branch 'upstream/dev' into ADReplicationSiteLink
1800Zeta Oct 10, 2019
c0a86e0
Update MSFT_ADReplicationSiteLink.psm1
1800Zeta Oct 10, 2019
46be221
Update MSFT_ADReplicationSiteLink.psm1
1800Zeta Oct 10, 2019
5cbca3c
Update MSFT_ADReplicationSiteLink.tests.ps1
1800Zeta Oct 10, 2019
e5c8a31
Update Examples
1800Zeta Oct 10, 2019
995596b
Update 3-ADReplicationSiteLink_EnableOptions_Config.ps1
1800Zeta Oct 10, 2019
91367cd
Further Feedback received
1800Zeta Oct 11, 2019
26e776e
Update MSFT_ADReplicationSiteLink.tests.ps1
1800Zeta Oct 14, 2019
76b9a2e
Update MSFT_ADReplicationSiteLink.psm1
1800Zeta Oct 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
- Changes to ADReplicationSubnet
- Added 'Description' attribute parameter ([issue #503](https://github.com/PowerShell/ActiveDirectoryDsc/issues/500))
- Added Integration testing ([issue #357](https://github.com/PowerShell/ActiveDirectoryDsc/issues/357))
- Changes to ADReplicationSiteLink
- Added Integration testing ([issue #356](https://github.com/PowerShell/ActiveDirectoryDsc/issues/356)).
- Added ability to set 'Options' such as Change Notification Replication ([issue #504](https://github.com/PowerShell/ActiveDirectoryDsc/issues/504)).
- Changes to ActiveDirectoryDsc.Common
- Fix `Test-DscPropertyState` Failing when Comparing $Null and Arrays. ([issue #513](https://github.com/PowerShell/ActiveDirectoryDsc/issues/513))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Get-TargetResource

try
{
$siteLink = Get-ADReplicationSiteLink -Identity $Name -Properties 'Description'
$siteLink = Get-ADReplicationSiteLink -Identity $Name -Properties 'Description', 'Options'
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException]
{
Expand All @@ -46,6 +46,9 @@ function Get-TargetResource
ReplicationFrequencyInMinutes = $null
SitesIncluded = $null
SitesExcluded = $SitesExcluded
OptionChangeNotification = $false
OptionTwoWaySync = $false
OptionDisableCompression = $false
Ensure = 'Absent'
}
$siteLink = $null
Expand All @@ -68,6 +71,15 @@ function Get-TargetResource
}
}

if ($null -eq $siteLink.Options)
{
$siteLinkOptions = Get-EnabledOptions -OptionValue 0
}
else
{
$siteLinkOptions = Get-EnabledOptions -OptionValue $siteLink.Options
}

$sitesExcludedEvaluated = $SitesExcluded |
Where-Object -FilterScript { $_ -notin $siteCommonNames }

Expand All @@ -78,6 +90,9 @@ function Get-TargetResource
ReplicationFrequencyInMinutes = $siteLink.ReplicationFrequencyInMinutes
SitesIncluded = $siteCommonNames
SitesExcluded = $sitesExcludedEvaluated
OptionChangeNotification = $siteLinkOptions.USE_NOTIFY
OptionTwoWaySync = $siteLinkOptions.TWOWAY_SYNC
OptionDisableCompression = $siteLinkOptions.DISABLE_COMPRESSION
Ensure = 'Present'
}
}
Expand Down Expand Up @@ -107,6 +122,15 @@ function Get-TargetResource
.PARAMETER SitesExcluded
Specifies the list of sites to remove from a site link.

.PARAMETER OptionChangeNotification
Enables or disables Change Notification Replication on a site link. Default value is $false.

.PARAMETER OptionTwoWaySync
Two Way Sync on a site link. Default value is $false.

.PARAMETER OptionDisableCompression
Enables or disables Compression on a site link. Default value is $false.

.PARAMETER Ensure
Specifies if the site link is created or deleted.
#>
Expand Down Expand Up @@ -139,6 +163,18 @@ function Set-TargetResource
[System.String[]]
$SitesExcluded,

[Parameter()]
[System.Boolean]
$OptionChangeNotification = $false,

[Parameter()]
[System.Boolean]
$OptionTwoWaySync = $false,

[Parameter()]
[System.Boolean]
$OptionDisableCompression = $false,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[System.String]
Expand Down Expand Up @@ -170,6 +206,8 @@ function Set-TargetResource
Identity = $Name
}

$replaceParameters = @{}

# build the SitesIncluded hashtable.
$sitesIncludedParameters = @{ }
if ($SitesExcluded)
Expand Down Expand Up @@ -199,15 +237,59 @@ function Set-TargetResource
$setParameters.Add('SitesIncluded', $sitesIncludedParameters)
}

# Calculate the Options value for Change Notification replication
if ($PSBoundParameters.ContainsKey('OptionChangeNotification'))
{
$changeNotification = $OptionChangeNotification
}
else
{
$changeNotification = $currentADSiteLink.OptionChangeNotification
}

if ($PSBoundParameters.ContainsKey('OptionTwoWaySync'))
{
$twoWaySync = $OptionTwoWaySync
}
else
{
$twoWaySync = $currentADSiteLink.OptionTwoWaySync
}

if ($PSBoundParameters.ContainsKey('OptionDisableCompression'))
{
$disableCompression = $OptionDisableCompression
}
else
{
$disableCompression = $currentADSiteLink.OptionDisableCompression
}

$optionsValue = ConvertTo-EnabledOptions -OptionChangeNotification $changeNotification -OptionTwoWaySync $twoWaySync -OptionDisableCompression $disableCompression

if ($optionsValue -eq 0)
{
$setParameters.Add('Clear', 'Options')
}
else
{
$replaceParameters.Add('Options', $optionsValue)
}

# Add the rest of the parameters.
foreach ($parameter in $PSBoundParameters.Keys)
{
if ($parameter -notmatch 'SitesIncluded|SitesExcluded|Name|Ensure')
if ($parameter -notmatch 'SitesIncluded|SitesExcluded|Name|Ensure|OptionChangeNotification|OptionTwoWaySync|OptionDisableCompression')
{
$setParameters.Add($parameter, $PSBoundParameters[$parameter])
}
}

if ($replaceParameters.Count -gt 0)
{
$setParameters.Add('Replace', $replaceParameters)
}

Set-ADReplicationSiteLink @setParameters
}
}
Expand Down Expand Up @@ -241,6 +323,15 @@ function Set-TargetResource
.PARAMETER SitesExcluded
Specifies the list of sites to remove from a site link.

.PARAMETER OptionChangeNotification
Enables or disables Change Notification Replication on a site link. Default value is $false.

.PARAMETER OptionTwoWaySync
Two Way Sync on a site link. Default value is $false.

.PARAMETER OptionDisableCompression
Enables or disables Compression on a site link. Default value is $false.

.PARAMETER Ensure
Specifies if the site link is created or deleted.
#>
Expand Down Expand Up @@ -274,6 +365,18 @@ function Test-TargetResource
[System.String[]]
$SitesExcluded,

[Parameter()]
[System.Boolean]
$OptionChangeNotification = $false,

[Parameter()]
[System.Boolean]
$OptionTwoWaySync = $false,

[Parameter()]
[System.Boolean]
$OptionDisableCompression = $false,

[Parameter()]
[ValidateSet('Present', 'Absent')]
[System.String]
Expand Down Expand Up @@ -309,10 +412,10 @@ function Test-TargetResource
}
}

# Test for Description|ReplicationFrequencyInMinutes|Cost.
foreach ($parameter in $PSBoundParameters.Keys)
{
if ($parameter -match 'Description|ReplicationFrequencyInMinutes|Cost')
# Test for Description|ReplicationFrequencyInMinutes|Cost.
if ($parameter -match 'Description|ReplicationFrequencyInMinutes|Cost|OptionChangeNotification|OptionTwoWaySync|OptionDisableCompression')
{
if ($PSBoundParameters[$parameter] -ne $currentSiteLink[$parameter])
{
Expand Down Expand Up @@ -353,4 +456,99 @@ function Resolve-SiteLinkName
return $adSite.Name
}

<#
.SYNOPSIS
Calculates the options enabled on a Site Link

.PARAMETER OptionValue
The value of currently enabled options
#>
function Get-EnabledOptions
{
[OutputType([System.Collections.Hashtable])]
[CmdletBinding()]

param
(
[Parameter(Mandatory = $true)]
[System.Int32]
$OptionValue
)

$returnValue = @{
USE_NOTIFY = $false
TWOWAY_SYNC = $false
DISABLE_COMPRESSION = $false
}

if (1 -band $optionValue)
{
$returnValue.USE_NOTIFY = $true
}

if (2 -band $optionValue)
{
$returnValue.TWOWAY_SYNC = $true
}

if (4 -band $optionValue)
{
$returnValue.DISABLE_COMPRESSION = $true
}

return $returnValue
}

<#
.SYNOPSIS
Calculates the options value for the given choices

.PARAMETER OptionChangeNotification
Enable/Disable Change notification replication

.PARAMETER OptionTwoWaySync
Enable/Disable Two Way sync

.PARAMETER OptionDisableCompression
Enable/Disable Compression
#>
function ConvertTo-EnabledOptions
{
[OutputType([System.Int32])]
[CmdletBinding()]
param
(
[Parameter()]
[System.Boolean]
$OptionChangeNotification,

[Parameter()]
[System.Boolean]
$OptionTwoWaySync,

[Parameter()]
[System.Boolean]
$OptionDisableCompression
)

$returnValue = 0

if ($OptionChangeNotification)
{
$returnValue = $returnValue + 1
}

if ($OptionTwoWaySync)
{
$returnValue = $returnValue + 2
}

if ($OptionDisableCompression)
{
$returnValue = $returnValue + 4
}

return $returnValue
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ class MSFT_ADReplicationSiteLink : OMI_BaseResource
[Write, Description("Specifies the list of sites included in the site link.")] String SitesIncluded[];
[Write, Description("Specifies the list of sites to exclude from the site link.")] String SitesExcluded[];
[Write, Description("Specifies if the site link should be present or absent. Default value is 'Present'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Write, Description("Enables or disables Change Notification Replication on a site link. Default value is $false.")] Boolean OptionChangeNotification;
[Write, Description("Enables or disables Two Way Sync on a site link. Default value is $false.")] Boolean OptionTwoWaySync;
[Write, Description("Enables or disables Compression on a site link. Default value is $false.")] Boolean OptionDisableCompression;
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
Write - String
Specifies the list of sites to exclude from the site link.

.PARAMETER OptionChangeNotification
Enables or disables Change Notification Replication on a site link. Default value is $false.

.PARAMETER OptionTwoWaySync
Two Way Sync on a site link. Default value is $false.

.PARAMETER OptionDisableCompression
Enables or disables Compression on a site link. Default value is $false.

.PARAMETER Ensure
Write - String
Allowed values: Present, Absent
Expand Down Expand Up @@ -80,4 +89,27 @@ Configuration ADReplicationSiteLink_ModifyExistingReplicationSiteLink_Config
}
}

.EXAMPLE 3

This configuration will modify an existing AD Replication Site Link.

Configuration ADReplicationSiteLink_EnableOptions_Config
{
Import-DscResource -Module ActiveDirectoryDsc

Node localhost
{
ADReplicationSiteLink 'HQSiteLink'
{
Name = 'HQSiteLInk'
SitesIncluded = 'site1'
SitesExcluded = 'site2'
Cost = 100
ReplicationFrequencyInMinutes = 20
OptionChangeNotification = $true
OptionTwoWaySync = $true
OptionDisableCompression = $true
Ensure = 'Present'
}
}
}
Loading