Skip to content

Commit

Permalink
Add SerialNumber as a disk identifier to Disk, DiskAccessPath and Wai… (
Browse files Browse the repository at this point in the history
#271)

* Add SerialNumber as a disk identifier to Disk, DiskAccessPath and WaitForDisk

* Remove disk serial number integration tests

* Add integration tests back in and note in README

* Fix typo

* Create new Testing section in the Disk resource README and add note

* Move comment
  • Loading branch information
dshelb committed Feb 6, 2023
1 parent b4f8a2a commit 4a9e4fa
Show file tree
Hide file tree
Showing 14 changed files with 473 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Pin Azure build agent vmImage to ubuntu-20.04 - Fixes [Issue #270] (https://github.com/dsccommunity/StorageDsc/issues/270).
- Remove confirmation prompt when Clear-Disk is called.
- Add mock Clear-Disk function and verification tests.
- Added support to use disk SerialNumber as a disk identifer - Fixes [Issue #259](https://github.com/dsccommunity/StorageDsc/issues/259).

### Fixed

Expand Down
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_Disk/DSC_Disk.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Get-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName')]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName', 'SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down Expand Up @@ -190,7 +190,7 @@ function Set-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName')]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName', 'SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down Expand Up @@ -687,7 +687,7 @@ function Test-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName')]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName', 'SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down
2 changes: 1 addition & 1 deletion source/DSCResources/DSC_Disk/DSC_Disk.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class DSC_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","Location","FriendlyName"}, Values{"Number","UniqueId","Guid","Location","FriendlyName"}] String DiskIdType;
[Write, Description("Specifies the identifier type the DiskId contains. Defaults to Number."), ValueMap{"Number","UniqueId","Guid","Location","FriendlyName","SerialNumber"}, Values{"Number","UniqueId","Guid","Location","FriendlyName","SerialNumber"}] 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;
Expand Down
10 changes: 7 additions & 3 deletions source/DSCResources/DSC_Disk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ The resource is used to initialize, format and mount the partition/volume as a d
letter.
The disk to add the partition/volume to is selected by specifying the _DiskId_ and
optionally _DiskIdType_.
The _DiskId_ value can be a _Disk Number_, _Unique Id_, _Guid_, _Location_ or _FriendlyName_.
The _DiskId_ value can be a _Disk Number_, _Unique Id_, _Guid_, _Location_, _FriendlyName_ or _SerialNumber_.

**Important: The _Disk Number_ is not a reliable method of selecting a disk because
it has been shown to change between reboots in some environments.
It is recommended to use the _Unique Id_ if possible.**

The _Disk Number_, _Unique Id_, _Guid_, _Location_ and _FriendlyName_ can be identified for a
The _Disk Number_, _Unique Id_, _Guid_, _Location_, _FriendlyName_ and _SerialNumber_ can be identified for a
disk by using the PowerShell command:

```powershell
Get-Disk | Select-Object -Property FriendlyName,DiskNumber,UniqueId,Guid,Location
Get-Disk | Select-Object -Property FriendlyName,DiskNumber,UniqueId,Guid,Location,SerialNumber
```

Note: The _Guid_ identifier method of specifying disks is only supported as an
Expand All @@ -23,6 +23,10 @@ identifier for disks with `GPT` partition table format. If the disk is `RAW`
be used. This is because the _Guid_ for a disk is only assigned once the partition
table for the disk has been created.

# Testing
Note: Integration tests are not run for the Disk resource when SerialNumber
is used since the virtual disk that is created does not have a serial number.

## Known Issues

### Defragsvc Conflict
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Get-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName')]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName', 'SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down Expand Up @@ -173,7 +173,7 @@ function Set-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName')]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName', 'SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down Expand Up @@ -585,7 +585,7 @@ function Test-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName')]
[ValidateSet('Number', 'UniqueId', 'Guid', 'Location', 'FriendlyName', 'SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DSC_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","Location","FriendlyName"}, Values{"Number","UniqueId","Guid","Location","FriendlyName"}] String DiskIdType;
[Write, Description("Specifies the identifier type the DiskId contains. Defaults to Number."), ValueMap{"Number","UniqueId","Guid","Location","FriendlyName","SerialNumber"}, Values{"Number","UniqueId","Guid","Location","FriendlyName","SerialNumber"}] String DiskIdType;
[Write, Description("Specifies the size of new volume.")] 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;
Expand Down
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_DiskAccessPath/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ The resource is used to initialize, format and mount the partition/volume to a f
access path.
The disk to add the partition/volume to is selected by specifying the _DiskId_ and
optionally _DiskIdType_.
The _DiskId_ value can be a _Disk Number_, _Unique Id_, _Guid_, _Location_ or _FriendlyName_.
The _DiskId_ value can be a _Disk Number_, _Unique Id_, _Guid_, _Location_, _FriendlyName_ or _SerialNumber_.

**Important: The _Disk Number_ is not a reliable method of selecting a disk because
it has been shown to change between reboots in some environments.
It is recommended to use the _Unique Id_ if possible.**

The _Disk Number_, _Unique Id_, _Guid_, _Location_ and _FriendlyName_ can be identified for a
The _Disk Number_, _Unique Id_, _Guid_, _Location_, _FriendlyName_ and _SerialNumber_ can be identified for a
disk by using the PowerShell command:

```powershell
Get-Disk | Select-Object -Property FriendlyName,DiskNumber,UniqueId,Guid,Location
Get-Disk | Select-Object -Property FriendlyName,DiskNumber,UniqueId,Guid,Location,SerialNumber
```

Note: The _Guid_ for a disk is only assigned once the partition table for the disk
Expand Down
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_WaitForDisk/DSC_WaitForDisk.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Get-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number','UniqueId','Guid','Location','FriendlyName')]
[ValidateSet('Number','UniqueId','Guid','Location','FriendlyName','SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down Expand Up @@ -94,7 +94,7 @@ function Set-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number','UniqueId','Guid','Location','FriendlyName')]
[ValidateSet('Number','UniqueId','Guid','Location','FriendlyName','SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down Expand Up @@ -176,7 +176,7 @@ function Test-TargetResource
$DiskId,

[Parameter()]
[ValidateSet('Number','UniqueId','Guid','Location','FriendlyName')]
[ValidateSet('Number','UniqueId','Guid','Location','FriendlyName','SerialNumber')]
[System.String]
$DiskIdType = 'Number',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class DSC_WaitForDisk : OMI_BaseResource
{
[Key, Description("Specifies the disk identifier for the disk to wait for.")] String DiskId;
[Write, Description("Specifies the identifier type the DiskId contains. Defaults to Number."), ValueMap{"Number","UniqueId","Guid","Location","FriendlyName"}, Values{"Number","UniqueId","Guid","Location","FriendlyName"}] String DiskIdType;
[Write, Description("Specifies the identifier type the DiskId contains. Defaults to Number."), ValueMap{"Number","UniqueId","Guid","Location","FriendlyName","SerialNumber"}, Values{"Number","UniqueId","Guid","Location","FriendlyName","SerialNumber"}] String DiskIdType;
[Write, Description("Specifies the number of seconds to wait for the disk to become available.")] Uint32 RetryIntervalSec;
[Write, Description("The number of times to loop the retry interval while waiting for the disk.")] Uint32 RetryCount;
[Read, Description("Will indicate whether Disk is available.")] Boolean IsAvailable;
Expand Down
6 changes: 3 additions & 3 deletions source/DSCResources/DSC_WaitForDisk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
This resource is used to wait for a disk to become available.
The disk to wait for is selected by specifying the _DiskId_ and optionally
_DiskIdType_.
The _DiskId_ value can be a _Disk Number_, _Unique Id_, _Guid_, _Location_ or _FriendlyName_.
The _DiskId_ value can be a _Disk Number_, _Unique Id_, _Guid_, _Location_, _FriendlyName_ or _SerialNumber_.

**Important: The _Disk Number_ is not a reliable method of selecting a disk because
it has been shown to change between reboots in some environments.
It is recommended to use the _Unique Id_ if possible.**

The _Disk Number_, _Unique Id_, _Guid_, _Location_ and _FriendlyName_ can be identified for a
The _Disk Number_, _Unique Id_, _Guid_, _Location_, _FriendlyName_ and _SerialNumber_ can be identified for a
disk by using the PowerShell command:

```powershell
Get-Disk | Select-Object -Property FriendlyName,DiskNumber,UniqueId,Guid,Location
Get-Disk | Select-Object -Property FriendlyName,DiskNumber,UniqueId,Guid,Location,SerialNumber
```

Note: The _Guid_ for a disk is only assigned once the partition table for the disk
Expand Down
4 changes: 2 additions & 2 deletions source/Modules/StorageDsc.Common/StorageDsc.Common.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ function Get-DiskByIdentifier
$DiskId,

[Parameter()]
[ValidateSet('Number','UniqueId','Guid','Location','FriendlyName')]
[ValidateSet('Number','UniqueId','Guid','Location','FriendlyName','SerialNumber')]
[System.String]
$DiskIdType = 'Number'
)

switch -regex ($DiskIdType)
{
'Number|UniqueId|FriendlyName' # for filters supported by the Get-Disk CmdLet
'Number|UniqueId|FriendlyName|SerialNumber' # for filters supported by the Get-Disk CmdLet
{
$diskIdParameter = @{
$DiskIdType = $DiskId
Expand Down
Loading

0 comments on commit 4a9e4fa

Please sign in to comment.