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

SqlAGReplica: Test doesn't check ReadOnlyRoutingList properly #1305

Closed
codykonior opened this issue Mar 13, 2019 · 0 comments · Fixed by #1312
Closed

SqlAGReplica: Test doesn't check ReadOnlyRoutingList properly #1305

codykonior opened this issue Mar 13, 2019 · 0 comments · Fixed by #1312
Labels
enhancement The issue is an enhancement request.

Comments

@codykonior
Copy link
Contributor

codykonior commented Mar 13, 2019

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

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

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

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

            AvailabilityGroupName = 'AG1'
            Name = 'SEC1N1'
            ReadOnlyRoutingConnectionUrl = 'tcp://SEC1N1.lab.com:1433'
            ReadOnlyRoutingList = 'SEC1N2', 'SEC1N3'
            PsDscRunAsCredential = $Credential
        }
    }
}

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

Although ReadOnlyRoutingList gets set properly, if you run the code a second time you get this result.

VERBOSE: [CHWK01]: LCM:  [ Start  Test     ]  [[SqlAGReplica]SEC1N1]
VERBOSE: [CHWK01]:                            [[SqlAGReplica]SEC1N1] Importing the module MSFT_SqlAGReplica in force mode.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]SEC1N1] Importing the module MSFT_SqlAGReplica in force mode.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]SEC1N1] Preferred module SqlServer found.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]SEC1N1] Importing PowerShell module 'SqlServer' with version '21.0.17279' from path 'C:\Program Files\WindowsPowerShell\Modules\SqlServer\SqlServer.psm1'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]SEC1N1] Connected to SQL instance 'SEC1N1'.
VERBOSE: [CHWK01]:                            [[SqlAGReplica]SEC1N1] 2019-03-14_00-14-48: 'ReadOnlyRoutingList' should be 'SEC1N2 SEC1N3' but is 'SEC1N2 SEC1N3'

It will trigger Set again, which does nothing, and so never reaches desired state.

Suggested solution to the issue

In the Test code there's a -ne comparison which isn't valid for the ReadOnlyRoutingList being a string array (it's the only one).

                    if ( $getTargetResourceResult.($parameterName) -ne $parameterValue )
                    {
                        New-VerboseMessage -Message "'$($parameterName)' should be '$($parameterValue)' but is '$($getTargetResourceResult.($parameterName))'"

                        $result = $False
                    }

To fix this the ReadOnlyRoutingList parameter can have an explicit different case that uses a string join with commas instead of the -ne comparison. That's how it's done in the Set portion and that bit is working great.

                    if ( ( $submittedParameters -contains 'ReadOnlyRoutingList' ) -and ( ( $ReadOnlyRoutingList -join ',' ) -ne ( $availabilityGroupReplica.ReadOnlyRoutingList -join ',' ) ) )

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

dev

@codykonior codykonior changed the title SqlAGReplica: Test method doesn't check ReadOnlyRoutingList properly SqlAGReplica: Test doesn't check ReadOnlyRoutingList properly Mar 13, 2019
@johlju johlju added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Mar 13, 2019
johlju pushed a commit that referenced this issue Mar 20, 2019
- Changes to SqlAGReplica
  - Test-Resource fixed to report whether ReadOnlyRoutingList desired state
     has been reached correctly (issue #1305).
@kwirkykat kwirkykat removed the in progress The issue is being actively worked on by someone. label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants