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

Add Azure endpoint for ClusterQuorum resource #279

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

hungtran84
Copy link

@hungtran84 hungtran84 commented Jun 28, 2022

Pull Request (PR) description

This PR is created for adopting Azure Government cloud where the resource endpoint is required.

This Pull Request (PR) fixes the following issues

Task list

  • Added an entry to the change log under the Unreleased section of the file CHANGELOG.md.
    Entry should say what was changed and how that affects users (if applicable), and
    reference the issue being resolved (if applicable).
  • Resource documentation updated in the resource's README.md.
  • Resource parameter descriptions updated in schema.mof.
  • Comment-based help updated, including parameter descriptions.
  • Localization strings added/updated in all localization files as appropriate.
  • Examples appropriately added/updated.
  • Unit tests added/updated. See DSC Community Testing Guidelines.
  • Integration tests added/updated (where possible). See DSC Community Testing Guidelines.
  • New/changed code adheres to DSC Community Style Guidelines.

This change is Reviewable

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @hungtran84)

a discussion (no related file):
The tests are failing. Looks like we need to add another mock for the added code in the get-function
https://dev.azure.com/dsccommunity/FailoverClusterDsc/_build/results?buildId=6286&view=logs&j=8af7cf9c-43a1-584d-6f5c-57bad8880974&t=a93ba588-7f3e-5259-6924-3f054a327451&l=881



source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 193 at r1 (raw file):

        'NodeAndCloudMajority'
        {
            Set-ClusterQuorum -CloudWitness -AccountName $Resource -AccessKey $StorageAccountAccessKey -Endpoint $Endpoint

I'm not familiar with using cloud witness, so I'm curios - is there no other scenario where Endpoint is not necessary so that we should not add it by default? If not, then this line looks good to me.

Googling it looks like it is necessary, just wanted to confirm if you know. 🙂

Code quote:

-Endpoint $Endpoint

source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 215 at r1 (raw file):

    .PARAMETER Endpoint
        Azure service endpoint. This paramter is required if the quorum type is set to NodeAndCloudMajority.
        The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net)

We should also add this text to the description in the schema mof since the schema MOF is used to generate the wiki documentation.

Code quote:

The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net)

source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 215 at r1 (raw file):

    .PARAMETER Endpoint
        Azure service endpoint. This paramter is required if the quorum type is set to NodeAndCloudMajority.
        The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net)

May also say? ...or a region specific endpoint
Saw it mentioned here: https://docs.microsoft.com/en-us/windows-server/failover-clustering/deploy-cloud-witness

Throughout comment-based help and schema MOF.

Code quote:

only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net)

source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 245 at r1 (raw file):

        [Parameter()]
        [System.String]
        $Endpoint = 'core.windows.net',

If the current state already has a different endpoint, should not Test-function return $false so that Set-function kan set the correct endpoint? When the endpoint is part of the configuration and the value is in desired state should Test-function return $true?

Code quote:

$Endpoint = 'core.windows.net'

@johlju johlju added the waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author. label Jun 28, 2022
@hungtran84
Copy link
Author

We should also add this text to the description in the schema mof since the schema MOF is used to generate the wiki documentation.

Already added to schema MOF file (if I'm not wrong)

If the current state already has a different endpoint, should not Test-function return $false so that Set-function kan set the correct endpoint? When the endpoint is part of the configuration and the value is in desired state should Test-function return $true?

I tried to remove the default value of Endpoint and set the mock value but no luck. Actually, I don't know much about DSC Unit test and struggle on trousbleshooting/resolving the failed test case.

@johlju could you help to solve it? Thank you in advanced

@stale
Copy link

stale bot commented Jul 30, 2022

Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again.

@stale stale bot added the abandoned The pull request has been abandoned. label Jul 30, 2022
@johlju johlju self-requested a review July 31, 2022 13:28
Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 4 files reviewed, 5 unresolved discussions (waiting on @hungtran84 and @johlju)


source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 215 at r1 (raw file):

Previously, johlju (Johan Ljunggren) wrote…

We should also add this text to the description in the schema mof since the schema MOF is used to generate the wiki documentation.

I mean ad the text The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net) to the parameter description in the schema.mof.

Code quote:

The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net)

@johlju
Copy link
Member

johlju commented Jul 31, 2022

/AzurePipelines run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 4 files reviewed, 6 unresolved discussions (waiting on @hungtran84 and @johlju)


