dsccommunity / HyperVDsc

This module contains DSC resources for deployment and configuration of Microsoft Hyper-V.
MIT License
114 stars 65 forks source link

DSC_VMSwitch - Proposal to change the usage of InterfaceDescription to InterfaceGuids ? #217

Closed gplenty closed 8 months ago

gplenty commented 9 months ago

Problem description

During debugging the error message,

`VERBOSE: [ServerA]: LCM:  [ Start  Resource ]  [[VMSwitch]ExternalSwitch]
VERBOSE: [ServerA]: LCM:  [ Start  Test     ]  [[VMSwitch]ExternalSwitch]
VERBOSE: [ServerA]:                            [[VMSwitch]ExternalSwitch] Checking if Switch 'vSwitch0' is 'Present' ...
VERBOSE: [ServerA]:                            [[VMSwitch]ExternalSwitch] Switch 'vSwitch0' is Present
VERBOSE: [ServerA]:                            [[VMSwitch]ExternalSwitch] Checking if Switch 'vSwitch0' has correct BandwidthReservationMode ...
VERBOSE: [ServerA]:                            [[VMSwitch]ExternalSwitch] Switch 'vSwitch0' has correct BandwidthReservationMode or it does not apply to this OS
VERBOSE: [ServerA]:                            [[VMSwitch]ExternalSwitch] Checking if Switch 'vSwitch0' has correct NetAdapterInterfaces ...
Cannot bind argument to parameter 'ReferenceObject' because it is null.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand
    + PSComputerName        : ServerA

VERBOSE: [ServerA]: LCM:  [ End    Test     ]  [[VMSwitch]ExternalSwitch]  in 2.0320 seconds.
The PowerShell DSC resource '[VMSwitch]ExternalSwitch' with SourceInfo 'C:\_HyperVDSC\script.ps1::256::9::VMSwitch' threw one or more non-terminating errors while
running the Test-TargetResource functionality. These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more
details.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : NonTerminatingErrorFromProvider
    + PSComputerName        : ServerA_
`

And confirming that the VMSwitch ExternalSwitch configuration is configured as required, it still fails with the same error message. If I remove the vSwitch0 section, then the DSC configuration is pushed and applied successfully.

        ### Configure vSwitch0
        VMSwitch ExternalSwitch
        {
            Ensure                = 'Present'
            Name                  = "vSwitch0"
            Type                  = 'External'
            EnableEmbeddedTeaming = $true
            DependsOn             = '[WindowsFeature]HyperV'
            BandwidthReservationMode = 'Weight'
            NetAdapterName        = 'NIC1','NIC2','NIC5','NIC6'
            LoadBalancingAlgorithm = 'HyperVPort'
        }

I looked further into the HyperVDSC\DSCResources\DSC_VMSwitch\DSC_VMSwitch.psm1 module and made this modification to use the GUID of the interface, as opposed to the InterfaceDescription. The reason for this, is because I have a Windows 2019 Server core Hyper-V cluster node, which has a difference between the InterfaceDescriptions

Lines 244 -> 262

                #$adapters = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescriptions -ErrorAction SilentlyContinue).Name
                $NetAdapterInterfaceGuids = $switch.NetAdapterInterfaceGuid
                $adapters = @()
                $NICS = @()
                foreach ($n in $NetAdapterInterfaceGuids) {
                $guid = "{" + ($n.Guid).ToUpper() + "}"
                $NICs += get-netadapter | where-object {$_.InterfaceGuid -eq $guid }
                $tmp_data = New-Object PSObject
                Add-Member -InputObject $tmp_data -MemberType NoteProperty -Name Name $($nics.name)
                Add-Member -InputObject $tmp_data -MemberType NoteProperty -Name InterfaceGuid $($guid)
                $adapters += $tmp_data   
                $NICS = @()
                }
                if ($null -ne (Compare-Object -ReferenceObject $adapters.name -DifferenceObject $NetAdapterName))
                {
                    Write-Verbose -Message ($script:localizedData.SwitchIncorrectNetworkAdapters -f $Name)
                    $removeReaddSwitch = $true
                }
            }

Lines 595 -> 616

                           #$adapters = (Get-NetAdapter -InterfaceDescription $switch.NetAdapterInterfaceDescriptions -ErrorAction SilentlyContinue).Name
                            $NetAdapterInterfaceGuids = $switch.NetAdapterInterfaceGuid
                            $adapters = @()
                            $NICS = @()
                            foreach ($n in $NetAdapterInterfaceGuids) {
                            $guid = "{" + ($n.Guid).ToUpper() + "}"
                            $NICs += get-netadapter | where-object {$_.InterfaceGuid -eq $guid }
                            $tmp_data = New-Object PSObject
                            Add-Member -InputObject $tmp_data -MemberType NoteProperty -Name Name $($nics.name)
                            Add-Member -InputObject $tmp_data -MemberType NoteProperty -Name InterfaceGuid $($guid)
                            $adapters += $tmp_data   
                            $NICS = @()
                            }
                            if ($null -ne (Compare-Object -ReferenceObject $adapters.name -DifferenceObject $NetAdapterName))
                            {
                                Write-Verbose -Message ($script:localizedData.IncorrectNetAdapterInterfaces -f $Name)
                                return $false
                            }
                            else
                            {
                                Write-Verbose -Message ($script:localizedData.CorrectNetAdapterInterfaces -f $Name)
                            }

