Skip to content

Commit d9ca402

Browse files
committed
Remove ProductVersion parameter and add edition check
1 parent b521c47 commit d9ca402

File tree

3 files changed

+61
-54
lines changed

3 files changed

+61
-54
lines changed

source/Classes/020.SqlRSSetup.ps1

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,7 @@
122122
is `7200` seconds (2 hours). If the setup process does not finish before
123123
this time, an exception will be thrown.
124124
125-
.PARAMETER ProductVersion
126-
Returns the product version of the installed product. This property is not
127-
configurable.
128-
129125
.NOTES
130-
The Get method will also return the ProductVersion property, which is not
131-
configurable. This property is set to the product version of the installed
132-
product.
133-
134126
The property InstanceName is the key property for this resource. It does
135127
not use a ValidateSet or Enum due to a limitation. A ValidateSet() or Enum
136128
would not allow a `$null` value to be set for the property. Setting
@@ -226,10 +218,6 @@ class SqlRSSetup : ResourceBase
226218
[Nullable[System.UInt32]]
227219
$Timeout = 7200
228220

229-
[DscProperty(NotConfigurable)]
230-
[System.String]
231-
$ProductVersion
232-
233221
SqlRSSetup () : base ($PSScriptRoot)
234222
{
235223
# These properties will not be enforced.
@@ -288,49 +276,75 @@ class SqlRSSetup : ResourceBase
288276
}
289277
}
290278

291-
$productVersionInDesiredState = $true
279+
$inDesiredState = $true
292280

293281
<#
294282
The product version is evaluated if action is Install, instance is
295283
installed and VersionUpgrade is set to $true.
296284
#>
297-
if ($this.Action -eq 'Install' -and $baseTestResult -and $this.VersionUpgrade)
285+
if ($this.Action -eq 'Install' -and $baseTestResult)
298286
{
299-
$fileVersion = Get-FileProductVersion -Path $this.MediaPath -ErrorAction 'Stop'
300-
301-
if ($fileVersion)
287+
if ($this.EditionUpgrade)
302288
{
303-
$keyProperties = @{
304-
InstanceName = $this.InstanceName
305-
}
289+
$currentState = Get-SqlDscRSSetupConfiguration -InstanceName $this.InstanceName
306290

307-
$getTargetResourceResult = $this.GetCurrentState($keyProperties)
308-
309-
if ([System.String]::IsNullOrEmpty($getTargetResourceResult.ProductVersion))
291+
if ([System.String]::IsNullOrEmpty($currentState.EditionId))
310292
{
311293
New-InvalidResultException -Message (
312-
$this.localizedData.CannotDetermineProductVersion -f $this.InstanceName
294+
$this.localizedData.CannotDetermineEdition -f $this.InstanceName
313295
)
314296
}
315297

316-
$installedVersion = [System.Version] $getTargetResourceResult.ProductVersion
298+
$currentEdition = ConvertTo-SqlDscEditionName -Id $currentState.EditionId
317299

318-
if ($installedVersion -lt $fileVersion)
300+
if ($currentEdition.Edition -ne $this.Edition)
319301
{
320-
$productVersionInDesiredState = $false
302+
$inDesiredState = $false
321303

322304
Write-Verbose -Message (
323-
$this.localizedData.NotDesiredProductVersion -f @(
324-
$fileVersion.ToString(),
305+
$this.localizedData.NotDesiredEdition -f @(
306+
$currentEdition.Edition,
325307
$this.InstanceName,
326-
$installedVersion.ToString()
308+
$this.Edition
327309
)
328310
)
329311
}
330312
}
313+
314+
if ($this.VersionUpgrade)
315+
{
316+
$fileVersion = Get-FileProductVersion -Path $this.MediaPath -ErrorAction 'Stop'
317+
318+
if ($fileVersion)
319+
{
320+
$currentState = Get-SqlDscRSSetupConfiguration -InstanceName $this.InstanceName
321+
322+
if ([System.String]::IsNullOrEmpty($currentState.ProductVersion))
323+
{
324+
New-InvalidResultException -Message (
325+
$this.localizedData.CannotDetermineProductVersion -f $this.InstanceName
326+
)
327+
}
328+
329+
$installedVersion = [System.Version] $currentState.ProductVersion
330+
331+
if ($installedVersion -lt $fileVersion)
332+
{
333+
$inDesiredState = $false
334+
335+
Write-Verbose -Message (
336+
$this.localizedData.NotDesiredProductVersion -f @(
337+
$fileVersion.ToString(),
338+
$this.InstanceName,
339+
$installedVersion.ToString()
340+
)
341+
)
342+
}
343+
}
344+
}
331345
}
332346

333-
return ($actionStateResult -and $productVersionInDesiredState)
347+
return ($actionStateResult -and $inDesiredState)
334348
}
335349

336350
[void] Set()
@@ -355,7 +369,6 @@ class SqlRSSetup : ResourceBase
355369
# This must be set to the correct valid value for base method Get() to work.
356370
InstanceName = $null
357371
InstallFolder = $null
358-
ProductVersion = $null
359372
}
360373

361374
# Get the configuration if installed
@@ -370,11 +383,6 @@ class SqlRSSetup : ResourceBase
370383

