Skip to content

Commit

Permalink
SqlServerMemory: Fix so auto memory on Azure VMs is reported correctly (
Browse files Browse the repository at this point in the history
#1285)

- Changes to SqlServerMemory
  - Updated Cim Class to Win32_ComputerSystem (instead of Win32_PhysicalMemory)
    because the correct memory size was not being detected correctly on Azure VMs (issue #914).
  • Loading branch information
ejleroy authored and johlju committed Feb 22, 2019
1 parent a84fcf1 commit 271e799
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
## 12.3.0.0

- Changes to SqlServerDsc
- Updated Cim Class to Win32_ComputerSystem (instead of Win32_PhysicalMemory)
because the correct memory size was not being detected correctly on Azure VMs
[issue #914](https://github.com/PowerShell/SqlServerDsc/issues/914)
[issue #1154](https://github.com/PowerShell/SqlServerDsc/issues/1154)
- Reverting the change that was made as part of the
[issue #1260](https://github.com/PowerShell/SqlServerDsc/issues/1260)
in the previous release, as it only mitigated the issue, it did not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function Get-SqlDscDynamicMaxMemory
{
try
{
$physicalMemory = ((Get-CimInstance -ClassName Win32_PhysicalMemory).Capacity | Measure-Object -Sum).Sum
$physicalMemory = (Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory
$physicalMemoryInMegaBytes = [Math]::Round($physicalMemory / 1MB)

# Find how much to save for OS: 20% of total ram for under 15GB / 12.5% for over 20GB
Expand Down
56 changes: 18 additions & 38 deletions Tests/Unit/MSFT_SqlServerMemory.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,12 @@ try
}

Mock -CommandName Get-CimInstance -MockWith {
$mockGetCimInstanceMem = @()

$mockGetCimInstanceMem += New-Object -TypeName PSObject -Property @{
Name = 'Physical Memory'
Tag = 'Physical Memory 0'
Capacity = 8589934592
New-Object -TypeName PSObject -Property @{
TotalPhysicalMemory = 17179869184
}

$mockGetCimInstanceMem += New-Object -TypeName PSObject -Property @{
Name = 'Physical Memory'
Tag = 'Physical Memory 1'
Capacity = 8589934592
}

$mockGetCimInstanceMem
} -ParameterFilter { $ClassName -eq 'Win32_PhysicalMemory' } -Verifiable
} -ParameterFilter { $ClassName -eq 'Win32_ComputerSystem' } -Verifiable

Mock -CommandName Get-CimInstance -MockWith {
$mockGetCimInstanceProc = [PSCustomObject]@{
Expand Down Expand Up @@ -317,9 +307,9 @@ try
Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context
}

It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' {
It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_ComputerSystem' {
Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter {
$ClassName -eq 'Win32_PhysicalMemory'
$ClassName -eq 'Win32_ComputerSystem'
} -Scope Context
}

Expand Down Expand Up @@ -361,9 +351,9 @@ try
Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context
}

It 'Should not call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' {
It 'Should not call the mock function Get-CimInstance with ClassName equal to Win32_ComputerSystem' {
Assert-MockCalled Get-CimInstance -Exactly -Times 0 -ParameterFilter {
$ClassName -eq 'Win32_PhysicalMemory'
$ClassName -eq 'Win32_ComputerSystem'
} -Scope Context
}

Expand Down Expand Up @@ -401,9 +391,9 @@ try
Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context
}

It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' {
It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_ComputerSystem' {
Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter {
$ClassName -eq 'Win32_PhysicalMemory'
$ClassName -eq 'Win32_ComputerSystem'
} -Scope Context
}

Expand Down Expand Up @@ -497,22 +487,12 @@ try
}

Mock -CommandName Get-CimInstance -MockWith {
$mockGetCimInstanceMem = @()

$mockGetCimInstanceMem += New-Object -TypeName PSObject -Property @{
Name = 'Physical Memory'
Tag = 'Physical Memory 0'
Capacity = 17179869184
}

$mockGetCimInstanceMem += New-Object -TypeName PSObject -Property @{
Name = 'Physical Memory'
Tag = 'Physical Memory 1'
Capacity = 17179869184
New-Object -TypeName PSObject -Property @{
TotalPhysicalMemory = 17179869184
}

$mockGetCimInstanceMem
} -ParameterFilter { $ClassName -eq 'Win32_PhysicalMemory' } -Verifiable
} -ParameterFilter { $ClassName -eq 'Win32_ComputerSystem' } -Verifiable

Mock -CommandName Get-CimInstance -MockWith {
$mockGetCimInstanceProc = [PSCustomObject]@{
Expand Down Expand Up @@ -636,9 +616,9 @@ try
Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context
}

It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' {
It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_ComputerSystem' {
Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter {
$ClassName -eq 'Win32_PhysicalMemory'
$ClassName -eq 'Win32_ComputerSystem'
} -Scope Context
}

Expand Down Expand Up @@ -678,9 +658,9 @@ try
Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context
}

It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' {
It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_ComputerSystem' {
Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter {
$ClassName -eq 'Win32_PhysicalMemory'
$ClassName -eq 'Win32_ComputerSystem'
} -Scope Context
}

Expand Down Expand Up @@ -768,9 +748,9 @@ try
Assert-MockCalled Connect-SQL -Exactly -Times 1 -Scope Context
}

It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_PhysicalMemory' {
It 'Should call the mock function Get-CimInstance with ClassName equal to Win32_ComputerSystem' {
Assert-MockCalled Get-CimInstance -Exactly -Times 1 -ParameterFilter {
$ClassName -eq 'Win32_PhysicalMemory'
$ClassName -eq 'Win32_ComputerSystem'
} -Scope Context
}

Expand Down

0 comments on commit 271e799

Please sign in to comment.