Verbose logs

PS C:\> Get-NetAdapter NIC1, NIC2, NIC5, NIC6 | Select-Object Name, InterfaceDescription | Sort-Object Name

Name InterfaceDescription
---- --------------------
NIC1 QLogic BCM57800 10 Gigabit Ethernet (NDIS VBD Client) #39
NIC2 QLogic BCM57800 10 Gigabit Ethernet (NDIS VBD Client) #40
NIC5 QLogic BCM57810 10 Gigabit Ethernet (NDIS VBD Client) #43
NIC6 QLogic BCM57810 10 Gigabit Ethernet (NDIS VBD Client) #44

PS C:\> Get-VMSwitch | Select-Object NetAdapterInterfaceDescriptions | fl

NetAdapterInterfaceDescriptions : {QLogic BCM57800 10 Gigabit Ethernet (NDIS VBD Client), QLogic BCM57800 10 Gigabit
                                  Ethernet (NDIS VBD Client) #2, QLogic BCM57810 10 Gigabit Ethernet (NDIS VBD
                                  Client), QLogic BCM57810 10 Gigabit Ethernet (NDIS VBD Client) #2}

PS C:\>

######

Output taken from the DSC push, once the c:\Program Files\WindowsPowerShell\Modules\HyperVDSC\DSCResources\DSC_VMSwitch\DSC_VMSwitch.psm1 had been modified and confirmed that the vSwitch configuration was successfully executed. 

VERBOSE: [SERVERA]: LCM:  [ Start  Resource ]  [[VMSwitch]ExternalSwitch]
VERBOSE: [SERVERA]: LCM:  [ Start  Test     ]  [[VMSwitch]ExternalSwitch]
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Checking if Switch 'vSwitch0' is 'Present' ...
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Switch 'vSwitch0' is Present
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Checking if Switch 'vSwitch0' has correct BandwidthReservationMode ...
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Switch 'vSwitch0' has correct BandwidthReservationMode or it does not apply to this OS
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Checking if Switch 'vSwitch0' has correct NetAdapterInterfaces ...
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Switch 'vSwitch0' has a correct list of network adapters
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Checking if Switch 'vSwitch0' has correct LoadBalancingAlgorithm ...
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Switch 'vSwitch0' has correct LoadBalancingAlgorithm
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Checking if Switch 'vSwitch0' has correct EnableEmbeddedTeaming ...
VERBOSE: [SERVERA]:                            [[VMSwitch]ExternalSwitch] Switch 'vSwitch0' has correct EnableEmbeddedTeaming or it does not apply to this OS
VERBOSE: [SERVERA]: LCM:  [ End    Test     ]  [[VMSwitch]ExternalSwitch]  in 2.2970 seconds.
VERBOSE: [SERVERA]: LCM:  [ Skip   Set      ]  [[VMSwitch]ExternalSwitch]
VERBOSE: [SERVERA]: LCM:  [ End    Resource ]  [[VMSwitch]ExternalSwitch]

DSC configuration

### Configure vSwitch0
        VMSwitch ExternalSwitch
        {
            Ensure                = 'Present'
            Name                  = "vSwitch0"
            Type                  = 'External'
            EnableEmbeddedTeaming = $true
            DependsOn             = '[WindowsFeature]HyperV'
            BandwidthReservationMode = 'Weight'
            NetAdapterName        = 'NIC1','NIC2','NIC5','NIC6'
            LoadBalancingAlgorithm = 'HyperVPort'
        }

Suggested solution

Due to the difference in the interface descriptions, I used the provided workaround to use the GUID instead. I'm also unsure why the difference even exists.

Operating system the target node is running

PS C:\> Get-ComputerInfo -Property @('OsName','OsOperatingSystemSKU','OSArchitecture','WindowsVersion','WindowsBuildLabEx','OsLanguage','OsMuiLanguages')

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

PowerShell version and build the target node is running

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.17763.4840
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.4840
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\>

HyperVDsc version

PS C:\> Get-Module -Name 'HyperVDsc' -ListAvailable | ft Name,Version,Path

Name      Version Path
----      ------- ----
HyperVDSC 4.0.0   C:\Program Files\WindowsPowerShell\Modules\HyperVDSC\HyperVDSC.psd1
gplenty commented 8 months ago

I'll close this Issue and work on trying to fix the hosts themselves, we've identified that seems to only occur with QLogic BCM57810 or QLogic BCM57800, so it's only a small fraction of hosts.