Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test buid monitor create opts #2429

Merged
Merged
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
149 changes: 149 additions & 0 deletions pkg/openstack/loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"sort"
"testing"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners"
v2monitors "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/monitors"
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/pools"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -2139,3 +2141,150 @@ func TestLbaasV2_getNetworkID(t *testing.T) {
})
}
}

func Test_buildMonitorCreateOpts(t *testing.T) {
type testArg struct {
lbaas *LbaasV2
svcConf *serviceConfig
port corev1.ServicePort
}
tests := []struct {
name string
testArg testArg
want v2monitors.CreateOpts
}{
{
name: "test for port protocol udp with ovn provider",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
},
lb: &gophercloud.ServiceClient{},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 6,
healthMonitorTimeout: 5,
healthMonitorMaxRetries: 4,
healthMonitorMaxRetriesDown: 3,
healthCheckNodePort: 32100,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolUDP,
},
},
want: v2monitors.CreateOpts{
Name: "test for port protocol udp with ovn provider",
Type: "UDP-CONNECT",
Delay: 6,
Timeout: 5,
MaxRetries: 4,
MaxRetriesDown: 3,
},
},
{
name: "using tcp with ovn provider",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 3,
healthMonitorTimeout: 8,
healthMonitorMaxRetries: 6,
healthMonitorMaxRetriesDown: 2,
healthCheckNodePort: 31200,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolTCP,
},
},
want: v2monitors.CreateOpts{
Name: "using tcp with ovn provider",
Type: "TCP",
Delay: 3,
Timeout: 8,
MaxRetries: 6,
MaxRetriesDown: 2,
},
},
{
name: "using node port zero",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "ovn",
},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 3,
healthMonitorTimeout: 5,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 2,
healthCheckNodePort: 0,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolTCP,
},
},
want: v2monitors.CreateOpts{
Name: "using node port zero",
Type: "TCP",
Delay: 3,
Timeout: 5,
MaxRetries: 1,
MaxRetriesDown: 2,
},
},
{
name: "using tcp protocol with not-ovn provider",
testArg: testArg{
lbaas: &LbaasV2{
LoadBalancer{
opts: LoadBalancerOpts{
LBProvider: "amphora",
},
lb: &gophercloud.ServiceClient{},
},
},
svcConf: &serviceConfig{
healthMonitorDelay: 3,
healthMonitorTimeout: 4,
healthMonitorMaxRetries: 1,
healthMonitorMaxRetriesDown: 5,
healthCheckNodePort: 310000,
},
port: corev1.ServicePort{
Protocol: corev1.ProtocolTCP,
},
},
want: v2monitors.CreateOpts{
Name: "using tcp protocol with not-ovn provider",
Type: "HTTP",
Delay: 3,
Timeout: 4,
MaxRetries: 1,
MaxRetriesDown: 5,

URLPath: "/healthz",
HTTPMethod: "GET",
ExpectedCodes: "200",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.testArg.lbaas.buildMonitorCreateOpts(tt.testArg.svcConf, tt.testArg.port, tt.name)
assert.Equal(t, tt.want, result)
})
}
}