dsccommunity / iSCSIDsc

DSC resources for configuring Windows iSCSI targets and initiators.
https://dsccommunity.org
MIT License
7 stars 10 forks source link

iSCSIInitiator: iSCSI initiator doesn't refresh when new target is added #43

Open kungfoome opened 5 years ago

kungfoome commented 5 years ago

Details of the scenario you tried and the problem that is occurring

I connect to get the target portal to get the target nodes. When running the DSC script the first time, it connects to the target and get's the current targets. No issues here. I now go back and add a new target and I want to initiate that new target. iSCSIInitiator resource can't find the new target because the connection hasn't been updated to reflect that.

Verbose logs showing the problem

VERBOSE: [DEV-TEST-DELETE]:                            [[iSCSIInitiator]iSCSIInitiator-tgt1] Set-TargetResource: Ensuring iSCSI Target 'iqn.2010-06.com.nutanix:dev-test-vg-delete-63dc3822-a5a1-4ad8-b8b2-db6bd27addff-
tgt1' is connected.
VERBOSE: [DEV-TEST-DELETE]: LCM:  [ End    Set      ]  [[iSCSIInitiator]iSCSIInitiator-tgt1]  in 0.0620 seconds.
PowerShell DSC resource DSR_iSCSIInitiator  failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common 
parameter is set to Stop: The target name is not found or is marked as hidden from login.  
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : DEV-TEST-DELETE

Running Update-IscsiTarget to refresh the targets and then running the config again works fine.

Suggested solution to the issue

A few possible solutions.

Add a new parameter to force refresh of target.

[Parameter()]
[System.Boolean]
$RefreshTargets = $false

if($RefreshTargets) { Update-IscsiTargetPortal $TargetPortalAddress }

Another option would be to check if target exists and if doesn't then run Update-IscsiTargetPortal. If after this it fails, then it really should be an error.

You can run Update-IscsiTarget, but it does take much longer than Update-IscsiTargetPortal and it appears to list the target as it should.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

iSCSIInitiator iSCSIInitiator-tgt0 {
    Ensure                 = 'Present'
    NodeAddress            = 'iqn.2010-06.com.nutanix:dev-test-vg-delete-63dc3822-a5a1-4ad8-b8b2-db6bd27addff-tgt0'
    TargetPortalAddress    = '192.168.100.1'
    IsPersistent           = $true
}