mirror of
https://github.com/openshift/installer.git
synced 2026-02-05 15:47:14 +01:00
Add unit tests for OpenStack platform defaults
Adds unit tests in platform_test.py to verify OpenStack platform defaults. Covers cases such as: - Assigning a default OpenShift-managed load balancer when none is specified - Handling user-managed load balancers with and without VIPs - Ensuring correct API and Ingress VIP assignments
This commit is contained in:
committed by
Stephen Finucane
parent
8931ff740b
commit
c9bfb8533e
120
pkg/types/openstack/defaults/platform_test.go
Normal file
120
pkg/types/openstack/defaults/platform_test.go
Normal file
@@ -0,0 +1,120 @@
|
||||
package defaults
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
configv1 "github.com/openshift/api/config/v1"
|
||||
"github.com/openshift/installer/pkg/ipnet"
|
||||
"github.com/openshift/installer/pkg/types"
|
||||
"github.com/openshift/installer/pkg/types/openstack"
|
||||
)
|
||||
|
||||
func validPlatform() *openstack.Platform {
|
||||
return &openstack.Platform{
|
||||
Cloud: "test-cloud",
|
||||
ExternalNetwork: "test-network",
|
||||
}
|
||||
}
|
||||
|
||||
func validNetworking() *types.Networking {
|
||||
return &types.Networking{
|
||||
NetworkType: "OVNKubernetes",
|
||||
MachineNetwork: []types.MachineNetworkEntry{{
|
||||
CIDR: *ipnet.MustParseCIDR("10.0.0.0/16"),
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetPlatformDefaults(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
platform *openstack.Platform
|
||||
config *types.InstallConfig
|
||||
networking *types.Networking
|
||||
expectedLB configv1.PlatformLoadBalancerType
|
||||
expectedAPIVIPs []string
|
||||
expectedIngressVIPs []string
|
||||
}{
|
||||
{
|
||||
name: "No load balancer provided",
|
||||
platform: func() *openstack.Platform {
|
||||
p := validPlatform()
|
||||
return p
|
||||
}(),
|
||||
networking: validNetworking(),
|
||||
expectedAPIVIPs: []string{"10.0.0.5"},
|
||||
expectedIngressVIPs: []string{"10.0.0.7"},
|
||||
expectedLB: "OpenShiftManagedDefault",
|
||||
},
|
||||
{
|
||||
name: "Default Openshift Managed load balancer VIPs provided",
|
||||
platform: func() *openstack.Platform {
|
||||
p := validPlatform()
|
||||
p.LoadBalancer = &configv1.OpenStackPlatformLoadBalancer{
|
||||
Type: configv1.LoadBalancerTypeOpenShiftManagedDefault,
|
||||
}
|
||||
p.APIVIPs = []string{"10.0.0.2"}
|
||||
p.IngressVIPs = []string{"10.0.0.3"}
|
||||
return p
|
||||
}(),
|
||||
networking: validNetworking(),
|
||||
expectedAPIVIPs: []string{"10.0.0.2"},
|
||||
expectedIngressVIPs: []string{"10.0.0.3"},
|
||||
expectedLB: "OpenShiftManagedDefault",
|
||||
},
|
||||
{
|
||||
name: "Default Openshift Managed load balancer no VIPs provided",
|
||||
platform: func() *openstack.Platform {
|
||||
p := validPlatform()
|
||||
p.LoadBalancer = &configv1.OpenStackPlatformLoadBalancer{
|
||||
Type: configv1.LoadBalancerTypeOpenShiftManagedDefault,
|
||||
}
|
||||
return p
|
||||
}(),
|
||||
networking: validNetworking(),
|
||||
expectedAPIVIPs: []string{"10.0.0.5"},
|
||||
expectedIngressVIPs: []string{"10.0.0.7"},
|
||||
expectedLB: "OpenShiftManagedDefault",
|
||||
},
|
||||
{
|
||||
name: "User managed load balancer VIPs provided",
|
||||
platform: func() *openstack.Platform {
|
||||
p := validPlatform()
|
||||
p.LoadBalancer = &configv1.OpenStackPlatformLoadBalancer{
|
||||
Type: configv1.LoadBalancerTypeUserManaged,
|
||||
}
|
||||
p.APIVIPs = []string{"192.168.100.10"}
|
||||
p.IngressVIPs = []string{"192.168.100.11"}
|
||||
return p
|
||||
}(),
|
||||
networking: validNetworking(),
|
||||
expectedAPIVIPs: []string{"192.168.100.10"},
|
||||
expectedIngressVIPs: []string{"192.168.100.11"},
|
||||
expectedLB: "UserManaged",
|
||||
},
|
||||
{
|
||||
name: "User managed load balancer no VIPs provided",
|
||||
platform: func() *openstack.Platform {
|
||||
p := validPlatform()
|
||||
p.LoadBalancer = &configv1.OpenStackPlatformLoadBalancer{
|
||||
Type: configv1.LoadBalancerTypeUserManaged,
|
||||
}
|
||||
return p
|
||||
}(),
|
||||
networking: validNetworking(),
|
||||
expectedAPIVIPs: []string(nil),
|
||||
expectedIngressVIPs: []string(nil),
|
||||
expectedLB: "UserManaged",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
SetPlatformDefaults(tc.platform, tc.networking)
|
||||
assert.Equal(t, tc.expectedLB, tc.platform.LoadBalancer.Type, "unexpected loadbalancer")
|
||||
assert.Equal(t, tc.expectedAPIVIPs, tc.platform.APIVIPs, "unexpected APIVIPs")
|
||||
assert.Equal(t, tc.expectedIngressVIPs, tc.platform.IngressVIPs, "unexpected IngressVIPs")
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user