NetworkingDsc icon indicating copy to clipboard operation
NetworkingDsc copied to clipboard

Can't test a configuration that depends on Rename-NetAdapter

Open nmdange2 opened this issue 5 years ago • 3 comments

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

I am attempting to run Test-DscConfiguration when I have to rename a network adapter and then assign a vlan. Even though I have DependsOn set, Test-DscConfiguration on the netadapteradvancedproperty is throwing a fatal error because the name does not exist. I am not sure if this is really an issue with this module or how Test-DscConfiguration works. I can successfully apply the configuration, but I can't test the configuration to see what changes will be made before applying them.

Verbose logs showing the problem

VERBOSE: : LCM: [ Start Resource ] [[NetAdapterName]RenameSMBNIC1] VERBOSE: : LCM: [ Start Test ] [[NetAdapterName]RenameSMBNIC1] VERBOSE: : [[NetAdapterName]RenameSMBNIC1] Test-TargetResource: Testing the network adapter Name 'SMB_A'. VERBOSE: : [[NetAdapterName]RenameSMBNIC1] Find-NetworkAdapter: Finding network adapters matching the parameters. VERBOSE: : [[NetAdapterName]RenameSMBNIC1] Test-TargetResource: Finding network adapter matching search criteria. VERBOSE: : [[NetAdapterName]RenameSMBNIC1] Find-NetworkAdapter: Finding network adapters matching the parameters. VERBOSE: : [[NetAdapterName]RenameSMBNIC1] Find-NetworkAdapter: 1 network adapters were found matching the parameters. VERBOSE: : [[NetAdapterName]RenameSMBNIC1] Test-TargetResource: network adapter Name 'Ethernet 2' does not match the adapter 'SMB_A' that was found. Rename required. VERBOSE: : LCM: [ End Test ] [[NetAdapterName]RenameSMBNIC1] False in 0.1410 seconds. VERBOSE: : LCM: [ End Resource ] [[NetAdapterName]RenameSMBNIC1] VERBOSE: : LCM: [ Start Resource ] [[NetAdapterAdvancedProperty]VlanSMBNic1] VERBOSE: : LCM: [ Start Test ] [[NetAdapterAdvancedProperty]VlanSMBNic1] VERBOSE: : [[NetAdapterAdvancedProperty]VlanSMBNic1] Test-TargetResource: Checking if network adapter exists or not. VERBOSE: : LCM: [ End Test ] [[NetAdapterAdvancedProperty]VlanSMBNic1] False in 0.1250 seconds. VERBOSE: : LCM: [ FAILEDCompare ] Completed processing compare operation. The operation returned False.

Suggested solution to the issue

Does not throwing a fatal error in Test-TargetResource when the adapter doesn't exist make sense to do?

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

NetAdapterName RenameSMBNIC1
{
	NewName = "SMB_A"
	MacAddress = $Node.SMB_NIC_1_MacAddr
	PhysicalMediaType = '802.3'
}

NetAdapterAdvancedProperty VlanSMBNic1
{
	NetworkAdapterName = "SMB_A"
	RegistryKeyword = "VlanID" 
	RegistryValue = 101
	DependsOn = "[NetAdapterName]RenameSMBNIC1"
}

The operating system the target node is running

OsName : Microsoft Windows Server 2019 Datacenter OsOperatingSystemSKU : DatacenterServerEdition OsArchitecture : 64-bit WindowsVersion : 1809 WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434 OsLanguage : en-US OsMuiLanguages : {en-US}

Version and build of PowerShell the target node is running

PSVersion 5.1.17763.592 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.592 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

Version of the DSC module that was used ('dev' if using current dev branch)

7.3.0.0

nmdange2 avatar Sep 04 '19 21:09 nmdange2

Hi @nmdange2, thank you for raising this. You do raise a good discussion point: should NetAdapterAdvancedProperty (and other similar networking resources) throw an exception in Test-TargetResource if the adapter does not exist?

At the moment, that is the behavior we have adopted, but it might be worth reconsidering.

Instead, should Test-TargetResource display a warning and just return $true instead if the adapter does not exist?

For Set-TargetResource however, we'd definitely want to throw a fatal exception.

Off the top of my head, I can't think of specific scenarios where removing the fatal error would cause a major issue. @johlju - any thoughts on this one?

PlagueHO avatar Sep 09 '19 07:09 PlagueHO

I would probably suggest Test-TargetResource should return $false if the adapter does not exist.

nmdange2 avatar Sep 27 '19 00:09 nmdange2

Sorry for taking so long to answer. @nmdange2's comment made the notification jump to the top of the list. 😃

I don't think neither Get-TargetResource or Test-TargetResource should throw an error if the adapter does not exist. Both Get-DscConfiguration and Test-DscConfiguration should be able to be run without throwing an error. Or using Invoke-DscResource with the method Test or Get.

When running Set-TargetResource either through Start-DscConfiguration or Invoke-DscResource with the method Set then the resource should throw an error if the adapter does not exist.

Test-TargetResource should return $false if Get-TargetResource returns that the adapter is not in desired state - not having the expected adapter is not the desired state. Get-TargetResource could have a red-only property AdapterPresent to further evaluate the state of the resource. This new property can be used by both the function Test-TargetResource or a user when running Get-DscConfiguration.

johlju avatar Sep 27 '19 15:09 johlju