Skip to content

Commit

Permalink
Merge pull request #1428 from Yvand/yvand/spfarm-add-flighting
Browse files Browse the repository at this point in the history
[SPFarm] Ensure that flights are registered in SharePoint Subscription
  • Loading branch information
ykuijs authored Apr 22, 2023
2 parents b7bf054 + 9d17ae8 commit 580a33f
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 43 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- SPFarm
- Updated to run cmdlet `Update-SPFlightsConfigFile` on SharePoint Subscription.

## [5.4.0] - 2023-04-04

### Fixed
Expand Down
15 changes: 15 additions & 0 deletions SharePointDsc/DSCResources/MSFT_SPFarm/MSFT_SPFarm.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ function Set-TargetResource
}

$PSBoundParameters.SkipRegisterAsDistributedCacheHost = $SkipRegisterAsDistributedCacheHost
$supportsFlighting = $false

if ($PSBoundParameters.ContainsKey("CentralAdministrationUrl"))
{
Expand Down Expand Up @@ -879,6 +880,7 @@ function Set-TargetResource
Write-Verbose -Message ("Detected Version: SharePoint Server Subscription Edition - " +
"configuring server as $($params.ServerRole)")
$supportsSettingApplicationCredentialKey = $true
$supportsFlighting = $true
}
$executeArgs.Add("LocalServerRole", $params.ServerRole)
}
Expand Down Expand Up @@ -907,6 +909,7 @@ function Set-TargetResource
Write-Verbose -Message ("Detected Version: SharePoint Server Subscription Edition - " +
"configuring server as $($params.ServerRole)")
$supportsSettingApplicationCredentialKey = $true
$supportsFlighting = $true
}
$executeArgs.Add("ServerRoleOptional", $true)
}
Expand Down Expand Up @@ -1095,6 +1098,18 @@ function Set-TargetResource
}
}

if ($supportsFlighting -eq $true)
{
$spRootRegKey = "hklm:SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\16.0"
$spsLocation = Get-SPDscRegistryKey -Key $spRootRegKey -Value "Location"
$flightsConfigJsonFile = Join-Path -Path $spsLocation -ChildPath "CONFIG\SPFlightRawConfig.json"
if ((Test-Path -Path $flightsConfigJsonFile -PathType Leaf) -eq $true)
{
Write-Verbose -Message "Starting Update-SPFlightsConfigFile"
Update-SPFlightsConfigFile -FilePath $flightsConfigJsonFile | Out-Null
}
}

# Run common tasks for a new server
Write-Verbose -Message "Starting Install-SPHelpCollection"
Install-SPHelpCollection -All | Out-Null
Expand Down
169 changes: 126 additions & 43 deletions tests/Unit/SharePointDsc/SharePointDsc.SPFarm.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Invoke-TestSetup

