Skip to content

Commit

Permalink
SqlSetup: Fix AddNode failing due to missing setup parameters (#2047)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabrond authored Oct 6, 2024
1 parent 6d8e2ff commit 5677cd5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- SqlSetup
- Fixed issue with AddNode where cluster IP information was not being passed to
setup.exe. ([issue #1171](https://github.com/dsccommunity/SqlServerDsc/issues/1171))

## [17.0.0] - 2024-09-30

### Added
Expand Down
25 changes: 13 additions & 12 deletions source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
#>
function Get-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called implicitly in several function, for example Get-SqlEngineProperties')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification = 'The command Connect-Sql is called implicitly in several function, for example Get-SqlEngineProperties')]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down Expand Up @@ -722,8 +722,8 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification='Because $global:DSCMachineStatus is used to trigger a Restart, either by force or when there are pending changes.')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification='Because $global:DSCMachineStatus is only set, never used (by design of Desired State Configuration).')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Justification = 'Because $global:DSCMachineStatus is used to trigger a Restart, either by force or when there are pending changes.')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Because $global:DSCMachineStatus is only set, never used (by design of Desired State Configuration).')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -1265,15 +1265,16 @@ function Set-TargetResource
$setupArguments['FailoverClusterDisks'] = ($failoverClusterDisks | Sort-Object)
}


# Determine network mapping for specific cluster installation types
if ($Action -in @('CompleteFailoverCluster', 'InstallFailoverCluster'))
if ($Action -in @('CompleteFailoverCluster', 'InstallFailoverCluster', 'AddNode'))
{
$clusterIPAddresses = @()

# If no IP Address has been specified, use "DEFAULT"
if ($FailoverClusterIPAddress.Count -eq 0)
{
$clusterIPAddresses += "DEFAULT"
$clusterIPAddresses += 'DEFAULT'
}
else
{
Expand Down Expand Up @@ -1525,7 +1526,7 @@ function Set-TargetResource
$setupArguments['ASSysAdminAccounts'] = @($PsDscContext.RunAsUser)
}

if ($PSBoundParameters.ContainsKey("ASSysAdminAccounts"))
if ($PSBoundParameters.ContainsKey('ASSysAdminAccounts'))
{
$setupArguments['ASSysAdminAccounts'] += $ASSysAdminAccounts
}
Expand Down Expand Up @@ -1636,20 +1637,20 @@ function Set-TargetResource

if ($SecurityMode -eq 'SQL')
{
$log = $log.Replace($SAPwd.GetNetworkCredential().Password, "********")
$log = $log.Replace($SAPwd.GetNetworkCredential().Password, '********')
}

if ($ProductKey -ne "")
if ($ProductKey -ne '')
{
$log = $log.Replace($ProductKey, "*****-*****-*****-*****-*****")
$log = $log.Replace($ProductKey, '*****-*****-*****-*****-*****')
}

$logVars = @('AgtSvcAccount', 'SQLSvcAccount', 'FTSvcAccount', 'RSSvcAccount', 'ASSvcAccount', 'ISSvcAccount')
foreach ($logVar in $logVars)
{
if ($PSBoundParameters.ContainsKey($logVar))
{
$log = $log.Replace((Get-Variable -Name $logVar).Value.GetNetworkCredential().Password, "********")
$log = $log.Replace((Get-Variable -Name $logVar).Value.GetNetworkCredential().Password, '********')
}
}

Expand Down Expand Up @@ -1996,7 +1997,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is implicitly called when Get-TargetResource is called')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification = 'The command Connect-Sql is implicitly called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down Expand Up @@ -2342,7 +2343,7 @@ function Test-TargetResource
Write-Verbose -Message $script:localizedData.EvaluatingClusterParameters

$variableNames = $PSBoundParameters.Keys |
Where-Object -FilterScript { $_ -imatch "^FailoverCluster" }
Where-Object -FilterScript { $_ -imatch '^FailoverCluster' }

foreach ($variableName in $variableNames)
{
Expand Down
2 changes: 0 additions & 2 deletions source/DSCResources/DSC_SqlSetup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,3 @@ AnalysisServicesConnection | A new method of loading the assembly *Microsoft.Ana
## Known issues

All issues are not listed here, see [here for all open issues](https://github.com/dsccommunity/SqlServerDsc/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+SqlSetup).

> [!IMPORTANT] The setup action AddNode is not currently functional.
18 changes: 18 additions & 0 deletions tests/Unit/DSC_SqlSetup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3226,6 +3226,22 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' {
Features = ''
}
}

$mockDynamicClusterSites = @(
@{
Name = 'SiteA'
Address = '10.0.0.10' # First site IP address
Mask = '255.255.255.0'
}
)

Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance_MSClusterNetwork -ParameterFilter {
($Namespace -eq 'root/MSCluster') -and ($ClassName -eq 'MSCluster_Network') -and ($Filter -eq 'Role >= 2')
}

Mock -CommandName Test-IPAddress -MockWith {
return $true
}
}

It 'Should pass proper parameters to setup' {
Expand All @@ -3240,6 +3256,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' {
SqlSvcPassword = 'SqlS3v!c3P@ssw0rd'
AsSvcAccount = 'COMPANY\AnalysisAccount'
AsSvcPassword = 'AnalysisS3v!c3P@ssw0rd'
FailoverClusterIPAddresses = 'IPv4;10.0.0.10;SiteA_Prod;255.255.255.0'
}

InModuleScope -ScriptBlock {
Expand All @@ -3255,6 +3272,7 @@ Describe 'SqlSetup\Set-TargetResource' -Tag 'Set' {
SqlSvcAccount = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @('COMPANY\SqlAccount', ('SqlS3v!c3P@ssw0rd' | ConvertTo-SecureString -AsPlainText -Force))
ASSvcAccount = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList @('COMPANY\AnalysisAccount', ('AnalysisS3v!c3P@ssw0rd' | ConvertTo-SecureString -AsPlainText -Force))
FailoverClusterNetworkName = 'TestDefaultCluster'
FailoverClusterIPAddress = '10.0.0.10'
SQLSysAdminAccounts = 'COMPANY\User1', 'COMPANY\SQLAdmins'
}

Expand Down

0 comments on commit 5677cd5

Please sign in to comment.