Skip to content

Commit

Permalink
Merge pull request #198 from JoshuaJSwain/jswain_accesspath_145
Browse files Browse the repository at this point in the history
Disk-AccessPath: fixing get-partition to pull current state of object
  • Loading branch information
PlagueHO authored Apr 15, 2019
2 parents 917f6c3 + 0a3e30e commit d1683a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

- DiskAccessPath:
- Added a Get-Partition to properly handle setting the NoDefaultDriveLetter
parameter - fixes [Issue #198](https://github.com/PowerShell/StorageDsc/pull/198).

## 4.6.0.0

- Fix example publish to PowerShell Gallery by adding `gallery_api`
Expand Down
25 changes: 14 additions & 11 deletions DSCResources/MSFT_DiskAccessPath/MSFT_DiskAccessPath.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -518,22 +518,25 @@ function Set-TargetResource
) -join '' )
} # if

# Get the partitions on the disk
$partition = $disk | Get-Partition -ErrorAction SilentlyContinue

# Get the current partition state for NoDefaultDriveLetter
$assignedPartition = $partition |
Where-Object -Property AccessPaths -Contains -Value $AccessPath

if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter)
{
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
"$($localizedData.NoDefaultDriveLetterMismatchMessage -f $assignedPartition.NoDefaultDriveLetter, $NoDefaultDriveLetter)"
) -join '' )
if ($assignedPartition.NoDefaultDriveLetter -ne $NoDefaultDriveLetter)
{
Write-Verbose -Message ( @(
"$($MyInvocation.MyCommand): "
"$($localizedData.NoDefaultDriveLetterMismatchMessage -f $assignedPartition.NoDefaultDriveLetter, $NoDefaultDriveLetter)"
) -join '' )

# 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
# Setting the partition property NoDefaultDriveLetter
Set-Partition -PartitionNumber $assignedPartition.PartitionNumber `
-DiskNumber $disk.Number `
-NoDefaultDriveLetter $NoDefaultDriveLetter
} # if
} # Set-TargetResource

<#
Expand Down
22 changes: 11 additions & 11 deletions Tests/Unit/MSFT_DiskAccessPath.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0OfflineDiskIdNumber
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1
Expand Down Expand Up @@ -724,7 +724,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0OfflineDiskIdUniqueId
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1
Expand Down Expand Up @@ -797,7 +797,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0OfflineDiskIdGuid
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1
Expand Down Expand Up @@ -869,7 +869,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0ReadonlyDiskIdNumber
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1
Expand Down Expand Up @@ -943,7 +943,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0OfflineRawDiskIdNumber
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 1
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1
Expand Down Expand Up @@ -1014,7 +1014,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0RawDiskIdNumber
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-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1
Expand Down Expand Up @@ -1083,7 +1083,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0DiskIdNumber
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 1
Expand Down Expand Up @@ -1291,7 +1291,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0DiskIdNumber
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 0
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0
Expand Down Expand Up @@ -1354,7 +1354,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0DiskIdNumber
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 0
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0
Expand Down Expand Up @@ -1417,7 +1417,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0DiskIdNumber
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 2
Assert-MockCalled -CommandName New-Partition -Exactly -Times 0
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0
Expand Down Expand Up @@ -1478,7 +1478,7 @@ try
-ParameterFilter $script:parameterFilter_Disk0DiskIdNumber
Assert-MockCalled -CommandName Set-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Initialize-Disk -Exactly -Times 0
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 1
Assert-MockCalled -CommandName Get-Partition -Exactly -Times 2
Assert-MockCalled -CommandName Get-Volume -Exactly -Times 1
Assert-MockCalled -CommandName New-Partition -Exactly -Times 0
Assert-MockCalled -CommandName Format-Volume -Exactly -Times 0
Expand Down

0 comments on commit d1683a4

Please sign in to comment.