Skip to content

Commit

Permalink
Changes to xCluster
Browse files Browse the repository at this point in the history
Resolved Script Analyzer rule warnings by changing Get-WmiObject to Get-CimInstance (issue dsccommunity#49).
  • Loading branch information
johlju committed Jul 14, 2017
1 parent cbe4e3f commit d51f44c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
(issue #72).
- Set-TargetResource now correctly throws and error if domain name cannot be
evaluated (issue #71).
- Resolved Script Analyzer rule warnings by changing Get-WmiObject to
Get-CimInstance (issue #49).
- Changes to xWaitForCluster
- Added example
- 1-WaitForFailoverClusterToBePresent.ps1
Expand Down
6 changes: 3 additions & 3 deletions DSCResources/MSFT_xCluster/MSFT_xCluster.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Get-TargetResource
$DomainAdministratorCredential
)

$computerInformation = Get-WmiObject -Class Win32_ComputerSystem
$computerInformation = Get-CimInstance -ClassName Win32_ComputerSystem
if (($null -eq $computerInformation) -or ($null -eq $computerInformation.Domain))
{
throw 'Can''t find machine''s domain name'
Expand Down Expand Up @@ -107,7 +107,7 @@ function Set-TargetResource

Write-Verbose -Message "Checking if Cluster $Name is present ..."

$computerInformation = Get-WmiObject -Class Win32_ComputerSystem
$computerInformation = Get-CimInstance -ClassName Win32_ComputerSystem
if (($null -eq $computerInformation) -or ($null -eq $computerInformation.Domain))
{
throw 'Can''t find machine''s domain name'
Expand Down Expand Up @@ -228,7 +228,7 @@ function Test-TargetResource

Write-Verbose -Message "Checking if Cluster $Name is present ..."

$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
$ComputerInfo = Get-CimInstance -ClassName Win32_ComputerSystem
if (($null -eq $ComputerInfo) -or ($null -eq $ComputerInfo.Domain))
{
throw "Can't find machine's domain name"
Expand Down
24 changes: 12 additions & 12 deletions Tests/Unit/MSFT_xCluster.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ try
$mockClusterName = 'CLUSTER001'
$mockStaticIpAddress = '192.168.10.10'

$mockGetWmiObject = {
$mockGetCimInstance = {
return [PSCustomObject] @{
Domain = $mockDynamicDomainName
Name = $mockDynamicServerName
}
}

$mockGetWmiObject_ParameterFilter = {
$Class -eq 'Win32_ComputerSystem'
$mockGetCimInstance_ParameterFilter = {
$ClassName -eq 'Win32_ComputerSystem'
}

$mockGetCluster = {
Expand Down Expand Up @@ -108,7 +108,7 @@ try
$mockDynamicDomainName = $null
$mockDynamicServerName = $mockServerName

Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable

{ Get-TargetResource @mockDefaultParameters } | Should -Throw "Can't find machine's domain name"
}
Expand All @@ -120,15 +120,15 @@ try
$mockDynamicServerName = $mockServerName

Mock -CommandName Get-Cluster -Verifiable
Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable

{ Get-TargetResource @mockDefaultParameters } | Should -Throw ("Can't find the cluster {0}" -f $mockClusterName)
}
}

Context 'When the system is not in the desired state' {
BeforeEach {
Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable
Mock -CommandName Get-Cluster -MockWith $mockGetCluster -ParameterFilter $mockGetCluster_ParameterFilter -Verifiable
Mock -CommandName Get-ClusterGroup -MockWith $mockGetClusterGroup -ParameterFilter $mockGetClusterGroup_ParameterFilter -Verifiable
Mock -CommandName Get-ClusterParameter -MockWith $mockGetClusterParameter -Verifiable
Expand Down Expand Up @@ -158,7 +158,7 @@ try
$mockDynamicDomainName = $null
$mockDynamicServerName = $mockServerName

Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable

{ Set-TargetResource @mockDefaultParameters } | Should -Throw "Can't find machine's domain name"
}
Expand All @@ -169,7 +169,7 @@ try
Mock -CommandName New-Cluster -Verifiable
Mock -CommandName Remove-ClusterNode -Verifiable
Mock -CommandName Add-ClusterNode -Verifiable
Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable
}

$mockDynamicDomainName = $mockDomainName
Expand Down Expand Up @@ -261,7 +261,7 @@ try
Mock -CommandName New-Cluster -Verifiable
Mock -CommandName Remove-ClusterNode -Verifiable
Mock -CommandName Add-ClusterNode -Verifiable
Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable
Mock -CommandName Get-Cluster -MockWith $mockGetCluster -ParameterFilter $mockGetCluster_ParameterFilter -Verifiable
Mock -CommandName Get-ClusterParameter -MockWith $mockGetClusterParameter -Verifiable

Expand Down Expand Up @@ -301,15 +301,15 @@ try
$mockDynamicDomainName = $null
$mockDynamicServerName = $mockServerName

Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable

{ Test-TargetResource @mockDefaultParameters } | Should -Throw "Can't find machine's domain name"
}
}

Context 'When the system is not in the desired state' {
BeforeEach {
Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable
}

$mockDynamicDomainName = $mockDomainName
Expand Down Expand Up @@ -374,7 +374,7 @@ try
Context 'When the system is in the desired state' {
BeforeEach {
Mock -CommandName Get-ClusterNode -MockWith $mockGetClusterNode -Verifiable
Mock -CommandName Get-WmiObject -MockWith $mockGetWmiObject -ParameterFilter $mockGetWmiObject_ParameterFilter -Verifiable
Mock -CommandName Get-CimInstance -MockWith $mockGetCimInstance -ParameterFilter $mockGetCimInstance_ParameterFilter -Verifiable
Mock -CommandName Get-Cluster -MockWith $mockGetCluster -ParameterFilter $mockGetCluster_ParameterFilter -Verifiable
}

Expand Down

0 comments on commit d51f44c

Please sign in to comment.