Skip to content

occm: convert bash based lbaas e2e tests into go tests - #3153

Open
kayrus wants to merge 1 commit into
kubernetes:masterfrom
kayrus:occm-lb-e2e-go-tests
Open

occm: convert bash based lbaas e2e tests into go tests#3153
kayrus wants to merge 1 commit into
kubernetes:masterfrom
kayrus:occm-lb-e2e-go-tests

Conversation

@kayrus

@kayrus kayrus commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

old bash based tests are slow and not modular. new go-based tests are modular, fast and provide more logs for debugging.

Special notes for reviewers:

The original bash tests had a bug where OVN provider failures were silently ignored. When creating an HTTP listener with OVN (which only supports TCP), the openstack loadbalancer listener create command would fail with HTTP 501, but the bash script didn't check the exit code and continued executing, causing the tests to pass despite the failure.

+ tests/e2e/cloudprovider/test-lb-service.sh:test_shared_user_lb:735 :   openstack loadbalancer listener create --protocol HTTP --protocol-port 80 8ff613e8-339f-43a8-9e81-23b11f7c7430
Provider 'ovn' does not support a requested option: OVN provider does not support HTTP protocol (HTTP 501) (Request-ID: req-98dceeba-f6a4-4aca-bbec-a1d4912eb683)

Full logs: https://storage.googleapis.com/kubernetes-ci-logs/pr-logs/pull/cloud-provider-openstack/3154/openstack-cloud-controller-manager-ovn-e2e-test-release-136/2082483820640079872/build-log.txt

Release note:

NONE

@kubernetes-prow kubernetes-prow Bot added the release-note-none Denotes a PR that doesn't merit a release note. label Jul 29, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign zetaab for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 29, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from gouthampacha and zetaab July 29, 2026 14:26
@kubernetes-prow kubernetes-prow Bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 29, 2026
@kayrus
kayrus force-pushed the occm-lb-e2e-go-tests branch 6 times, most recently from 5216215 to 68d2acb Compare July 29, 2026 20:02
Comment on lines +26 to +37
gomega.Expect(err).NotTo(gomega.HaveOccurred())

err = createNamespace(ginkgo.GinkgoT().Context(), tstCtx)
gomega.Expect(err).NotTo(gomega.HaveOccurred())

err = createDeployment(ginkgo.GinkgoT().Context(), tstCtx)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
})

ginkgo.AfterEach(func() {
if autoCleanup {
cleanupResources(ginkgo.GinkgoT().Context(), tstCtx)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If setupTestContext or createDeployment fails in BeforeEach, tstCtx is nil here and this will panic. You can add a guard like: if autoCleanup && tstCtx != nil {

framework.Logf("Initial member ports: %v", initialMemberPorts)

// Validate member ports match NodePorts
gomega.Expect(len(initialMemberPorts)).To(gomega.Equal(len(initialNodePorts)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The original bash test explicitly failed if the NodePort did not change after update (if [[ ${member_port} == ${member_ports} ]]). This version only logs. If the point of this test is to verify Kubernetes assigns a new NodePort and the LB member is updated to match it, so please restore the assertion

}

_, err = tstCtx.k8sClient.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
if err != nil && !strings.Contains(err.Error(), "already exists") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use k8serrors.IsAlreadyExists(err) / k8serrors.IsNotFound(err) from k8s.io/apimachinery/pkg/api/errors instead of strings.Contains(err.Error(), "already exists"). String matching on error messages is fragile across API versions and locales


ginkgo.BeforeEach(func() {
var err error
tstCtx, err = setupTestContext(ginkgo.GinkgoT().Context())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

BeforeEach re-authenticates to OpenStack and creates all clients before every single test. Move the client setup to BeforeSuite/AfterSuite and only reset createdServices/createdFIPs/createdLBs slices in BeforeEach. This will significantly reduce test setup time

framework.Logf("Load balancer %s is ACTIVE", lbID)
return true, nil
}
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

http.DefaultClient has no timeout. A connection that is established but never returns data will hang the test indefinitely. It could be better to use &http.Client{Timeout: 10 * time.Second} for connectivity checks

}

fileName := time.Now().Format("20060102-150405") + "-api-debug.log"
logFile, err := os.Create(filepath.Join(dir, fileName))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

logFile is opened here but never stored or closed. If the test process is killed, buffered log data may be lost. Store the *os.File in testContext and close it in cleanup, or use defer in initAPILogger with a registry in BeforeSuite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants