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
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

## [Unreleased]

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

### Changed

- FailoverClusterDsc
Expand Down
38 changes: 34 additions & 4 deletions source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ function Get-TargetResource
$clusterQuorumResource = $getClusterQuorumResult.QuorumResource |
Get-ClusterParameter -Name AccountName |
Select-Object -ExpandProperty Value
$clusterQuorumEndpoint = $getClusterQuorumResult.QuorumResource |
Get-ClusterParameter -Name EndpointInfo |
Select-Object -ExpandProperty Value
}
else
{
Expand All @@ -104,6 +107,7 @@ function Get-TargetResource
IsSingleInstance = $IsSingleInstance
Type = $clusterQuorumType
Resource = $clusterQuorumResource
Endpoint = $clusterQuorumEndpoint
StorageAccountAccessKey = "" # Return an empty value since we cannot retrieve the current Access Key
}
}
Expand All @@ -123,6 +127,10 @@ function Get-TargetResource
The name of the disk, file share or Azure storage account resource to use
as witness. This parameter is optional if the quorum type is set to NodeMajority.

.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)

.PARAMETER StorageAccountAccessKey
The access key of the Azure storage account to use as witness.
This parameter is required if the quorum type is set to NodeAndCloudMajority.
Expand All @@ -147,6 +155,10 @@ function Set-TargetResource
[System.String]
$Resource,

[Parameter()]
[System.String]
$Endpoint,

[Parameter()]
[System.String]
$StorageAccountAccessKey
Expand Down Expand Up @@ -178,7 +190,7 @@ function Set-TargetResource

'NodeAndCloudMajority'
{
Set-ClusterQuorum -CloudWitness -AccountName $Resource -AccessKey $StorageAccountAccessKey
Set-ClusterQuorum -CloudWitness -AccountName $Resource -AccessKey $StorageAccountAccessKey -Endpoint $Endpoint
}
}
}
Expand All @@ -198,6 +210,10 @@ function Set-TargetResource
The name of the disk, file share or Azure storage account resource to use
as witness. This parameter is optional if the quorum type is set to NodeMajority.

.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)

.PARAMETER StorageAccountAccessKey
The access key of the Azure storage account to use as witness.
This parameter is required if the quorum type is set to NodeAndCloudMajority.
Expand All @@ -224,6 +240,10 @@ function Test-TargetResource
[System.String]
$Resource,

[Parameter()]
[System.String]
$Endpoint,

[Parameter()]
[System.String]
$StorageAccountAccessKey
Expand All @@ -233,11 +253,21 @@ function Test-TargetResource

$getGetTargetResourceResult = Get-TargetResource -IsSingleInstance $IsSingleInstance

$testTargetResourceReturnValue = $false
$testTargetResourceReturnValue = $true

if ($getGetTargetResourceResult.Type -ne $Type)
{
$testTargetResourceReturnValue = $false
}

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

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

$testTargetResourceReturnValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ class DSC_ClusterQuorum : OMI_BaseResource
[Key, Description("Specifies the resource is a single instance, the value must be `'Yes'`."), ValueMap{"Yes"}, Values{"Yes"}] string IsSingleInstance;
[Write, Description("Quorum type to use."), ValueMap{"NodeMajority", "NodeAndDiskMajority", "NodeAndFileShareMajority", "NodeAndCloudMajority", "DiskOnly"}, Values{"NodeMajority", "NodeAndDiskMajority", "NodeAndFileShareMajority", "NodeAndCloudMajority", "DiskOnly"}] string Type;
[Write, Description("The name of the disk, file share or Azure storage account resource to use as witness. This parameter is optional if the quorum type is set to `'NodeMajority'`.")] String Resource;
[Write, Description("Azure service endpoint. This parameter is required if the quorum type is set to `'NodeAndCloudMajority'`.")] String Endpoint;
[Write, Description("The access key of the Azure storage account to use as witness. This parameter is required if the quorum type is set to `'NodeAndCloudMajority'`. **NOTE!** The key is currently not updated if the resource is already set.")] String StorageAccountAccessKey;
};
19 changes: 17 additions & 2 deletions tests/Unit/DSC_ClusterQuorum.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ foreach ($moduleVersion in @('2012', '2016'))
$mockQuorumFileShareWitnessPath = '\\FILE01\CLUSTER01'
$mockQuorumAccountName = 'AccountName'
$mockQuorumAccessKey = 'USRuD354YbOHkPI35SUVyMj2W3odWekMIEdj3n2qAbc0yzqwpMwH-+M+GHJ27OuA5FkTxsbBF9qGc6r6UM3ipg=='
$mockQuorumAccountEndpoint = 'endpoint.azure.dummy'

$mockGetClusterQuorum = {
$getClusterQuorumReturnValue = [PSCustomObject] @{
Expand Down Expand Up @@ -162,6 +163,7 @@ foreach ($moduleVersion in @('2012', '2016'))
$CloudWitness -eq $true `
-and $AccountName -eq $mockQuorumAccountName `
-and $AccessKey -eq $mockQuorumAccessKey
# -and $Endpoint -eq $mockQuorumAccountEndpoint
}

$mockDefaultParameters = @{
Expand All @@ -173,7 +175,18 @@ foreach ($moduleVersion in @('2012', '2016'))
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

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

Expand Down Expand Up @@ -315,6 +328,7 @@ foreach ($moduleVersion in @('2012', '2016'))
$getTargetResourceResult = Get-TargetResource @mockTestParameters
$getTargetResourceResult.Type | Should -Be $mockQuorumType_NodeAndCloudMajority
$getTargetResourceResult.Resource | Should -Be $mockQuorumAccountName
$getTargetResourceResult.Endpoint | Should -Be $mockQuorumAccountEndpoint
}
}
}
Expand Down Expand Up @@ -495,6 +509,7 @@ foreach ($moduleVersion in @('2012', '2016'))

$mockTestParameters['Type'] = $mockQuorumType_NodeAndCloudMajority
$mockTestParameters['Resource'] = $mockQuorumAccountName
$mockTestParameters['Endpoint'] = $mockQuorumAccountEndpoint
$mockTestParameters['StorageAccountAccessKey'] = $mockQuorumAccessKey
}

Expand Down Expand Up @@ -634,7 +649,7 @@ foreach ($moduleVersion in @('2012', '2016'))
$mockTestParameters['Type'] = $mockQuorumType_NodeAndCloudMajority
$mockTestParameters['Resource'] = $mockQuorumAccountName
$mockTestParameters['StorageAccountAccessKey'] = $mockQuorumAccessKey

$mockTestParameters['Endpoint'] = $mockQuorumAccountEndpoint
$mockDynamicQuorumResourceName = $mockQuorumAccountName
}

Expand Down