source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 256 at r2 (raw file):

    $getGetTargetResourceResult = Get-TargetResource -IsSingleInstance $IsSingleInstance

    $testTargetResourceReturnValue = $false

This should only do the evaluation if the parameters was assigned. So maybe we have tu reverse it to something like this (this will also fix Resource):

    $testTargetResourceReturnValue = $true

    if ($getGetTargetResourceResult.Type -ne $Type)
    {
        $testTargetResourceReturnValue = $false
    }
    
    if ($PSBoundParameters.ContainsKey('Resource') -and $getGetTargetResourceResult.Resource -ne $Resource)
    {
        $testTargetResourceReturnValue = $false
    }
    
    if ($PSBoundParameters.ContainsKey('Endpoint') -and $getGetTargetResourceResult.Endpoint -ne $Endpoint)
    {
        $testTargetResourceReturnValue = $false
    }

Suggestion:

    $testTargetResourceReturnValue = $true

    if ($getGetTargetResourceResult.Type -ne $Type)
    {
        $testTargetResourceReturnValue = $false
    }
    
    if ($PSBoundParameters.ContainsKey('Resource') -and $getGetTargetResourceResult.Resource -ne $Resource)
    {
        $testTargetResourceReturnValue = $false
    }
    
    if ($PSBoundParameters.ContainsKey('Endpoint') -and $getGetTargetResourceResult.Endpoint -ne $Endpoint)
    {
        $testTargetResourceReturnValue = $false
    }

@johlju johlju self-requested a review July 31, 2022 13:49
@hungtran84
Copy link
Author

hungtran84 commented Jul 31, 2022 via email

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 4 files reviewed, 8 unresolved discussions (waiting on @hungtran84 and @johlju)


source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 98 at r2 (raw file):

            Select-Object -ExpandProperty Value
        $clusterQuorumEndpoint = $getClusterQuorumResult.QuorumResource |
            Get-ClusterParameter -Name EndpointInfo |

The tests are failing on this row because the command Get-ClusterParameter is not mocked with that parameter resulting in that the stub command is called (which correctly throws). See next comment in the tests.

Code quote:

Get-ClusterParameter -Name EndpointInfo 

tests/Unit/DSC_ClusterQuorum.Tests.ps1 line 177 at r2 (raw file):

                    Mock -CommandName 'Get-ClusterQuorum' -MockWith $mockGetClusterQuorum
                    Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_SharePath -ParameterFilter $mockGetClusterParameter_SharePath_ParameterFilter
                    Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_AccountName -ParameterFilter $mockGetClusterParameter_AccountName_ParameterFilter

Se previous comment in the code regarding Get-ClusterParameter. Here we need to add a new line to mock the command Get-CLusterParameter correctly.

After line 177, add:

Mock -CommandName 'Get-ClusterParameter' -MockWith {
    return @(
        # MAKE SURE TO RETURN THE CORRECT PROPERTIES OF EndpointInfo, I don't know the properties...This was just a guess copied from previous tests.
        [PSCustomObject] @{
            ClusterObject = '?'
            Name          = 'EndpointInfo'
            IsReadOnly    = '?'
            ParameterType = '?'
            Value         = 'endpoint.azure.dummy'
        }
    )
} -ParameterFilter {
    $Name -eq 'EndpointInfo'
}

Code quote:

Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_AccountName -ParameterFilter $mockGetClusterParameter_AccountName_ParameterFilter

@johlju johlju self-requested a review July 31, 2022 14:08
@johlju johlju removed the abandoned The pull request has been abandoned. label Jul 31, 2022
@johlju
Copy link
Member

johlju commented Jul 31, 2022

@hungtran84 let me know when you done above changes and I take a look again.

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 4 files reviewed, 9 unresolved discussions (waiting on @hungtran84 and @johlju)


tests/Unit/DSC_ClusterQuorum.Tests.ps1 line 383 at r3 (raw file):

                    Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_SharePath -ParameterFilter $mockGetClusterParameter_SharePath_ParameterFilter
                    Mock -CommandName 'Get-ClusterParameter' -MockWith $mockGetClusterParameter_AccountName -ParameterFilter $mockGetClusterParameter_AccountName_ParameterFilter

