Skip to content

Commit

Permalink
Merge pull request #49 from iainbrighton/Issue48
Browse files Browse the repository at this point in the history
Fixes BandwidthReservationMode bug
  • Loading branch information
TravisEz13 committed Mar 16, 2016
2 parents a57e3ac + 8c7b0c6 commit af57c8f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 28 deletions.
62 changes: 34 additions & 28 deletions DSCResources/MSFT_xVMSwitch/MSFT_xVMSwitch.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -228,48 +228,54 @@ function Test-TargetResource
# If switch should be present, check the switch type
if($Ensure -eq 'Present')
{
# If the BandwidthReservsationMode is correct, or if $switch.BandwidthReservationMode is $null which means it isn't supported on the OS
Write-Verbose -Message "Checking if Switch $Name has correct BandwidthReservationMode ..."
if($switch.BandwidthReservationMode -eq $BandwidthReservationMode -or $switch.BandwidthReservationMode -eq $null)
## Only check the BandwidthReservationMode if specified
if($PSBoundParameters.ContainsKey('BandwidthReservationMode'))
{
Write-Verbose -Message "Switch $Name has correct BandwidthReservationMode or it does not apply to this OS"
# If the BandwidthReservationMode is correct, or if $switch.BandwidthReservationMode is $null which means it isn't supported on the OS
Write-Verbose -Message "Checking if Switch $Name has correct BandwidthReservationMode ..."
if($switch.BandwidthReservationMode -eq $BandwidthReservationMode -or $switch.BandwidthReservationMode -eq $null)
{
Write-Verbose -Message "Switch $Name has correct BandwidthReservationMode or it does not apply to this OS"
}
else
{
Write-Verbose -Message "Switch $Name does not have correct BandwidthReservationMode "
return $false
}
}

# If switch is the external type, check additional propeties
if($switch.SwitchType -eq 'External')
# If switch is the external type, check additional propeties
if($switch.SwitchType -eq 'External')
{
Write-Verbose -Message "Checking if Switch $Name has correct NetAdapterInterface ..."
if((Get-NetAdapter -Name $NetAdapterName -ErrorAction SilentlyContinue).InterfaceDescription -ne $switch.NetAdapterInterfaceDescription)
{
Write-Verbose -Message "Checking if Switch $Name has correct NetAdapterInterface ..."
if((Get-NetAdapter -Name $NetAdapterName -ErrorAction SilentlyContinue).InterfaceDescription -ne $switch.NetAdapterInterfaceDescription)
return $false
}
else
{
Write-Verbose -Message "Switch $Name has correct NetAdapterInterface"
}

if($PSBoundParameters.ContainsKey("AllowManagementOS"))
{
Write-Verbose -Message "Checking if Switch $Name has AllowManagementOS set correctly..."
if(($switch.AllowManagementOS -ne $AllowManagementOS))
{
return $false
}
else
{
Write-Verbose -Message "Switch $Name has correct NetAdapterInterface"
}

if($PSBoundParameters.ContainsKey("AllowManagementOS"))
{
Write-Verbose -Message "Checking if Switch $Name has AllowManagementOS set correctly..."
if(($switch.AllowManagementOS -ne $AllowManagementOS))
{
return $false
}
else
{
Write-Verbose -Message "Switch $Name has AllowManagementOS set correctly"
}
Write-Verbose -Message "Switch $Name has AllowManagementOS set correctly"
}
return $true
}
else
{
return $true
}
return $true
}
else
{
return $false
return $true
}

}
# If switch should be absent, but is there, return $false
else
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Please see the Examples section for more details.

* MSFT_xVMHyperV: Fixed bug causing Test-TargetResource to fail when VM had snapshots.
* MSFT_xVMHyperV: Adds localization support.
* MSFT_xVMSwitch: Fixes bug where virtual switches are duplicated when BandwidthReservationMode is not specified.

### 3.3.0.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ Describe 'xVMSwitch' {
$targetResource = Test-TargetResource -Name 'SomeSwitch' -BandwidthReservationMode 'NA' -Type 'External' -NetAdapterName 'SomeNIC' -Ensure 'Present' -AllowManagementOS $true
$targetResource | Should Be $true
}

It 'Passes when "BandwidthReservationMode" does not match but is not specified (#48)' {
$global:mockedVMSwitch = New-MockedVMSwitch -Name 'SomeSwitch' -BandwidthReservationMode 'Absolute'
$targetResource = Test-TargetResource -Name 'SomeSwitch' -Type 'Internal' -Ensure 'Present'
$targetResource | Should Be $true
}
}


Expand Down

0 comments on commit af57c8f

Please sign in to comment.