Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Fixing bug in New-NsxLoadBalancerPool #611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions module/PowerNSX.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -31089,8 +31089,9 @@ function New-NsxLoadBalancerPool {
write-warning "Load Balancer feature is not enabled on edge $($edgeId). Use Set-NsxLoadBalancer -Enabled to enable."
}

[System.XML.XMLElement]$xmlPool = $_LoadBalancer.OwnerDocument.CreateElement("pool")
$_LoadBalancer.appendChild($xmlPool) | out-null
[System.XML.XmlDocument]$xmldoc = New-Object System.XML.XmlDocument
[System.XML.XMLElement]$xmlPool = $xmldoc.CreateElement("pool")
$xmldoc.appendChild($xmlPool) | out-null

Add-XmlElement -xmlRoot $xmlPool -xmlElementName "name" -xmlElementText $Name
Add-XmlElement -xmlRoot $xmlPool -xmlElementName "description" -xmlElementText $Description
Expand All @@ -31108,11 +31109,11 @@ function New-NsxLoadBalancerPool {
}
}

$URI = "/api/4.0/edges/$EdgeId/loadbalancer/config"
$body = $_LoadBalancer.OuterXml
$URI = "/api/4.0/edges/$EdgeId/loadbalancer/config/pools"
$body = $xmlPool.OuterXml

Write-Progress -activity "Update Edge Services Gateway $($EdgeId)" -status "Load Balancer Config"
$null = invoke-nsxwebrequest -method "put" -uri $URI -body $body -connection $connection
$null = invoke-nsxwebrequest -method "post" -uri $URI -body $body -connection $connection
write-progress -activity "Update Edge Services Gateway $($EdgeId)" -completed

$UpdatedEdge = Get-NsxEdge -objectId $($EdgeId) -connection $connection
Expand Down
31 changes: 31 additions & 0 deletions tests/integration/20.LB.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ Describe "Edge Load Balancer" {

}

# Test to cover a bug where New-NsxLoadBalancerPool fails to create a new pool on the Edge,
# when Edge already has one existing pool and one existing VIP.
Context "Load Balancer Pool (Extended)" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load Balancer Pool (Add Multiple Pool) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this bug happens only under certain circumstances, when:

  1. You already have one pool
  2. You already have one VIP
  3. And you trying to add a second pool - that's when the bug manifests itself

I had a long post under #434 explaining why this happens.

This test is more for demonstration purposes and for confirming that the issue is fixed by the submitted commits. It's up to you if you want to keep this test moving forward, to make sure this bug never get reintroduced into the code again in future versions.

From pure testing purposes, it doesn't test anything more than the already existing "Load Balancer Pool" test.

Hope that makes sense.


it "Add LB Pools" {
# Add first LB pool
$vmmember1 = New-NsxLoadBalancerMemberSpec -name "VM01" -IpAddress 2.2.2.1 -Port 80
$lb_pool = Get-NsxEdge $lbedge1name | Get-NsxLoadBalancer | New-NsxLoadBalancerPool -name "pester_lb_pool1" -Description "Pester LB Pool 1" -Transparent:$false -Algorithm round-robin -Memberspec $vmmember1 -Monitor $Monitor

# Add an LB VIP
$lb_app_profile = Get-NsxEdge $lbedge1name | Get-NsxLoadBalancer | New-NsxLoadBalancerApplicationProfile -Name "pester_lb_app_profile" -Type http
Get-NsxEdge -Name $lbedge1name | Get-NsxLoadBalancer | Add-NsxLoadBalancerVip -name "pester_vip" -Description "Pester VIP" -ipaddress 1.1.1.1 -Protocol http -Port 80 -ApplicationProfile $lb_app_profile -DefaultPool $lb_pool -AccelerationEnable

# Add second LB Pool
$vmmember2 = New-NsxLoadBalancerMemberSpec -name "VM02" -IpAddress 2.2.2.2 -Port 80
Get-NsxEdge $lbedge1name | Get-NsxLoadBalancer | New-NsxLoadBalancerPool -name "pester_lb_pool2" -Description "Pester LB Pool 2" -Transparent:$false -Algorithm round-robin -Memberspec $vmmember2 -Monitor $Monitor
}

it "Remove LB Pools" {
# Remove second LB pool
Get-NsxEdge $lbedge1name | Get-NsxLoadBalancer | Get-NsxLoadBalancerPool -name "pester_lb_pool2" | Remove-NsxLoadBalancerPool -confirm:$false

# Remove LB VIP
Get-NsxEdge $lbedge1name | Get-NsxLoadBalancer | Get-NsxLoadBalancerVIP -name "pester_vip" | Remove-NsxLoadBalancerVIP -confirm:$false
Get-NsxEdge $lbedge1name | Get-NsxLoadBalancer | Get-NsxLoadBalancerApplicationProfile -Name "pester_lb_app_profile" | Remove-NsxLoadBalancerApplicationProfile -confirm:$false

# Remove first LB pool
Get-NsxEdge $lbedge1name | Get-NsxLoadBalancer | Get-NsxLoadBalancerPool -name "pester_lb_pool1" | Remove-NsxLoadBalancerPool -confirm:$false
}
}

Context 'Load Balancer Pool Member' {
BeforeAll {
#Create LB Pool
Expand Down