Skip to content

Commit

Permalink
Add tests for custom subnetID feature
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 committed Feb 16, 2024
1 parent 9984ad6 commit 810433c
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,60 @@ var _ = Describe("load balancer machine", Serial, Ordered, func() {
})
}) // openstack not working

Context("customizable subnetID features", func() {
BeforeEach(func() {
lbm.Spec.Infrastructure.DefaultNetwork.SubnetworkID = ptr.To("lb-subnetworkID")
})

It("should create openstack resources", func() {
lbmNN := runtimeClient.ObjectKeyFromObject(lbm)

Eventually(func(g Gomega) {
var actual yawolv1beta1.LoadBalancerMachine
g.Expect(k8sClient.Get(ctx, lbmNN, &actual)).To(Succeed())

g.Expect(actual.Status.ServerID).ToNot(BeNil())
g.Expect(actual.Status.DefaultPortID).ToNot(BeNil())

_, err := client.ServerClientObj.Get(ctx, *actual.Status.ServerID)
g.Expect(err).To(Succeed())

port, err := client.PortClientObj.Get(ctx, *actual.Status.DefaultPortID)
g.Expect(err).To(Succeed())
g.Expect(len(port.FixedIPs)).To(Equal(1))

g.Expect(port.FixedIPs[0].SubnetID).To(Equal("lb-subnetworkID"))
}, timeout, interval).Should(Succeed())
})
}) // customizable subnetID features

Context("fallback to default subnetID", func() {
BeforeEach(func() {
lbm.Spec.Infrastructure.DefaultNetwork.SubnetworkID = nil // unset
})

It("should create openstack resources", func() {
lbmNN := runtimeClient.ObjectKeyFromObject(lbm)

Eventually(func(g Gomega) {
var actual yawolv1beta1.LoadBalancerMachine
g.Expect(k8sClient.Get(ctx, lbmNN, &actual)).To(Succeed())

g.Expect(actual.Status.ServerID).ToNot(BeNil())
g.Expect(actual.Status.DefaultPortID).ToNot(BeNil())

_, err := client.ServerClientObj.Get(ctx, *actual.Status.ServerID)
g.Expect(err).To(Succeed())

port, err := client.PortClientObj.Get(ctx, *actual.Status.DefaultPortID)
g.Expect(err).To(Succeed())
g.Expect(len(port.FixedIPs)).To(Equal(1))

g.Expect(port.FixedIPs[0].SubnetID).To(Equal("default-subnet-id"))
}, timeout, interval).Should(Succeed())
})
}) // fallback to default subnetID

Context("additionalNetworks features", func() {
BeforeEach(func() {
lbm.Spec.Infrastructure.AdditionalNetworks = []yawolv1beta1.LoadBalancerAdditionalNetwork{
Expand Down
10 changes: 9 additions & 1 deletion internal/openstack/testing/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,20 @@ func GetFakeClient() *MockClient {
},
CreateFunc: func(ctx context.Context, optsBuilder ports.CreateOptsBuilder) (*ports.Port, error) {
opts := optsBuilder.(ports.CreateOpts)
var fixedIPs []ports.IP
if opts.FixedIPs != nil {
fixedIPs = opts.FixedIPs.([]ports.IP)
}

subnetID := "default-subnet-id"
if len(fixedIPs) > 0 {
subnetID = fixedIPs[0].SubnetID
}
port := &ports.Port{
ID: getID(&client),
Name: opts.Name,
NetworkID: opts.NetworkID,
FixedIPs: []ports.IP{{IPAddress: generateIP()}},
FixedIPs: []ports.IP{{SubnetID: subnetID, IPAddress: generateIP()}},
}

if opts.SecurityGroups != nil {
Expand Down

0 comments on commit 810433c

Please sign in to comment.