Need to add the mock here too.

                    Mock -CommandName 'Get-ClusterParameter' -MockWith {
                        return @(
                            [PSCustomObject] @{
                                Object = 'Cloud Witness'
                                Name   = 'EndpointInfo'
                                Type   = 'String'
                                Value  = 'endpoint.azure.dummy'
                            }
                        )
                    } -ParameterFilter {
                        $Name -eq 'EndpointInfo'
                    }

@johlju johlju self-requested a review August 1, 2022 17:10
@codecov
Copy link

codecov bot commented Aug 2, 2022

Codecov Report

Merging #279 (7ec21f6) into main (faa9aa3) will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #279   +/-   ##
===================================
  Coverage   100%   100%           
===================================
  Files         8      8           
  Lines       611    619    +8     
===================================
+ Hits        611    619    +8     
Impacted Files Coverage Δ
...Resources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 100% <100%> (ø)

@hungtran84
Copy link
Author

@johlju It seems that all the tests passed, could you help to review my PR again?

@johlju
Copy link
Member

johlju commented Aug 2, 2022

Great work! I will review as soon as I have a chance.

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! A few more comments.

Reviewed 1 of 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @hungtran84)


CHANGELOG.md line 11 at r4 (raw file):

- ClusterQuorum
  - New parameter Endpoint to support Azure Government cloud. Default value now is only for the commercial one.

This text is no longer accurate as there is no default value.

Code quote:

Default value now is only for the commercial one.

source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 98 at r4 (raw file):

            Select-Object -ExpandProperty Value
        $clusterQuorumEndpoint = $getClusterQuorumResult.QuorumResource |
            Get-ClusterParameter -Name EndpointInfo |

Just want to verify, I assume this pipeline returns $null if there is no endpoint info to return, is that correct? Just want to verify that the command Get-ClusterParameter does not throw if there is no endpoint info.

Code quote:

        $clusterQuorumEndpoint = $getClusterQuorumResult.QuorumResource |
            Get-ClusterParameter -Name EndpointInfo |
            Select-Object -ExpandProperty Value

source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 131 at r4 (raw file):

    .PARAMETER Endpoint
        Azure service endpoint. This paramter is required if the quorum type is set to NodeAndCloudMajority.

This is no longer accurate as it is now optional, we no longer have a default value. We should correct this text.

Code quote:

        Azure service endpoint. This paramter is required if the quorum type is set to NodeAndCloudMajority.
        The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net)

source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 193 at r4 (raw file):

        'NodeAndCloudMajority'
        {
            Set-ClusterQuorum -CloudWitness -AccountName $Resource -AccessKey $StorageAccountAccessKey -Endpoint $Endpoint

This should only use parameter Endpoint if it is set.

Suggestion:

$setClusterQuorumParameters = @{
    CloudWitness = $true
    AccountName  = $Resource
    AccessKey    = $StorageAccountAccessKey
}

if ($PSBoundParameters.ContainsKey('Endpoint'))
{
    $setClusterQuorumParameters.Endpoint = $Endpoint
}

Set-ClusterQuorum @setClusterQuorumParameters

source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 line 214 at r4 (raw file):

    .PARAMETER Endpoint
        Azure service endpoint. This paramter is required if the quorum type is set to NodeAndCloudMajority.

This is no longer accurate as it is now optional, we no longer have a default value. We should correct this text.

Code quote:

        Azure service endpoint. This paramter is required if the quorum type is set to NodeAndCloudMajority.
        The default value is core.windows.net and only need to override when using Azure Government Cloud (eg: core.usgovcloudapi.net)

tests/Unit/DSC_ClusterQuorum.Tests.ps1 line 166 at r4 (raw file):

                    -and $AccountName -eq $mockQuorumAccountName `
                    -and $AccessKey -eq $mockQuorumAccessKey
                    # -and $Endpoint -eq $mockQuorumAccountEndpoint

If this was not needed we should remove the commented line.

Code quote:

# -and $Endpoint -eq $mockQuorumAccountEndpoint

@stale
Copy link

stale bot commented Sep 20, 2022

Labeling this pull request (PR) as abandoned since it has gone 14 days or more since the last update. An abandoned PR can be continued by another contributor. The abandoned label will be removed if work on this PR is taken up again.

@stale stale bot added the abandoned The pull request has been abandoned. label Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abandoned The pull request has been abandoned. waiting for code fix A review left open comments, and the pull request is waiting for changes to be pushed by the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClusterQuorum: Doesn't support Azure Gov Cloud
2 participants