vmware / dscr-for-vmware

The Repository contains Microsoft PowerShell Desired State Configuration (DSC) Resources for managing VC and ESXi settings.
Other
139 stars 41 forks source link

DSC Resource VMHostVssTeaming fails to update vss config #282

Closed mikedonleyuoy closed 3 years ago

mikedonleyuoy commented 3 years ago

When applying VMHostVssTeaming config, the following error is produced when applying DSC config using Start-DSCConfiguration

PowerShell DSC resource VMware.vSphereDSC failed to execute Set functionality with error message: The Virtual Switch Teaming Policy Config could not be updated: Exception calling "UpdateNetworkConfig" with "2" argument(s): "A specified parameter was not correct: "

  • CategoryInfo : InvalidOperation: (:) [], CimException
  • FullyQualifiedErrorId : ProviderOperationExecutionFailure
  • PSComputerName : localhost

DSC config is as detailed in https://github.com/vmware/dscr-for-vmware/blob/master/Examples/Vss_Config.ps1, or example on https://github.com/vmware/dscr-for-vmware/wiki/VMHostVssTeaming with changes for vmnic names for my local config.

Problem appears to occur when executing the 'modify' operation against the ESXi host on this line in VMware-vSphereDSC.Helper.psm1

$NetworkSystem.UpdateNetworkConfig($configNet, [VMware.Vim.HostConfigChangeMode]::modify)

It appears that the config in $configNet is invalid, though I've not figured out why.

Tested against current repo and v2.1.0.58. ESXi 6.7.0 build 16713306.

mikedonleyuoy commented 3 years ago

OK, I think there are two issues here.

  1. If you use VMHostVssTeaming resource. it has a dependency on a valid VMHostVssBridge config beforehand, so if the VMHostVssTeaming refers to two nics (e.g. vmnic0 and vmnic1), but a VMHostVssBridge hasn't been run before adding those nics to the bridge (ie. the bridge contains only one nic e.g. vmnic0), the error will be produced. So the workaround is to ensure you have something like the following on your config prior to using VMHostVssTeaming
            VMHostVssBridge "VMHostVSSBridge_$Server" {
                Name = $Server
                Server = $Server
                Credential = $Credential
                Ensure = 'Present'
                VssName = 'vSwitch0'
                NicDevice = @('vmnic0', 'vmnic1')
            }

A possible fix, might be to throw an error if one or more nics referenced in the VMHostVssTeaming aren't in the bridge, in the way that we already throw if the vssbridge contains no nics?

  1. If any of the nics have previously been set to standby, (e.g. vmnic0 Active, vmnic1 Standby), and you attempt to change the config to set them as active e.g ActiveNic = @('vmnic0','vmnic1'), this fails because the standby nic is sent to the host in both the active list and standby list. This can be see from the hostd.log file on the esxi host.
-->                   nicOrder = (vim.host.NetworkPolicy.NicOrderPolicy) {
-->                      activeNic = (string) [
-->                         "vmnic0",
-->                         "vmnic1"
-->                      ],
-->                      standbyNic = (string) [
-->                         "vmnic1"
-->                      ]
-->                   }

This suggests a problem on these lines in VMware.vSphereDSC.Helper.psm1

if (![string]::IsNullOrEmpty($VssTeamingConfig.ActiveNic)) { $hostVirtualSwitchConfig.Spec.Policy.NicTeaming.NicOrder.ActiveNic = $VssTeamingConfig.ActiveNic }
if (![string]::IsNullOrEmpty($VssTeamingConfig.StandbyNic)) { $hostVirtualSwitchConfig.Spec.Policy.NicTeaming.NicOrder.StandbyNic = $VssTeamingConfig.StandbyNic }
SimeonGerginov commented 3 years ago

The bug was fixed with PR #296, so the update of the teaming policy of the standard switch should work as expected with the latest version of the module.