dsccommunity / dsccommunity/SqlServerDsc

SqlAGReplica: Test may calculate EndpointHostName incorrectly

Open
#1,304 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
PowerShell
Stars
385
Forks
224
PR merge metrics
No merged PRs in 30d

Description

This is a very low priority issue as it's not blocking me on anything.

Details of the scenario you tried and the problem that is occurring

I was testing a DSC which modifies the ReadOnlyRoutingConnectionUrl.

$configurationData = @{
    AllNodes = @(
        @{
            NodeName = '*'
            PsDscAllowPlainTextPassword = $true
            PsDscAllowDomainUser = $true
        }
        @{
         NodeName = 'localhost'
        }
    )
}

configuration Blah {
    param(
        $Credential
    )
    Import-DscResource -Module SqlServerDsc

    Node $AllNodes.NodeName {    
        SqlAGReplica Blah {
            ServerName = 'DAC1N1'
            InstanceName = 'MSSQLSERVER'

            AvailabilityGroupName = 'AG1'
            Name = 'DAC1N1'
            ReadOnlyRoutingConnectionUrl = 'tcp://DAC1N1.lab.com:1433'
            PsDscRunAsCredential = $Credential
        }
    }
}

if (!$credential) { $credential = Get-Credential LAB\LocalAdministrator }
Blah -Credential $credential -ConfigurationData $configurationData
Start-DscConfiguration -Force -Wait -Verbose -Path Blah

In this case DAC1N1 is a secondary, the code finds SEC1N1 is the primary, connects to that to do its update and everything is fine.

But if you try to be smart and connect to the primary first go (ServerName = 'SEC1N1') and expect it just to modify the AG for DAC1N1 things go awry.

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer CHWK01 with user sid S-1-5-21-4179733049-4140502011-3911003846-1106.
VERBOSE: [CHWK01]: LCM:  [ Start  Set      ]
VERBOSE: [CHWK01]:                            [DSCEngine] Importing the module C:\Program Files\WindowsPowerShell\Modules\SqlServerDsc\DscResources\MSFT_SqlAGReplica\MSFT_SqlAGReplica.psm1 in force mode.
VERBOSE: [CHWK01]: LCM:  [ Start  Resource ]  [[SqlAGReplica]Blah]
VERBOSE: [CHWK01]: LCM:  [ Start  Test     ]  [[SqlAGReplica]Blah]
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Importing the module MSFT_SqlAGReplica in force mode.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Importing the module MSFT_SqlAGReplica in force mode.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Preferred module SqlServer found.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Importing PowerShell module 'SqlServer' with version '21.0.17279' from path 'C:\Program Files\WindowsPowerShell\Modules\SqlServer\SqlServer.psm1'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Connected to SQL instance 'SEC1N1'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] 2019-03-13_23-47-10: 'EndpointHostName' should be 'SEC1N1' but is 'DAC1N1'
VERBOSE: [CHWK01]: LCM:  [ End    Test     ]  [[SqlAGReplica]Blah]  in 1.5470 seconds.
VERBOSE: [CHWK01]: LCM:  [ Start  Set      ]  [[SqlAGReplica]Blah]
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Importing the module MSFT_SqlAGReplica in force mode.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Importing the module MSFT_SqlAGReplica in force mode.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Preferred module SqlServer found.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Importing PowerShell module 'SqlServer' with version '21.0.17279' from path 'C:\Program Files\WindowsPowerShell\Modules\SqlServer\SqlServer.psm1'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Found PowerShell module SqlServer already imported in the session.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Connected to SQL instance 'SEC1N1'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] The recommended account 'NT SERVICE\ClusSvc' is missing one or more of the following permissions: Trying with 'NT AUTHORITY\SYSTEM'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Getting the effective permissions for the login 'NT AUTHORITY\SYSTEM' on 'MSSQLSERVER'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Found PowerShell module SqlServer already imported in the session.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] Connected to SQL instance 'SEC1N1'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]Blah] The cluster login 'NT AUTHORITY\SYSTEM' has the required permissions.
VERBOSE: [CHWK01]: LCM:  [ End    Set      ]  [[SqlAGReplica]Blah]  in 0.8290 seconds.
VERBOSE: [CHWK01]: LCM:  [ End    Resource ]  [[SqlAGReplica]Blah]
VERBOSE: [CHWK01]: LCM:  [ End    Set      ]
VERBOSE: [CHWK01]: LCM:  [ End    Set      ]    in  2.5190 seconds.
VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 2.541 seconds

It seems that the code in SqlAGReplica connects to whatever the ServerName\InstanceName is and uses that to get the EndpointPort and EndpointHostName information. So if you specify a different replica, these are populated incorrectly and so show as "not in desired state".

When the Set code runs, I didn't specify an EndpointPort or EndpointHostName explicitly so they won't be changed. This is a good thing but means desired state is never achieved.

Suggested solution to the issue

I'm not sure whether this should just be a documentation change to make clear that ServerName and InstanceName should match the Name.

Otherwise we could make a third connection to Name and use that to populate Endpoint variable details instead of $serverObject.

Version of the DSC module that was used ('dev' if using current dev branch)

dev

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with DscResources/MSFT_SqlAGReplica/MSFT_SqlAGReplica.psm1 and trace how SqlAGReplica obtains EndpointPort and EndpointHostName during Test when ServerName differs from Name. Compare the Test and Set paths using the reported SEC1N1/DAC1N1 scenario. Done means the resource evaluates the endpoint details for the intended replica and can reach the desired state without changing unspecified endpoint properties.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, sql
Domain
databases, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.