Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disk-AccessPath: fixing get-partition to pull current state of object #198

Merged
merged 7 commits into from
Apr 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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