From 0da4081d64fcc257d5f81663a94818cdc41a17c3 Mon Sep 17 00:00:00 2001 From: Hung Tran Date: Tue, 28 Jun 2022 11:08:54 +0000 Subject: [PATCH 01/10] Add Azure endpoint for ClusterQuorum resource --- .../DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 | 22 ++++++++++++++++++- .../DSC_ClusterQuorum.schema.mof | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 index 80e8109..f64de33 100644 --- a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 +++ b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 @@ -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 { @@ -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 } } @@ -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. @@ -147,6 +155,10 @@ function Set-TargetResource [System.String] $Resource, + [Parameter()] + [System.String] + $Endpoint = 'core.windows.net', + [Parameter()] [System.String] $StorageAccountAccessKey @@ -178,7 +190,7 @@ function Set-TargetResource 'NodeAndCloudMajority' { - Set-ClusterQuorum -CloudWitness -AccountName $Resource -AccessKey $StorageAccountAccessKey + Set-ClusterQuorum -CloudWitness -AccountName $Resource -AccessKey $StorageAccountAccessKey -Endpoint $Endpoint } } } @@ -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. @@ -224,6 +240,10 @@ function Test-TargetResource [System.String] $Resource, + [Parameter()] + [System.String] + $Endpoint = 'core.windows.net', + [Parameter()] [System.String] $StorageAccountAccessKey diff --git a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.schema.mof b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.schema.mof index b903cf0..ffe2563 100644 --- a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.schema.mof +++ b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.schema.mof @@ -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; }; From 6381b49eb0153b721a292ada525f6b20950834c1 Mon Sep 17 00:00:00 2001 From: Hung Tran Date: Tue, 28 Jun 2022 11:17:14 +0000 Subject: [PATCH 02/10] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad17ae1..5427d9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 67a96ad285aa15d00b1c624b4d6ac0387c2be5d2 Mon Sep 17 00:00:00 2001 From: hungts Date: Fri, 1 Jul 2022 11:25:23 +0700 Subject: [PATCH 03/10] Update test function --- .../DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 index f64de33..b52e41e 100644 --- a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 +++ b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 @@ -157,7 +157,7 @@ function Set-TargetResource [Parameter()] [System.String] - $Endpoint = 'core.windows.net', + $Endpoint, [Parameter()] [System.String] @@ -242,7 +242,7 @@ function Test-TargetResource [Parameter()] [System.String] - $Endpoint = 'core.windows.net', + $Endpoint, [Parameter()] [System.String] @@ -255,7 +255,7 @@ function Test-TargetResource $testTargetResourceReturnValue = $false - if ($getGetTargetResourceResult.Type -eq $Type -and $getGetTargetResourceResult.Resource -eq $Resource) + if ($getGetTargetResourceResult.Type -eq $Type -and $getGetTargetResourceResult.Resource -eq $Resource -and $getGetTargetResourceResult.Endpoint -eq $Endpoint) { $testTargetResourceReturnValue = $true } From fade434ad131fbe9129a54bcf5b7fa470aafbdf7 Mon Sep 17 00:00:00 2001 From: hungts Date: Fri, 1 Jul 2022 11:56:59 +0700 Subject: [PATCH 04/10] Add mock value --- tests/Unit/DSC_ClusterQuorum.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 index 8ae455e..b98ef20 100644 --- a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 +++ b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 @@ -56,6 +56,7 @@ foreach ($moduleVersion in @('2012', '2016')) $mockQuorumFileShareWitnessPath = '\\FILE01\CLUSTER01' $mockQuorumAccountName = 'AccountName' $mockQuorumAccessKey = 'USRuD354YbOHkPI35SUVyMj2W3odWekMIEdj3n2qAbc0yzqwpMwH-+M+GHJ27OuA5FkTxsbBF9qGc6r6UM3ipg==' + $mockQuorumAccountName = 'endpoint.azure.dummy' $mockGetClusterQuorum = { $getClusterQuorumReturnValue = [PSCustomObject] @{ @@ -162,6 +163,7 @@ foreach ($moduleVersion in @('2012', '2016')) $CloudWitness -eq $true ` -and $AccountName -eq $mockQuorumAccountName ` -and $AccessKey -eq $mockQuorumAccessKey + -and $AccountEndpoint -eq $mockQuorumAccountEndpoint } $mockDefaultParameters = @{ @@ -315,6 +317,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 } } } From 35bf1a6738f48387de8bfcbe2a117468416dbd9b Mon Sep 17 00:00:00 2001 From: hungts Date: Fri, 1 Jul 2022 15:33:50 +0700 Subject: [PATCH 05/10] Add mock value --- tests/Unit/DSC_ClusterQuorum.Tests.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 index b98ef20..edea476 100644 --- a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 +++ b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 @@ -56,7 +56,7 @@ foreach ($moduleVersion in @('2012', '2016')) $mockQuorumFileShareWitnessPath = '\\FILE01\CLUSTER01' $mockQuorumAccountName = 'AccountName' $mockQuorumAccessKey = 'USRuD354YbOHkPI35SUVyMj2W3odWekMIEdj3n2qAbc0yzqwpMwH-+M+GHJ27OuA5FkTxsbBF9qGc6r6UM3ipg==' - $mockQuorumAccountName = 'endpoint.azure.dummy' + $mockQuorumAccountEndpoint = 'endpoint.azure.dummy' $mockGetClusterQuorum = { $getClusterQuorumReturnValue = [PSCustomObject] @{ @@ -163,7 +163,7 @@ foreach ($moduleVersion in @('2012', '2016')) $CloudWitness -eq $true ` -and $AccountName -eq $mockQuorumAccountName ` -and $AccessKey -eq $mockQuorumAccessKey - -and $AccountEndpoint -eq $mockQuorumAccountEndpoint + -and $Endpoint -eq $mockQuorumAccountEndpoint } $mockDefaultParameters = @{ @@ -175,6 +175,7 @@ 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 $mockGetClusterParameter_AccountName -ParameterFilter $mockGetClusterParameter_AccountName_ParameterFilter $mockTestParameters = $mockDefaultParameters.Clone() } @@ -498,6 +499,7 @@ foreach ($moduleVersion in @('2012', '2016')) $mockTestParameters['Type'] = $mockQuorumType_NodeAndCloudMajority $mockTestParameters['Resource'] = $mockQuorumAccountName + $mockTestParameters['Endpoint'] = $mockQuorumAccountEndpoint $mockTestParameters['StorageAccountAccessKey'] = $mockQuorumAccessKey } From 2147a57d86ea8a7d7d441a117dadb249f1eba50b Mon Sep 17 00:00:00 2001 From: hungts Date: Fri, 1 Jul 2022 15:37:56 +0700 Subject: [PATCH 06/10] Add mock value --- tests/Unit/DSC_ClusterQuorum.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 index edea476..e137a88 100644 --- a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 +++ b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 @@ -175,7 +175,6 @@ 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 $mockGetClusterParameter_AccountName -ParameterFilter $mockGetClusterParameter_AccountName_ParameterFilter $mockTestParameters = $mockDefaultParameters.Clone() } From 95b97ad5dc97311f9ff6aa898ddfbc1a5b9bb74c Mon Sep 17 00:00:00 2001 From: hungts Date: Mon, 1 Aug 2022 09:25:37 +0700 Subject: [PATCH 07/10] Fix unit test --- .../DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 | 16 +++++++++++++--- tests/Unit/DSC_ClusterQuorum.Tests.ps1 | 13 ++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 index b52e41e..bd29291 100644 --- a/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 +++ b/source/DSCResources/DSC_ClusterQuorum/DSC_ClusterQuorum.psm1 @@ -253,11 +253,21 @@ function Test-TargetResource $getGetTargetResourceResult = Get-TargetResource -IsSingleInstance $IsSingleInstance - $testTargetResourceReturnValue = $false + $testTargetResourceReturnValue = $true - if ($getGetTargetResourceResult.Type -eq $Type -and $getGetTargetResourceResult.Resource -eq $Resource -and $getGetTargetResourceResult.Endpoint -eq $Endpoint) + if ($getGetTargetResourceResult.Type -ne $Type) { - $testTargetResourceReturnValue = $true + $testTargetResourceReturnValue = $false + } + + if ($PSBoundParameters.ContainsKey('Resource') -and $getGetTargetResourceResult.Resource -ne $Resource) + { + $testTargetResourceReturnValue = $false + } + + if ($PSBoundParameters.ContainsKey('Endpoint') -and $getGetTargetResourceResult.Endpoint -ne $Endpoint) + { + $testTargetResourceReturnValue = $false } $testTargetResourceReturnValue diff --git a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 index e137a88..1a4a7a9 100644 --- a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 +++ b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 @@ -175,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() } From 91b35499f6f0ed563bf6f6e9b62027455acfa642 Mon Sep 17 00:00:00 2001 From: hungts Date: Mon, 1 Aug 2022 09:43:16 +0700 Subject: [PATCH 08/10] Fix unit test --- tests/Unit/DSC_ClusterQuorum.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 index 1a4a7a9..12e7b08 100644 --- a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 +++ b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 @@ -649,7 +649,7 @@ foreach ($moduleVersion in @('2012', '2016')) $mockTestParameters['Type'] = $mockQuorumType_NodeAndCloudMajority $mockTestParameters['Resource'] = $mockQuorumAccountName $mockTestParameters['StorageAccountAccessKey'] = $mockQuorumAccessKey - + $mockTestParameters['Endpoint'] = $mockQuorumAccountEndpoint $mockDynamicQuorumResourceName = $mockQuorumAccountName } From a9c955f53d21769e41461f62e5354394a214604b Mon Sep 17 00:00:00 2001 From: hungts Date: Mon, 1 Aug 2022 09:55:18 +0700 Subject: [PATCH 09/10] Fix unit test --- tests/Unit/DSC_ClusterQuorum.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 index 12e7b08..44fa300 100644 --- a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 +++ b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 @@ -163,7 +163,7 @@ foreach ($moduleVersion in @('2012', '2016')) $CloudWitness -eq $true ` -and $AccountName -eq $mockQuorumAccountName ` -and $AccessKey -eq $mockQuorumAccessKey - -and $Endpoint -eq $mockQuorumAccountEndpoint + # -and $Endpoint -eq $mockQuorumAccountEndpoint } $mockDefaultParameters = @{ From 7ec21f6b8d3bb33431196deea2cf578983af6f93 Mon Sep 17 00:00:00 2001 From: hungts Date: Tue, 2 Aug 2022 12:10:32 +0700 Subject: [PATCH 10/10] Add the new mock --- tests/Unit/DSC_ClusterQuorum.Tests.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 index 44fa300..c825ee7 100644 --- a/tests/Unit/DSC_ClusterQuorum.Tests.ps1 +++ b/tests/Unit/DSC_ClusterQuorum.Tests.ps1 @@ -380,7 +380,19 @@ 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() }