371384
$currentState.InstanceName = $rsConfiguration.InstanceName
372385
$currentState.InstallFolder = $rsConfiguration.InstallFolder
373-
374-
if (-not ([System.String]::IsNullOrEmpty($rsConfiguration.ProductVersion)))
375-
{
376-
$currentState.ProductVersion = $rsConfiguration.ProductVersion
377-
}
378386
}
379387
else
380388
{

source/en-US/SqlRSSetup.strings.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ ConvertFrom-StringData @'
2929
NotDesiredProductVersion = The product version '{0}' is not the desired for the instance '{1}'. Desired version in executable: '{2}'.
3030
InstanceName_Invalid = The instance name '{0}' is invalid. Only one of the supported instance name can be used, either SSRS or PBIRS depending on what setup executable is used.
3131
CannotDetermineProductVersion = Could not determine the product version for the installed instance '{0}'. Run the command `Get-SqlDscRSSetupConfiguration -InstanceName '{0}'` to get the configuration for the instance and verify that it returns a valid product version.
32+
CannotDetermineEdition = Could not determine the edition for the installed instance '{0}'. Run the command `Get-SqlDscRSSetupConfiguration -InstanceName '{0}'` to get the configuration for the instance and verify that it returns a valid edition.
33+
NotDesiredEdition = The edition '{0}' is not the desired for the instance '{1}'. Desired edition in executable: '{2}'.
3234
'@

tests/Unit/Classes/SqlRSSetup.Tests.ps1

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Describe 'SqlRSSetup\Get()' -Tag 'Get' {
9898
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
9999
return [System.Collections.Hashtable] @{
100100
InstanceName = 'SSRS'
101-
ProductVersion = '14.0.0'
102101
}
103102
} -PassThru |
104103
Add-Member -Force -MemberType 'ScriptMethod' -Name 'AssertProperties' -Value {
@@ -127,7 +126,6 @@ Describe 'SqlRSSetup\Get()' -Tag 'Get' {
127126
$currentState.SuppressRestart | Should -BeFalse
128127
$currentState.ForceRestart | Should -BeFalse
129128
$currentState.VersionUpgrade | Should -BeNullOrEmpty
130-
$currentState.ProductVersion | Should -Be '14.0.0'
131129
}
132130
}
133131
}
@@ -183,7 +181,6 @@ Describe 'SqlRSSetup\Get()' -Tag 'Get' {
183181
$currentState.SuppressRestart | Should -BeFalse
184182
$currentState.ForceRestart | Should -BeFalse
185183
$currentState.VersionUpgrade | Should -BeNullOrEmpty
186-
$currentState.ProductVersion | Should -BeNullOrEmpty
187184
}
188185
}
189186
}
@@ -306,12 +303,6 @@ Describe 'SqlRSSetup\Test()' -Tag 'Test' {
306303
VersionUpgrade = $true
307304
MediaPath = $TestDrive
308305
} |
309-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
310-
return [System.Collections.Hashtable] @{
311-
InstanceName = 'SSRS'
312-
ProductVersion = '9.9.99'
313-
}
314-
} -PassThru |
315306
# Mock method Compare() which is called by the base method Set()
316307
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
317308
return $null
@@ -327,6 +318,13 @@ Describe 'SqlRSSetup\Test()' -Tag 'Test' {
327318
Mock -CommandName Get-FileProductVersion -MockWith {
328319
return [System.Version] '9.9.99'
329320
}
321+
322+
Mock -CommandName Get-SqlDscRSSetupConfiguration -MockWith {
323+
return [System.Collections.Hashtable] @{
324+
InstanceName = 'SSRS'
325+
ProductVersion = '9.9.99'
326+
}
327+
}
330328
}
331329

332330
It 'Should return $true' {
@@ -442,12 +440,6 @@ Describe 'SqlRSSetup\Test()' -Tag 'Test' {
442440
VersionUpgrade = $true
443441
MediaPath = $TestDrive
444442
} |
445-
Add-Member -Force -MemberType 'ScriptMethod' -Name 'GetCurrentState' -Value {
446-
return [System.Collections.Hashtable] @{
447-
InstanceName = 'SSRS'
448-
ProductVersion = '5.5.0'
449-
}
450-
} -PassThru |
451443
# Mock method Compare() which is called by the base method Set()
452444
Add-Member -Force -MemberType 'ScriptMethod' -Name 'Compare' -Value {
453445
return $null
@@ -463,6 +455,13 @@ Describe 'SqlRSSetup\Test()' -Tag 'Test' {
463455
Mock -CommandName Get-FileProductVersion -MockWith {
464456
return [System.Version] '9.9.99'
465457
}
458+
459+
Mock -CommandName Get-SqlDscRSSetupConfiguration -MockWith {
460+
return [System.Collections.Hashtable] @{
461+
InstanceName = 'SSRS'
462+
ProductVersion = '5.5.0'
463+
}
464+
}
466465
}
467466

468467
It 'Should return $false' {
@@ -588,7 +587,6 @@ Describe 'SqlRSSetup\GetCurrentState()' -Tag 'GetCurrentState' {
588587
[PSCustomObject] @{
589588
InstanceName = 'SSRS'
590589
InstallFolder = 'C:\Program Files\SSRS'
591-
ProductVersion = '15.0.2000.5'
592590
}
593591
)
594592
}
@@ -604,7 +602,6 @@ Describe 'SqlRSSetup\GetCurrentState()' -Tag 'GetCurrentState' {
604602
)
605603

606604
$currentState.InstanceName | Should -Be 'SSRS'
607-
$currentState.ProductVersion | Should -Be '15.0.2000.5'
608605
$currentState.InstallFolder | Should -Be 'C:\Program Files\SSRS'
609606
}
610607
}

0 commit comments

Comments
 (0)