From 2aa8c45de8a975301da55ac3bf2889e4da77e75a Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 25 Jan 2019 13:38:03 -0500 Subject: [PATCH 01/48] added NoDefaultDriveLetter param and set-partition --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 724dd417..93c178da 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -162,6 +162,10 @@ function Set-TargetResource [System.String] $AccessPath, + [Parameter()] + [System.Boolean] + $NoDefaultDriveLetter = $true, + [Parameter(Mandatory = $true)] [System.String] $DiskId, @@ -497,6 +501,10 @@ function Set-TargetResource -DiskNumber $disk.Number ` -PartitionNumber $partition.PartitionNumber + Set-Partition -PartitionNumber $partition.PartitionNumber ` + -DiskNumber $disk.Number ` + -NoDefaultDriveLetter $NoDefaultDriveLetter + Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.SuccessfullyInitializedMessage -f $AccessPath) From 6d0b4837152c680b867f49a7575d3493abe423b1 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 25 Jan 2019 13:52:34 -0500 Subject: [PATCH 02/48] update diskaccesspath schema mof --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof | 1 + 1 file changed, 1 insertion(+) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof index 3e49fd07..9c05ebe1 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.schema.mof @@ -3,6 +3,7 @@ class MSFT_DiskAccessPath : OMI_BaseResource { [Key, Description("Specifies the access path folder to the assign the disk volume to.")] String AccessPath; + [Write, Description("Specifies no automatic drive letter assignment to the partition: Defaults to True")] Boolean NoDefaultDriveLetter; [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 size of new volume.")] Uint64 Size; From 145ed822f88bdbb2983c07312d24d1295e15cbfa Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 25 Jan 2019 13:55:50 -0500 Subject: [PATCH 03/48] update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57b26aef..b5aa1d4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ - Moved the Code of Conduct text out of the README.md and into a CODE\_OF\_CONDUCT.md file. +- DiskAccessPath + update the resource to not assign a drive letter by default when adding + a disk access path. Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). + ## 4.3.0.0 - WaitForDisk: From 307b593a91e08540b90a520ce85ec8569d375e31 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 25 Jan 2019 14:29:27 -0500 Subject: [PATCH 04/48] update comments and changelog --- CHANGELOG.md | 9 +++++++-- .../MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5aa1d4f..5b04c5cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,13 @@ CODE\_OF\_CONDUCT.md file. - DiskAccessPath - update the resource to not assign a drive letter by default when adding - a disk access path. Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). + Update the resource to not assign a drive letter by default when adding + a disk access path. Adding a Set-Partition -NoDefaultDriveLetter $NoDefaultDriveLetter block + defaulting to true. When adding access paths the disks will no longer have + drive letters automatically assigned on next reboot which is the desired + behavior. + + Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). ## 4.3.0.0 diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 93c178da..41e6d092 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -501,6 +501,7 @@ function Set-TargetResource -DiskNumber $disk.Number ` -PartitionNumber $partition.PartitionNumber + # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot Set-Partition -PartitionNumber $partition.PartitionNumber ` -DiskNumber $disk.Number ` -NoDefaultDriveLetter $NoDefaultDriveLetter From b500eadca5845d4d9af402f7df9f49fd57905c84 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 25 Jan 2019 14:45:41 -0500 Subject: [PATCH 05/48] adding get-target param and return --- .../MSFT_DiskAccessPath.psm1 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 41e6d092..d2fc3f62 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -55,6 +55,10 @@ function Get-TargetResource [System.String] $AccessPath, + [Parameter()] + [System.Boolean] + $NoDefaultDriveLetter = $true, + [Parameter(Mandatory = $true)] [System.String] $DiskId, @@ -115,13 +119,14 @@ function Get-TargetResource -ErrorAction SilentlyContinue).BlockSize $returnValue = @{ - DiskId = $DiskId - DiskIdType = $DiskIdType - AccessPath = $AccessPath - Size = $assignedPartition.Size - FSLabel = $FSLabel - AllocationUnitSize = $blockSize - FSFormat = $fileSystem + DiskId = $DiskId + DiskIdType = $DiskIdType + AccessPath = $AccessPath + NoDefaultDriveLetter = $partition.NoDefaultDriveLetter + Size = $assignedPartition.Size + FSLabel = $FSLabel + AllocationUnitSize = $blockSize + FSFormat = $fileSystem } $returnValue } # Get-TargetResource From 30710ad566946c13a13e4c7e257d75d4d1ca3328 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 25 Jan 2019 15:05:20 -0500 Subject: [PATCH 06/48] adding parameter synop and localized message with test-target on param --- .../MSFT_DiskAccessPath.psm1 | 24 +++++++++++++++++++ .../en-us/MSFT_DiskAccessPath.strings.psd1 | 1 + 2 files changed, 25 insertions(+) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index d2fc3f62..42501d0c 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -27,6 +27,9 @@ $localizedData = Get-LocalizedData ` .PARAMETER AccessPath Specifies the access path folder to the assign the disk volume to + .PARAMETER NoDefaultDriveLetter + Specifies the partition drive letter assignment behavior. Defaults to True. + .PARAMETER DiskId Specifies the disk identifier for the disk to modify. @@ -138,6 +141,9 @@ function Get-TargetResource .PARAMETER AccessPath Specifies the access path folder to the assign the disk volume to + .PARAMETER NoDefaultDriveLetter + Specifies the partition drive letter assignment behavior. Defaults to True. + .PARAMETER DiskId Specifies the disk identifier for the disk to modify. @@ -525,6 +531,9 @@ function Set-TargetResource .PARAMETER AccessPath Specifies the access path folder to the assign the disk volume to + .PARAMETER NoDefaultDriveLetter + Specifies the partition drive letter assignment behavior. Defaults to True. + .PARAMETER DiskId Specifies the disk identifier for the disk to modify. @@ -553,6 +562,10 @@ function Test-TargetResource [System.String] $AccessPath, + [Parameter()] + [System.Boolean] + $NoDefaultDriveLetter = $true, + [Parameter(Mandatory = $true)] [System.String] $DiskId, @@ -637,6 +650,17 @@ function Test-TargetResource # Get the partitions on the disk $partition = $disk | Get-Partition -ErrorAction SilentlyContinue + # Check if the partition NoDefaultDriveLetter parameter is correct + + if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($localizedData.NoDefaultDriveLetterMismatchMessage -f $NoDefaultDriveLetter) + ) -join '' ) + return $false + } # if + # Check if the disk has an existing partition assigned to the access path $assignedPartition = $partition | Where-Object -Property AccessPaths -Contains -Value $AccessPath diff --git a/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 b/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 index 775fcc85..ca7fe1f1 100644 --- a/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 +++ b/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 @@ -20,6 +20,7 @@ DiskReadOnlyMessage = Disk with {0} '{1}'is readonly. DiskNotGPTMessage = Disk with {0} '{1}' is initialised with '{2}' partition style. GPT required. AccessPathNotFoundMessage = A volume assigned to access path '{0}' was not found. + NoDefaultDriveLetterMismatchMessage = Partition default drive assigmemt parameter does not match '{0}'. SizeMismatchMessage = Partition assigned to access path '{0}' has size {1}, which does not match expected size {2}. AllocationUnitSizeMismatchMessage = Volume assigned to access path '{0}' has allocation unit size {1} KB does not match expected allocation unit size {2} KB. FileSystemFormatMismatch = Volume assigned to access path '{0}' filesystem format '{1}' does not match expected format '{2}'. From 91c04eb00451a5a08ca26406f81d06f61a99e671 Mon Sep 17 00:00:00 2001 From: Daniel Scott-Raynsford Date: Mon, 28 Jan 2019 19:26:54 +1300 Subject: [PATCH 07/48] Opt-in to Example Publishing --- CHANGELOG.md | 2 ++ appveyor.yml | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a63685e8..cac14424 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Opt-in to Example publishing to PowerShell Gallery - fixes [Issue #186](https://github.com/PowerShell/StorageDsc/issues/186). + ## 4.4.0.0 - Refactored module folder structure to move resource to root folder of diff --git a/appveyor.yml b/appveyor.yml index 146e15ea..00806ad7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -38,5 +38,4 @@ deploy_script: -Type 'Wiki' ` -ResourceModuleName $moduleName - Invoke-AppVeyorDeployTask ` - -OptIn @() + Invoke-AppVeyorDeployTask From 8a353db052be7f00a0b0ebf0828ab9091af004f8 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Mon, 28 Jan 2019 16:45:11 -0500 Subject: [PATCH 08/48] fixing logic in set and test --- .../MSFT_DiskAccessPath.psm1 | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 42501d0c..7974cfdf 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -512,16 +512,29 @@ function Set-TargetResource -DiskNumber $disk.Number ` -PartitionNumber $partition.PartitionNumber + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($localizedData.SuccessfullyInitializedMessage -f $AccessPath) + ) -join '' ) + } # if + + #get the current partition state for NoDefaultDriveLetter + $partition = $disk | Get-Partition -ErrorAction SilentlyContinue + + if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) + { + # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot Set-Partition -PartitionNumber $partition.PartitionNumber ` - -DiskNumber $disk.Number ` - -NoDefaultDriveLetter $NoDefaultDriveLetter + -DiskNumber $disk.Number ` + -NoDefaultDriveLetter $NoDefaultDriveLetter Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.SuccessfullyInitializedMessage -f $AccessPath) ) -join '' ) } # if + } # Set-TargetResource <# From 34595bfa8f0cd530cb6d8023e1a3cbeed5807cd4 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Mon, 28 Jan 2019 16:51:34 -0500 Subject: [PATCH 09/48] formatting --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 1 - 1 file changed, 1 deletion(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 7974cfdf..92fc0504 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -523,7 +523,6 @@ function Set-TargetResource if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) { - # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot Set-Partition -PartitionNumber $partition.PartitionNumber ` -DiskNumber $disk.Number ` From bbadb5d1ea71b21aab6bfef0a03b1d4d2785bc10 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Mon, 28 Jan 2019 16:52:13 -0500 Subject: [PATCH 10/48] formatting --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3d06d6e..bd149760 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,8 +14,9 @@ - DiskAccessPath Update the resource to not assign a drive letter by default when adding - a disk access path. Adding a Set-Partition -NoDefaultDriveLetter $NoDefaultDriveLetter block - defaulting to true. When adding access paths the disks will no longer have + a disk access path. Adding a Set-Partition -NoDefaultDriveLetter + $NoDefaultDriveLetter block defaulting to true. + When adding access paths the disks will no longer have drive letters automatically assigned on next reboot which is the desired behavior. From 10d74c8a8fc392d71187e7e5b31a5d75f2e14197 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Mon, 28 Jan 2019 19:17:25 -0500 Subject: [PATCH 11/48] unit test run --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd149760..053efb6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ When adding access paths the disks will no longer have drive letters automatically assigned on next reboot which is the desired behavior. + -whitespace deploy 1 Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). From 6f7708b295c3e1daad3db0ce39c58070dd2429f2 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 29 Jan 2019 11:48:01 -0500 Subject: [PATCH 12/48] unit test run int --- Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 b/Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 index da5ccff5..898042f1 100644 --- a/Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 @@ -62,7 +62,7 @@ try @{ NodeName = 'localhost' AccessPath = $accessPathA - DiskId = $disk.Number + DiskId = [int]$disk.Number DiskIdType = 'Number' FSLabel = $FSLabelA Size = 100MB From 76057d8f79d1ae8f0bc921f6a8ad3ed81a8a1429 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 29 Jan 2019 13:26:45 -0500 Subject: [PATCH 13/48] unit test run int --- Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 b/Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 index 898042f1..da5ccff5 100644 --- a/Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 +++ b/Tests/Integration/MSFT_DiskAccessPath.Integration.Tests.ps1 @@ -62,7 +62,7 @@ try @{ NodeName = 'localhost' AccessPath = $accessPathA - DiskId = [int]$disk.Number + DiskId = $disk.Number DiskIdType = 'Number' FSLabel = $FSLabelA Size = 100MB From 0a1d73658bdaec6e503ce3e90ad1ef0280c1f31d Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 29 Jan 2019 18:55:39 -0500 Subject: [PATCH 14/48] adding fix for selecting the partition from and array based on access path --- .../MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 92fc0504..f8568c0c 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -519,19 +519,20 @@ function Set-TargetResource } # if #get the current partition state for NoDefaultDriveLetter - $partition = $disk | Get-Partition -ErrorAction SilentlyContinue + $partition = $disk | Get-Partition | + Where-Object -Property AccessPaths -Contains -Value $AccessPath -ErrorAction SilentlyContinue if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $NoDefaultDriveLetter)" + ) -join '' ) + # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot Set-Partition -PartitionNumber $partition.PartitionNumber ` -DiskNumber $disk.Number ` -NoDefaultDriveLetter $NoDefaultDriveLetter - - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($localizedData.SuccessfullyInitializedMessage -f $AccessPath) - ) -join '' ) } # if } # Set-TargetResource From 339100a85a89fffbd827f27c293cdbdd115065c1 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 29 Jan 2019 19:24:59 -0500 Subject: [PATCH 15/48] fix return partition data for NoDefaultDriveLetter in get --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index f8568c0c..f8a2c8f8 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -125,7 +125,7 @@ function Get-TargetResource DiskId = $DiskId DiskIdType = $DiskIdType AccessPath = $AccessPath - NoDefaultDriveLetter = $partition.NoDefaultDriveLetter + NoDefaultDriveLetter = $assignedPartition.NoDefaultDriveLetter Size = $assignedPartition.Size FSLabel = $FSLabel AllocationUnitSize = $blockSize From c10f31b7823d8ca114e092abf23850c1f2053a23 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 29 Jan 2019 19:42:05 -0500 Subject: [PATCH 16/48] adding mocks for set-partition that wil run any time Add-PartitionAccessPath is called --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index c9e0edac..3aa78f29 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -545,6 +545,10 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -611,6 +615,10 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -678,6 +686,10 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -745,6 +757,10 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -815,6 +831,10 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -880,6 +900,10 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -942,6 +966,10 @@ try -MockWith { $script:mockedPartition } ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` From b27167adca50e6a893edbcd0f8679d5aaf63c6cb Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 09:11:56 -0500 Subject: [PATCH 17/48] adjusting NoDefaultDriveLetterMismatchMessage for debugging unit tests --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 2 +- .../MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index f8a2c8f8..bbb30fa1 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -526,7 +526,7 @@ function Set-TargetResource { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $NoDefaultDriveLetter)" + "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $partition.NoDefaultDriveLetter, $NoDefaultDriveLetter)" ) -join '' ) # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot diff --git a/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 b/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 index ca7fe1f1..b553a135 100644 --- a/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 +++ b/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 @@ -20,7 +20,7 @@ DiskReadOnlyMessage = Disk with {0} '{1}'is readonly. DiskNotGPTMessage = Disk with {0} '{1}' is initialised with '{2}' partition style. GPT required. AccessPathNotFoundMessage = A volume assigned to access path '{0}' was not found. - NoDefaultDriveLetterMismatchMessage = Partition default drive assigmemt parameter does not match '{0}'. + NoDefaultDriveLetterMismatchMessage = Partition default drive assigmemt parameter '{0}' does not match '{1}'. SizeMismatchMessage = Partition assigned to access path '{0}' has size {1}, which does not match expected size {2}. AllocationUnitSizeMismatchMessage = Volume assigned to access path '{0}' has allocation unit size {1} KB does not match expected allocation unit size {2} KB. FileSystemFormatMismatch = Volume assigned to access path '{0}' filesystem format '{1}' does not match expected format '{2}'. From fe14d81117fb4cf2d6b880641be57284889778ae Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 11:24:31 -0500 Subject: [PATCH 18/48] adjusting if to check for null partition return --- .../MSFT_DiskAccessPath.psm1 | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index bbb30fa1..62d966df 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -522,17 +522,20 @@ function Set-TargetResource $partition = $disk | Get-Partition | Where-Object -Property AccessPaths -Contains -Value $AccessPath -ErrorAction SilentlyContinue - if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) + if ($partition.NoDefaultDriveLetter) { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $partition.NoDefaultDriveLetter, $NoDefaultDriveLetter)" - ) -join '' ) + if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $partition.NoDefaultDriveLetter, $NoDefaultDriveLetter)" + ) -join '' ) - # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot - Set-Partition -PartitionNumber $partition.PartitionNumber ` - -DiskNumber $disk.Number ` - -NoDefaultDriveLetter $NoDefaultDriveLetter + # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot + Set-Partition -PartitionNumber $partition.PartitionNumber ` + -DiskNumber $disk.Number ` + -NoDefaultDriveLetter $NoDefaultDriveLetter + } # if } # if } # Set-TargetResource From f1f1c70efe49875d5e515a0f3c4a746f3ed34991 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 12:11:43 -0500 Subject: [PATCH 19/48] unit tests --- .../MSFT_DiskAccessPath.psm1 | 1 - Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 56 +++++++++++-------- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 62d966df..3a18102c 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -667,7 +667,6 @@ function Test-TargetResource $partition = $disk | Get-Partition -ErrorAction SilentlyContinue # Check if the partition NoDefaultDriveLetter parameter is correct - if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) { Write-Verbose -Message ( @( diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 3aa78f29..552b5137 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -545,10 +545,6 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable - Mock ` - -CommandName Set-Partition ` - -Verifiable - Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -562,6 +558,10 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + # mocks that should not be called Mock -CommandName Initialize-Disk @@ -586,6 +586,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -615,10 +616,6 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable - Mock ` - -CommandName Set-Partition ` - -Verifiable - Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -632,6 +629,10 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + # mocks that should not be called Mock -CommandName Initialize-Disk @@ -657,6 +658,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -686,10 +688,6 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable - Mock ` - -CommandName Set-Partition ` - -Verifiable - Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -703,6 +701,11 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + + # mocks that should not be called Mock -CommandName Initialize-Disk @@ -728,6 +731,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -798,6 +802,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -831,10 +836,6 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable - Mock ` - -CommandName Set-Partition ` - -Verifiable - Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -848,6 +849,10 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + # mocks that should not be called It 'Should not throw an exception' { @@ -871,6 +876,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -900,10 +906,6 @@ try -MockWith { $script:mockedPartitionNoAccess } ` -Verifiable - Mock ` - -CommandName Set-Partition ` - -Verifiable - Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -917,6 +919,10 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + # mocks that should not be called Mock -CommandName Set-Disk @@ -941,6 +947,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -966,10 +973,6 @@ try -MockWith { $script:mockedPartition } ` -Verifiable - Mock ` - -CommandName Set-Partition ` - -Verifiable - Mock ` -CommandName Get-Volume ` -MockWith { $script:mockedVolumeUnformatted } ` @@ -983,6 +986,10 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + # mocks that should not be called Mock -CommandName Set-Disk Mock -CommandName Initialize-Disk @@ -1008,6 +1015,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } From 0e0b98e397524f5e8e3c44d4528f3d5a1c311af9 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 12:35:33 -0500 Subject: [PATCH 20/48] fix $partition.NoDefaultDriveLetter verbose params --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 3a18102c..349e1224 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -671,7 +671,7 @@ function Test-TargetResource { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - $($localizedData.NoDefaultDriveLetterMismatchMessage -f $NoDefaultDriveLetter) + $($localizedData.NoDefaultDriveLetterMismatchMessage -f $partition.NoDefaultDriveLetter, $NoDefaultDriveLetter) ) -join '' ) return $false } # if From 0b9cb7ffb2f0c8e7277feb4b8c1443a429f3b7a9 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 12:45:11 -0500 Subject: [PATCH 21/48] fix $partition.NoDefaultDriveLetter in set also --- .../MSFT_DiskAccessPath.psm1 | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 349e1224..0a7514b9 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -519,8 +519,8 @@ function Set-TargetResource } # if #get the current partition state for NoDefaultDriveLetter - $partition = $disk | Get-Partition | - Where-Object -Property AccessPaths -Contains -Value $AccessPath -ErrorAction SilentlyContinue + $assignedPartition = $partition | + Where-Object -Property AccessPaths -Contains -Value $AccessPath if ($partition.NoDefaultDriveLetter) { @@ -528,11 +528,11 @@ function Set-TargetResource { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " - "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $partition.NoDefaultDriveLetter, $NoDefaultDriveLetter)" + "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $assignedPartition.NoDefaultDriveLetter, $NoDefaultDriveLetter)" ) -join '' ) # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot - Set-Partition -PartitionNumber $partition.PartitionNumber ` + Set-Partition -PartitionNumber $assignedPartition.PartitionNumber ` -DiskNumber $disk.Number ` -NoDefaultDriveLetter $NoDefaultDriveLetter } # if @@ -666,15 +666,7 @@ function Test-TargetResource # Get the partitions on the disk $partition = $disk | Get-Partition -ErrorAction SilentlyContinue - # Check if the partition NoDefaultDriveLetter parameter is correct - if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) - { - Write-Verbose -Message ( @( - "$($MyInvocation.MyCommand): " - $($localizedData.NoDefaultDriveLetterMismatchMessage -f $partition.NoDefaultDriveLetter, $NoDefaultDriveLetter) - ) -join '' ) - return $false - } # if + # Check if the disk has an existing partition assigned to the access path $assignedPartition = $partition | @@ -689,6 +681,16 @@ function Test-TargetResource return $false } # if + # Check if the partition NoDefaultDriveLetter parameter is correct + if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) + { + Write-Verbose -Message ( @( + "$($MyInvocation.MyCommand): " + $($localizedData.NoDefaultDriveLetterMismatchMessage -f $assignedPartition.NoDefaultDriveLetter, $NoDefaultDriveLetter) + ) -join '' ) + return $false + } # if + # Partition size was passed so check it if ($Size) { From 1d45fb2bee073ad359a80aac4990d39d572d43f0 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 12:46:54 -0500 Subject: [PATCH 22/48] fix $partition.NoDefaultDriveLetter in set also --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 0a7514b9..4235fab6 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -522,9 +522,9 @@ function Set-TargetResource $assignedPartition = $partition | Where-Object -Property AccessPaths -Contains -Value $AccessPath - if ($partition.NoDefaultDriveLetter) + if ($assignedPartition.NoDefaultDriveLetter) { - if ($partition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) + if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) { Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " From f61cf5f9f385ea3bffedcfc7e97291897eb0b929 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 12:57:22 -0500 Subject: [PATCH 23/48] fix PartitionAlreadyAssignedMessage returns array in some cases --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 4235fab6..5af20fae 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -424,7 +424,7 @@ function Set-TargetResource Write-Verbose -Message ( @( "$($MyInvocation.MyCommand): " $($localizedData.PartitionAlreadyAssignedMessage -f ` - $AccessPath, $partition.PartitionNumber) + $AccessPath, $assignedPartition.PartitionNumber) ) -join '' ) $assignAccessPath = $false From 854559c44a1380dbff5f9b718251899330c85156 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 13:20:59 -0500 Subject: [PATCH 24/48] fixed logic for if defautl drive letter --- DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 3 --- 1 file changed, 3 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 5af20fae..9cb1ef5b 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -522,8 +522,6 @@ function Set-TargetResource $assignedPartition = $partition | Where-Object -Property AccessPaths -Contains -Value $AccessPath - if ($assignedPartition.NoDefaultDriveLetter) - { if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter) { Write-Verbose -Message ( @( @@ -536,7 +534,6 @@ function Set-TargetResource -DiskNumber $disk.Number ` -NoDefaultDriveLetter $NoDefaultDriveLetter } # if - } # if } # Set-TargetResource From 021c2fa8e41e022177107296e32c59eb8ffd80bc Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 13:39:41 -0500 Subject: [PATCH 25/48] adding param -NoDefaultDriveLetter $script:NoDefaultDriveLetter to unit tests --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 552b5137..d1d32c49 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -33,6 +33,7 @@ try $script:testDiskUniqueId = 'TESTDISKUNIQUEID' $script:testDiskGptGuid = [guid]::NewGuid() $script:testDiskMbrGuid = '123456' + $script:NoDefaultDriveLetter = $true $script:mockedDisk0 = [pscustomobject] @{ Number = $script:testDiskNumber @@ -1670,6 +1671,7 @@ try $script:result = Test-TargetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -AllocationUnitSize 4096 ` -Size 124 ` -Verbose @@ -1724,6 +1726,7 @@ try $script:result = Test-TargetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -AllocationUnitSize 4097 ` -Verbose } | Should -Not -Throw @@ -1780,6 +1783,7 @@ try $script:result = Test-TargetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -FSFormat 'ReFS' ` -Verbose } | Should -Not -Throw @@ -1835,6 +1839,7 @@ try $script:result = Test-TargetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -FSLabel 'NewLabel' ` -Verbose } | Should -Not -Throw @@ -1890,6 +1895,7 @@ try $script:result = Test-TargetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -AllocationUnitSize 4096 ` -Size $script:mockedPartition.Size ` -FSFormat $script:mockedVolume.FileSystem ` From 9515dc936e34fcbbc4c82e184dbd6e58474ee108 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 13:43:22 -0500 Subject: [PATCH 26/48] adding param -NoDefaultDriveLetter $script:NoDefaultDriveLetter to unit tests --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index d1d32c49..9a664c32 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -1207,6 +1207,7 @@ try Set-targetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -Verbose } | Should -Not -Throw } @@ -1264,6 +1265,7 @@ try Set-targetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -Size $script:mockedPartitionSize ` -Verbose } | Should -Not -Throw @@ -1322,6 +1324,7 @@ try Set-targetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -Verbose } | Should -Not -Throw } @@ -1380,6 +1383,7 @@ try Set-targetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -FSLabel 'NewLabel' ` -Verbose } | Should -Not -Throw From a1bb926ceb7e20eede95a42e066819df4b27abd9 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 14:06:53 -0500 Subject: [PATCH 27/48] adding param to mocked partition --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 9a664c32..0020d1b4 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -87,6 +87,7 @@ try IsOffline = $false IsReadOnly = $false PartitionStyle = 'Raw' + NoDefaultDriveLetter = $true } $script:mockedCim = [pscustomobject] @{BlockSize = 4096} @@ -98,9 +99,10 @@ try '\\?\Volume{2d313fdd-e4a4-4f31-9784-dad758e0030f}\' $script:testAccessPath ) - Size = $script:mockedPartitionSize - PartitionNumber = 1 - Type = 'Basic' + Size = $script:mockedPartitionSize + PartitionNumber = 1 + Type = 'Basic' + NoDefaultDriveLetter = $script:NoDefaultDriveLetter } $script:mockedPartitionNoAccess = [pscustomobject] @{ From c86cbae220451869624a8d9492e3503ea2ca35e5 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 14:22:20 -0500 Subject: [PATCH 28/48] remove mock call set-partition --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 0020d1b4..aaf2636c 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -112,6 +112,7 @@ try Size = $script:mockedPartitionSize PartitionNumber = 1 Type = 'Basic' + NoDefaultDriveLetter = $script:NoDefaultDriveLetter } $script:mockedVolume = [pscustomobject] @{ @@ -589,7 +590,6 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 - Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -645,6 +645,7 @@ try -DiskId $script:mockedDisk0Offline.UniqueId ` -DiskIdType 'UniqueId' ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -Verbose } | Should -Not -Throw } @@ -661,7 +662,6 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 - Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -734,7 +734,6 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 - Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -805,7 +804,6 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 - Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -879,7 +877,6 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 - Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -950,7 +947,6 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 - Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -1002,6 +998,7 @@ try Set-targetResource ` -DiskId $script:mockedDisk0.Number ` -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` -Verbose } | Should -Not -Throw } @@ -1018,7 +1015,6 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 - Assert-MockCalled -CommandName Set-Partition -Times 1 } } From 0fda5deee07a79347c4d6cb5d8ae92ca6dc55f01 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 14:28:05 -0500 Subject: [PATCH 29/48] changelog update --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 053efb6b..bd149760 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,6 @@ When adding access paths the disks will no longer have drive letters automatically assigned on next reboot which is the desired behavior. - -whitespace deploy 1 Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). From e9cb26d6b9c5c3899b627b5cb28f8ac236ecbcbf Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 14:48:11 -0500 Subject: [PATCH 30/48] fixing noaccess mock partition and adding set-partition mock tests --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index aaf2636c..9fcf2fe9 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -108,6 +108,7 @@ try $script:mockedPartitionNoAccess = [pscustomobject] @{ AccessPaths = @( '\\?\Volume{2d313fdd-e4a4-4f31-9784-dad758e0030f}\' + $script:testAccessPath ) Size = $script:mockedPartitionSize PartitionNumber = 1 @@ -590,6 +591,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -662,6 +664,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -734,6 +737,8 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 + } } @@ -804,6 +809,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -877,6 +883,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -947,6 +954,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -1015,6 +1023,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 1 Assert-MockCalled -CommandName Format-Volume -Times 1 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -1281,6 +1290,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 0 Assert-MockCalled -CommandName Format-Volume -Times 0 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } @@ -1339,6 +1349,7 @@ try Assert-MockCalled -CommandName New-Partition -Times 0 Assert-MockCalled -CommandName Format-Volume -Times 0 Assert-MockCalled -CommandName Add-PartitionAccessPath -Times 1 + Assert-MockCalled -CommandName Set-Partition -Times 1 } } From 237005a659f18ad04bed45585fa62c142548c17c Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 15:09:35 -0500 Subject: [PATCH 31/48] testing set-partition mocks with parition obj set as false --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 9fcf2fe9..7f0c70aa 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -87,7 +87,6 @@ try IsOffline = $false IsReadOnly = $false PartitionStyle = 'Raw' - NoDefaultDriveLetter = $true } $script:mockedCim = [pscustomobject] @{BlockSize = 4096} @@ -102,7 +101,7 @@ try Size = $script:mockedPartitionSize PartitionNumber = 1 Type = 'Basic' - NoDefaultDriveLetter = $script:NoDefaultDriveLetter + NoDefaultDriveLetter = $false } $script:mockedPartitionNoAccess = [pscustomobject] @{ @@ -113,7 +112,7 @@ try Size = $script:mockedPartitionSize PartitionNumber = 1 Type = 'Basic' - NoDefaultDriveLetter = $script:NoDefaultDriveLetter + NoDefaultDriveLetter = $false } $script:mockedVolume = [pscustomobject] @{ @@ -565,6 +564,7 @@ try Mock ` -CommandName Set-Partition ` + -Verifiable # mocks that should not be called From c338c34b2f7d5812b2d734b7d6bcd83e27d16769 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 15:17:31 -0500 Subject: [PATCH 32/48] fix typo --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 7f0c70aa..1ea15dd6 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -564,7 +564,6 @@ try Mock ` -CommandName Set-Partition ` - -Verifiable # mocks that should not be called From 57cfed33d79ad251a78a67cf90bffaf1f83b6339 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 15:23:15 -0500 Subject: [PATCH 33/48] set-partition tests on no access volume --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 1ea15dd6..1c1274fa 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -101,13 +101,12 @@ try Size = $script:mockedPartitionSize PartitionNumber = 1 Type = 'Basic' - NoDefaultDriveLetter = $false + NoDefaultDriveLetter = $True } $script:mockedPartitionNoAccess = [pscustomobject] @{ AccessPaths = @( '\\?\Volume{2d313fdd-e4a4-4f31-9784-dad758e0030f}\' - $script:testAccessPath ) Size = $script:mockedPartitionSize PartitionNumber = 1 @@ -1260,6 +1259,10 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + # mocks that should not be called Mock -CommandName Set-Disk Mock -CommandName Initialize-Disk @@ -1320,6 +1323,10 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable + Mock ` + -CommandName Set-Partition ` + -Verifiable + # mocks that should not be called Mock -CommandName Set-Disk Mock -CommandName Initialize-Disk From 29a4a261bce638e8581e1d6f006b0e5a1f4dd8c3 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 17:43:53 -0500 Subject: [PATCH 34/48] setting mocked partition defautldriveletter false to test --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 1c1274fa..6055088c 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -101,7 +101,7 @@ try Size = $script:mockedPartitionSize PartitionNumber = 1 Type = 'Basic' - NoDefaultDriveLetter = $True + NoDefaultDriveLetter = $false } $script:mockedPartitionNoAccess = [pscustomobject] @{ From f7f0789b9c2a8b8004133141b9609f698a42f02c Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 18:07:42 -0500 Subject: [PATCH 35/48] setting mocked partition defautldriveletter true to test --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 6055088c..82c0d53a 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -101,7 +101,7 @@ try Size = $script:mockedPartitionSize PartitionNumber = 1 Type = 'Basic' - NoDefaultDriveLetter = $false + NoDefaultDriveLetter = $true } $script:mockedPartitionNoAccess = [pscustomobject] @{ From 6b9bdf772a500835aed876e9023d34f234f089de Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 31 Jan 2019 18:34:03 -0500 Subject: [PATCH 36/48] adding separate parition mock when add-partitionaccesspath is run on a new partition --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 82c0d53a..c341fffa 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -104,6 +104,16 @@ try NoDefaultDriveLetter = $true } + $script:mockedPartitionNDefaultDriveLetter = [pscustomobject] @{ + AccessPaths = @( + '\\?\Volume{2d313fdd-e4a4-4f31-9784-dad758e0030f}\' + $script:testAccessPath + ) + Size = $script:mockedPartitionSize + PartitionNumber = 1 + Type = 'Basic' + NoDefaultDriveLetter = $false + } $script:mockedPartitionNoAccess = [pscustomobject] @{ AccessPaths = @( '\\?\Volume{2d313fdd-e4a4-4f31-9784-dad758e0030f}\' @@ -975,7 +985,7 @@ try Mock ` -CommandName New-Partition ` - -MockWith { $script:mockedPartition } ` + -MockWith { $script:mockedPartitionNDefaultDriveLetter } ` -Verifiable Mock ` From 2dfa84a0a7497e55c27d960fbb3d2a64cab561c6 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 5 Feb 2019 14:05:20 -0500 Subject: [PATCH 37/48] changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd149760..215a2d27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,13 +13,12 @@ - Explicitly removed extra hidden files from release package - DiskAccessPath - Update the resource to not assign a drive letter by default when adding + Updated the resource to not assign a drive letter by default when adding a disk access path. Adding a Set-Partition -NoDefaultDriveLetter $NoDefaultDriveLetter block defaulting to true. When adding access paths the disks will no longer have drive letters automatically assigned on next reboot which is the desired behavior. - Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). ## 4.3.0.0 From 490fad570d84600bc255d6c322b6dc32918e2aa9 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 5 Feb 2019 14:21:12 -0500 Subject: [PATCH 38/48] changelog --- CHANGELOG.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c7a18e6..bf1dd71b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ ## Unreleased - Opt-in to Example publishing to PowerShell Gallery - fixes [Issue #186](https://github.com/PowerShell/StorageDsc/issues/186). +- DiskAccessPath + Updated the resource to not assign a drive letter by default when adding + a disk access path. Adding a Set-Partition -NoDefaultDriveLetter + $NoDefaultDriveLetter block defaulting to true. + When adding access paths the disks will no longer have + drive letters automatically assigned on next reboot which is the desired + behavior. + Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). ## 4.4.0.0 @@ -14,15 +22,6 @@ CODE\_OF\_CONDUCT.md file. - Explicitly removed extra hidden files from release package -- DiskAccessPath - Updated the resource to not assign a drive letter by default when adding - a disk access path. Adding a Set-Partition -NoDefaultDriveLetter - $NoDefaultDriveLetter block defaulting to true. - When adding access paths the disks will no longer have - drive letters automatically assigned on next reboot which is the desired - behavior. - Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). - ## 4.3.0.0 - WaitForDisk: From b7b1ac191644e6f79fd78aea02b1174775158bca Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Thu, 7 Feb 2019 16:10:01 -0500 Subject: [PATCH 39/48] fix typo mockedPartitionNDefaultDriveLetter --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index c341fffa..084df02f 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -104,7 +104,7 @@ try NoDefaultDriveLetter = $true } - $script:mockedPartitionNDefaultDriveLetter = [pscustomobject] @{ + $script:mockedPartitionNoDefaultDriveLetter = [pscustomobject] @{ AccessPaths = @( '\\?\Volume{2d313fdd-e4a4-4f31-9784-dad758e0030f}\' $script:testAccessPath @@ -985,7 +985,7 @@ try Mock ` -CommandName New-Partition ` - -MockWith { $script:mockedPartitionNDefaultDriveLetter } ` + -MockWith { $script:mockedPartitionNoDefaultDriveLetter } ` -Verifiable Mock ` From 882b222105d8226d3c0a73454f75d151477c8435 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 8 Feb 2019 08:23:38 -0500 Subject: [PATCH 40/48] adding test-targetresource for NoDefaultDriveLetter mismatch eq false --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 084df02f..c0c87ceb 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -1889,6 +1889,62 @@ try } } + Context 'Test mismatching NoDefaultDriveLetter using Disk Number' { + # verifiable (should be called) mocks + Mock ` + -CommandName Assert-AccessPathValid ` + -MockWith { $script:testAccessPath } ` + -Verifiable + + Mock ` + -CommandName Get-DiskByIdentifier ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0.Number -and $DiskIdType -eq 'Number' } ` + -MockWith { $script:mockedDisk0 } ` + -Verifiable + + Mock ` + -CommandName Get-Partition ` + -MockWith { $script:mockedPartitionNoDefaultDriveLetter } ` + -Verifiable + + Mock ` + -CommandName Get-Volume ` + -MockWith { $script:mockedVolume } ` + -Verifiable + + Mock ` + -CommandName Get-CimInstance ` + -MockWith { $script:mockedCim } ` + -Verifiable + + $script:result = $null + + It 'Should not throw an exception' { + { + $script:result = Test-TargetResource ` + -DiskId $script:mockedDisk0.Number ` + -AccessPath $script:testAccessPath ` + -NoDefaultDriveLetter $script:NoDefaultDriveLetter ` + -FSLabel 'myLabel' ` + -Verbose + } | Should -Not -Throw + } + + It 'Should return false' { + $script:result | Should -Be $false + } + + It 'Should call the correct mocks' { + Assert-VerifiableMock + Assert-MockCalled -CommandName Assert-AccessPathValid -Times 1 + Assert-MockCalled -CommandName Get-DiskByIdentifier -Times 1 ` + -ParameterFilter { $DiskId -eq $script:mockedDisk0.Number -and $DiskIdType -eq 'Number' } + Assert-MockCalled -CommandName Get-Partition -Times 1 + Assert-MockCalled -CommandName Get-Volume -Times 1 + Assert-MockCalled -CommandName Get-CimInstance -Times 1 + } + } + Context 'Test all disk properties matching using Disk Number' { # verifiable (should be called) mocks Mock ` From 682c5973d5791da0dcc78733f5537f99765139db Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 8 Feb 2019 08:51:53 -0500 Subject: [PATCH 41/48] remove cim-instance mock - not testing block size --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index c0c87ceb..0934b958 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -1912,11 +1912,6 @@ try -MockWith { $script:mockedVolume } ` -Verifiable - Mock ` - -CommandName Get-CimInstance ` - -MockWith { $script:mockedCim } ` - -Verifiable - $script:result = $null It 'Should not throw an exception' { From e68de52d06729ef3bf05ed8b40527e8db37f9885 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 8 Feb 2019 12:20:46 -0500 Subject: [PATCH 42/48] nodriveletter test --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 0934b958..9873118f 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -1935,8 +1935,6 @@ try Assert-MockCalled -CommandName Get-DiskByIdentifier -Times 1 ` -ParameterFilter { $DiskId -eq $script:mockedDisk0.Number -and $DiskIdType -eq 'Number' } Assert-MockCalled -CommandName Get-Partition -Times 1 - Assert-MockCalled -CommandName Get-Volume -Times 1 - Assert-MockCalled -CommandName Get-CimInstance -Times 1 } } From 49c3f2348c838d193e0be7fc18f24afc3a11339a Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Fri, 8 Feb 2019 13:01:38 -0500 Subject: [PATCH 43/48] nodriveletter test --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index 9873118f..fea59b1f 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -1907,11 +1907,6 @@ try -MockWith { $script:mockedPartitionNoDefaultDriveLetter } ` -Verifiable - Mock ` - -CommandName Get-Volume ` - -MockWith { $script:mockedVolume } ` - -Verifiable - $script:result = $null It 'Should not throw an exception' { From cae19d41fe1e1b75f0458d529b3fbaf6d7570961 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 19 Feb 2019 12:06:10 -0500 Subject: [PATCH 44/48] changelog syntax fixes --- CHANGELOG.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1dd71b..4d370148 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,14 +3,13 @@ ## Unreleased - Opt-in to Example publishing to PowerShell Gallery - fixes [Issue #186](https://github.com/PowerShell/StorageDsc/issues/186). -- DiskAccessPath - Updated the resource to not assign a drive letter by default when adding - a disk access path. Adding a Set-Partition -NoDefaultDriveLetter - $NoDefaultDriveLetter block defaulting to true. - When adding access paths the disks will no longer have - drive letters automatically assigned on next reboot which is the desired - behavior. - Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). +- DiskAccessPath: + - Updated the resource to not assign a drive letter by default when adding + a disk access path. Adding a Set-Partition -NoDefaultDriveLetter + $NoDefaultDriveLetter block defaulting to true. + When adding access paths the disks will no longer have + drive letters automatically assigned on next reboot which is the desired + behavior - Fixes [Issue #145](https://github.com/PowerShell/StorageDsc/issues/145). ## 4.4.0.0 From 2d8e1a6b7c31a20e81a2b1a78251434d4a51ede3 Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 19 Feb 2019 12:12:37 -0500 Subject: [PATCH 45/48] formatting and spacing on diskaccesspath --- .../MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 index 9cb1ef5b..f963dd73 100644 --- a/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 +++ b/DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1 @@ -28,7 +28,7 @@ $localizedData = Get-LocalizedData ` Specifies the access path folder to the assign the disk volume to .PARAMETER NoDefaultDriveLetter - Specifies the partition drive letter assignment behavior. Defaults to True. + Prevents a default drive letter from being assigned to a newly created partition. Defaults to True. .PARAMETER DiskId Specifies the disk identifier for the disk to modify. @@ -142,7 +142,7 @@ function Get-TargetResource Specifies the access path folder to the assign the disk volume to .PARAMETER NoDefaultDriveLetter - Specifies the partition drive letter assignment behavior. Defaults to True. + Prevents a default drive letter from being assigned to a newly created partition. Defaults to True. .PARAMETER DiskId Specifies the disk identifier for the disk to modify. @@ -518,7 +518,7 @@ function Set-TargetResource ) -join '' ) } # if - #get the current partition state for NoDefaultDriveLetter + # Get the current partition state for NoDefaultDriveLetter $assignedPartition = $partition | Where-Object -Property AccessPaths -Contains -Value $AccessPath @@ -529,12 +529,11 @@ function Set-TargetResource "$($localizedData.NoDefaultDriveLetterMismatchMessage -f $assignedPartition.NoDefaultDriveLetter, $NoDefaultDriveLetter)" ) -join '' ) - # setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot + # Setting the partition property NoDefaultDriveLetter to True to prevent adding drive letter on reboot Set-Partition -PartitionNumber $assignedPartition.PartitionNumber ` -DiskNumber $disk.Number ` -NoDefaultDriveLetter $NoDefaultDriveLetter } # if - } # Set-TargetResource <# @@ -545,7 +544,7 @@ function Set-TargetResource Specifies the access path folder to the assign the disk volume to .PARAMETER NoDefaultDriveLetter - Specifies the partition drive letter assignment behavior. Defaults to True. + Prevents a default drive letter from being assigned to a newly created partition. Defaults to True. .PARAMETER DiskId Specifies the disk identifier for the disk to modify. @@ -663,8 +662,6 @@ function Test-TargetResource # Get the partitions on the disk $partition = $disk | Get-Partition -ErrorAction SilentlyContinue - - # Check if the disk has an existing partition assigned to the access path $assignedPartition = $partition | Where-Object -Property AccessPaths -Contains -Value $AccessPath From a92e0658a526ee5941109f6a15baf9a06b0a97ad Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 19 Feb 2019 12:13:51 -0500 Subject: [PATCH 46/48] clarify NoDefaultDriveLetterMismatchMessage letter --- .../MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 b/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 index b553a135..80f68c89 100644 --- a/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 +++ b/DSCResources/MSFT_DiskAccessPath/en-us/MSFT_DiskAccessPath.strings.psd1 @@ -20,7 +20,7 @@ DiskReadOnlyMessage = Disk with {0} '{1}'is readonly. DiskNotGPTMessage = Disk with {0} '{1}' is initialised with '{2}' partition style. GPT required. AccessPathNotFoundMessage = A volume assigned to access path '{0}' was not found. - NoDefaultDriveLetterMismatchMessage = Partition default drive assigmemt parameter '{0}' does not match '{1}'. + NoDefaultDriveLetterMismatchMessage = Partition default drive letter assigmemt parameter '{0}' does not match '{1}'. SizeMismatchMessage = Partition assigned to access path '{0}' has size {1}, which does not match expected size {2}. AllocationUnitSizeMismatchMessage = Volume assigned to access path '{0}' has allocation unit size {1} KB does not match expected allocation unit size {2} KB. FileSystemFormatMismatch = Volume assigned to access path '{0}' filesystem format '{1}' does not match expected format '{2}'. From 7575659b76cb2860164e6672a9e3b2f890f4949c Mon Sep 17 00:00:00 2001 From: Josh Swain Date: Tue, 19 Feb 2019 12:22:53 -0500 Subject: [PATCH 47/48] clarify unit test context and formatting --- Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 index fea59b1f..247ab8f7 100644 --- a/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 +++ b/Tests/Unit/MSFT_DiskAccessPath.Tests.ps1 @@ -532,7 +532,7 @@ try #region Function Set-TargetResource Describe 'MSFT_DiskAccessPath\Set-TargetResource' { - Context 'Offline GPT disk using Disk Number' { + Context 'Offline GPT disk using Disk Number with NoDefaultDriveLetter set to False' { # verifiable (should be called) mocks Mock ` -CommandName Assert-AccessPathValid ` @@ -571,7 +571,7 @@ try -CommandName Add-PartitionAccessPath ` -Verifiable - Mock ` + Mock ` -CommandName Set-Partition ` -Verifiable @@ -603,7 +603,7 @@ try } } - Context 'Offline GPT disk using Disk Unique Id' { + Context 'Offline GPT disk using Disk Unique Id with NoDefaultDriveLetter set to False' { # verifiable (should be called) mocks Mock ` -CommandName Assert-AccessPathValid ` @@ -1187,7 +1187,7 @@ try } } - Context 'Online GPT disk with partition/volume already assigned using Disk Number' { + Context 'Online GPT disk with partition/volume already assigned using Disk Number with NoDefaultDriveLetter set to False' { # verifiable (should be called) mocks Mock ` -CommandName Assert-AccessPathValid ` @@ -1306,7 +1306,7 @@ try } } - Context 'Online GPT disk containing matching partition but not assigned using Disk Number with no size parameter specified' { + Context 'Online GPT disk containing matching partition but not assigned using Disk Number with no size parameter specified with NoDefaultDriveLetter set to False' { # verifiable (should be called) mocks Mock ` -CommandName Assert-AccessPathValid ` From 587c178aca01ed5a7de0e9e5ac7a642d3861b573 Mon Sep 17 00:00:00 2001 From: Katie Kragenbrink Date: Wed, 20 Feb 2019 11:19:19 -0800 Subject: [PATCH 48/48] Releasing version 4.5.0.0 --- CHANGELOG.md | 2 ++ StorageDsc.psd1 | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d370148..14f598fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +## 4.5.0.0 + - Opt-in to Example publishing to PowerShell Gallery - fixes [Issue #186](https://github.com/PowerShell/StorageDsc/issues/186). - DiskAccessPath: - Updated the resource to not assign a drive letter by default when adding diff --git a/StorageDsc.psd1 b/StorageDsc.psd1 index 3f613390..abb096a0 100644 --- a/StorageDsc.psd1 +++ b/StorageDsc.psd1 @@ -10,7 +10,7 @@ # RootModule = '' # Version number of this module. -moduleVersion = '4.4.0.0' +moduleVersion = '4.5.0.0' # ID used to uniquely identify this module GUID = '00d73ca1-58b5-46b7-ac1a-5bfcf5814faf' @@ -102,13 +102,14 @@ PrivateData = @{ # IconUri = '' # ReleaseNotes of this module - ReleaseNotes = '- Refactored module folder structure to move resource to root folder of - repository and remove test harness - fixes [Issue 169](https://github.com/PowerShell/StorageDsc/issues/169). -- Updated Examples to support deployment to PowerShell Gallery scripts. -- Removed limitation on using Pester 4.0.8 during AppVeyor CI. -- Moved the Code of Conduct text out of the README.md and into a - CODE\_OF\_CONDUCT.md file. -- Explicitly removed extra hidden files from release package + ReleaseNotes = '- Opt-in to Example publishing to PowerShell Gallery - fixes [Issue 186](https://github.com/PowerShell/StorageDsc/issues/186). +- DiskAccessPath: + - Updated the resource to not assign a drive letter by default when adding + a disk access path. Adding a Set-Partition -NoDefaultDriveLetter + $NoDefaultDriveLetter block defaulting to true. + When adding access paths the disks will no longer have + drive letters automatically assigned on next reboot which is the desired + behavior - Fixes [Issue 145](https://github.com/PowerShell/StorageDsc/issues/145). ' @@ -137,3 +138,4 @@ PrivateData = @{ +