dsccommunity / StorageDsc

DSC resource module is used to manage storage on Windows Servers.
https://dsccommunity.org
MIT License
71 stars 52 forks source link

xDiskAccessPath - One or more parameter values passed to the method were invalid #102

Closed Zuldan closed 7 years ago

Zuldan commented 7 years ago

When use xDiskAccessPath I get the error "One or more parameter values passed to the method were invalid" and "The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input." I had previously tested 2.9.0.0 and 3.1.0.0 and found both version working but I've realized today that they were being used lab servers that already had Mount Points created. Today, I created a production server (disks offline and uninitialized) and the above errors appeared with both 2.9.0.0 and 3.1.0.0. The issue exists with both disk types, DiskNumber and UniqueId.

First consistency check

VERBOSE: [LABSERVER02]: LCM:  [ Start  Set      ]  [[xDiskAccessPath]DiskAccessPathSQLDATA01]
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Setting disk with Number '4' status for access path 'C:\MountPoint\SQLDATA01'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Checking disk with Number '4' partition style.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Disk with Number '4' is already initialized with GPT.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Disk with Number '4' does not contain a partition assigned to access path 'C:\MountPoint\SQLDATA01\'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Creating partition on disk with Number '4' using all free space.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Formatting the volume as 'NTFS'.
Invoke-CimMethod : One or more parameter values passed to the method were invalid.
At C:\DSC\SQLTest.ps1:20 char:5
+     Invoke-CimMethod -CimSession $ServerName -Name PerformRequiredCon ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_Volume (Ob...0-8343-9e9f...):) [Invoke-CimMethod], CimException
    + FullyQualifiedErrorId : MI RESULT 4,Format-Volume,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
    + PSComputerName        : LABSERVER02

Invoke-CimMethod : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At C:\DSC\SQLTest.ps1:20 char:5
+     Invoke-CimMethod -CimSession $ServerName -Name PerformRequiredCon ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (MSFT_Disk (Obje...d_virtual_d...):) [Invoke-CimMethod], CimException
    + FullyQualifiedErrorId : InputObjectNotBound,Add-PartitionAccessPath,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
    + PSComputerName        : LABSERVER02

VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Successfully initialized volume and assigned to access path 'C:\MountPoint\SQLDATA01\'.
VERBOSE: [LABSERVER02]: LCM:  [ End    Set      ]  [[xDiskAccessPath]DiskAccessPathSQLDATA01]  in 3.4250 seconds.
Invoke-CimMethod : The PowerShell DSC resource '[xDiskAccessPath]DiskAccessPathSQLDATA01' with SourceInfo 'C:\Program 
Files\WindowsPowerShell\Modules\BVISMServerEnforcer\Files\Roles\BaseSQLServerStandalone\BaseSQLServerStandaloneConfig.ps1::140::17::xDiskAccessPath' threw one or more non-terminating errors while running the Set-TargetResource functionality. These errors 
are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.
At C:\DSC\SQLTest.ps1:20 char:5
+     Invoke-CimMethod -CimSession $ServerName -Name PerformRequiredCon ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-CimMethod], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
    + PSComputerName        : LABSERVER02

Second consistency check (not changing anything)

VERBOSE: [LABSERVER02]: LCM:  [ Start  Set      ]  [[xDiskAccessPath]DiskAccessPathSQLDATA01]
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Setting disk with Number '4' status for access path 'C:\MountPoint\SQLDATA01'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Checking disk with Number '4' partition style.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Disk with Number '4' is already initialized with GPT.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Disk with Number '4' does not contain a partition assigned to access path 'C:\MountPoint\SQLDATA01\'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Creating partition on disk with Number '4' using all free space.
Invoke-CimMethod : Not enough available capacity
At C:\DSC\SQLTest.ps1:20 char:5
+     Invoke-CimMethod -CimSession $ServerName -Name PerformRequiredCon ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (StorageWMI:) [Invoke-CimMethod], CimException
    + FullyQualifiedErrorId : StorageWMI 40000,New-Partition,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
    + PSComputerName        : LABSERVER02

VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Volume assigned to access path 'C:\MountPoint\SQLDATA01\' filesystem format '' does not match expected format 'NTFS'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Changing Volume assigned to access path 'C:\MountPoint\SQLDATA01\' label to 'SQLDATA01'.
Invoke-CimMethod : Cannot validate argument on parameter 'PartitionNumber'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At C:\DSC\SQLTest.ps1:20 char:5
+     Invoke-CimMethod -CimSession $ServerName -Name PerformRequiredCon ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Invoke-CimMethod], CimException

Third consistency check (manually used Disk Management to map the mount points to various directories in C:\MountPoint)