$script:testEnvironment = Initialize-TestEnvironment `
-DSCModuleName $script:DSCModuleName `
-DSCResourceName $script:DSCResourceFullName `
-DscResourceName $script:DSCResourceFullName `
-ResourceType 'Mof' `
-TestType 'Unit'
}
Expand Down Expand Up @@ -109,6 +109,31 @@ try
}
return $returnVal
}
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return "Connection string example"
}
}
Mock -CommandName Test-Path {
if ($Path -eq "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\CONFIG\SPFlightRawConfig.json")
{
return $true
}
else
{
return $true
}
}
if ($Global:SPDscHelper.CurrentStubBuildNumber.Major -eq 16 -and
$Global:SPDscHelper.CurrentStubBuildNumber.Build -gt 13000)
{
Mock -CommandName Update-SPFlightsConfigFile -MockWith { }
}

function Add-SPDscEvent
{
Expand Down Expand Up @@ -231,7 +256,16 @@ try
RunCentralAdmin = $true
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down Expand Up @@ -281,7 +315,16 @@ try
RunCentralAdmin = $false
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down Expand Up @@ -330,7 +373,16 @@ try
RunCentralAdmin = $true
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down Expand Up @@ -381,7 +433,16 @@ try
RunCentralAdmin = $false
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down Expand Up @@ -475,7 +536,16 @@ try
RunCentralAdmin = $true
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down Expand Up @@ -558,7 +628,16 @@ try
RunCentralAdmin = $true
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
if ($global:SPDscConfigLockTriggered)
Expand Down Expand Up @@ -623,10 +702,6 @@ try
CentralAdministrationUrl = "https://admin.contoso.com"
}

Mock -CommandName Get-SPDscRegistryKey -MockWith {
return "Connection string example"
}

Mock -CommandName Get-SPFarm -MockWith {
return @{
Name = $testParams.FarmConfigDatabaseName
Expand Down Expand Up @@ -738,10 +813,6 @@ try
CentralAdministrationUrl = "http://localhost:8080"
}

Mock -CommandName Get-SPDscRegistryKey -MockWith {
return "Connection string example"
}

Mock -CommandName Get-SPFarm -MockWith {
return @{
Name = $testParams.FarmConfigDatabaseName
Expand Down Expand Up @@ -841,10 +912,6 @@ try
CentralAdministrationPort = 8080
}

Mock -CommandName Get-SPDscRegistryKey -MockWith {
return "Connection string example"
}

Mock -CommandName Get-SPFarm -MockWith {
return @{
Name = $testParams.FarmConfigDatabaseName
Expand Down Expand Up @@ -934,10 +1001,6 @@ try
CentralAdministrationAuth = "Kerberos"
}

Mock -CommandName Get-SPDscRegistryKey -MockWith {
return "Connection string example"
}

Mock -CommandName Get-SPFarm -MockWith {
return @{
Name = $testParams.FarmConfigDatabaseName
Expand Down Expand Up @@ -1075,10 +1138,6 @@ try
CentralAdministrationAuth = "NTLM"
}

Mock -CommandName Get-SPDscRegistryKey -MockWith {
return "Connection string example"
}

Mock -CommandName Get-SPFarm -MockWith {
return @{
Name = $testParams.FarmConfigDatabaseName
Expand Down Expand Up @@ -1215,10 +1274,6 @@ try
CentralAdministrationPort = 80
}

Mock -CommandName Get-SPDscRegistryKey -MockWith {
return "Connection string example"
}

Mock -CommandName Get-SPFarm -MockWith {
return @{
Name = $testParams.FarmConfigDatabaseName
Expand Down Expand Up @@ -1358,10 +1413,6 @@ try
CentralAdministrationPort = 443
}

Mock -CommandName Get-SPDscRegistryKey -MockWith {
return "Connection string example"
}

Mock -CommandName Get-SPFarm -MockWith {
return @{
Name = $testParams.FarmConfigDatabaseName
Expand Down Expand Up @@ -1500,7 +1551,16 @@ try
RunCentralAdmin = $true
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down Expand Up @@ -1578,7 +1638,16 @@ try
RunCentralAdmin = $true
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down Expand Up @@ -1657,10 +1726,6 @@ try
CentralAdministrationPort = 443
}

Mock -CommandName Get-SPDscRegistryKey -MockWith {
return "Connection string example"
}

Mock -CommandName Get-SPFarm -MockWith {
return @{
Name = $testParams.FarmConfigDatabaseName
Expand Down Expand Up @@ -2265,7 +2330,16 @@ try
RunCentralAdmin = $true
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down Expand Up @@ -2413,7 +2487,16 @@ try
RunCentralAdmin = $false
}

Mock -CommandName "Get-SPDscRegistryKey" -MockWith { return $null }
Mock -CommandName Get-SPDscRegistryKey -MockWith {
if ($Value -eq "Location")
{
return "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16"
}
elseif ($Value -eq "dsn")
{
return $null
}
}
Mock -CommandName "Get-SPFarm" -MockWith { return $null }
Mock -CommandName "Get-SPDscConfigDBStatus" -MockWith {
return @{
Expand Down

0 comments on commit 580a33f

Please sign in to comment.