From 99ead80a5c155c1bd402c3c059ade876d19ad106 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 8 Sep 2018 19:42:31 +1200 Subject: [PATCH 01/18] Added PartitionStyle parameter to Disk --- CHANGELOG.md | 3 + .../DSCResources/MSFT_Disk/MSFT_Disk.psm1 | 146 ++-- .../MSFT_Disk/MSFT_Disk.schema.mof | 1 + .../DSCResources/MSFT_Disk/README.md | 3 + .../MSFT_Disk/en-us/MSFT_Disk.strings.psd1 | 8 +- .../MSFT_Disk.Integration.Tests.ps1 | 290 ++++++-- Tests/Integration/MSFT_Disk.config.ps1 | 24 +- Tests/Unit/MSFT_Disk.Tests.ps1 | 660 +++++++++++++----- 8 files changed, 823 insertions(+), 312 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b06ea0ce..fa9ecff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- Disk: + - Added `PartitionType` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). + ## 4.1.0.0 - Enabled PSSA rule violations to fail build - Fixes [Issue #149](https://github.com/PowerShell/StorageDsc/issues/149). diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 index 1324aec7..b7e8ccb3 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 @@ -33,6 +33,9 @@ $localizedData = Get-LocalizedData ` .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. + .PARAMETER PartitionStyle + Specifies the partition style of the disk. Defaults to GPT. + .PARAMETER Size Specifies the size of new volume (use all available space on disk if not provided). @@ -70,6 +73,11 @@ function Get-TargetResource [System.String] $DiskIdType = 'Number', + [Parameter()] + [ValidateSet('GPT', 'MBR')] + [System.String] + $PartitionStyle = 'GPT', + [Parameter()] [System.UInt64] $Size, @@ -124,17 +132,16 @@ function Get-TargetResource -Query "SELECT BlockSize from Win32_Volume WHERE DriveLetter = '$($DriveLetter):'" ` -ErrorAction SilentlyContinue).BlockSize - $returnValue = @{ + return @{ DiskId = $DiskId DiskIdType = $DiskIdType DriveLetter = $partition.DriveLetter + PartitionStyle = $disk.PartitionStyle Size = $partition.Size FSLabel = $FSLabel AllocationUnitSize = $blockSize FSFormat = $fileSystem } - - $returnValue } # Get-TargetResource <# @@ -150,6 +157,9 @@ function Get-TargetResource .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. + .PARAMETER PartitionStyle + Specifies the partition style of the disk. Defaults to GPT. + .PARAMETER Size Specifies the size of new volume. Leave empty to use the remaining free space. @@ -188,6 +198,11 @@ function Set-TargetResource [System.String] $DiskIdType = 'Number', + [Parameter()] + [ValidateSet('GPT', 'MBR')] + [System.String] + $PartitionStyle = 'GPT', + [Parameter()] [System.UInt64] $Size, @@ -269,41 +284,35 @@ function Set-TargetResource -DiskIdType $DiskIdType } - switch ($disk.PartitionStyle) + if ($disk.PartitionStyle -eq 'RAW') { - 'RAW' - { - # The disk partition table is not yet initialized, so initialize it with GPT - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($localizedData.InitializingDiskMessage -f $DiskIdType, $DiskId) - ) -join '' ) - - $disk | Initialize-Disk ` - -PartitionStyle 'GPT' - - break - } # 'RAW' + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($localizedData.InitializingDiskMessage -f $DiskIdType, $DiskId, $PartitionStyle) + ) -join '' ) - 'GPT' + $disk | Initialize-Disk -PartitionStyle $PartitionStyle + } + else + { + if ($disk.PartitionStyle -eq $PartitionStyle) { - # The disk partition is already initialized with GPT. + # The disk partition is already initialized with the correct partition style Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.DiskAlreadyInitializedMessage -f $DiskIdType, $DiskId) + $($localizedData.DiskAlreadyInitializedMessage ` + -f $DiskIdType, $DiskId, $disk.PartitionStyle) ) -join '' ) - break - } # 'GPT' - - default + } + else { - # This disk is initialized but not as GPT - so raise an exception. + # This disk is initialized but with the incorrect partition style New-InvalidOperationException ` - -Message ($localizedData.DiskAlreadyInitializedError -f ` - $DiskIdType, $DiskId, $Disk.PartitionStyle) - } # default - } # switch + -Message ($localizedData.DiskInitializedWithWrongPartitionStyleError ` + -f $DiskIdType, $DiskId, $Disk.PartitionStyle, $PartitionStyle) + } + } # Get the partitions on the disk $partition = $disk | Get-Partition -ErrorAction SilentlyContinue @@ -318,7 +327,8 @@ function Set-TargetResource # There is no partiton with this drive letter Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.DriveNotFoundOnPartitionMessage -f $DiskIdType, $DiskId, $DriveLetter) + $($localizedData.DriveNotFoundOnPartitionMessage ` + -f $DiskIdType, $DiskId, $DriveLetter) ) -join '' ) # Are there any partitions defined on this disk? @@ -335,14 +345,14 @@ function Set-TargetResource if ($partition) { # A partition matching the required size was found - Write-Verbose -Message ($localizedData.MatchingPartitionFoundMessage -f ` - $DiskIdType, $DiskId, $partition.PartitionNumber) + Write-Verbose -Message ($localizedData.MatchingPartitionFoundMessage ` + -f $DiskIdType, $DiskId, $partition.PartitionNumber) } else { # A partition matching the required size was not found - Write-Verbose -Message ($localizedData.MatchingPartitionNotFoundMessage -f ` - $DiskIdType, $DiskId) + Write-Verbose -Message ($localizedData.MatchingPartitionNotFoundMessage ` + -f $DiskIdType, $DiskId) } # if } else @@ -351,8 +361,8 @@ function Set-TargetResource No size specified, so see if there is a partition that has a volume matching the file system type that is not assigned to a drive letter. #> - Write-Verbose -Message ($localizedData.MatchingPartitionNoSizeMessage -f ` - $DiskIdType, $DiskId) + Write-Verbose -Message ($localizedData.MatchingPartitionNoSizeMessage ` + -f $DiskIdType, $DiskId) $searchPartitions = $partition | Where-Object -FilterScript { $_.Type -eq 'Basic' -and -not [System.Char]::IsLetter($_.DriveLetter) @@ -363,8 +373,8 @@ function Set-TargetResource foreach ($searchPartition in $searchPartitions) { # Look for the volume in the partition. - Write-Verbose -Message ($localizedData.SearchForVolumeMessage -f ` - $DiskIdType, $DiskId, $searchPartition.PartitionNumber, $FSFormat) + Write-Verbose -Message ($localizedData.SearchForVolumeMessage ` + -f $DiskIdType, $DiskId, $searchPartition.PartitionNumber, $FSFormat) $searchVolumes = $searchPartition | Get-Volume @@ -380,8 +390,8 @@ function Set-TargetResource #> $partition = $searchPartition - Write-Verbose -Message ($localizedData.VolumeFoundMessage -f ` - $DiskIdType, $DiskId, $searchPartition.PartitionNumber, $FSFormat) + Write-Verbose -Message ($localizedData.VolumeFoundMessage ` + -f $DiskIdType, $DiskId, $searchPartition.PartitionNumber, $FSFormat) break } # if @@ -433,7 +443,7 @@ function Set-TargetResource Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " ($localizedData.NewPartitionIsReadOnlyMessage ` - -f $DiskIdType, $DiskId, $partition.PartitionNumber) + -f $DiskIdType, $DiskId, $partition.PartitionNumber) ) -join '' ) Start-Sleep -Seconds 1 @@ -447,8 +457,8 @@ function Set-TargetResource { # The partition is still readonly - throw an exception New-InvalidOperationException ` - -Message ($localizedData.NewParitionIsReadOnlyError -f ` - $DiskIdType, $DiskId, $partition.PartitionNumber) + -Message ($localizedData.NewParitionIsReadOnlyError ` + -f $DiskIdType, $DiskId, $partition.PartitionNumber) } # if $assignDriveLetter = $true @@ -458,8 +468,8 @@ function Set-TargetResource # The disk already has a partition on it that is assigned to the Drive Letter Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.PartitionAlreadyAssignedMessage -f ` - $DriveLetter, $assignedPartition.PartitionNumber) + $($localizedData.PartitionAlreadyAssignedMessage ` + -f $DriveLetter, $assignedPartition.PartitionNumber) ) -join '' ) $assignDriveLetter = $false @@ -485,7 +495,7 @@ function Set-TargetResource Write-Warning -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.ResizeRefsNotPossibleMessage ` - -f $DriveLetter, $assignedPartition.Size, $Size) + -f $DriveLetter, $assignedPartition.Size, $Size) ) -join '' ) } @@ -494,7 +504,7 @@ function Set-TargetResource Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.SizeMismatchCorrectionMessage ` - -f $DriveLetter, $assignedPartition.Size, $Size) + -f $DriveLetter, $assignedPartition.Size, $Size) ) -join '' ) if ($Size -gt $supportedSize.SizeMax) @@ -565,16 +575,16 @@ function Set-TargetResource # The file system format does not match Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.FileSystemFormatMismatch -f ` - $DriveLetter, $fileSystem, $FSFormat) + $($localizedData.FileSystemFormatMismatch ` + -f $DriveLetter, $fileSystem, $FSFormat) ) -join '' ) if ($AllowDestructive) { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.VolumeFormatInProgressMessage -f ` - $DriveLetter, $fileSystem, $FSFormat) + $($localizedData.VolumeFormatInProgressMessage ` + -f $DriveLetter, $fileSystem, $FSFormat) ) -join '' ) $formatParam = @{ @@ -602,7 +612,7 @@ function Set-TargetResource Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.ChangingVolumeLabelMessage ` - -f $DriveLetter, $FSLabel) + -f $DriveLetter, $FSLabel) ) -join '' ) $volume | Set-Volume -NewFileSystemLabel $FSLabel @@ -635,6 +645,9 @@ function Set-TargetResource .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. + .PARAMETER PartitionStyle + Specifies the partition style of the disk. Defaults to GPT. + .PARAMETER Size Specifies the size of new volume. Leave empty to use the remaining free space. @@ -672,6 +685,11 @@ function Test-TargetResource [System.String] $DiskIdType = 'Number', + [Parameter()] + [ValidateSet('GPT', 'MBR')] + [System.String] + $PartitionStyle = 'GPT', + [Parameter()] [System.UInt64] $Size, @@ -740,20 +758,32 @@ function Test-TargetResource { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.DiskReadOnlyMessage -f $DiskIdType, $DiskId) + $($localizedData.DiskReadOnlyMessage ` + -f $DiskIdType, $DiskId) ) -join '' ) return $false } # if - if ($disk.PartitionStyle -ne 'GPT') + if ($disk.PartitionStyle -ne $PartitionStyle) { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.DiskNotGPTMessage -f $DiskIdType, $DiskId, $Disk.PartitionStyle) + $($localizedData.DiskPartitionNotMatchMessage ` + -f $DiskIdType, $DiskId, $Disk.PartitionStyle, $PartitionStyle) ) -join '' ) - return $false + if ($disk.PartitionStyle -eq 'RAW' -or ($AllowDestructive -and $ClearDisk)) + { + return $false + } + else + { + # This disk is initialized but with the incorrect partition style + New-InvalidOperationException ` + -Message ($localizedData.DiskInitializedWithWrongPartitionStyleError ` + -f $DiskIdType, $DiskId, $Disk.PartitionStyle, $PartitionStyle) + } } # if $partition = Get-Partition ` @@ -840,7 +870,7 @@ function Test-TargetResource Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.FileSystemFormatMismatch ` - -f $DriveLetter, $fileSystem, $FSFormat) + -f $DriveLetter, $fileSystem, $FSFormat) ) -join '' ) if ($AllowDestructive) @@ -860,7 +890,7 @@ function Test-TargetResource Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.DriveLabelMismatch ` - -f $DriveLetter, $label, $FSLabel) + -f $DriveLetter, $label, $FSLabel) ) -join '' ) return $false diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof index 0b0c77aa..df0d9939 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof @@ -5,6 +5,7 @@ class MSFT_Disk : OMI_BaseResource [Key, Description("Specifies the identifier for which disk to modify.")] String DriveLetter; [Required, Description("Specifies the disk identifier for the disk to modify.")] String DiskId; [Write, Description("Specifies the identifier type the DiskId contains. Defaults to Number."), ValueMap{"Number","UniqueId","Guid"}, Values{"Number","UniqueId","Guid"}] String DiskIdType; + [Write, Description("Specifies the partition style of the disk. Defaults to GPT."), ValueMap{"MBR","GPT"}, Values{"MBR","GPT"}] String PartitionStyle; [Write, Description("Specifies the size of new volume. Leave empty to use the remaining free space.")] Uint64 Size; [Write, Description("Define volume label if required.")] String FSLabel; [Write, Description("Specifies the allocation unit size to use when formatting the volume.")] Uint32 AllocationUnitSize; diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md b/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md index 523a7ce6..e4ea8dbd 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md @@ -20,3 +20,6 @@ Get-Disk | Select-Object -Property FriendlyName,DiskNumber,UniqueId,Guid Note: The _Guid_ for a disk is only assigned once the partition table for the disk has been created (e.g. the disk has been initialized). Therefore to use this method of disk selection the disk must have been initialized by some other method. + +The _Guid_ identifier method of specifying disks is only supported as an identifier +for disks formatted with `GPT` partition table style. diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 b/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 index afcee61b..6c8e82c0 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 @@ -4,8 +4,8 @@ SetDiskOnlineMessage = Setting disk with {0} '{1}' online. SetDiskReadWriteMessage = Setting disk with {0} '{1}' to read/write. CheckingDiskPartitionStyleMessage = Checking disk with {0} '{1}' partition style. - InitializingDiskMessage = Initializing disk with {0} '{1}'. - DiskAlreadyInitializedMessage = Disk with {0} '{1}' is already initialized with GPT. + InitializingDiskMessage = Initializing disk with {0} '{1}' as '{2}'. + DiskAlreadyInitializedMessage = Disk with {0} '{1}' is already initialized with '{2}'. CreatingPartitionMessage = Creating partition on disk with {0} '{1}' with drive letter '{2}' using {3}. FormattingVolumeMessage = Formatting the volume as '{0}'. SuccessfullyInitializedMessage = Successfully initialized '{0}'. @@ -18,7 +18,8 @@ DiskNotFoundMessage = Disk with {0} '{1}' was not found. DiskNotOnlineMessage = Disk with {0} '{1}' is not online. DiskReadOnlyMessage = Disk with {0} '{1}' is readonly. - DiskNotGPTMessage = Disk with {0} '{1}' is initialized with '{2}' partition style. GPT required. + DiskPartitionNotMatchMessage = Disk with {0} '{1}' is initialized with '{2}' partition style but '{3}' required. + DiskInitializedWithWrongPartitionStyleError = Disk with {0} '{1}' is already initialized with '{2}' but should be '{3}'. Set AllowDestructive and ClearDisk to 'True' to allow disk to be reinitialized. DriveLetterNotFoundMessage = Drive {0} was not found. SizeMismatchMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. Set AllowDestructive to 'True' to enable resizing of partition. SizeMismatchWithAllowDestructiveMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. @@ -33,7 +34,6 @@ MatchingPartitionFoundMessage = Disk with {0} '{1}' already contains partitions, and partition '{2}' matches required size. DriveNotFoundOnPartitionMessage = Disk with {0} '{1}' does not contain a partition assigned to drive letter '{2}'. ClearingDiskMessage = Clearing disk with {0} '{1}' of all existing partitions and volumes. - DiskAlreadyInitializedError = Disk with {0} '{1}' is already initialized with {2}. NewParitionIsReadOnlyError = New partition '{2}' on disk with {0} '{1}' did not become writable in the expected time. VolumeFormatInProgressMessage = Switch AllowDestructive is specified. Attempting to format volume on {0} with '{2}', was '{1}'. SizeMismatchCorrectionMessage = Switch AllowDestructive is specified. Attempting to resize partition {0} from {1} to {2}. diff --git a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 index ca508907..c521aede 100644 --- a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 @@ -52,12 +52,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -81,11 +82,12 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' $current.FSLabel | Should -Be $FSLabelA $current.Size | Should -Be 100MB } @@ -98,11 +100,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.Number - DiskIdType = 'Number' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelB } ) } @@ -126,12 +129,13 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number $current.DriveLetter | Should -Be $driveLetterB $current.FSLabel | Should -Be $FSLabelB + $current.PartitionStyle | Should -Be 'GPT' $current.Size | Should -Be 935198720 } } @@ -184,12 +188,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - FSLabel = $FSLabelA - Size = 50MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 50MB } ) } @@ -213,11 +218,12 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' $current.FSLabel | Should -Be $FSLabelA $current.FSFormat | Should -Be 'NTFS' $current.Size | Should -Be 50MB @@ -260,7 +266,7 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigAllowDestructive" } $current.DiskId | Should -Be $disk.Number @@ -291,6 +297,142 @@ try Remove-Item -Path $VHDPath -Force } } + + Context 'Partition and format newly provisioned disk using Disk Number with one volume using MBR then convert to GPT' { + BeforeAll { + # Create a VHD and attach it to the computer + $VHDPath = Join-Path -Path $TestDrive ` + -ChildPath 'TestDisk.vhd' + $null = New-VDisk -Path $VHDPath -SizeInMB 1024 + $null = Mount-DiskImage -ImagePath $VHDPath -StorageType VHD -NoDriveLetter + $diskImage = Get-DiskImage -ImagePath $VHDPath + $disk = Get-Disk -Number $diskImage.Number + $FSLabelA = 'TestDiskA' + + # Get a spare drive letters + $lastDrive = ((Get-Volume).DriveLetter | Sort-Object | Select-Object -Last 1) + $driveLetterA = [char](([int][char]$lastDrive) + 1) + } + + Context "Create volume on Disk Number $($disk.Number)" { + It 'Should compile and apply the MOF without throwing' { + { + # This is to pass to the Config + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'MBR' + FSLabel = $FSLabelA + Size = 50MB + } + ) + } + + & "$($script:DSCResourceName)_Config" ` + -OutputPath $TestDrive ` + -ConfigurationData $configData + + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" + } + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'MBR' + $current.FSLabel | Should -Be $FSLabelA + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 50MB + } + } + + Context "Resize partition on Disk Number $($disk.Number) with AllowDestructive" { + It 'Should compile and apply the MOF without throwing' { + { + # This is to pass to the Config + $configData = @{ + AllNodes = @( + @{ + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 50MB + + } + ) + } + + & "$($script:DSCResourceName)_ConfigClearDisk" ` + -OutputPath $TestDrive ` + -ConfigurationData $configData + + Start-DscConfiguration ` + -Path $TestDrive ` + -ComputerName localhost ` + -Wait ` + -Verbose ` + -Force ` + -ErrorAction Stop + } | Should -Not -Throw + } + + It 'Should be able to call Get-DscConfiguration without throwing' { + { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + } + + It 'Should have set the resource and all the parameters should match' { + $current = Get-DscConfiguration | Where-Object -FilterScript { + $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigClearDisk" + } + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA + $current.PartitionStyle | Should -Be 'GPT' + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 1040104960 + } + } + + # A system partition will have been added to the disk as well as the test partition + It 'Should have 2 partitions on disk' { + ($disk | Get-Partition).Count | Should -Be 2 + } + + <# + Get a list of all drives mounted - this works better on Windows Server 2012 R2 than + trying to get the drive mounted by name. + #> + $drives = Get-PSDrive + + It "Should have attached drive $driveLetterA" { + $drives | Where-Object -Property Name -eq $driveLetterA | Should -Not -BeNullOrEmpty + } + + AfterAll { + Dismount-DiskImage -ImagePath $VHDPath -StorageType VHD + Remove-Item -Path $VHDPath -Force + } + } #endregion #region Integration Tests for Disk Unique Id @@ -319,12 +461,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -348,11 +491,12 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.UniqueId $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' $current.FSLabel | Should -Be $FSLabelA $current.Size | Should -Be 100MB } @@ -365,13 +509,14 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - FSLabel = $FSLabelA - Size = 900MB - FSFormat = 'ReFS' + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 900MB + FSFormat = 'ReFS' } ) } @@ -395,11 +540,12 @@ try } It 'should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigClearDisk" } $current.DiskId | Should -Be $disk.UniqueId $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' $current.FSLabel | Should -Be $FSLabelA $current.Size | Should -Be 900MB $current.FSFormat | Should -Be 'ReFS' @@ -413,11 +559,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionStyle = 'GPT' + FSLabel = $FSLabelB } ) } @@ -441,10 +588,11 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.UniqueId + $current.PartitionStyle | Should -Be 'GPT' $current.DriveLetter | Should -Be $driveLetterB $current.FSLabel | Should -Be $FSLabelB $current.Size | Should -Be 96337920 @@ -497,12 +645,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Guid - DiskIdType = 'Guid' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Guid + DiskIdType = 'Guid' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -526,10 +675,11 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Guid + $current.PartitionStyle | Should -Be 'GPT' $current.DriveLetter | Should -Be $driveLetterA $current.FSLabel | Should -Be $FSLabelA $current.Size | Should -Be 100MB @@ -543,11 +693,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.Guid - DiskIdType = 'Guid' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.Guid + DiskIdType = 'Guid' + PartitionStyle = 'GPT' + FSLabel = $FSLabelB } ) } @@ -571,10 +722,11 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Guid + $current.PartitionStyle | Should -Be 'GPT' $current.DriveLetter | Should -Be $driveLetterB $current.FSLabel | Should -Be $FSLabelB $current.Size | Should -Be 935198720 @@ -625,11 +777,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - FSLabel = $FSLabelA + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA } ) } @@ -653,10 +806,11 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number + $current.PartitionStyle | Should -Be 'GPT' $current.DriveLetter | Should -Be $driveLetterA $current.FSLabel | Should -Be $FSLabelA } @@ -675,11 +829,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - FSLabel = $FSLabelA + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA } ) } @@ -703,10 +858,11 @@ try } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object { + $current = Get-DscConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number + $current.PartitionStyle | Should -Be 'GPT' $current.DriveLetter | Should -Be $driveLetterA $current.FSLabel | Should -Be $FSLabelA } diff --git a/Tests/Integration/MSFT_Disk.config.ps1 b/Tests/Integration/MSFT_Disk.config.ps1 index 7f6d8c14..3ee7ed58 100644 --- a/Tests/Integration/MSFT_Disk.config.ps1 +++ b/Tests/Integration/MSFT_Disk.config.ps1 @@ -7,21 +7,23 @@ configuration MSFT_Disk_Config { { Disk Integration_Test { - DiskId = $Node.DiskId - DiskIdType = $Node.DiskIdType - DriveLetter = $Node.DriveLetter - FSLabel = $Node.FSLabel - Size = $Node.Size + DiskId = $Node.DiskId + DiskIdType = $Node.DiskIdType + PartitionStyle = $Node.PartitionStyle + DriveLetter = $Node.DriveLetter + FSLabel = $Node.FSLabel + Size = $Node.Size } } else { Disk Integration_Test { - DiskId = $Node.DiskId - DiskIdType = $Node.DiskIdType - DriveLetter = $Node.DriveLetter - FSLabel = $Node.FSLabel + DiskId = $Node.DiskId + DiskIdType = $Node.DiskIdType + PartitionStyle = $Node.PartitionStyle + DriveLetter = $Node.DriveLetter + FSLabel = $Node.FSLabel } } } @@ -38,6 +40,7 @@ configuration MSFT_Disk_ConfigAllowDestructive { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -51,6 +54,7 @@ configuration MSFT_Disk_ConfigAllowDestructive { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel FSFormat = $Node.FSFormat @@ -71,6 +75,7 @@ configuration MSFT_Disk_ConfigClearDisk { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -85,6 +90,7 @@ configuration MSFT_Disk_ConfigClearDisk { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel FSFormat = $Node.FSFormat diff --git a/Tests/Unit/MSFT_Disk.Tests.ps1 b/Tests/Unit/MSFT_Disk.Tests.ps1 index ea8b1c34..4a265c75 100644 --- a/Tests/Unit/MSFT_Disk.Tests.ps1 +++ b/Tests/Unit/MSFT_Disk.Tests.ps1 @@ -31,10 +31,10 @@ try $script:testDriveLetter = 'G' $script:testDiskNumber = 1 $script:testDiskUniqueId = 'TESTDISKUNIQUEID' + $script:testDiskParitionStyle = 'GPT' $script:testDiskGptGuid = [guid]::NewGuid() - $script:testDiskMbrGuid = '123456' - $script:mockedDisk0 = [pscustomobject] @{ + $script:mockedDisk0Gpt = [pscustomobject] @{ Number = $script:testDiskNumber UniqueId = $script:testDiskUniqueId Guid = $script:testDiskGptGuid @@ -46,13 +46,22 @@ try $script:mockedDisk0Mbr = [pscustomobject] @{ Number = $script:testDiskNumber UniqueId = $script:testDiskUniqueId - Guid = $script:testDiskMbrGuid + Guid = '' IsOffline = $false IsReadOnly = $false PartitionStyle = 'MBR' } - $script:mockedDisk0Offline = [pscustomobject] @{ + $script:mockedDisk0Raw = [pscustomobject] @{ + Number = $script:testDiskNumber + UniqueId = $script:testDiskUniqueId + Guid = '' + IsOffline = $false + IsReadOnly = $false + PartitionStyle = 'RAW' + } + + $script:mockedDisk0GptOffline = [pscustomobject] @{ Number = $script:testDiskNumber UniqueId = $script:testDiskUniqueId Guid = $script:testDiskGptGuid @@ -61,16 +70,16 @@ try PartitionStyle = 'GPT' } - $script:mockedDisk0OfflineRaw = [pscustomobject] @{ + $script:mockedDisk0RawOffline = [pscustomobject] @{ Number = $script:testDiskNumber UniqueId = $script:testDiskUniqueId Guid = '' IsOffline = $true IsReadOnly = $false - PartitionStyle = 'Raw' + PartitionStyle = 'RAW' } - $script:mockedDisk0Readonly = [pscustomobject] @{ + $script:mockedDisk0GptReadonly = [pscustomobject] @{ Number = $script:testDiskNumber UniqueId = $script:testDiskUniqueId Guid = $script:testDiskGptGuid @@ -79,15 +88,6 @@ try PartitionStyle = 'GPT' } - $script:mockedDisk0Raw = [pscustomobject] @{ - Number = $script:testDiskNumber - UniqueId = $script:testDiskUniqueId - Guid = '' - IsOffline = $false - IsReadOnly = $false - PartitionStyle = 'Raw' - } - $script:mockedCim = [pscustomobject] @{BlockSize = 4096} $script:mockedPartitionSize = 1GB @@ -139,7 +139,7 @@ try } $script:parameterFilter_MockedDisk0Number = { - $DiskId -eq $script:mockedDisk0.Number -and $DiskIdType -eq 'Number' + $DiskId -eq $script:mockedDisk0Gpt.Number -and $DiskIdType -eq 'Number' } #endregion @@ -319,7 +319,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -333,12 +333,16 @@ try -Verifiable $resource = Get-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -Verbose - It "Should return DiskId $($script:mockedDisk0.Number)" { - $resource.DiskId | Should -Be $script:mockedDisk0.Number + It "Should return DiskId $($script:mockedDisk0Gpt.Number)" { + $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Number + } + + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -380,8 +384,8 @@ try Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0.UniqueId -and $DiskIdType -eq 'UniqueId' } ` - -MockWith { $script:mockedDisk0 } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0Gpt.UniqueId -and $DiskIdType -eq 'UniqueId' } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -395,13 +399,17 @@ try -Verifiable $resource = Get-TargetResource ` - -DiskId $script:mockedDisk0.UniqueId ` + -DiskId $script:mockedDisk0Gpt.UniqueId ` -DiskIdType 'UniqueId' ` -DriveLetter $script:testDriveLetter ` -Verbose - It "Should return DiskId $($script:mockedDisk0.UniqueId)" { - $resource.DiskId | Should -Be $script:mockedDisk0.UniqueId + It "Should return DiskId $($script:mockedDisk0Gpt.UniqueId)" { + $resource.DiskId | Should -Be $script:mockedDisk0Gpt.UniqueId + } + + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -428,7 +436,7 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0.UniqueId -and $DiskIdType -eq 'UniqueId' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0Gpt.UniqueId -and $DiskIdType -eq 'UniqueId' } Assert-MockCalled -CommandName Get-Partition -Exactly 1 Assert-MockCalled -CommandName Get-Volume -Exactly 1 } @@ -443,8 +451,8 @@ try Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0.Guid -and $DiskIdType -eq 'Guid' } ` - -MockWith { $script:mockedDisk0 } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0Gpt.Guid -and $DiskIdType -eq 'Guid' } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -458,13 +466,17 @@ try -Verifiable $resource = Get-TargetResource ` - -DiskId $script:mockedDisk0.Guid ` + -DiskId $script:mockedDisk0Gpt.Guid ` -DiskIdType 'Guid' ` -DriveLetter $script:testDriveLetter ` -Verbose - It "Should return DiskId $($script:mockedDisk0.Guid)" { - $resource.DiskId | Should -Be $script:mockedDisk0.Guid + It "Should return DiskId $($script:mockedDisk0Gpt.Guid)" { + $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Guid + } + + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -491,7 +503,7 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0.Guid -and $DiskIdType -eq 'Guid' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0Gpt.Guid -and $DiskIdType -eq 'Guid' } Assert-MockCalled -CommandName Get-Partition -Exactly 1 Assert-MockCalled -CommandName Get-Volume -Exactly 1 } @@ -506,8 +518,8 @@ try Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0.Guid -and $DiskIdType -eq 'Guid' } ` - -MockWith { $script:mockedDisk0 } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0Gpt.Guid -and $DiskIdType -eq 'Guid' } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -521,13 +533,17 @@ try -Verifiable $resource = Get-TargetResource ` - -DiskId $script:mockedDisk0.Guid ` + -DiskId $script:mockedDisk0Gpt.Guid ` -DiskIdType 'Guid' ` -DriveLetter $script:testDriveLetter ` -Verbose - It "Should return DiskId $($script:mockedDisk0.Guid)" { - $resource.DiskId | Should -Be $script:mockedDisk0.Guid + It "Should return DiskId $($script:mockedDisk0Gpt.Guid)" { + $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Guid + } + + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -554,7 +570,7 @@ try Assert-VerifiableMock Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0.Guid -and $DiskIdType -eq 'Guid' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0Gpt.Guid -and $DiskIdType -eq 'Guid' } Assert-MockCalled -CommandName Get-Partition -Exactly 1 Assert-MockCalled -CommandName Get-Volume -Exactly 1 } @@ -569,7 +585,133 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` + -Verifiable + + Mock ` + -CommandName Get-Partition ` + -Verifiable + + Mock ` + -CommandName Get-Volume ` + -Verifiable + + $resource = Get-TargetResource ` + -DiskId $script:mockedDisk0Gpt.Number ` + -DriveLetter $script:testDriveLetter ` + -Verbose + + It "Should return DiskId $($script:mockedDisk0Gpt.Number)" { + $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Number + } + + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle + } + + It "Should return an empty drive letter" { + $resource.DriveLetter | Should -Be $null + } + + It "Should return a zero size" { + $resource.Size | Should -Be $null + } + + It "Should return no FSLabel" { + $resource.FSLabel | Should -Be '' + } + + It "Should return an AllocationUnitSize of 0" { + $resource.AllocationUnitSize | Should -Be $null + } + + It "Should return no FSFormat" { + $resource.FSFormat | Should -Be $null + } + + It 'Should call the correct mocks' { + Assert-VerifiableMock + Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 + Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly 1 ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number + Assert-MockCalled -CommandName Get-Partition -Exactly 1 + Assert-MockCalled -CommandName Get-Volume -Exactly 1 + } + } + + Context 'Online MBR disk with no partition using Disk Number' { + # verifiable (should be called) mocks + Mock ` + -CommandName Get-CimInstance ` + -Verifiable + + Mock ` + -CommandName Get-DiskByIdentifier ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number ` + -MockWith { $script:mockedDisk0Mbr } ` + -Verifiable + + Mock ` + -CommandName Get-Partition ` + -Verifiable + + Mock ` + -CommandName Get-Volume ` + -Verifiable + + $resource = Get-TargetResource ` + -DiskId $script:mockedDisk0Mbr.Number ` + -DriveLetter $script:testDriveLetter ` + -Verbose + + It "Should return DiskId $($script:mockedDisk0Mbr.Number)" { + $resource.DiskId | Should -Be $script:mockedDisk0Mbr.Number + } + + It "Should return PartitionStyle $($script:mockedDisk0Mbr.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Mbr.PartitionStyle + } + + It "Should return an empty drive letter" { + $resource.DriveLetter | Should -Be $null + } + + It "Should return a zero size" { + $resource.Size | Should -Be $null + } + + It "Should return no FSLabel" { + $resource.FSLabel | Should -Be '' + } + + It "Should return an AllocationUnitSize of 0" { + $resource.AllocationUnitSize | Should -Be $null + } + + It "Should return no FSFormat" { + $resource.FSFormat | Should -Be $null + } + + It 'Should call the correct mocks' { + Assert-VerifiableMock + Assert-MockCalled -CommandName Get-CimInstance -Exactly 1 + Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly 1 ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number + Assert-MockCalled -CommandName Get-Partition -Exactly 1 + Assert-MockCalled -CommandName Get-Volume -Exactly 1 + } + } + + Context 'Online RAW disk with no partition using Disk Number' { + # verifiable (should be called) mocks + Mock ` + -CommandName Get-CimInstance ` + -Verifiable + + Mock ` + -CommandName Get-DiskByIdentifier ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number ` + -MockWith { $script:mockedDisk0Raw } ` -Verifiable Mock ` @@ -581,12 +723,16 @@ try -Verifiable $resource = Get-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Raw.Number ` -DriveLetter $script:testDriveLetter ` -Verbose - It "Should return DiskId $($script:mockedDisk0.Number)" { - $resource.DiskId | Should -Be $script:mockedDisk0.Number + It "Should return DiskId $($script:mockedDisk0Raw.Number)" { + $resource.DiskId | Should -Be $script:mockedDisk0Raw.Number + } + + It "Should return PartitionStyle $($script:mockedDisk0Raw.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Raw.PartitionStyle } It "Should return an empty drive letter" { @@ -627,8 +773,8 @@ try # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.Number -and $DiskIdType -eq 'Number' } ` - -MockWith { $script:mockedDisk0Offline } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.Number -and $DiskIdType -eq 'Number' } ` + -MockWith { $script:mockedDisk0GptOffline } ` -Verifiable Mock ` @@ -664,7 +810,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0Offline.Number ` + -DiskId $script:mockedDisk0GptOffline.Number ` -Driveletter $script:testDriveLetter ` -Verbose } | Should -Not -Throw @@ -673,7 +819,7 @@ try It 'Should call the correct mocks' { Assert-VerifiableMock Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.Number -and $DiskIdType -eq 'Number' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.Number -and $DiskIdType -eq 'Number' } Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 @@ -689,8 +835,8 @@ try # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.UniqueId -and $DiskIdType -eq 'UniqueId' } ` - -MockWith { $script:mockedDisk0Offline } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.UniqueId -and $DiskIdType -eq 'UniqueId' } ` + -MockWith { $script:mockedDisk0GptOffline } ` -Verifiable Mock ` @@ -728,7 +874,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0Offline.UniqueId ` + -DiskId $script:mockedDisk0GptOffline.UniqueId ` -DiskIdType 'UniqueId' ` -Driveletter $script:testDriveLetter ` -Verbose @@ -738,7 +884,7 @@ try It 'Should call the correct mocks' { Assert-VerifiableMock Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.UniqueId -and $DiskIdType -eq 'UniqueId' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.UniqueId -and $DiskIdType -eq 'UniqueId' } Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 @@ -756,8 +902,8 @@ try # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.Guid -and $DiskIdType -eq 'Guid' } ` - -MockWith { $script:mockedDisk0Offline } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.Guid -and $DiskIdType -eq 'Guid' } ` + -MockWith { $script:mockedDisk0GptOffline } ` -Verifiable Mock ` @@ -795,7 +941,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0Offline.Guid ` + -DiskId $script:mockedDisk0GptOffline.Guid ` -DiskIdType 'Guid' ` -Driveletter $script:testDriveLetter ` -Verbose @@ -805,7 +951,7 @@ try It 'Should call the correct mocks' { Assert-VerifiableMock Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.Guid -and $DiskIdType -eq 'Guid' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.Guid -and $DiskIdType -eq 'Guid' } Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1 Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 @@ -824,7 +970,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0Readonly } ` + -MockWith { $script:mockedDisk0GptReadonly } ` -Verifiable Mock ` @@ -862,7 +1008,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0Readonly.Number ` + -DiskId $script:mockedDisk0GptReadonly.Number ` -Driveletter $script:testDriveLetter ` -Verbose } | Should -Not -Throw @@ -890,7 +1036,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0OfflineRaw } ` + -MockWith { $script:mockedDisk0RawOffline } ` -Verifiable Mock ` @@ -929,7 +1075,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0OfflineRaw.Number ` + -DiskId $script:mockedDisk0RawOffline.Number ` -Driveletter $script:testDriveLetter ` -Verbose } | Should -Not -Throw @@ -1026,7 +1172,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1061,7 +1207,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -Verbose } | Should -Not -Throw @@ -1089,7 +1235,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1122,7 +1268,7 @@ try It 'Should throw NewParitionIsReadOnlyError' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -Verbose } | Should -Throw $errorRecord @@ -1170,10 +1316,10 @@ try Mock -CommandName Set-Partition $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskAlreadyInitializedError -f ` - 'Number', $script:mockedDisk0Mbr.Number, $script:mockedDisk0Mbr.PartitionStyle) + -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` + 'Number', $script:mockedDisk0Mbr.Number, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') - It 'Should throw DiskAlreadyInitializedError' { + It 'Should not throw DiskInitializedWithWrongPartitionStyleError' { { Set-TargetResource ` -DiskId $script:mockedDisk0Mbr.Number ` @@ -1196,7 +1342,7 @@ try } } - Context 'Online MBR disk using Disk Unique Id' { + Context 'Online MBR disk using Disk Unique Id but GPT required and AllowDestructive and ClearDisk are false' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1213,10 +1359,10 @@ try Mock -CommandName Set-Partition $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskAlreadyInitializedError -f ` - 'UniqueId', $script:mockedDisk0Mbr.UniqueId, $script:mockedDisk0Mbr.PartitionStyle) + -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` + 'UniqueId', $script:mockedDisk0Mbr.UniqueId, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') - It 'Should throw DiskAlreadyInitializedError' { + It 'Should throw DiskInitializedWithWrongPartitionStyleError' { { Set-TargetResource ` -DiskId $script:mockedDisk0Mbr.UniqueId ` @@ -1239,55 +1385,12 @@ try } } - Context 'Online MBR disk using Disk Guid' { - # verifiable (should be called) mocks - Mock ` - -CommandName Get-DiskByIdentifier ` - -MockWith { $script:mockedDisk0Mbr } ` - -Verifiable - - # mocks that should not be called - Mock -CommandName Set-Disk - Mock -CommandName Initialize-Disk - Mock -CommandName Get-Partition - Mock -CommandName New-Partition - Mock -CommandName Format-Volume - Mock -CommandName Get-Volume - Mock -CommandName Set-Partition - - $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskAlreadyInitializedError -f ` - 'Guid', $script:mockedDisk0Mbr.Guid, $script:mockedDisk0Mbr.PartitionStyle) - - It 'Should throw DiskAlreadyInitializedError' { - { - Set-TargetResource ` - -DiskId $script:mockedDisk0Mbr.Guid ` - -DiskIdType 'Guid' ` - -Driveletter $script:testDriveLetter ` - -Verbose - } | Should -Throw $errorRecord - } - - It 'Should call the correct mocks' { - Assert-VerifiableMock - Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 - Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Partition -Exactly -Times 0 - Assert-MockCalled -CommandName Get-Volume -Exactly -Times 0 - Assert-MockCalled -CommandName New-Partition -Exactly -Times 0 - Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0 - Assert-MockCalled -CommandName Set-Partition -Exactly -Times 0 - } - } - Context 'Online GPT disk with partition/volume already assigned using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1310,7 +1413,7 @@ try It 'Should not throw an exception' { { Set-targetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -Verbose } | Should -Not -Throw @@ -1335,7 +1438,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1361,7 +1464,7 @@ try It 'Should not throw an exception' { { Set-targetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -Size $script:mockedPartitionSize ` -Verbose @@ -1387,7 +1490,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1421,7 +1524,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter 'H' ` -Verbose } | Should -Not -Throw @@ -1446,7 +1549,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1472,7 +1575,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter 'H' ` -Verbose } | Should -Not -Throw @@ -1497,7 +1600,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1524,7 +1627,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -FSLabel 'NewLabel' ` -Verbose @@ -1551,7 +1654,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1584,7 +1687,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -Size ($script:mockedPartitionSize + 1024) ` -AllowDestructive $true ` @@ -1613,7 +1716,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1649,7 +1752,7 @@ try It 'Should throw FreeSpaceViolationError' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -Size ($script:mockedPartitionSize + 1024) ` -AllowDestructive $true ` @@ -1680,7 +1783,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1721,7 +1824,7 @@ try It 'Should not throw' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -AllowDestructive $true ` -FSLabel 'NewLabel' ` @@ -1751,7 +1854,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1790,7 +1893,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -Size ($script:mockedPartitionSize + 1024) ` -AllowDestructive $true ` @@ -1822,7 +1925,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1852,7 +1955,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -Size $script:mockedPartitionSize ` -FSFormat 'ReFS' ` @@ -1876,12 +1979,12 @@ try } } - Context 'When AllowDestructive enabled with Online GPT disk containing arbitrary partitions' { + Context 'When AllowDestructive and ClearDisk enabled with Online GPT disk containing arbitrary partitions' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -1897,6 +2000,7 @@ try Mock ` -CommandName Set-Volume ` -Verifiable + Mock ` -CommandName Clear-Disk ` -Verifiable @@ -1911,7 +2015,7 @@ try It 'Should not throw an exception' { { Set-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -Driveletter $script:testDriveLetter ` -Size $script:mockedPartitionSize ` -FSLabel 'NewLabel' ` @@ -1935,6 +2039,97 @@ try Assert-MockCalled -CommandName Set-Volume -Exactly -Times 1 } } + + Context 'When AllowDestructive and ClearDisk enabled with Online MBR disk containing arbitrary partitions but GPT required' { + <# + This variable is so that we can change the behavior of the + Get-DiskByIdentifier mock after the first time it is called + in the Set-TargetResource function. + #> + $script:getDiskByIdentifierCalled = $false + + $script:parameterFilter_MockedDisk0Number = { + $DiskId -eq $script:mockedDisk0Gpt.Number -and $DiskIdType -eq 'Number' + } + + # verifiable (should be called) mocks + Mock ` + -CommandName Get-DiskByIdentifier ` + -ParameterFilter { + $DiskId -eq $script:mockedDisk0Gpt.Number ` + -and $DiskIdType -eq 'Number' ` + -and $script:getDiskByIdentifierCalled -eq $false + } ` + -MockWith { + $script:getDiskByIdentifierCalled = $true + return $script:mockedDisk0Mbr + } ` + -Verifiable + + Mock ` + -CommandName Get-DiskByIdentifier ` + -ParameterFilter { + $DiskId -eq $script:mockedDisk0Gpt.Number ` + -and $DiskIdType -eq 'Number' ` + -and $script:getDiskByIdentifierCalled -eq $true + } ` + -MockWith { + return $script:mockedDisk0Raw + } ` + -Verifiable + + Mock ` + -CommandName Get-Partition ` + -MockWith { $script:mockedPartition } ` + -Verifiable + + Mock ` + -CommandName Get-Volume ` + -MockWith { $script:mockedVolume } ` + -Verifiable + + Mock ` + -CommandName Set-Volume ` + -Verifiable + + Mock ` + -CommandName Clear-Disk ` + -Verifiable + + # mocks that should not be called + Mock -CommandName Set-Disk + Mock -CommandName Initialize-Disk + Mock -CommandName New-Partition + Mock -CommandName Format-Volume + Mock -CommandName Set-Partition + + It 'Should not throw an exception' { + { + Set-TargetResource ` + -DiskId $script:mockedDisk0Gpt.Number ` + -Driveletter $script:testDriveLetter ` + -Size $script:mockedPartitionSize ` + -FSLabel 'NewLabel' ` + -AllowDestructive $true ` + -ClearDisk $true ` + -Verbose + } | Should -Not -Throw + } + + It 'Should call the correct mocks' { + Assert-VerifiableMock + Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 2 ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number + Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0 + Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1 + Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1 + Assert-MockCalled -CommandName New-Partition -Exactly -Times 0 + Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0 + Assert-MockCalled -CommandName Set-Partition -Exactly -Times 0 + Assert-MockCalled -CommandName Set-Volume -Exactly -Times 1 + } + } } #endregion @@ -1949,7 +2144,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0Offline } ` + -MockWith { $script:mockedDisk0GptOffline } ` -Verifiable # mocks that should not be called @@ -1962,7 +2157,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0Offline.Number ` + -DiskId $script:mockedDisk0GptOffline.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` -Verbose @@ -1987,8 +2182,8 @@ try # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.Number -and $DiskIdType -eq 'Number' } ` - -MockWith { $script:mockedDisk0Offline } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.Number -and $DiskIdType -eq 'Number' } ` + -MockWith { $script:mockedDisk0GptOffline } ` -Verifiable # mocks that should not be called @@ -2001,7 +2196,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0Offline.Number ` + -DiskId $script:mockedDisk0GptOffline.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` -Verbose @@ -2015,7 +2210,7 @@ try It 'Should call the correct mocks' { Assert-VerifiableMock Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.Number -and $DiskIdType -eq 'Number' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.Number -and $DiskIdType -eq 'Number' } Assert-MockCalled -CommandName Get-Partition -Exactly -Times 0 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 0 Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 0 @@ -2026,8 +2221,8 @@ try # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0.UniqueId -and $DiskIdType -eq 'UniqueId' } ` - -MockWith { $script:mockedDisk0Offline } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0Gpt.UniqueId -and $DiskIdType -eq 'UniqueId' } ` + -MockWith { $script:mockedDisk0GptOffline } ` -Verifiable # mocks that should not be called @@ -2040,7 +2235,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0Offline.UniqueId ` + -DiskId $script:mockedDisk0GptOffline.UniqueId ` -DiskIdType 'UniqueId' ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` @@ -2055,7 +2250,7 @@ try It 'Should call the correct mocks' { Assert-VerifiableMock Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.UniqueId -and $DiskIdType -eq 'UniqueId' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.UniqueId -and $DiskIdType -eq 'UniqueId' } Assert-MockCalled -CommandName Get-Partition -Exactly -Times 0 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 0 Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 0 @@ -2066,8 +2261,8 @@ try # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0.Guid -and $DiskIdType -eq 'Guid' } ` - -MockWith { $script:mockedDisk0Offline } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0Gpt.Guid -and $DiskIdType -eq 'Guid' } ` + -MockWith { $script:mockedDisk0GptOffline } ` -Verifiable # mocks that should not be called @@ -2080,7 +2275,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0Offline.Guid ` + -DiskId $script:mockedDisk0GptOffline.Guid ` -DiskIdType 'Guid' ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` @@ -2095,7 +2290,7 @@ try It 'Should call the correct mocks' { Assert-VerifiableMock Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Offline.Guid -and $DiskIdType -eq 'Guid' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptOffline.Guid -and $DiskIdType -eq 'Guid' } Assert-MockCalled -CommandName Get-Partition -Exactly -Times 0 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 0 Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 0 @@ -2106,8 +2301,8 @@ try # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Readonly.Number -and $DiskIdType -eq 'Number' } ` - -MockWith { $script:mockedDisk0Readonly } ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptReadonly.Number -and $DiskIdType -eq 'Number' } ` + -MockWith { $script:mockedDisk0GptReadonly } ` -Verifiable # mocks that should not be called @@ -2120,7 +2315,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0Readonly.Number ` + -DiskId $script:mockedDisk0GptReadonly.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` -Verbose @@ -2134,7 +2329,7 @@ try It 'Should call the correct mocks' { Assert-VerifiableMock Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` - -ParameterFilter { $DiskId -eq $script:mockedDisk0Readonly.Number -and $DiskIdType -eq 'Number' } + -ParameterFilter { $DiskId -eq $script:mockedDisk0GptReadonly.Number -and $DiskIdType -eq 'Number' } Assert-MockCalled -CommandName Get-Partition -Exactly -Times 0 Assert-MockCalled -CommandName Get-Volume -Exactly -Times 0 Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 0 @@ -2180,12 +2375,129 @@ try } } + Context 'When testing online disk using Disk Number with partition style GPT but requiring MBR' { + # verifiable (should be called) mocks + Mock ` + -CommandName Get-DiskByIdentifier ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number ` + -MockWith { $script:mockedDisk0Mbr } ` + -Verifiable + + # mocks that should not be called + Mock -CommandName Get-Volume + Mock -CommandName Get-Partition + Mock -CommandName Get-CimInstance + + $errorRecord = Get-InvalidOperationRecord ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` + 'Number', $script:mockedDisk0Mbr.Number, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') + + It 'Should throw DiskInitializedWithWrongPartitionStyleError' { + { + Test-TargetResource ` + -DiskId $script:mockedDisk0Mbr.Number ` + -DriveLetter $script:testDriveLetter ` + -AllocationUnitSize 4096 ` + -Verbose + } | Should -Throw $errorRecord + } + + It 'Should call the correct mocks' { + Assert-VerifiableMock + Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 0 + Assert-MockCalled -CommandName Get-Volume -Exactly -Times 0 + Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 0 + } + } + + Context 'When testing online disk using Disk Number with partition style MBR but requiring GPT' { + # verifiable (should be called) mocks + Mock ` + -CommandName Get-DiskByIdentifier ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number ` + -MockWith { $script:mockedDisk0Gpt } ` + -Verifiable + + # mocks that should not be called + Mock -CommandName Get-Volume + Mock -CommandName Get-Partition + Mock -CommandName Get-CimInstance + + $errorRecord = Get-InvalidOperationRecord ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` + 'Number', $script:mockedDisk0Gpt.Number, $script:mockedDisk0Gpt.PartitionStyle, 'MBR') + + It 'Should throw DiskInitializedWithWrongPartitionStyleError' { + { + Test-TargetResource ` + -DiskId $script:mockedDisk0Gpt.Number ` + -DriveLetter $script:testDriveLetter ` + -AllocationUnitSize 4096 ` + -PartitionStyle 'MBR' ` + -Verbose + } | Should -Throw $errorRecord + } + + It 'Should call the correct mocks' { + Assert-VerifiableMock + Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 0 + Assert-MockCalled -CommandName Get-Volume -Exactly -Times 0 + Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 0 + } + } + + Context 'When testing online disk using Disk Number with partition style MBR but requiring GPT and AllowDestructive and ClearDisk is True' { + # verifiable (should be called) mocks + Mock ` + -CommandName Get-DiskByIdentifier ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number ` + -MockWith { $script:mockedDisk0Gpt } ` + -Verifiable + + # mocks that should not be called + Mock -CommandName Get-Volume + Mock -CommandName Get-Partition + Mock -CommandName Get-CimInstance + + $script:result = $null + + It 'Should not throw an exception' { + { + $script:result = Test-TargetResource ` + -DiskId $script:mockedDisk0Gpt.Number ` + -DriveLetter $script:testDriveLetter ` + -AllocationUnitSize 4096 ` + -PartitionStyle 'MBR' ` + -AllowDestructive $true ` + -ClearDisk $true ` + -Verbose + } | Should -Not -Throw + } + + It 'Should be false' { + $script:result | Should -Be $false + } + + It 'Should call the correct mocks' { + Assert-VerifiableMock + Assert-MockCalled -CommandName Get-DiskByIdentifier -Exactly -Times 1 ` + -ParameterFilter $script:parameterFilter_MockedDisk0Number + Assert-MockCalled -CommandName Get-Partition -Exactly -Times 0 + Assert-MockCalled -CommandName Get-Volume -Exactly -Times 0 + Assert-MockCalled -CommandName Get-CimInstance -Exactly -Times 0 + } + } + Context 'When testing mismatching partition size using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2208,7 +2520,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` -Size ($script:mockedPartitionSize + 1MB) ` @@ -2235,7 +2547,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2253,7 +2565,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` -Size ($script:mockedPartitionSize + 1MB) ` @@ -2282,7 +2594,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2315,7 +2627,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` -Verbose @@ -2342,7 +2654,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2369,7 +2681,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` -AllowDestructive $true ` @@ -2396,7 +2708,7 @@ try # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2417,7 +2729,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4097 ` -AllowDestructive $true ` @@ -2443,7 +2755,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2466,7 +2778,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -FSFormat 'ReFS' ` -Verbose @@ -2492,7 +2804,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2515,7 +2827,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -FSFormat 'ReFS' ` -AllowDestructive $true ` @@ -2542,7 +2854,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2565,7 +2877,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -FSLabel 'NewLabel' ` -Verbose @@ -2591,7 +2903,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2612,7 +2924,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter 'Z' ` -Verbose } | Should -Not -Throw @@ -2637,7 +2949,7 @@ try Mock ` -CommandName Get-DiskByIdentifier ` -ParameterFilter $script:parameterFilter_MockedDisk0Number ` - -MockWith { $script:mockedDisk0 } ` + -MockWith { $script:mockedDisk0Gpt } ` -Verifiable Mock ` @@ -2660,7 +2972,7 @@ try It 'Should not throw an exception' { { $script:result = Test-TargetResource ` - -DiskId $script:mockedDisk0.Number ` + -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` -Size $script:mockedPartition.Size ` From ef92e0c6f89f7561645a8f4fa0f53ef3a300bb99 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 8 Sep 2018 20:02:59 +1200 Subject: [PATCH 02/18] Minor test corrections --- .../DSCResources/MSFT_Disk/MSFT_Disk.psm1 | 22 +++++--- .../MSFT_Disk/MSFT_Disk.schema.mof | 2 +- .../MSFT_Disk.Integration.Tests.ps1 | 52 +++++++++---------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 index b7e8ccb3..bb1512be 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 @@ -35,24 +35,32 @@ $localizedData = Get-LocalizedData ` .PARAMETER PartitionStyle Specifies the partition style of the disk. Defaults to GPT. + This value of this parameter is ignored. .PARAMETER Size Specifies the size of new volume (use all available space on disk if not provided). + This value of this parameter is ignored. .PARAMETER FSLabel Specifies the volume label to assign to the volume. + This value of this parameter is ignored. .PARAMETER AllocationUnitSize Specifies the allocation unit size to use when formatting the volume. + This value of this parameter is ignored. .PARAMETER FSFormat Specifies the file system format of the new volume. + This value of this parameter is ignored. .PARAMETER AllowDestructive - Specifies if potentially destructive operations may occur + Specifies if potentially destructive operations may occur. + This value of this parameter is ignored. .PARAMETER ClearDisk - Specifies if the disks partition schema should be removed entirely, even if data and oem partitions are present. Only possible with AllowDestructive enabled. + Specifies if the disks partition schema should be removed entirely, even if data and OEM + partitions are present. Only possible with AllowDestructive enabled. + This value of this parameter is ignored. #> function Get-TargetResource { @@ -173,10 +181,11 @@ function Get-TargetResource Specifies the file system format of the new volume. .PARAMETER AllowDestructive - Specifies if potentially destructive operations may occur + Specifies if potentially destructive operations may occur. .PARAMETER ClearDisk - Specifies if the disks partition schema should be removed entirely, even if data and oem partitions are present. Only possible with AllowDestructive enabled. + Specifies if the disks partition schema should be removed entirely, even if data and OEM + partitions are present. Only possible with AllowDestructive enabled. #> function Set-TargetResource { @@ -661,10 +670,11 @@ function Set-TargetResource Specifies the file system format of the new volume. .PARAMETER AllowDestructive - Specifies if potentially destructive operations may occur + Specifies if potentially destructive operations may occur. .PARAMETER ClearDisk - Specifies if the disks partition schema should be removed entirely, even if data and oem partitions are present. Only possible with AllowDestructive enabled. + Specifies if the disks partition schema should be removed entirely, even if data and OEM + partitions are present. Only possible with AllowDestructive enabled. #> function Test-TargetResource { diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof index df0d9939..f91078fd 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof @@ -11,5 +11,5 @@ class MSFT_Disk : OMI_BaseResource [Write, Description("Specifies the allocation unit size to use when formatting the volume.")] Uint32 AllocationUnitSize; [Write, Description("Specifies the file system format of the new volume."), ValueMap{"NTFS","ReFS"}, Values{"NTFS","ReFS"}] String FSFormat; [Write, Description("Specifies if potentially destructive operations may occur.")] Boolean AllowDestructive; - [Write, Description("Specifies if the disks partition schema should be removed entirely, even if data and oem partitions are present. Only possible with AllowDestructive enabled.")] Boolean ClearDisk; + [Write, Description("Specifies if the disks partition schema should be removed entirely, even if data and OEM partitions are present. Only possible with AllowDestructive enabled.")] Boolean ClearDisk; }; diff --git a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 index c521aede..541654c3 100644 --- a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 @@ -78,11 +78,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number @@ -125,11 +125,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number @@ -214,11 +214,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number @@ -262,11 +262,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigAllowDestructive" } $current.DiskId | Should -Be $disk.Number @@ -347,11 +347,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number @@ -397,11 +397,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigClearDisk" } $current.DiskId | Should -Be $disk.Number @@ -487,11 +487,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.UniqueId @@ -536,11 +536,11 @@ try } It 'should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigClearDisk" } $current.DiskId | Should -Be $disk.UniqueId @@ -584,11 +584,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.UniqueId @@ -671,11 +671,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Guid @@ -718,11 +718,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Guid @@ -802,11 +802,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number @@ -854,11 +854,11 @@ try } It 'Should be able to call Get-DscConfiguration without throwing' { - { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw + { $script:currentConfiguration = Get-DscConfiguration -Verbose -ErrorAction Stop } | Should -Not -Throw } It 'Should have set the resource and all the parameters should match' { - $current = Get-DscConfiguration | Where-Object -FilterScript { + $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } $current.DiskId | Should -Be $disk.Number From 4a1d9d1d95c604b6cc6b0bf8527a7aa368ba402f Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 9 Sep 2018 19:28:49 +1200 Subject: [PATCH 03/18] Renamed PartitionStyle to PartitionFormat --- .../DSCResources/MSFT_Disk/MSFT_Disk.psm1 | 55 ++-- .../MSFT_Disk/MSFT_Disk.schema.mof | 2 +- .../DSCResources/MSFT_Disk/README.md | 2 +- .../MSFT_Disk/en-us/MSFT_Disk.strings.psd1 | 6 +- .../StorageDsc.Common/StorageDsc.Common.psm1 | 3 +- .../MSFT_Disk.Integration.Tests.ps1 | 284 +++++++++--------- Tests/Integration/MSFT_Disk.config.ps1 | 30 +- Tests/Unit/MSFT_Disk.Tests.ps1 | 85 +++--- 8 files changed, 231 insertions(+), 236 deletions(-) diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 index bb1512be..40e5d071 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 @@ -33,8 +33,8 @@ $localizedData = Get-LocalizedData ` .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. - .PARAMETER PartitionStyle - Specifies the partition style of the disk. Defaults to GPT. + .PARAMETER PartitionFormat + Specifies the partition format of the disk. Defaults to GPT. This value of this parameter is ignored. .PARAMETER Size @@ -84,7 +84,7 @@ function Get-TargetResource [Parameter()] [ValidateSet('GPT', 'MBR')] [System.String] - $PartitionStyle = 'GPT', + $PartitionFormat = 'GPT', [Parameter()] [System.UInt64] @@ -133,9 +133,6 @@ function Get-TargetResource -DriveLetter $DriveLetter ` -ErrorAction SilentlyContinue - $fileSystem = $volume.FileSystem - $FSLabel = $volume.FileSystemLabel - $blockSize = (Get-CimInstance ` -Query "SELECT BlockSize from Win32_Volume WHERE DriveLetter = '$($DriveLetter):'" ` -ErrorAction SilentlyContinue).BlockSize @@ -144,11 +141,11 @@ function Get-TargetResource DiskId = $DiskId DiskIdType = $DiskIdType DriveLetter = $partition.DriveLetter - PartitionStyle = $disk.PartitionStyle + PartitionFormat = $disk.PartitionStyle Size = $partition.Size - FSLabel = $FSLabel + FSLabel = $volume.FileSystemLabel AllocationUnitSize = $blockSize - FSFormat = $fileSystem + FSFormat = $volume.FileSystem } } # Get-TargetResource @@ -165,8 +162,8 @@ function Get-TargetResource .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. - .PARAMETER PartitionStyle - Specifies the partition style of the disk. Defaults to GPT. + .PARAMETER PartitionFormat + Specifies the partition format of the disk. Defaults to GPT. .PARAMETER Size Specifies the size of new volume. Leave empty to use the remaining free space. @@ -210,7 +207,7 @@ function Set-TargetResource [Parameter()] [ValidateSet('GPT', 'MBR')] [System.String] - $PartitionStyle = 'GPT', + $PartitionFormat = 'GPT', [Parameter()] [System.UInt64] @@ -275,7 +272,7 @@ function Set-TargetResource Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.CheckingDiskPartitionStyleMessage -f $DiskIdType, $DiskId) + $($localizedData.CheckingDiskPartitionFormatMessage -f $DiskIdType, $DiskId) ) -join '' ) if ($AllowDestructive -and $ClearDisk -and $disk.PartitionStyle -ne 'RAW') @@ -297,16 +294,16 @@ function Set-TargetResource { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.InitializingDiskMessage -f $DiskIdType, $DiskId, $PartitionStyle) + $($localizedData.InitializingDiskMessage -f $DiskIdType, $DiskId, $PartitionFormat) ) -join '' ) - $disk | Initialize-Disk -PartitionStyle $PartitionStyle + $disk | Initialize-Disk -PartitionStyle $PartitionFormat } else { - if ($disk.PartitionStyle -eq $PartitionStyle) + if ($disk.PartitionStyle -eq $PartitionFormat) { - # The disk partition is already initialized with the correct partition style + # The disk partition is already initialized with the correct partition format Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.DiskAlreadyInitializedMessage ` @@ -316,10 +313,10 @@ function Set-TargetResource } else { - # This disk is initialized but with the incorrect partition style + # This disk is initialized but with the incorrect partition format New-InvalidOperationException ` - -Message ($localizedData.DiskInitializedWithWrongPartitionStyleError ` - -f $DiskIdType, $DiskId, $Disk.PartitionStyle, $PartitionStyle) + -Message ($localizedData.DiskInitializedWithWrongPartitionFormatError ` + -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionFormat) } } @@ -654,8 +651,8 @@ function Set-TargetResource .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. - .PARAMETER PartitionStyle - Specifies the partition style of the disk. Defaults to GPT. + .PARAMETER PartitionFormat + Specifies the partition format of the disk. Defaults to GPT. .PARAMETER Size Specifies the size of new volume. Leave empty to use the remaining free space. @@ -698,7 +695,7 @@ function Test-TargetResource [Parameter()] [ValidateSet('GPT', 'MBR')] [System.String] - $PartitionStyle = 'GPT', + $PartitionFormat = 'GPT', [Parameter()] [System.UInt64] @@ -775,12 +772,12 @@ function Test-TargetResource return $false } # if - if ($disk.PartitionStyle -ne $PartitionStyle) + if ($disk.PartitionStyle -ne $PartitionFormat) { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.DiskPartitionNotMatchMessage ` - -f $DiskIdType, $DiskId, $Disk.PartitionStyle, $PartitionStyle) + $($localizedData.DiskPartitionFormatNotMatchMessage ` + -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionFormat) ) -join '' ) if ($disk.PartitionStyle -eq 'RAW' -or ($AllowDestructive -and $ClearDisk)) @@ -789,10 +786,10 @@ function Test-TargetResource } else { - # This disk is initialized but with the incorrect partition style + # This disk is initialized but with the incorrect partition format New-InvalidOperationException ` - -Message ($localizedData.DiskInitializedWithWrongPartitionStyleError ` - -f $DiskIdType, $DiskId, $Disk.PartitionStyle, $PartitionStyle) + -Message ($localizedData.DiskInitializedWithWrongPartitionFormatError ` + -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionFormat) } } # if diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof index f91078fd..c97690eb 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof @@ -5,7 +5,7 @@ class MSFT_Disk : OMI_BaseResource [Key, Description("Specifies the identifier for which disk to modify.")] String DriveLetter; [Required, Description("Specifies the disk identifier for the disk to modify.")] String DiskId; [Write, Description("Specifies the identifier type the DiskId contains. Defaults to Number."), ValueMap{"Number","UniqueId","Guid"}, Values{"Number","UniqueId","Guid"}] String DiskIdType; - [Write, Description("Specifies the partition style of the disk. Defaults to GPT."), ValueMap{"MBR","GPT"}, Values{"MBR","GPT"}] String PartitionStyle; + [Write, Description("Specifies the partition format of the disk. Defaults to GPT."), ValueMap{"MBR","GPT"}, Values{"MBR","GPT"}] String PartitionFormat; [Write, Description("Specifies the size of new volume. Leave empty to use the remaining free space.")] Uint64 Size; [Write, Description("Define volume label if required.")] String FSLabel; [Write, Description("Specifies the allocation unit size to use when formatting the volume.")] Uint32 AllocationUnitSize; diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md b/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md index e4ea8dbd..ad1a4174 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md @@ -22,4 +22,4 @@ has been created (e.g. the disk has been initialized). Therefore to use this met of disk selection the disk must have been initialized by some other method. The _Guid_ identifier method of specifying disks is only supported as an identifier -for disks formatted with `GPT` partition table style. +for disks with `GPT` partition table format. diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 b/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 index 6c8e82c0..d18b4974 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 +++ b/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 @@ -3,7 +3,7 @@ SettingDiskMessage = Setting disk with {0} '{1}' status for drive letter '{2}'. SetDiskOnlineMessage = Setting disk with {0} '{1}' online. SetDiskReadWriteMessage = Setting disk with {0} '{1}' to read/write. - CheckingDiskPartitionStyleMessage = Checking disk with {0} '{1}' partition style. + CheckingDiskPartitionFormatMessage = Checking disk with {0} '{1}' partition format. InitializingDiskMessage = Initializing disk with {0} '{1}' as '{2}'. DiskAlreadyInitializedMessage = Disk with {0} '{1}' is already initialized with '{2}'. CreatingPartitionMessage = Creating partition on disk with {0} '{1}' with drive letter '{2}' using {3}. @@ -18,8 +18,8 @@ DiskNotFoundMessage = Disk with {0} '{1}' was not found. DiskNotOnlineMessage = Disk with {0} '{1}' is not online. DiskReadOnlyMessage = Disk with {0} '{1}' is readonly. - DiskPartitionNotMatchMessage = Disk with {0} '{1}' is initialized with '{2}' partition style but '{3}' required. - DiskInitializedWithWrongPartitionStyleError = Disk with {0} '{1}' is already initialized with '{2}' but should be '{3}'. Set AllowDestructive and ClearDisk to 'True' to allow disk to be reinitialized. + DiskPartitionFormatNotMatchMessage = Disk with {0} '{1}' is initialized with partition format '{2}' but '{3}' required. + DiskInitializedWithWrongPartitionFormatError = Disk with {0} '{1}' is already initialized with partition format '{2}' but '{3}' required. Set AllowDestructive and ClearDisk to 'True' to allow disk to be reinitialized. DriveLetterNotFoundMessage = Drive {0} was not found. SizeMismatchMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. Set AllowDestructive to 'True' to enable resizing of partition. SizeMismatchWithAllowDestructiveMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. diff --git a/Modules/StorageDsc/Modules/StorageDsc.Common/StorageDsc.Common.psm1 b/Modules/StorageDsc/Modules/StorageDsc.Common/StorageDsc.Common.psm1 index bf77ee7b..5a8853fb 100644 --- a/Modules/StorageDsc/Modules/StorageDsc.Common/StorageDsc.Common.psm1 +++ b/Modules/StorageDsc/Modules/StorageDsc.Common/StorageDsc.Common.psm1 @@ -139,8 +139,7 @@ function Get-DiskByIdentifier if ($DiskIdType -eq 'Guid') { # The Disk Id requested uses a Guid so have to get all disks and filter - $disk = Get-Disk ` - -ErrorAction SilentlyContinue | + $disk = Get-Disk -ErrorAction SilentlyContinue | Where-Object -Property Guid -EQ $DiskId } else diff --git a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 index 541654c3..9cebf7cd 100644 --- a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 @@ -52,13 +52,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionStyle = 'GPT' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -85,11 +85,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionStyle | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.Size | Should -Be 100MB + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionFormat | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.Size | Should -Be 100MB } } @@ -100,12 +100,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionStyle = 'GPT' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionFormat = 'GPT' + FSLabel = $FSLabelB } ) } @@ -132,11 +132,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterB - $current.FSLabel | Should -Be $FSLabelB - $current.PartitionStyle | Should -Be 'GPT' - $current.Size | Should -Be 935198720 + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterB + $current.FSLabel | Should -Be $FSLabelB + $current.PartitionFormat | Should -Be 'GPT' + $current.Size | Should -Be 935198720 } } @@ -188,13 +188,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionStyle = 'GPT' - FSLabel = $FSLabelA - Size = 50MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA + Size = 50MB } ) } @@ -221,12 +221,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionStyle | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 50MB + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionFormat | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 50MB } } @@ -321,13 +321,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionStyle = 'MBR' - FSLabel = $FSLabelA - Size = 50MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionFormat = 'MBR' + FSLabel = $FSLabelA + Size = 50MB } ) } @@ -354,12 +354,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionStyle | Should -Be 'MBR' - $current.FSLabel | Should -Be $FSLabelA - $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 50MB + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionFormat | Should -Be 'MBR' + $current.FSLabel | Should -Be $FSLabelA + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 50MB } } @@ -370,13 +370,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionStyle = 'GPT' - FSLabel = $FSLabelA - Size = 50MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA + Size = 50MB } ) @@ -404,12 +404,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigClearDisk" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA - $current.PartitionStyle | Should -Be 'GPT' - $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 1040104960 + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA + $current.PartitionFormat | Should -Be 'GPT' + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 1040104960 } } @@ -461,13 +461,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - PartitionStyle = 'GPT' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -494,11 +494,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.UniqueId - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionStyle | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.Size | Should -Be 100MB + $current.DiskId | Should -Be $disk.UniqueId + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionFormat | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.Size | Should -Be 100MB } } @@ -509,14 +509,14 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - PartitionStyle = 'GPT' - FSLabel = $FSLabelA - Size = 900MB - FSFormat = 'ReFS' + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA + Size = 900MB + FSFormat = 'ReFS' } ) } @@ -543,12 +543,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigClearDisk" } - $current.DiskId | Should -Be $disk.UniqueId - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionStyle | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.Size | Should -Be 900MB - $current.FSFormat | Should -Be 'ReFS' + $current.DiskId | Should -Be $disk.UniqueId + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionFormat | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.Size | Should -Be 900MB + $current.FSFormat | Should -Be 'ReFS' } } @@ -559,12 +559,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - PartitionStyle = 'GPT' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionFormat = 'GPT' + FSLabel = $FSLabelB } ) } @@ -591,11 +591,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.UniqueId - $current.PartitionStyle | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterB - $current.FSLabel | Should -Be $FSLabelB - $current.Size | Should -Be 96337920 + $current.DiskId | Should -Be $disk.UniqueId + $current.PartitionFormat | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterB + $current.FSLabel | Should -Be $FSLabelB + $current.Size | Should -Be 96337920 } } @@ -645,13 +645,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Guid - DiskIdType = 'Guid' - PartitionStyle = 'GPT' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Guid + DiskIdType = 'Guid' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -678,11 +678,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Guid - $current.PartitionStyle | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA - $current.Size | Should -Be 100MB + $current.DiskId | Should -Be $disk.Guid + $current.PartitionFormat | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA + $current.Size | Should -Be 100MB } } @@ -693,12 +693,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.Guid - DiskIdType = 'Guid' - PartitionStyle = 'GPT' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.Guid + DiskIdType = 'Guid' + PartitionFormat = 'GPT' + FSLabel = $FSLabelB } ) } @@ -725,11 +725,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Guid - $current.PartitionStyle | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterB - $current.FSLabel | Should -Be $FSLabelB - $current.Size | Should -Be 935198720 + $current.DiskId | Should -Be $disk.Guid + $current.PartitionFormat | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterB + $current.FSLabel | Should -Be $FSLabelB + $current.Size | Should -Be 935198720 } } @@ -777,12 +777,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionStyle = 'GPT' - FSLabel = $FSLabelA + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA } ) } @@ -809,10 +809,10 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.PartitionStyle | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA + $current.DiskId | Should -Be $disk.Number + $current.PartitionFormat | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA } } @@ -829,12 +829,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionStyle = 'GPT' - FSLabel = $FSLabelA + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA } ) } @@ -861,10 +861,10 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.PartitionStyle | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA + $current.DiskId | Should -Be $disk.Number + $current.PartitionFormat | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA } } diff --git a/Tests/Integration/MSFT_Disk.config.ps1 b/Tests/Integration/MSFT_Disk.config.ps1 index 3ee7ed58..b652c795 100644 --- a/Tests/Integration/MSFT_Disk.config.ps1 +++ b/Tests/Integration/MSFT_Disk.config.ps1 @@ -7,23 +7,23 @@ configuration MSFT_Disk_Config { { Disk Integration_Test { - DiskId = $Node.DiskId - DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle - DriveLetter = $Node.DriveLetter - FSLabel = $Node.FSLabel - Size = $Node.Size + DiskId = $Node.DiskId + DiskIdType = $Node.DiskIdType + PartitionFormat = $Node.PartitionFormat + DriveLetter = $Node.DriveLetter + FSLabel = $Node.FSLabel + Size = $Node.Size } } else { Disk Integration_Test { - DiskId = $Node.DiskId - DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle - DriveLetter = $Node.DriveLetter - FSLabel = $Node.FSLabel + DiskId = $Node.DiskId + DiskIdType = $Node.DiskIdType + PartitionFormat = $Node.PartitionFormat + DriveLetter = $Node.DriveLetter + FSLabel = $Node.FSLabel } } } @@ -40,7 +40,7 @@ configuration MSFT_Disk_ConfigAllowDestructive { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionFormat = $Node.PartitionFormat DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -54,7 +54,7 @@ configuration MSFT_Disk_ConfigAllowDestructive { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionFormat = $Node.PartitionFormat DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel FSFormat = $Node.FSFormat @@ -75,7 +75,7 @@ configuration MSFT_Disk_ConfigClearDisk { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionFormat = $Node.PartitionFormat DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -90,7 +90,7 @@ configuration MSFT_Disk_ConfigClearDisk { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionFormat = $Node.PartitionFormat DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel FSFormat = $Node.FSFormat diff --git a/Tests/Unit/MSFT_Disk.Tests.ps1 b/Tests/Unit/MSFT_Disk.Tests.ps1 index 4a265c75..1d21e28b 100644 --- a/Tests/Unit/MSFT_Disk.Tests.ps1 +++ b/Tests/Unit/MSFT_Disk.Tests.ps1 @@ -31,7 +31,6 @@ try $script:testDriveLetter = 'G' $script:testDiskNumber = 1 $script:testDiskUniqueId = 'TESTDISKUNIQUEID' - $script:testDiskParitionStyle = 'GPT' $script:testDiskGptGuid = [guid]::NewGuid() $script:mockedDisk0Gpt = [pscustomobject] @{ @@ -341,8 +340,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Number } - It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -408,8 +407,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.UniqueId } - It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -475,8 +474,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Guid } - It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -542,8 +541,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Guid } - It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -605,28 +604,28 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Number } - It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return an empty drive letter" { - $resource.DriveLetter | Should -Be $null + $resource.DriveLetter | Should -BeNullOrEmpty } It "Should return a zero size" { - $resource.Size | Should -Be $null + $resource.Size | Should -BeNullOrEmpty } It "Should return no FSLabel" { - $resource.FSLabel | Should -Be '' + $resource.FSLabel | Should -BeNullOrEmpty } It "Should return an AllocationUnitSize of 0" { - $resource.AllocationUnitSize | Should -Be $null + $resource.AllocationUnitSize | Should -BeNullOrEmpty } It "Should return no FSFormat" { - $resource.FSFormat | Should -Be $null + $resource.FSFormat | Should -BeNullOrEmpty } It 'Should call the correct mocks' { @@ -668,28 +667,28 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Mbr.Number } - It "Should return PartitionStyle $($script:mockedDisk0Mbr.PartitionStyle)" { - $resource.PartitionStyle | Should -Be $script:mockedDisk0Mbr.PartitionStyle + It "Should return PartitionFormat $($script:mockedDisk0Mbr.PartitionStyle)" { + $resource.PartitionFormat | Should -Be $script:mockedDisk0Mbr.PartitionStyle } It "Should return an empty drive letter" { - $resource.DriveLetter | Should -Be $null + $resource.DriveLetter | Should -BeNullOrEmpty } It "Should return a zero size" { - $resource.Size | Should -Be $null + $resource.Size | Should -BeNullOrEmpty } It "Should return no FSLabel" { - $resource.FSLabel | Should -Be '' + $resource.FSLabel | Should -BeNullOrEmpty } It "Should return an AllocationUnitSize of 0" { - $resource.AllocationUnitSize | Should -Be $null + $resource.AllocationUnitSize | Should -BeNullOrEmpty } It "Should return no FSFormat" { - $resource.FSFormat | Should -Be $null + $resource.FSFormat | Should -BeNullOrEmpty } It 'Should call the correct mocks' { @@ -731,28 +730,28 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Raw.Number } - It "Should return PartitionStyle $($script:mockedDisk0Raw.PartitionStyle)" { - $resource.PartitionStyle | Should -Be $script:mockedDisk0Raw.PartitionStyle + It "Should return PartitionFormat $($script:mockedDisk0Raw.PartitionStyle)" { + $resource.PartitionFormat | Should -Be $script:mockedDisk0Raw.PartitionStyle } It "Should return an empty drive letter" { - $resource.DriveLetter | Should -Be $null + $resource.DriveLetter | Should -BeNullOrEmpty } It "Should return a zero size" { - $resource.Size | Should -Be $null + $resource.Size | Should -BeNullOrEmpty } It "Should return no FSLabel" { - $resource.FSLabel | Should -Be '' + $resource.FSLabel | Should -BeNullOrEmpty } It "Should return an AllocationUnitSize of 0" { - $resource.AllocationUnitSize | Should -Be $null + $resource.AllocationUnitSize | Should -BeNullOrEmpty } It "Should return no FSFormat" { - $resource.FSFormat | Should -Be $null + $resource.FSFormat | Should -BeNullOrEmpty } It 'Should call the correct mocks' { @@ -1316,10 +1315,10 @@ try Mock -CommandName Set-Partition $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionFormatError -f ` 'Number', $script:mockedDisk0Mbr.Number, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') - It 'Should not throw DiskInitializedWithWrongPartitionStyleError' { + It 'Should not throw DiskInitializedWithWrongPartitionFormatError' { { Set-TargetResource ` -DiskId $script:mockedDisk0Mbr.Number ` @@ -1359,10 +1358,10 @@ try Mock -CommandName Set-Partition $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionFormatError -f ` 'UniqueId', $script:mockedDisk0Mbr.UniqueId, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') - It 'Should throw DiskInitializedWithWrongPartitionStyleError' { + It 'Should throw DiskInitializedWithWrongPartitionFormatError' { { Set-TargetResource ` -DiskId $script:mockedDisk0Mbr.UniqueId ` @@ -2375,7 +2374,7 @@ try } } - Context 'When testing online disk using Disk Number with partition style GPT but requiring MBR' { + Context 'When testing online disk using Disk Number with partition format GPT but requiring MBR' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -2389,10 +2388,10 @@ try Mock -CommandName Get-CimInstance $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionFormatError -f ` 'Number', $script:mockedDisk0Mbr.Number, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') - It 'Should throw DiskInitializedWithWrongPartitionStyleError' { + It 'Should throw DiskInitializedWithWrongPartitionFormatError' { { Test-TargetResource ` -DiskId $script:mockedDisk0Mbr.Number ` @@ -2412,7 +2411,7 @@ try } } - Context 'When testing online disk using Disk Number with partition style MBR but requiring GPT' { + Context 'When testing online disk using Disk Number with partition format MBR but requiring GPT' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -2426,16 +2425,16 @@ try Mock -CommandName Get-CimInstance $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionFormatError -f ` 'Number', $script:mockedDisk0Gpt.Number, $script:mockedDisk0Gpt.PartitionStyle, 'MBR') - It 'Should throw DiskInitializedWithWrongPartitionStyleError' { + It 'Should throw DiskInitializedWithWrongPartitionFormatError' { { Test-TargetResource ` -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` - -PartitionStyle 'MBR' ` + -PartitionFormat 'MBR' ` -Verbose } | Should -Throw $errorRecord } @@ -2450,7 +2449,7 @@ try } } - Context 'When testing online disk using Disk Number with partition style MBR but requiring GPT and AllowDestructive and ClearDisk is True' { + Context 'When testing online disk using Disk Number with partition format MBR but requiring GPT and AllowDestructive and ClearDisk is True' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -2471,7 +2470,7 @@ try -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` - -PartitionStyle 'MBR' ` + -PartitionFormat 'MBR' ` -AllowDestructive $true ` -ClearDisk $true ` -Verbose From 624a9c1b790a6c6388d4f7cbb7dc7a89d12a8b8b Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 9 Sep 2018 19:37:32 +1200 Subject: [PATCH 04/18] Corrected Integration Tests for Disk --- .../MSFT_Disk.Integration.Tests.ps1 | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 index 9cebf7cd..3cace0f9 100644 --- a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 @@ -237,12 +237,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - FSLabel = $FSLabelA - FSFormat = 'NTFS' + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionFormat = 'GPT' + FSLabel = $FSLabelA + FSFormat = 'NTFS' } ) } @@ -269,11 +270,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigAllowDestructive" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA - $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 1040104960 + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionFormat | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 1040104960 } } @@ -376,8 +378,8 @@ try DiskIdType = 'Number' PartitionFormat = 'GPT' FSLabel = $FSLabelA + FSFormat = 'NTFS' Size = 50MB - } ) } From d2ace1dd997fd87f24c80ec1b76d7e15c5c65218 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 9 Sep 2018 19:45:58 +1200 Subject: [PATCH 05/18] Final correction to Disk Integration tests --- Tests/Integration/MSFT_Disk.Integration.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 index 3cace0f9..711cf4ca 100644 --- a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 @@ -230,7 +230,7 @@ try } } - Context "Resize partition on Disk Number $($disk.Number) with AllowDestructive" { + Context "Resize partition on Disk Number $($disk.Number) to use all free space with AllowDestructive" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -365,7 +365,7 @@ try } } - Context "Resize partition on Disk Number $($disk.Number) with AllowDestructive" { + Context "Resize partition on Disk Number $($disk.Number) to use 50MB with AllowDestructive" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -411,7 +411,7 @@ try $current.FSLabel | Should -Be $FSLabelA $current.PartitionFormat | Should -Be 'GPT' $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 1040104960 + $current.Size | Should -Be 52428800 } } From 540adca62077c11c2530de6f9cb2ff7cd261d4a9 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 9 Sep 2018 19:54:33 +1200 Subject: [PATCH 06/18] Opt-in to new Common Tests --- .MetaTestOptIn.json | 4 +++- CHANGELOG.md | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index 6f385f87..ac9383d4 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -6,5 +6,7 @@ "Common Tests - Required Script Analyzer Rules", "Common Tests - Flagged Script Analyzer Rules", "Common Tests - New Error-Level Script Analyzer Rules", - "Common Tests - Custom Script Analyzer Rules" + "Common Tests - Custom Script Analyzer Rules", + "Common Tests - Validate Example Files To Be Published", + "Common Tests - Validate Markdown Links" ] diff --git a/CHANGELOG.md b/CHANGELOG.md index fa9ecff7..6aeef92c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## Unreleased - Disk: - - Added `PartitionType` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). + - Added `PartitionFormat` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). +- Opt-in to Common Tests `Common Tests - Validate Example Files + To Be Published` and `Common Tests - Validate Markdown Links` ## 4.1.0.0 From 4e617331c4f722138a1403df0246f6801cccf1e8 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 9 Sep 2018 20:05:02 +1200 Subject: [PATCH 07/18] Added VSCode and PSSA settings --- .vscode/analyzersettings.psd1 | 53 +++++++++++++++++++++++++++++++++++ .vscode/settings.json | 3 +- CHANGELOG.md | 3 +- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 .vscode/analyzersettings.psd1 diff --git a/.vscode/analyzersettings.psd1 b/.vscode/analyzersettings.psd1 new file mode 100644 index 00000000..be415e4d --- /dev/null +++ b/.vscode/analyzersettings.psd1 @@ -0,0 +1,53 @@ +@{ + <# + For the custom rules to work, the DscResource.Tests repo must be + cloned. It is automatically clone as soon as any unit or + integration tests are run. + #> + CustomRulePath = '.\DSCResource.Tests\DscResource.AnalyzerRules' + + IncludeRules = @( + # DSC Resource Kit style guideline rules. + 'PSAvoidDefaultValueForMandatoryParameter', + 'PSAvoidDefaultValueSwitchParameter', + 'PSAvoidInvokingEmptyMembers', + 'PSAvoidNullOrEmptyHelpMessageAttribute', + 'PSAvoidUsingCmdletAliases', + 'PSAvoidUsingComputerNameHardcoded', + 'PSAvoidUsingDeprecatedManifestFields', + 'PSAvoidUsingEmptyCatchBlock', + 'PSAvoidUsingInvokeExpression', + 'PSAvoidUsingPositionalParameters', + 'PSAvoidShouldContinueWithoutForce', + 'PSAvoidUsingWMICmdlet', + 'PSAvoidUsingWriteHost', + 'PSDSCReturnCorrectTypesForDSCFunctions', + 'PSDSCStandardDSCFunctionsInResource', + 'PSDSCUseIdenticalMandatoryParametersForDSC', + 'PSDSCUseIdenticalParametersForDSC', + 'PSMisleadingBacktick', + 'PSMissingModuleManifestField', + 'PSPossibleIncorrectComparisonWithNull', + 'PSProvideCommentHelp', + 'PSReservedCmdletChar', + 'PSReservedParams', + 'PSUseApprovedVerbs', + 'PSUseCmdletCorrectly', + 'PSUseOutputTypeCorrectly', + 'PSAvoidGlobalVars', + 'PSAvoidUsingConvertToSecureStringWithPlainText', + 'PSAvoidUsingPlainTextForPassword', + 'PSAvoidUsingUsernameAndPasswordParams', + 'PSDSCUseVerboseMessageInDSCResource', + 'PSShouldProcess', + 'PSUseDeclaredVarsMoreThanAssignments', + 'PSUsePSCredentialType', + + <# + This is to test all the DSC Resource Kit custom rules. + The name of the function-blocks of each custom rule start + with 'Measure*'. + #> + 'Measure-*' + ) +} diff --git a/.vscode/settings.json b/.vscode/settings.json index cd3d82e8..43f01cf9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,5 +10,6 @@ "powershell.codeFormatting.ignoreOneLineBlock": false, "powershell.codeFormatting.preset": "Custom", "files.trimTrailingWhitespace": true, - "files.insertFinalNewline": true + "files.insertFinalNewline": true, + "powershell.scriptAnalysis.settingsPath": ".vscode\\analyzersettings.psd1" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aeef92c..bb2549c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ - Disk: - Added `PartitionFormat` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). - Opt-in to Common Tests `Common Tests - Validate Example Files - To Be Published` and `Common Tests - Validate Markdown Links` + To Be Published` and `Common Tests - Validate Markdown Links`. +- Added .VSCode settings for applying DSC PSSA rules - fixes [Issue #168](https://github.com/PowerShell/StorageDsc/issues/168). ## 4.1.0.0 From 15e25afa6e446075b7951a143e82ad1a7feb7b92 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 9 Sep 2018 20:19:22 +1200 Subject: [PATCH 08/18] Opt in to additional tests --- .MetaTestOptIn.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index ac9383d4..48ace66f 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -8,5 +8,7 @@ "Common Tests - New Error-Level Script Analyzer Rules", "Common Tests - Custom Script Analyzer Rules", "Common Tests - Validate Example Files To Be Published", - "Common Tests - Validate Markdown Links" + "Common Tests - Validate Markdown Links", + "Common Tests - Spellcheck Markdown Files", + "Common Tests - Relative Path Length" ] From cd172e4b57ed2ce0696f48babaf5f55022e9eb6f Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sun, 9 Sep 2018 20:27:43 +1200 Subject: [PATCH 09/18] Remove Opt-in to Spellcheck till harness removed --- .MetaTestOptIn.json | 1 - CHANGELOG.md | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index 48ace66f..a5f60a34 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -9,6 +9,5 @@ "Common Tests - Custom Script Analyzer Rules", "Common Tests - Validate Example Files To Be Published", "Common Tests - Validate Markdown Links", - "Common Tests - Spellcheck Markdown Files", "Common Tests - Relative Path Length" ] diff --git a/CHANGELOG.md b/CHANGELOG.md index bb2549c4..03934fa0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,10 @@ - Disk: - Added `PartitionFormat` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). -- Opt-in to Common Tests `Common Tests - Validate Example Files - To Be Published` and `Common Tests - Validate Markdown Links`. +- Opt-in to Common Tests: + - Common Tests - Validate Example Files To Be Published + - Common Tests - Validate Markdown Links + - Common Tests - Relative Path Length - Added .VSCode settings for applying DSC PSSA rules - fixes [Issue #168](https://github.com/PowerShell/StorageDsc/issues/168). ## 4.1.0.0 From b7c1749482757fb02de714bfe958106e47a3650f Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Tue, 11 Sep 2018 09:58:01 +1200 Subject: [PATCH 10/18] Renamed MSFT_Disk to MSFTDSC_Disk --- CHANGELOG.md | 4 +- .../MSFTDSC_Disk.psm1} | 50 +-- .../MSFTDSC_Disk.schema.mof} | 4 +- .../{MSFT_Disk => MSFTDSC_Disk}/README.md | 0 .../en-us/MSFTDSC_Disk.strings.psd1} | 6 +- .../MSFT_DiskAccessPath.schema.mof | 2 +- .../MSFT_Disk.Integration.Tests.ps1 | 314 +++++++++--------- Tests/Integration/MSFT_Disk.config.ps1 | 18 +- .../MSFT_DiskAccessPath.config.ps1 | 2 +- Tests/Unit/MSFT_Disk.Tests.ps1 | 62 ++-- 10 files changed, 232 insertions(+), 230 deletions(-) rename Modules/StorageDsc/DSCResources/{MSFT_Disk/MSFT_Disk.psm1 => MSFTDSC_Disk/MSFTDSC_Disk.psm1} (96%) rename Modules/StorageDsc/DSCResources/{MSFT_Disk/MSFT_Disk.schema.mof => MSFTDSC_Disk/MSFTDSC_Disk.schema.mof} (86%) rename Modules/StorageDsc/DSCResources/{MSFT_Disk => MSFTDSC_Disk}/README.md (100%) rename Modules/StorageDsc/DSCResources/{MSFT_Disk/en-us/MSFT_Disk.strings.psd1 => MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1} (89%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03934fa0..27dcbe23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## Unreleased - Disk: - - Added `PartitionFormat` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). + - Added `PartitionStyle` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). + - Changed MOF name from `MSFT_Disk` to `MSFTDSC_Disk` to remove conflict + with Windows built-in CIM class. - Opt-in to Common Tests: - Common Tests - Validate Example Files To Be Published - Common Tests - Validate Markdown Links diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1 similarity index 96% rename from Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 rename to Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1 index 40e5d071..988af8f7 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.psm1 +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1 @@ -17,7 +17,7 @@ Import-Module -Name (Join-Path -Path $modulePath ` # Import Localization Strings $localizedData = Get-LocalizedData ` - -ResourceName 'MSFT_Disk' ` + -ResourceName 'MSFTDSC_Disk' ` -ResourcePath (Split-Path -Parent $Script:MyInvocation.MyCommand.Path) <# @@ -33,8 +33,8 @@ $localizedData = Get-LocalizedData ` .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. - .PARAMETER PartitionFormat - Specifies the partition format of the disk. Defaults to GPT. + .PARAMETER PartitionStyle + Specifies the partition style of the disk. Defaults to GPT. This value of this parameter is ignored. .PARAMETER Size @@ -84,7 +84,7 @@ function Get-TargetResource [Parameter()] [ValidateSet('GPT', 'MBR')] [System.String] - $PartitionFormat = 'GPT', + $PartitionStyle = 'GPT', [Parameter()] [System.UInt64] @@ -141,7 +141,7 @@ function Get-TargetResource DiskId = $DiskId DiskIdType = $DiskIdType DriveLetter = $partition.DriveLetter - PartitionFormat = $disk.PartitionStyle + PartitionStyle = $disk.PartitionStyle Size = $partition.Size FSLabel = $volume.FileSystemLabel AllocationUnitSize = $blockSize @@ -162,8 +162,8 @@ function Get-TargetResource .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. - .PARAMETER PartitionFormat - Specifies the partition format of the disk. Defaults to GPT. + .PARAMETER PartitionStyle + Specifies the partition style of the disk. Defaults to GPT. .PARAMETER Size Specifies the size of new volume. Leave empty to use the remaining free space. @@ -207,7 +207,7 @@ function Set-TargetResource [Parameter()] [ValidateSet('GPT', 'MBR')] [System.String] - $PartitionFormat = 'GPT', + $PartitionStyle = 'GPT', [Parameter()] [System.UInt64] @@ -272,7 +272,7 @@ function Set-TargetResource Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.CheckingDiskPartitionFormatMessage -f $DiskIdType, $DiskId) + $($localizedData.CheckingDiskPartitionStyleMessage -f $DiskIdType, $DiskId) ) -join '' ) if ($AllowDestructive -and $ClearDisk -and $disk.PartitionStyle -ne 'RAW') @@ -294,16 +294,16 @@ function Set-TargetResource { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.InitializingDiskMessage -f $DiskIdType, $DiskId, $PartitionFormat) + $($localizedData.InitializingDiskMessage -f $DiskIdType, $DiskId, $PartitionStyle) ) -join '' ) - $disk | Initialize-Disk -PartitionStyle $PartitionFormat + $disk | Initialize-Disk -PartitionStyle $PartitionStyle } else { - if ($disk.PartitionStyle -eq $PartitionFormat) + if ($disk.PartitionStyle -eq $PartitionStyle) { - # The disk partition is already initialized with the correct partition format + # The disk partition is already initialized with the correct partition style Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.DiskAlreadyInitializedMessage ` @@ -313,10 +313,10 @@ function Set-TargetResource } else { - # This disk is initialized but with the incorrect partition format + # This disk is initialized but with the incorrect partition style New-InvalidOperationException ` - -Message ($localizedData.DiskInitializedWithWrongPartitionFormatError ` - -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionFormat) + -Message ($localizedData.DiskInitializedWithWrongPartitionStyleError ` + -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionStyle) } } @@ -651,8 +651,8 @@ function Set-TargetResource .PARAMETER DiskIdType Specifies the identifier type the DiskId contains. Defaults to Number. - .PARAMETER PartitionFormat - Specifies the partition format of the disk. Defaults to GPT. + .PARAMETER PartitionStyle + Specifies the partition style of the disk. Defaults to GPT. .PARAMETER Size Specifies the size of new volume. Leave empty to use the remaining free space. @@ -695,7 +695,7 @@ function Test-TargetResource [Parameter()] [ValidateSet('GPT', 'MBR')] [System.String] - $PartitionFormat = 'GPT', + $PartitionStyle = 'GPT', [Parameter()] [System.UInt64] @@ -772,12 +772,12 @@ function Test-TargetResource return $false } # if - if ($disk.PartitionStyle -ne $PartitionFormat) + if ($disk.PartitionStyle -ne $PartitionStyle) { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.DiskPartitionFormatNotMatchMessage ` - -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionFormat) + $($localizedData.DiskPartitionStyleNotMatchMessage ` + -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionStyle) ) -join '' ) if ($disk.PartitionStyle -eq 'RAW' -or ($AllowDestructive -and $ClearDisk)) @@ -786,10 +786,10 @@ function Test-TargetResource } else { - # This disk is initialized but with the incorrect partition format + # This disk is initialized but with the incorrect partition style New-InvalidOperationException ` - -Message ($localizedData.DiskInitializedWithWrongPartitionFormatError ` - -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionFormat) + -Message ($localizedData.DiskInitializedWithWrongPartitionStyleError ` + -f $DiskIdType, $DiskId, $disk.PartitionStyle, $PartitionStyle) } } # if diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof similarity index 86% rename from Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof rename to Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof index c97690eb..9bd05e74 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/MSFT_Disk.schema.mof +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof @@ -1,11 +1,11 @@ [ClassVersion("1.0.0.0"), FriendlyName("Disk")] -class MSFT_Disk : OMI_BaseResource +class MSFTDSC_Disk : OMI_BaseResource { [Key, Description("Specifies the identifier for which disk to modify.")] String DriveLetter; [Required, Description("Specifies the disk identifier for the disk to modify.")] String DiskId; [Write, Description("Specifies the identifier type the DiskId contains. Defaults to Number."), ValueMap{"Number","UniqueId","Guid"}, Values{"Number","UniqueId","Guid"}] String DiskIdType; - [Write, Description("Specifies the partition format of the disk. Defaults to GPT."), ValueMap{"MBR","GPT"}, Values{"MBR","GPT"}] String PartitionFormat; + [Write, Description("Specifies the partition style of the disk. Defaults to GPT."), ValueMap{"MBR","GPT"}, Values{"MBR","GPT"}] String PartitionStyle; [Write, Description("Specifies the size of new volume. Leave empty to use the remaining free space.")] Uint64 Size; [Write, Description("Define volume label if required.")] String FSLabel; [Write, Description("Specifies the allocation unit size to use when formatting the volume.")] Uint32 AllocationUnitSize; diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/README.md b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md similarity index 100% rename from Modules/StorageDsc/DSCResources/MSFT_Disk/README.md rename to Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md diff --git a/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1 similarity index 89% rename from Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 rename to Modules/StorageDsc/DSCResources/MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1 index d18b4974..a4532dea 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_Disk/en-us/MSFT_Disk.strings.psd1 +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1 @@ -3,7 +3,7 @@ SettingDiskMessage = Setting disk with {0} '{1}' status for drive letter '{2}'. SetDiskOnlineMessage = Setting disk with {0} '{1}' online. SetDiskReadWriteMessage = Setting disk with {0} '{1}' to read/write. - CheckingDiskPartitionFormatMessage = Checking disk with {0} '{1}' partition format. + CheckingDiskPartitionStyleMessage = Checking disk with {0} '{1}' partition style. InitializingDiskMessage = Initializing disk with {0} '{1}' as '{2}'. DiskAlreadyInitializedMessage = Disk with {0} '{1}' is already initialized with '{2}'. CreatingPartitionMessage = Creating partition on disk with {0} '{1}' with drive letter '{2}' using {3}. @@ -18,8 +18,8 @@ DiskNotFoundMessage = Disk with {0} '{1}' was not found. DiskNotOnlineMessage = Disk with {0} '{1}' is not online. DiskReadOnlyMessage = Disk with {0} '{1}' is readonly. - DiskPartitionFormatNotMatchMessage = Disk with {0} '{1}' is initialized with partition format '{2}' but '{3}' required. - DiskInitializedWithWrongPartitionFormatError = Disk with {0} '{1}' is already initialized with partition format '{2}' but '{3}' required. Set AllowDestructive and ClearDisk to 'True' to allow disk to be reinitialized. + DiskPartitionStyleNotMatchMessage = Disk with {0} '{1}' is initialized with partition style '{2}' but '{3}' required. + DiskInitializedWithWrongPartitionStyleError = Disk with {0} '{1}' is already initialized with partition style '{2}' but '{3}' required. Set AllowDestructive and ClearDisk to 'True' to allow disk to be reinitialized. DriveLetterNotFoundMessage = Drive {0} was not found. SizeMismatchMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. Set AllowDestructive to 'True' to enable resizing of partition. SizeMismatchWithAllowDestructiveMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. diff --git a/Modules/StorageDsc/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof b/Modules/StorageDsc/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof index 3e49fd07..f0ccf421 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof +++ b/Modules/StorageDsc/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof @@ -1,6 +1,6 @@ [ClassVersion("1.0.0.0"), FriendlyName("DiskAccessPath")] -class MSFT_DiskAccessPath : OMI_BaseResource +class MSFTDSC_DiskAccessPath : OMI_BaseResource { [Key, Description("Specifies the access path folder to the assign the disk volume to.")] String AccessPath; [Required, Description("Specifies the disk identifier for the disk to modify.")] String DiskId; diff --git a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 index 711cf4ca..4b34a711 100644 --- a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 @@ -1,5 +1,5 @@ $script:DSCModuleName = 'StorageDsc' -$script:DSCResourceName = 'MSFT_Disk' +$script:DSCResourceName = 'MSFTDSC_Disk' Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global @@ -52,13 +52,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -85,11 +85,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionFormat | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.Size | Should -Be 100MB + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.Size | Should -Be 100MB } } @@ -100,12 +100,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionFormat = 'GPT' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelB } ) } @@ -132,11 +132,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterB - $current.FSLabel | Should -Be $FSLabelB - $current.PartitionFormat | Should -Be 'GPT' - $current.Size | Should -Be 935198720 + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterB + $current.FSLabel | Should -Be $FSLabelB + $current.PartitionStyle | Should -Be 'GPT' + $current.Size | Should -Be 935198720 } } @@ -188,13 +188,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA - Size = 50MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 50MB } ) } @@ -221,12 +221,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionFormat | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 50MB + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 50MB } } @@ -237,13 +237,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA - FSFormat = 'NTFS' + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + FSFormat = 'NTFS' } ) } @@ -270,12 +270,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigAllowDestructive" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionFormat | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 1040104960 + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 1040104960 } } @@ -323,13 +323,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionFormat = 'MBR' - FSLabel = $FSLabelA - Size = 50MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'MBR' + FSLabel = $FSLabelA + Size = 50MB } ) } @@ -356,12 +356,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionFormat | Should -Be 'MBR' - $current.FSLabel | Should -Be $FSLabelA - $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 50MB + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'MBR' + $current.FSLabel | Should -Be $FSLabelA + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 50MB } } @@ -372,14 +372,14 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA - FSFormat = 'NTFS' - Size = 50MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + FSFormat = 'NTFS' + Size = 50MB } ) } @@ -406,12 +406,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigClearDisk" } - $current.DiskId | Should -Be $disk.Number - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA - $current.PartitionFormat | Should -Be 'GPT' - $current.FSFormat | Should -Be 'NTFS' - $current.Size | Should -Be 52428800 + $current.DiskId | Should -Be $disk.Number + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA + $current.PartitionStyle | Should -Be 'GPT' + $current.FSFormat | Should -Be 'NTFS' + $current.Size | Should -Be 52428800 } } @@ -463,13 +463,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -496,11 +496,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.UniqueId - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionFormat | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.Size | Should -Be 100MB + $current.DiskId | Should -Be $disk.UniqueId + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.Size | Should -Be 100MB } } @@ -511,14 +511,14 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA - Size = 900MB - FSFormat = 'ReFS' + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 900MB + FSFormat = 'ReFS' } ) } @@ -545,12 +545,12 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_ConfigClearDisk" } - $current.DiskId | Should -Be $disk.UniqueId - $current.DriveLetter | Should -Be $driveLetterA - $current.PartitionFormat | Should -Be 'GPT' - $current.FSLabel | Should -Be $FSLabelA - $current.Size | Should -Be 900MB - $current.FSFormat | Should -Be 'ReFS' + $current.DiskId | Should -Be $disk.UniqueId + $current.DriveLetter | Should -Be $driveLetterA + $current.PartitionStyle | Should -Be 'GPT' + $current.FSLabel | Should -Be $FSLabelA + $current.Size | Should -Be 900MB + $current.FSFormat | Should -Be 'ReFS' } } @@ -561,12 +561,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.UniqueId - DiskIdType = 'UniqueId' - PartitionFormat = 'GPT' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.UniqueId + DiskIdType = 'UniqueId' + PartitionStyle = 'GPT' + FSLabel = $FSLabelB } ) } @@ -593,11 +593,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.UniqueId - $current.PartitionFormat | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterB - $current.FSLabel | Should -Be $FSLabelB - $current.Size | Should -Be 96337920 + $current.DiskId | Should -Be $disk.UniqueId + $current.PartitionStyle | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterB + $current.FSLabel | Should -Be $FSLabelB + $current.Size | Should -Be 96337920 } } @@ -647,13 +647,13 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Guid - DiskIdType = 'Guid' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA - Size = 100MB + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Guid + DiskIdType = 'Guid' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA + Size = 100MB } ) } @@ -680,11 +680,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Guid - $current.PartitionFormat | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA - $current.Size | Should -Be 100MB + $current.DiskId | Should -Be $disk.Guid + $current.PartitionStyle | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA + $current.Size | Should -Be 100MB } } @@ -695,12 +695,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterB - DiskId = $disk.Guid - DiskIdType = 'Guid' - PartitionFormat = 'GPT' - FSLabel = $FSLabelB + NodeName = 'localhost' + DriveLetter = $driveLetterB + DiskId = $disk.Guid + DiskIdType = 'Guid' + PartitionStyle = 'GPT' + FSLabel = $FSLabelB } ) } @@ -727,11 +727,11 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Guid - $current.PartitionFormat | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterB - $current.FSLabel | Should -Be $FSLabelB - $current.Size | Should -Be 935198720 + $current.DiskId | Should -Be $disk.Guid + $current.PartitionStyle | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterB + $current.FSLabel | Should -Be $FSLabelB + $current.Size | Should -Be 935198720 } } @@ -779,12 +779,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA } ) } @@ -811,10 +811,10 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.PartitionFormat | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA + $current.DiskId | Should -Be $disk.Number + $current.PartitionStyle | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA } } @@ -831,12 +831,12 @@ try $configData = @{ AllNodes = @( @{ - NodeName = 'localhost' - DriveLetter = $driveLetterA - DiskId = $disk.Number - DiskIdType = 'Number' - PartitionFormat = 'GPT' - FSLabel = $FSLabelA + NodeName = 'localhost' + DriveLetter = $driveLetterA + DiskId = $disk.Number + DiskIdType = 'Number' + PartitionStyle = 'GPT' + FSLabel = $FSLabelA } ) } @@ -863,10 +863,10 @@ try $current = $script:currentConfiguration | Where-Object -FilterScript { $_.ConfigurationName -eq "$($script:DSCResourceName)_Config" } - $current.DiskId | Should -Be $disk.Number - $current.PartitionFormat | Should -Be 'GPT' - $current.DriveLetter | Should -Be $driveLetterA - $current.FSLabel | Should -Be $FSLabelA + $current.DiskId | Should -Be $disk.Number + $current.PartitionStyle | Should -Be 'GPT' + $current.DriveLetter | Should -Be $driveLetterA + $current.FSLabel | Should -Be $FSLabelA } } diff --git a/Tests/Integration/MSFT_Disk.config.ps1 b/Tests/Integration/MSFT_Disk.config.ps1 index b652c795..acbc737c 100644 --- a/Tests/Integration/MSFT_Disk.config.ps1 +++ b/Tests/Integration/MSFT_Disk.config.ps1 @@ -1,4 +1,4 @@ -configuration MSFT_Disk_Config { +configuration MSFTDSC_Disk_Config { Import-DscResource -ModuleName StorageDsc @@ -9,7 +9,7 @@ configuration MSFT_Disk_Config { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionFormat = $Node.PartitionFormat + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -21,7 +21,7 @@ configuration MSFT_Disk_Config { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionFormat = $Node.PartitionFormat + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel } @@ -29,7 +29,7 @@ configuration MSFT_Disk_Config { } } -configuration MSFT_Disk_ConfigAllowDestructive { +configuration MSFTDSC_Disk_ConfigAllowDestructive { Import-DscResource -ModuleName StorageDsc @@ -40,7 +40,7 @@ configuration MSFT_Disk_ConfigAllowDestructive { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionFormat = $Node.PartitionFormat + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -54,7 +54,7 @@ configuration MSFT_Disk_ConfigAllowDestructive { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionFormat = $Node.PartitionFormat + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel FSFormat = $Node.FSFormat @@ -64,7 +64,7 @@ configuration MSFT_Disk_ConfigAllowDestructive { } } -configuration MSFT_Disk_ConfigClearDisk { +configuration MSFTDSC_Disk_ConfigClearDisk { Import-DscResource -ModuleName StorageDsc @@ -75,7 +75,7 @@ configuration MSFT_Disk_ConfigClearDisk { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionFormat = $Node.PartitionFormat + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -90,7 +90,7 @@ configuration MSFT_Disk_ConfigClearDisk { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionFormat = $Node.PartitionFormat + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel FSFormat = $Node.FSFormat diff --git a/Tests/Integration/MSFT_DiskAccessPath.config.ps1 b/Tests/Integration/MSFT_DiskAccessPath.config.ps1 index 0fe97d22..aeec7293 100644 --- a/Tests/Integration/MSFT_DiskAccessPath.config.ps1 +++ b/Tests/Integration/MSFT_DiskAccessPath.config.ps1 @@ -1,4 +1,4 @@ -configuration MSFT_DiskAccessPath_Config { +configuration MSFTDSC_DiskAccessPath_Config { Import-DscResource -ModuleName StorageDsc diff --git a/Tests/Unit/MSFT_Disk.Tests.ps1 b/Tests/Unit/MSFT_Disk.Tests.ps1 index 1d21e28b..39d8d7f3 100644 --- a/Tests/Unit/MSFT_Disk.Tests.ps1 +++ b/Tests/Unit/MSFT_Disk.Tests.ps1 @@ -1,5 +1,5 @@ $script:DSCModuleName = 'StorageDsc' -$script:DSCResourceName = 'MSFT_Disk' +$script:DSCResourceName = 'MSFTDSC_Disk' Import-Module -Name (Join-Path -Path (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath 'TestHelpers') -ChildPath 'CommonTestHelper.psm1') -Global @@ -307,7 +307,7 @@ try #endregion #region Function Get-TargetResource - Describe 'MSFT_Disk\Get-TargetResource' { + Describe 'MSFTDSC_Disk\Get-TargetResource' { Context 'Online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Number' { # verifiable (should be called) mocks Mock ` @@ -340,8 +340,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Number } - It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -407,8 +407,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.UniqueId } - It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -474,8 +474,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Guid } - It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -541,8 +541,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Guid } - It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return DriveLetter $($script:testDriveLetter)" { @@ -604,8 +604,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Gpt.Number } - It "Should return PartitionFormat $($script:mockedDisk0Gpt.PartitionStyle)" { - $resource.PartitionFormat | Should -Be $script:mockedDisk0Gpt.PartitionStyle + It "Should return PartitionStyle $($script:mockedDisk0Gpt.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Gpt.PartitionStyle } It "Should return an empty drive letter" { @@ -667,8 +667,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Mbr.Number } - It "Should return PartitionFormat $($script:mockedDisk0Mbr.PartitionStyle)" { - $resource.PartitionFormat | Should -Be $script:mockedDisk0Mbr.PartitionStyle + It "Should return PartitionStyle $($script:mockedDisk0Mbr.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Mbr.PartitionStyle } It "Should return an empty drive letter" { @@ -730,8 +730,8 @@ try $resource.DiskId | Should -Be $script:mockedDisk0Raw.Number } - It "Should return PartitionFormat $($script:mockedDisk0Raw.PartitionStyle)" { - $resource.PartitionFormat | Should -Be $script:mockedDisk0Raw.PartitionStyle + It "Should return PartitionStyle $($script:mockedDisk0Raw.PartitionStyle)" { + $resource.PartitionStyle | Should -Be $script:mockedDisk0Raw.PartitionStyle } It "Should return an empty drive letter" { @@ -767,7 +767,7 @@ try #endregion #region Function Set-TargetResource - Describe 'MSFT_Disk\Set-TargetResource' { + Describe 'MSFTDSC_Disk\Set-TargetResource' { Context 'Offline GPT disk using Disk Number' { # verifiable (should be called) mocks Mock ` @@ -1315,10 +1315,10 @@ try Mock -CommandName Set-Partition $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskInitializedWithWrongPartitionFormatError -f ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` 'Number', $script:mockedDisk0Mbr.Number, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') - It 'Should not throw DiskInitializedWithWrongPartitionFormatError' { + It 'Should not throw DiskInitializedWithWrongPartitionStyleError' { { Set-TargetResource ` -DiskId $script:mockedDisk0Mbr.Number ` @@ -1358,10 +1358,10 @@ try Mock -CommandName Set-Partition $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskInitializedWithWrongPartitionFormatError -f ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` 'UniqueId', $script:mockedDisk0Mbr.UniqueId, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') - It 'Should throw DiskInitializedWithWrongPartitionFormatError' { + It 'Should throw DiskInitializedWithWrongPartitionStyleError' { { Set-TargetResource ` -DiskId $script:mockedDisk0Mbr.UniqueId ` @@ -2133,7 +2133,7 @@ try #endregion #region Function Test-TargetResource - Describe 'MSFT_Disk\Test-TargetResource' { + Describe 'MSFTDSC_Disk\Test-TargetResource' { Mock ` -CommandName Get-CimInstance ` -MockWith { $script:mockedCim } @@ -2374,7 +2374,7 @@ try } } - Context 'When testing online disk using Disk Number with partition format GPT but requiring MBR' { + Context 'When testing online disk using Disk Number with partition style GPT but requiring MBR' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -2388,10 +2388,10 @@ try Mock -CommandName Get-CimInstance $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskInitializedWithWrongPartitionFormatError -f ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` 'Number', $script:mockedDisk0Mbr.Number, $script:mockedDisk0Mbr.PartitionStyle, 'GPT') - It 'Should throw DiskInitializedWithWrongPartitionFormatError' { + It 'Should throw DiskInitializedWithWrongPartitionStyleError' { { Test-TargetResource ` -DiskId $script:mockedDisk0Mbr.Number ` @@ -2411,7 +2411,7 @@ try } } - Context 'When testing online disk using Disk Number with partition format MBR but requiring GPT' { + Context 'When testing online disk using Disk Number with partition style MBR but requiring GPT' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -2425,16 +2425,16 @@ try Mock -CommandName Get-CimInstance $errorRecord = Get-InvalidOperationRecord ` - -Message ($LocalizedData.DiskInitializedWithWrongPartitionFormatError -f ` + -Message ($LocalizedData.DiskInitializedWithWrongPartitionStyleError -f ` 'Number', $script:mockedDisk0Gpt.Number, $script:mockedDisk0Gpt.PartitionStyle, 'MBR') - It 'Should throw DiskInitializedWithWrongPartitionFormatError' { + It 'Should throw DiskInitializedWithWrongPartitionStyleError' { { Test-TargetResource ` -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` - -PartitionFormat 'MBR' ` + -PartitionStyle 'MBR' ` -Verbose } | Should -Throw $errorRecord } @@ -2449,7 +2449,7 @@ try } } - Context 'When testing online disk using Disk Number with partition format MBR but requiring GPT and AllowDestructive and ClearDisk is True' { + Context 'When testing online disk using Disk Number with partition style MBR but requiring GPT and AllowDestructive and ClearDisk is True' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -2470,7 +2470,7 @@ try -DiskId $script:mockedDisk0Gpt.Number ` -DriveLetter $script:testDriveLetter ` -AllocationUnitSize 4096 ` - -PartitionFormat 'MBR' ` + -PartitionStyle 'MBR' ` -AllowDestructive $true ` -ClearDisk $true ` -Verbose From 22169aa6b9e01a3c8c15ba89d42de53033543be7 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Tue, 11 Sep 2018 11:05:31 +1200 Subject: [PATCH 11/18] Correct filenames of integration tests: --- ...k.Integration.Tests.ps1 => MSFTDSC_Disk.Integration.Tests.ps1} | 0 .../Integration/{MSFT_Disk.config.ps1 => MSFTDSC_Disk.config.ps1} | 0 Tests/Unit/{MSFT_Disk.Tests.ps1 => MSFTDSC_Disk.Tests.ps1} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename Tests/Integration/{MSFT_Disk.Integration.Tests.ps1 => MSFTDSC_Disk.Integration.Tests.ps1} (100%) rename Tests/Integration/{MSFT_Disk.config.ps1 => MSFTDSC_Disk.config.ps1} (100%) rename Tests/Unit/{MSFT_Disk.Tests.ps1 => MSFTDSC_Disk.Tests.ps1} (100%) diff --git a/Tests/Integration/MSFT_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 similarity index 100% rename from Tests/Integration/MSFT_Disk.Integration.Tests.ps1 rename to Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 diff --git a/Tests/Integration/MSFT_Disk.config.ps1 b/Tests/Integration/MSFTDSC_Disk.config.ps1 similarity index 100% rename from Tests/Integration/MSFT_Disk.config.ps1 rename to Tests/Integration/MSFTDSC_Disk.config.ps1 diff --git a/Tests/Unit/MSFT_Disk.Tests.ps1 b/Tests/Unit/MSFTDSC_Disk.Tests.ps1 similarity index 100% rename from Tests/Unit/MSFT_Disk.Tests.ps1 rename to Tests/Unit/MSFTDSC_Disk.Tests.ps1 From a778280510fd229c8f39012185c2e771bfe15237 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Tue, 11 Sep 2018 11:23:32 +1200 Subject: [PATCH 12/18] Revert accidental change to DiskAccessPath --- .../MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof | 2 +- Tests/Integration/MSFT_DiskAccessPath.config.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/StorageDsc/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof b/Modules/StorageDsc/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof index f0ccf421..3e49fd07 100644 --- a/Modules/StorageDsc/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof +++ b/Modules/StorageDsc/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof @@ -1,6 +1,6 @@ [ClassVersion("1.0.0.0"), FriendlyName("DiskAccessPath")] -class MSFTDSC_DiskAccessPath : OMI_BaseResource +class MSFT_DiskAccessPath : OMI_BaseResource { [Key, Description("Specifies the access path folder to the assign the disk volume to.")] String AccessPath; [Required, Description("Specifies the disk identifier for the disk to modify.")] String DiskId; diff --git a/Tests/Integration/MSFT_DiskAccessPath.config.ps1 b/Tests/Integration/MSFT_DiskAccessPath.config.ps1 index aeec7293..0fe97d22 100644 --- a/Tests/Integration/MSFT_DiskAccessPath.config.ps1 +++ b/Tests/Integration/MSFT_DiskAccessPath.config.ps1 @@ -1,4 +1,4 @@ -configuration MSFTDSC_DiskAccessPath_Config { +configuration MSFT_DiskAccessPath_Config { Import-DscResource -ModuleName StorageDsc From 599b614866ffb9cc560c829f3f613ad85a5be0c8 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Thu, 13 Sep 2018 18:48:24 +1200 Subject: [PATCH 13/18] Added comment to DISK MOF --- .../StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof index 9bd05e74..07d3d30d 100644 --- a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof @@ -1,5 +1,6 @@ [ClassVersion("1.0.0.0"), FriendlyName("Disk")] +// This resource uses the MSFTDSC Prefix to prevent conflict with built in MSFT_Disk CIM Class. class MSFTDSC_Disk : OMI_BaseResource { [Key, Description("Specifies the identifier for which disk to modify.")] String DriveLetter; From a0b4c6bf2a9b0f3086aaa72fc8b1bdb7028c8ea8 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Fri, 14 Sep 2018 22:28:29 +1200 Subject: [PATCH 14/18] Changes as per PR Comments --- CHANGELOG.md | 2 +- .../DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1 | 14 +++++++------- .../MSFTDSC_Disk/MSFTDSC_Disk.schema.mof | 2 +- .../MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1 | 8 ++++---- .../Integration/MSFTDSC_Disk.Integration.Tests.ps1 | 4 ++-- Tests/Integration/MSFTDSC_Disk.config.ps1 | 12 ++++++------ 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27dcbe23..218f6326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Disk: - Added `PartitionStyle` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). - Changed MOF name from `MSFT_Disk` to `MSFTDSC_Disk` to remove conflict - with Windows built-in CIM class. + with Windows built-in CIM class - Fixes [Issue #167](https://github.com/PowerShell/StorageDsc/issues/167). - Opt-in to Common Tests: - Common Tests - Validate Example Files To Be Published - Common Tests - Validate Markdown Links diff --git a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1 b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1 index 988af8f7..7f18dfd0 100644 --- a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1 +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.psm1 @@ -35,32 +35,32 @@ $localizedData = Get-LocalizedData ` .PARAMETER PartitionStyle Specifies the partition style of the disk. Defaults to GPT. - This value of this parameter is ignored. + This parameter is not used in Get-TargetResource. .PARAMETER Size Specifies the size of new volume (use all available space on disk if not provided). - This value of this parameter is ignored. + This parameter is not used in Get-TargetResource. .PARAMETER FSLabel Specifies the volume label to assign to the volume. - This value of this parameter is ignored. + This parameter is not used in Get-TargetResource. .PARAMETER AllocationUnitSize Specifies the allocation unit size to use when formatting the volume. - This value of this parameter is ignored. + This parameter is not used in Get-TargetResource. .PARAMETER FSFormat Specifies the file system format of the new volume. - This value of this parameter is ignored. + This parameter is not used in Get-TargetResource. .PARAMETER AllowDestructive Specifies if potentially destructive operations may occur. - This value of this parameter is ignored. + This parameter is not used in Get-TargetResource. .PARAMETER ClearDisk Specifies if the disks partition schema should be removed entirely, even if data and OEM partitions are present. Only possible with AllowDestructive enabled. - This value of this parameter is ignored. + This parameter is not used in Get-TargetResource. #> function Get-TargetResource { diff --git a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof index 07d3d30d..5ab930f7 100644 --- a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/MSFTDSC_Disk.schema.mof @@ -1,6 +1,6 @@ [ClassVersion("1.0.0.0"), FriendlyName("Disk")] -// This resource uses the MSFTDSC Prefix to prevent conflict with built in MSFT_Disk CIM Class. +// This resource uses the MSFTDSC prefix to prevent conflict with built in MSFT_Disk CIM class. class MSFTDSC_Disk : OMI_BaseResource { [Key, Description("Specifies the identifier for which disk to modify.")] String DriveLetter; diff --git a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1 b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1 index a4532dea..cbdd331b 100644 --- a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1 +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/en-us/MSFTDSC_Disk.strings.psd1 @@ -18,10 +18,10 @@ DiskNotFoundMessage = Disk with {0} '{1}' was not found. DiskNotOnlineMessage = Disk with {0} '{1}' is not online. DiskReadOnlyMessage = Disk with {0} '{1}' is readonly. - DiskPartitionStyleNotMatchMessage = Disk with {0} '{1}' is initialized with partition style '{2}' but '{3}' required. - DiskInitializedWithWrongPartitionStyleError = Disk with {0} '{1}' is already initialized with partition style '{2}' but '{3}' required. Set AllowDestructive and ClearDisk to 'True' to allow disk to be reinitialized. + DiskPartitionStyleNotMatchMessage = Disk with {0} '{1}' is initialized with partition style '{2}' but '{3}' is required. + DiskInitializedWithWrongPartitionStyleError = Disk with {0} '{1}' is already initialized with partition style '{2}' but '{3}' is required. Set AllowDestructive and ClearDisk to $true to allow disk to be reinitialized. DriveLetterNotFoundMessage = Drive {0} was not found. - SizeMismatchMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. Set AllowDestructive to 'True' to enable resizing of partition. + SizeMismatchMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. Set AllowDestructive to $true to enable resizing of partition. SizeMismatchWithAllowDestructiveMessage = Partition assigned to drive {0} has size {1}, which does not match expected size {2}. AllocationUnitSizeMismatchMessage = Volume assigned to drive {0} has allocation unit size {1} KB does not match expected allocation unit size {2} KB. FileSystemFormatMismatch = Volume assigned to drive {0} filesystem format '{1}' does not match expected format '{2}'. @@ -39,5 +39,5 @@ SizeMismatchCorrectionMessage = Switch AllowDestructive is specified. Attempting to resize partition {0} from {1} to {2}. FreeSpaceViolationError = Attempted to resize partition {0} from {1} to {2} while maximum allowed size was {3}. ResizeRefsNotPossibleMessage = Skipping resize of {0} from {1} to {2}. Resizing ReFS partitions is currently not possible. - ResizeNotAllowedMessage = Skipping resize of {0} from {1} to {2}. AllowDestructive is not set to 'True'. + ResizeNotAllowedMessage = Skipping resize of {0} from {1} to {2}. AllowDestructive is not set to $true. '@ diff --git a/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 index 4b34a711..db637530 100644 --- a/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 +++ b/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 @@ -365,7 +365,7 @@ try } } - Context "Resize partition on Disk Number $($disk.Number) to use 50MB with AllowDestructive" { + Context "Clear Disk Number $($disk.Number) and change the partition style to GPT and add a 50MB partition" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -504,7 +504,7 @@ try } } - Context "Resize first volume on Disk Unique Id $($disk.UniqueId)" { + Context "Resize first volume on Disk Unique Id $($disk.UniqueId) and allowing the disk to be cleared" { It 'should compile and apply the MOF without throwing' { { # This is to pass to the Config diff --git a/Tests/Integration/MSFTDSC_Disk.config.ps1 b/Tests/Integration/MSFTDSC_Disk.config.ps1 index acbc737c..97dcb1ff 100644 --- a/Tests/Integration/MSFTDSC_Disk.config.ps1 +++ b/Tests/Integration/MSFTDSC_Disk.config.ps1 @@ -9,7 +9,7 @@ configuration MSFTDSC_Disk_Config { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -21,7 +21,7 @@ configuration MSFTDSC_Disk_Config { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel } @@ -40,7 +40,7 @@ configuration MSFTDSC_Disk_ConfigAllowDestructive { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -54,7 +54,7 @@ configuration MSFTDSC_Disk_ConfigAllowDestructive { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel FSFormat = $Node.FSFormat @@ -75,7 +75,7 @@ configuration MSFTDSC_Disk_ConfigClearDisk { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel Size = $Node.Size @@ -90,7 +90,7 @@ configuration MSFTDSC_Disk_ConfigClearDisk { { DiskId = $Node.DiskId DiskIdType = $Node.DiskIdType - PartitionStyle = $Node.PartitionStyle + PartitionStyle = $Node.PartitionStyle DriveLetter = $Node.DriveLetter FSLabel = $Node.FSLabel FSFormat = $Node.FSFormat From ab44d378d46f4b06d937b56cd925443c19ed67b0 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Wed, 19 Sep 2018 19:46:16 +1200 Subject: [PATCH 15/18] Changes as per PR comments --- .../DSCResources/MSFTDSC_Disk/README.md | 11 +++-- .../MSFTDSC_Disk.Integration.Tests.ps1 | 38 ++++++++-------- Tests/Unit/MSFTDSC_Disk.Tests.ps1 | 44 +++++++++---------- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md index ad1a4174..303aa84a 100644 --- a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md @@ -17,9 +17,8 @@ PowerShell command: Get-Disk | Select-Object -Property FriendlyName,DiskNumber,UniqueId,Guid ``` -Note: The _Guid_ for a disk is only assigned once the partition table for the disk -has been created (e.g. the disk has been initialized). Therefore to use this method -of disk selection the disk must have been initialized by some other method. - -The _Guid_ identifier method of specifying disks is only supported as an identifier -for disks with `GPT` partition table format. +Note: The _Guid_ identifier method of specifying disks is only supported as an +identifier for disks with `GPT` partition table format. If the disk is `RAW` +(e.g. the disk has been initialized) then the _Guid_ identifier method can not +be used. This is because the _Guid_ for a disk is only assigned once the partition +table for the disk has been created. diff --git a/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 b/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 index db637530..e5a268b9 100644 --- a/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 +++ b/Tests/Integration/MSFTDSC_Disk.Integration.Tests.ps1 @@ -27,7 +27,7 @@ try Describe "$($script:DSCResourceName)_Integration" { #region Integration Tests for DiskNumber - Context 'Partition and format newly provisioned disk using Disk Number with two volumes and assign Drive Letters' { + Context 'When partitioning and formatting a newly provisioned disk using Disk Number with two volumes and assigning Drive Letters' { BeforeAll { # Create a VHD and attach it to the computer $VHDPath = Join-Path -Path $TestDrive ` @@ -45,7 +45,7 @@ try $driveLetterB = [char](([int][char]$lastDrive) + 2) } - Context "Create first volume on Disk Number $($disk.Number)" { + Context "When creating the first volume on Disk Number $($disk.Number)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -93,7 +93,7 @@ try } } - Context "Create second volume on Disk Number $($disk.Number)" { + Context "When creating the second volume on Disk Number $($disk.Number)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -165,7 +165,7 @@ try } } - Context 'Partition and format newly provisioned disk using Disk Number with one volume and assign Drive Letters then resize' { + Context 'When partitioniong and formatting a newly provisioned disk using Disk Number with one volume and assigning Drive Letters then resizing' { BeforeAll { # Create a VHD and attach it to the computer $VHDPath = Join-Path -Path $TestDrive ` @@ -181,7 +181,7 @@ try $driveLetterA = [char](([int][char]$lastDrive) + 1) } - Context "Create volume on Disk Number $($disk.Number)" { + Context "When creating a volume on Disk Number $($disk.Number)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -230,7 +230,7 @@ try } } - Context "Resize partition on Disk Number $($disk.Number) to use all free space with AllowDestructive" { + Context "When resizing a partition on Disk Number $($disk.Number) to use all free space with AllowDestructive" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -300,7 +300,7 @@ try } } - Context 'Partition and format newly provisioned disk using Disk Number with one volume using MBR then convert to GPT' { + Context 'When partitioning and formatting a newly provisioned disk using Disk Number with one volume using MBR then convert to GPT' { BeforeAll { # Create a VHD and attach it to the computer $VHDPath = Join-Path -Path $TestDrive ` @@ -316,7 +316,7 @@ try $driveLetterA = [char](([int][char]$lastDrive) + 1) } - Context "Create volume on Disk Number $($disk.Number)" { + Context "When creating a volume on Disk Number $($disk.Number)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -365,7 +365,7 @@ try } } - Context "Clear Disk Number $($disk.Number) and change the partition style to GPT and add a 50MB partition" { + Context "When clearing Disk Number $($disk.Number) and changing the partition style to GPT and adding a 50MB partition" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -438,7 +438,7 @@ try #endregion #region Integration Tests for Disk Unique Id - Context 'Partition and format newly provisioned disk using Unique Id with two volumes and assign Drive Letters' { + Context 'When partitioning and formatting a newly provisioned disk using Unique Id with two volumes and assigning Drive Letters' { BeforeAll { # Create a VHD and attach it to the computer $VHDPath = Join-Path -Path $TestDrive ` @@ -456,7 +456,7 @@ try $driveLetterB = [char](([int][char]$lastDrive) + 2) } - Context "Create first volume on Disk Unique Id $($disk.UniqueId)" { + Context "When creating the first volume on Disk Unique Id $($disk.UniqueId)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -504,7 +504,7 @@ try } } - Context "Resize first volume on Disk Unique Id $($disk.UniqueId) and allowing the disk to be cleared" { + Context "When resizing the first volume on Disk Unique Id $($disk.UniqueId) and allowing the disk to be cleared" { It 'should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -554,7 +554,7 @@ try } } - Context "Create second volume on Disk Unique Id $($disk.UniqueId)" { + Context "When creating second volume on Disk Unique Id $($disk.UniqueId)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -622,7 +622,7 @@ try #endregion #region Integration Tests for Disk Guid - Context 'Partition and format newly provisioned disk using Guid with two volumes and assign Drive Letters' { + Context 'When partitioning and formating a newly provisioned disk using Guid with two volumes and assign Drive Letters' { BeforeAll { # Create a VHD and attach it to the computer $VHDPath = Join-Path -Path $TestDrive ` @@ -640,7 +640,7 @@ try $driveLetterB = [char](([int][char]$lastDrive) + 2) } - Context "Create first volume on Disk Guid $($disk.Guid)" { + Context "When creating the first volume on Disk Guid $($disk.Guid)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -688,7 +688,7 @@ try } } - Context "Create first volume on Disk Guid $($disk.Guid)" { + Context "When creating the first volume on Disk Guid $($disk.Guid)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -756,7 +756,7 @@ try #endregion #region Integration Tests for DiskNumber to test if a single disk with a volume using the whole disk can be remounted - Context 'Partition a disk using Disk Number with a single volume using the whole disk, dismount the volume then reprovision it' { + Context 'When partitioning a disk using Disk Number with a single volume using the whole disk, dismounting the volume then reprovisioning it' { BeforeAll { # Create a VHD and attach it to the computer $VHDPath = Join-Path -Path $TestDrive ` @@ -772,7 +772,7 @@ try $driveLetterA = [char](([int][char]$lastDrive) + 1) } - Context "Create first volume on Disk Number $($disk.Number)" { + Context "When creating the first volume on Disk Number $($disk.Number)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config @@ -824,7 +824,7 @@ try -PartitionNumber 2 ` -AccessPath "$($driveLetterA):" - Context "Attach first volume on Disk Number $($disk.Number)" { + Context "When attaching the first volume on Disk Number $($disk.Number)" { It 'Should compile and apply the MOF without throwing' { { # This is to pass to the Config diff --git a/Tests/Unit/MSFTDSC_Disk.Tests.ps1 b/Tests/Unit/MSFTDSC_Disk.Tests.ps1 index 39d8d7f3..778ee63e 100644 --- a/Tests/Unit/MSFTDSC_Disk.Tests.ps1 +++ b/Tests/Unit/MSFTDSC_Disk.Tests.ps1 @@ -308,7 +308,7 @@ try #region Function Get-TargetResource Describe 'MSFTDSC_Disk\Get-TargetResource' { - Context 'Online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Number' { + Context 'When online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-CimInstance ` @@ -374,7 +374,7 @@ try } } - Context 'Online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Unique Id' { + Context 'When online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Unique Id' { # verifiable (should be called) mocks Mock ` -CommandName Get-CimInstance ` @@ -441,7 +441,7 @@ try } } - Context 'Online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Guid' { + Context 'When online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Guid' { # verifiable (should be called) mocks Mock ` -CommandName Get-CimInstance ` @@ -508,7 +508,7 @@ try } } - Context 'Online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Guid' { + Context 'When online GPT disk with a partition/volume and correct Drive Letter assigned using Disk Guid' { # verifiable (should be called) mocks Mock ` -CommandName Get-CimInstance ` @@ -575,7 +575,7 @@ try } } - Context 'Online GPT disk with no partition using Disk Number' { + Context 'When online GPT disk with no partition using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-CimInstance ` @@ -638,7 +638,7 @@ try } } - Context 'Online MBR disk with no partition using Disk Number' { + Context 'When online MBR disk with no partition using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-CimInstance ` @@ -701,7 +701,7 @@ try } } - Context 'Online RAW disk with no partition using Disk Number' { + Context 'When online RAW disk with no partition using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-CimInstance ` @@ -768,7 +768,7 @@ try #region Function Set-TargetResource Describe 'MSFTDSC_Disk\Set-TargetResource' { - Context 'Offline GPT disk using Disk Number' { + Context 'When offline GPT disk using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -830,7 +830,7 @@ try } } - Context 'Offline GPT disk using Disk Unique Id' { + Context 'When offline GPT disk using Disk Unique Id' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -897,7 +897,7 @@ try } } - Context 'Offline GPT disk using Disk Guid' { + Context 'When offline GPT disk using Disk Guid' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -964,7 +964,7 @@ try } } - Context 'Readonly GPT disk using Disk Number' { + Context 'When readonly GPT disk using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1030,7 +1030,7 @@ try } } - Context 'Offline RAW disk using Disk Number' { + Context 'When offline RAW disk using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1097,7 +1097,7 @@ try } } - Context 'Online RAW disk with Size using Disk Number' { + Context 'When online RAW disk with Size using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1166,7 +1166,7 @@ try } } - Context 'Online GPT disk with no partitions using Disk Number' { + Context 'When online GPT disk with no partitions using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1229,7 +1229,7 @@ try } } - Context 'Online GPT disk with no partitions using Disk Number, partition fails to become writeable' { + Context 'When online GPT disk with no partitions using Disk Number, partition fails to become writeable' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1297,7 +1297,7 @@ try } } - Context 'Online MBR disk using Disk Number' { + Context 'When online MBR disk using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1341,7 +1341,7 @@ try } } - Context 'Online MBR disk using Disk Unique Id but GPT required and AllowDestructive and ClearDisk are false' { + Context 'When online MBR disk using Disk Unique Id but GPT required and AllowDestructive and ClearDisk are false' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1384,7 +1384,7 @@ try } } - Context 'Online GPT disk with partition/volume already assigned using Disk Number' { + Context 'When online GPT disk with partition/volume already assigned using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1432,7 +1432,7 @@ try } } - Context 'Online GPT disk containing matching partition but not assigned using Disk Number' { + Context 'When online GPT disk containing matching partition but not assigned using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1484,7 +1484,7 @@ try } } - Context 'Online GPT disk with a partition/volume and wrong Drive Letter assigned using Disk Number' { + Context 'When online GPT disk with a partition/volume and wrong Drive Letter assigned using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1543,7 +1543,7 @@ try } } - Context 'Online GPT disk with a partition/volume and no Drive Letter assigned using Disk Number' { + Context 'When online GPT disk with a partition/volume and no Drive Letter assigned using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` @@ -1594,7 +1594,7 @@ try } } - Context 'Online GPT disk with a partition/volume and wrong Volume Label assigned using Disk Number' { + Context 'When online GPT disk with a partition/volume and wrong Volume Label assigned using Disk Number' { # verifiable (should be called) mocks Mock ` -CommandName Get-DiskByIdentifier ` From 905b4e2f1a34b2f5808fcf9ffc52b5e926b3bcd2 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Sat, 22 Sep 2018 09:03:40 +1200 Subject: [PATCH 16/18] Added 'defragsvc' service conflict known issue to README.MD for Disk --- CHANGELOG.md | 3 +++ .../DSCResources/MSFTDSC_Disk/README.md | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 218f6326..45c0a3f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ - Common Tests - Validate Markdown Links - Common Tests - Relative Path Length - Added .VSCode settings for applying DSC PSSA rules - fixes [Issue #168](https://github.com/PowerShell/StorageDsc/issues/168). +- Disk: + - Added 'defragsvc' service conflict known issue to README.MD - fixes + [Issue #172](https://github.com/PowerShell/StorageDsc/issues/172). ## 4.1.0.0 diff --git a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md index 303aa84a..501f3bfc 100644 --- a/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md +++ b/Modules/StorageDsc/DSCResources/MSFTDSC_Disk/README.md @@ -22,3 +22,21 @@ identifier for disks with `GPT` partition table format. If the disk is `RAW` (e.g. the disk has been initialized) then the _Guid_ identifier method can not be used. This is because the _Guid_ for a disk is only assigned once the partition table for the disk has been created. + +## Known Issues + +The 'defragsvc' service ('Optimize Drives') may cause the following errors when +enabled with this resource. The following error may occur when testing the state +of the resource: + +```text +PartitionSupportedSize ++ CategoryInfo : NotSpecified: (StorageWMI:) [], CimException ++ FullyQualifiedErrorId : StorageWMI 4,Get-PartitionSupportedSize ++ PSComputerName : localhost +``` + +The 'defragsvc' service should be stopped and set to manual start up to prevent +this error. Use the `Service` resource in either the 'xPSDesiredStateConfgiuration' +or 'PSDSCResources' resource module to set the 'defragsvc' service is always +stopped and set to manual start up. From 2cdc9eda7db66491d67e403561e712aae43357b4 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Tue, 25 Sep 2018 21:40:28 +1200 Subject: [PATCH 17/18] Correct style violations in support modules --- CHANGELOG.md | 2 + .../StorageDsc.Common/StorageDsc.Common.psm1 | 11 ++-- .../StorageDsc.ResourceHelper.psm1 | 59 ++++++++++++++----- 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45c0a3f7..4e21345e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ - Disk: - Added 'defragsvc' service conflict known issue to README.MD - fixes [Issue #172](https://github.com/PowerShell/StorageDsc/issues/172). +- Corrected style violations in StorageDsc.Common module - fixes [Issue #153](https://github.com/PowerShell/StorageDsc/issues/153). +- Corrected style violations in StorageDsc.ResourceHelper module. ## 4.1.0.0 diff --git a/Modules/StorageDsc/Modules/StorageDsc.Common/StorageDsc.Common.psm1 b/Modules/StorageDsc/Modules/StorageDsc.Common/StorageDsc.Common.psm1 index 5a8853fb..ed65249e 100644 --- a/Modules/StorageDsc/Modules/StorageDsc.Common/StorageDsc.Common.psm1 +++ b/Modules/StorageDsc/Modules/StorageDsc.Common/StorageDsc.Common.psm1 @@ -21,14 +21,15 @@ $localizedData = Get-LocalizedData ` function Assert-DriveLetterValid { [CmdletBinding()] - [OutputType([String])] + [OutputType([System.String])] param ( - [Parameter(Mandatory)] + [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] $DriveLetter, + [Parameter()] [Switch] $Colon ) @@ -69,14 +70,15 @@ function Assert-DriveLetterValid function Assert-AccessPathValid { [CmdletBinding()] - [OutputType([String])] + [OutputType([System.String])] param ( - [Parameter(Mandatory)] + [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] [System.String] $AccessPath, + [Parameter()] [Switch] $Slash ) @@ -176,6 +178,7 @@ function Test-AccessPathAssignedToLocal ) $accessPathAssigned = $false + foreach ($path in $AccessPath) { if ($path -match '[a-zA-Z]:\\') diff --git a/Modules/StorageDsc/Modules/StorageDsc.ResourceHelper/StorageDsc.ResourceHelper.psm1 b/Modules/StorageDsc/Modules/StorageDsc.ResourceHelper/StorageDsc.ResourceHelper.psm1 index 5cb0d29a..bfd7f243 100644 --- a/Modules/StorageDsc/Modules/StorageDsc.ResourceHelper/StorageDsc.ResourceHelper.psm1 +++ b/Modules/StorageDsc/Modules/StorageDsc.ResourceHelper/StorageDsc.ResourceHelper.psm1 @@ -21,12 +21,18 @@ function Test-IsNanoServer <# .SYNOPSIS Tests if the the specified command is found. + + .PARAMETER Name + The name of the command to find. + #> function Test-Command { param ( - [String] $Name + [Parameter(Mandatory = $true)] + [System.String] + $Name ) return ($null -ne (Get-Command -Name $Name -ErrorAction Continue 2> $null)) @@ -49,21 +55,30 @@ function New-InvalidArgumentException ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $Message, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] + $ArgumentName + ) + + $argumentException = New-Object -TypeName 'ArgumentException' -ArgumentList @( + $Message $ArgumentName ) - $argumentException = New-Object -TypeName 'ArgumentException' -ArgumentList @( $Message, - $ArgumentName ) $newObjectParams = @{ TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( $argumentException, $ArgumentName, 'InvalidArgument', $null ) + ArgumentList = @( + $argumentException + $ArgumentName + 'InvalidArgument' + $null + ) } + $errorRecord = New-Object @newObjectParams throw $errorRecord @@ -85,7 +100,7 @@ function New-InvalidOperationException param ( [ValidateNotNullOrEmpty()] - [String] + [System.String] $Message, [ValidateNotNull()] @@ -100,20 +115,29 @@ function New-InvalidOperationException elseif ($null -eq $ErrorRecord) { $invalidOperationException = - New-Object -TypeName 'InvalidOperationException' -ArgumentList @( $Message ) + New-Object -TypeName 'InvalidOperationException' -ArgumentList @( + $Message + ) } else { $invalidOperationException = - New-Object -TypeName 'InvalidOperationException' -ArgumentList @( $Message, - $ErrorRecord.Exception ) + New-Object -TypeName 'InvalidOperationException' -ArgumentList @( + $Message + $ErrorRecord.Exception + ) } $newObjectParams = @{ TypeName = 'System.Management.Automation.ErrorRecord' - ArgumentList = @( $invalidOperationException.ToString(), 'MachineStateIncorrect', - 'InvalidOperation', $null ) + ArgumentList = @( + $invalidOperationException.ToString() + 'MachineStateIncorrect' + 'InvalidOperation' + $null + ) } + $errorRecordToThrow = New-Object @newObjectParams throw $errorRecordToThrow } @@ -141,12 +165,12 @@ function Get-LocalizedData ( [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $ResourceName, [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()] - [String] + [System.String] $ResourcePath ) @@ -166,5 +190,8 @@ function Get-LocalizedData return $localizedData } -Export-ModuleMember -Function @( 'Test-IsNanoServer', 'New-InvalidArgumentException', - 'New-InvalidOperationException', 'Get-LocalizedData' ) +Export-ModuleMember -Function ` + Test-IsNanoServer, ` + New-InvalidArgumentException, ` + New-InvalidOperationException, ` + Get-LocalizedData From 1dd42fe8e0bac29e54ef56eb252b014b20158cf6 Mon Sep 17 00:00:00 2001 From: Katie Keim Date: Wed, 24 Oct 2018 15:24:59 -0700 Subject: [PATCH 18/18] Releasing version 4.2.0.0 --- CHANGELOG.md | 2 ++ Modules/StorageDsc/StorageDsc.psd1 | 27 +++++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e21345e..8a6e77bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +## 4.2.0.0 + - Disk: - Added `PartitionStyle` parameter - Fixes [Issue #137](https://github.com/PowerShell/StorageDsc/issues/37). - Changed MOF name from `MSFT_Disk` to `MSFTDSC_Disk` to remove conflict diff --git a/Modules/StorageDsc/StorageDsc.psd1 b/Modules/StorageDsc/StorageDsc.psd1 index 4709f1c4..812fc476 100644 --- a/Modules/StorageDsc/StorageDsc.psd1 +++ b/Modules/StorageDsc/StorageDsc.psd1 @@ -10,7 +10,7 @@ # RootModule = '' # Version number of this module. -moduleVersion = '4.1.0.0' +moduleVersion = '4.2.0.0' # ID used to uniquely identify this module GUID = '00d73ca1-58b5-46b7-ac1a-5bfcf5814faf' @@ -102,18 +102,20 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '- Enabled PSSA rule violations to fail build - Fixes [Issue 149](https://github.com/PowerShell/StorageDsc/issues/149). -- Fixed markdown rule violations in CHANGELOG.MD. + ReleaseNotes = '- Disk: + - Added `PartitionStyle` parameter - Fixes [Issue 137](https://github.com/PowerShell/StorageDsc/issues/37). + - Changed MOF name from `MSFT_Disk` to `MSFTDSC_Disk` to remove conflict + with Windows built-in CIM class - Fixes [Issue 167](https://github.com/PowerShell/StorageDsc/issues/167). +- Opt-in to Common Tests: + - Common Tests - Validate Example Files To Be Published + - Common Tests - Validate Markdown Links + - Common Tests - Relative Path Length +- Added .VSCode settings for applying DSC PSSA rules - fixes [Issue 168](https://github.com/PowerShell/StorageDsc/issues/168). - Disk: - - Corrected message strings. - - Added message when partition resize required but `AllowDestructive` - parameter is not enabled. - - Fix error when `Size` not specified and `AllowDestructive` is `$true` - and partition can be expanded - Fixes [Issue 162](https://github.com/PowerShell/StorageDsc/issues/162). - - Fix incorrect error displaying when newly created partition is not - made Read/Write. - - Change verbose messages to show warnings when a partition resize would - have occured but the `AllowDestructive` flag is set to `$false`. + - Added "defragsvc" service conflict known issue to README.MD - fixes + [Issue 172](https://github.com/PowerShell/StorageDsc/issues/172). +- Corrected style violations in StorageDsc.Common module - fixes [Issue 153](https://github.com/PowerShell/StorageDsc/issues/153). +- Corrected style violations in StorageDsc.ResourceHelper module. ' @@ -139,3 +141,4 @@ PrivateData = @{ +