VERBOSE: [LABSERVER02]: LCM:  [ Start  Resource ]  [[xDiskAccessPath]DiskAccessPathSQLDATA01]
VERBOSE: [LABSERVER02]: LCM:  [ Start  Test     ]  [[xDiskAccessPath]DiskAccessPathSQLDATA01]
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Test-TargetResource: Testing disk with Number '4' status for access path 'C:\MountPoint\SQLDATA01'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Test-TargetResource: Checking if disk with Number '4' is initialized.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Perform operation 'Query CimInstances' with following parameters, ''queryExpression' = SELECT BlockSize from Win32_Volume WHERE Name = 'C:\\MountPoint\\SQLDATA
01\\','queryDialect' = WQL,'namespaceName' = root\cimv2'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Operation 'Query CimInstances' complete.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Test-TargetResource: Volume assigned to access path 'C:\MountPoint\SQLDATA01\' filesystem format '' does not match expected format 'NTFS'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Test-TargetResource: Volume assigned to access path 'C:\MountPoint\SQLDATA01\' label '' does not match expected label 'SQLDATA01'.
VERBOSE: [LABSERVER02]: LCM:  [ End    Test     ]  [[xDiskAccessPath]DiskAccessPathSQLDATA01]  in 0.2030 seconds.
VERBOSE: [LABSERVER02]: LCM:  [ Start  Set      ]  [[xDiskAccessPath]DiskAccessPathSQLDATA01]
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Setting disk with Number '4' status for access path 'C:\MountPoint\SQLDATA01'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Checking disk with Number '4' partition style.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Disk with Number '4' is already initialized with GPT.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Partition 'System.Object[]' is already assigned to access path 'C:\MountPoint\SQLDATA01\'.
VERBOSE: [LABSERVER02]:                            [[xDiskAccessPath]DiskAccessPathSQLDATA01] Set-TargetResource: Formatting the volume as 'NTFS'.
Invoke-CimMethod : No matching MSFT_Volume objects found by CIM query for enumerating instances of the ROOT/Microsoft/Windows/Storage/MSFT_Volume class on the  CIM server, that are associated with the following instance: MSFT_Partition (DiskId = 
"\\?\scsi#disk&ven_vmware&prod_virtual_d..., Offset = 17408). Verify query parameters and retry.
At C:\DSC\SQLTest.ps1:20 char:5
+     Invoke-CimMethod -CimSession $ServerName -Name PerformRequiredCon ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (MSFT_Volume:) [Invoke-CimMethod], CimException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound,Format-Volume,Microsoft.Management.Infrastructure.CimCmdlets.InvokeCimMethodCommand
    + PSComputerName        : LABSERVER02

VERBOSE: [LABSERVER02]: LCM:  [ End    Set      ]  [[xDiskAccessPath]DiskAccessPathSQLDATA01]  in 1.8900 seconds.

Forth consistency check (100% compliant)

PlagueHO commented 7 years ago

Hi @Zuldan - thanks for the detailed info. I'm just trying to replicate this now.

Can you confirm the OS Version you're installing onto and also if possible post the config? I'll continue to look into this now though.

Zuldan commented 7 years ago

@PlagueHO thank you for looking at this so quickly. I created a second VM just to make sure it wasn't a once off issue but got the same problem.

OS is 2012 R2 (latest Windows Updates and running WMF 5.1). The VM has 16 disks in total. I'll do my best to get you the config tonight as soon as I get access to my laptop.

I really hope this isn't just my environment and I'm wasting your time.

PlagueHO commented 7 years ago

@Zuldan - definitely want to get this one sorted. I can see some things that aren't right in your logs, but I'm just trying to figure out how they got to that state.

I'm testing on a Windows Server 2016 Hyper-V VM at the moment and using the following config to test:

Configuration Example
{

    Import-DSCResource -ModuleName xStorage

    node $AllNodes.NodeName
    {
        xWaitforDisk Disk1
        {
             DiskId = 1
             RetryIntervalSec = 60
             RetryCount = 60
        }

        xDiskAccessPath DataVolume
        {
             DiskId = 1
             AccessPath = 'c:\SQLData'
             DependsOn = '[xWaitForDisk]Disk1'
        }

        xWaitforDisk Disk2
        {
             DiskId = 2
             RetryIntervalSec = 60
             RetryCount = 60
        }

        xDiskAccessPath LogVolume
        {
             DiskId = 2
             AccessPath = 'c:\SQLLog'
             DependsOn = '[xWaitForDisk]Disk2'
        }
    }
}

$configData = @{
    AllNodes = @(
        @{
            NodeName                    = 'SA-DC1'
            PsDscAllowPlainTextPassword = $true
        }
    )
}

Example -OutputPath $ENV:Temp -ConfigurationData $configData
Start-DscConfiguration -Path $ENV:Temp -ComputerName 'SA-DC1' -Wait -Verbose -Force

Both Disk1 and Disk2 were completely uninitialized and were offline. They both resulted in the disks being onlined, partitioned, formatted and mounted to the folders as expected: image

So I'm not sure what exactly is going wrong. But I'll continue to investigate.

PlagueHO commented 7 years ago

Hi @Zuldan - are you able to describe the state your disks/partitions were before running your configs? I'm wondering if the disks being partitioned but not mounted is the problem?

The reason I'm thinking this is that I'm not seeing any info on the disks being initialized or bought online which is what I'd expect to see with a clean disk. I'm also seeing strange partition info. So I'm just trying some experiments with disks in different states, but any info you can provide will be very helpful!

Zuldan commented 7 years ago

All disks were completely uninitialized and were offline. The other info I have is disk 4 is being configured first. I guess the main difference between our environments is you have Hyper-V and I have ESXi. I wouldn't expect Powershell cmdlets to behave differently though.

I've almost got the kids in bed so more info should arrive soon.

PlagueHO commented 7 years ago

Hi @Zuldan - I've managed to replicate the problem and it seems to only occur on Windows Server 2012 R2. I've been testing on Windows 10 and Windows Server 2016. The AppVeyor CI process runs Windows Server 2016 as well.

So now I can replicate it I should be able to fix it, which is good news.

I did identify another problem as well which I'll log and repair in a separate issue.

PlagueHO commented 7 years ago

I think this problem is also the same one as this one: https://github.com/PowerShell/xStorage/issues/85

Zuldan commented 7 years ago

Fantastic @PlagueHO I was about to spin up another VM to try replicate the problem again. I thought the resource might be seeing something unexpected. Notice the 'System.Object[]' in the Verbose message.

Set-TargetResource: Partition 'System.Object[]' is already assigned to access path 'C:\MountPoint\SQLDATA01\'.

PlagueHO commented 7 years ago

@Zuldan - I've figured out the problem: In Windows Server 2012 R2 the Add-PartitionAccessPath cmdlet doesn't support having a Disk object piped to it, whereas this is supported in Windows Server 2016 and Windows 10.

E.g. This works in Windows Server 2016, but not Windows Sever 2012 R2:

$disk | Add-PartitionAccessPath `
            -AccessPath $AccessPath `
            -PartitionNumber $partition.PartitionNumber

So I need to change it to:

Add-PartitionAccessPath `
            -AccessPath $AccessPath `
            -DiskNumber $disk.Number `
            -PartitionNumber $partition.PartitionNumber

So I'll make the changes now and submit the PR tonight. So if you're feeling adventurous tomorrow you'll be able to try my branch. I did find one other problem that can occur (as I mentioned earlier) that I'd like to also fix, but I'll fix it in a separate PR.

Zuldan commented 7 years ago

Fantastic! good work. I'll try it tomorrow morning and report back. Really appreciate you looking at this so quickly.

I'm guessing you'll also need to do the same for UniqueId.

Add-PartitionAccessPath `
            -AccessPath $AccessPath `
            -DiskNumber $disk.UniqueId `
            -PartitionNumber $partition.PartitionNumber
Zuldan commented 7 years ago

Actually ignore the above code. That doesn't make sense. I'm sure you know what I mean ;P

PlagueHO commented 7 years ago

@Zuldan - haha yep - I know exactly what you mean. I don't need to worry about the UniqueId vs Number thing though because the $Disk object already contains the Disk that was retrieved using the required identifier.

I also figured out why these tests never caught the problem: The integration tests can't run on AppVeyor because they require Hyper-V so that a VHDX can be created and mounted. This is because I need the New-VHD cmdlet which is only available in Hyper-V (which is a pain because it really shouldn't require this - as you can still mount VHDs as disks without Hyper-V). You can't of course enable Hyper-V on AppVeyor - and all my testing is being done on Windows Server 2016.

So I'm going to try and figure out a way of creating VHD files without Hyper-V.

PlagueHO commented 7 years ago

@Zuldan - here is the new fixed version in my repo: https://github.com/PlagueHO/xStorage/tree/Issue-102

I'm going to try and get DISKPART to create the VHD to use for testing in AppVeyor which will allow more effective automated testing. So I won't submit this PR until I can get that working- so that will be tomorrow night.

Thanks for your patience and help!

Zuldan commented 7 years ago

@PlagueHO I can confirm it's working fine now on 2012 R2. Many thanks again! You are owed many beers.

PlagueHO commented 7 years ago

@Zuldan - always a pleasure - and I did write the code that original broke it :grin: But it happens and is just a chance for me to implement better automated tests! I actually have come up with a way I can run the tests in AppVeyor against WS2012R2 so that it should be tested every time.