From 4063b71ef0fbbc3c878e77c42c96db58f3b3ec49 Mon Sep 17 00:00:00 2001 From: Tao Zou Date: Tue, 5 Nov 2024 16:11:31 +0800 Subject: [PATCH] Add staticroute e2e test Add staticroute e2e test --- pkg/nsx/services/staticroute/staticroute.go | 8 ++-- test/e2e/manifest/nsx_staticroute_test.go | 45 +++++++++++++++++++ .../manifest/testStaticRoute/staticroute.yaml | 8 ++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 test/e2e/manifest/nsx_staticroute_test.go create mode 100644 test/e2e/manifest/testStaticRoute/staticroute.yaml diff --git a/pkg/nsx/services/staticroute/staticroute.go b/pkg/nsx/services/staticroute/staticroute.go index 4a007b538..ed47fb4df 100644 --- a/pkg/nsx/services/staticroute/staticroute.go +++ b/pkg/nsx/services/staticroute/staticroute.go @@ -120,7 +120,7 @@ func (service *StaticRouteService) DeleteStaticRouteByPath(orgId string, project return err } - log.Info("successfully deleted NSX StaticRoute", "nsxStaticRoute", *staticroute.Id) + log.Info("Successfully deleted NSX StaticRoute", "nsxStaticRoute", *staticroute.Id) return nil } func (service *StaticRouteService) GetUID(staticroute *model.StaticRoutes) *string { @@ -173,17 +173,17 @@ func (service *StaticRouteService) ListStaticRoute() []*model.StaticRoutes { func (service *StaticRouteService) Cleanup(ctx context.Context) error { staticRouteSet := service.ListStaticRoute() - log.Info("cleanup staticroute", "count", len(staticRouteSet)) + log.Info("Cleanup staticroute", "count", len(staticRouteSet)) for _, staticRoute := range staticRouteSet { path := strings.Split(*staticRoute.Path, "/") - log.Info("removing staticroute", "staticroute path", *staticRoute.Path) + log.Info("Deleting staticroute", "staticroute path", *staticRoute.Path) select { case <-ctx.Done(): return errors.Join(nsxutil.TimeoutFailed, ctx.Err()) default: err := service.DeleteStaticRouteByPath(path[2], path[4], path[6], *staticRoute.Id) if err != nil { - log.Error(err, "remove staticroute failed", "staticroute id", *staticRoute.Id) + log.Error(err, "Delete staticroute failed", "staticroute id", *staticRoute.Id) return err } } diff --git a/test/e2e/manifest/nsx_staticroute_test.go b/test/e2e/manifest/nsx_staticroute_test.go new file mode 100644 index 000000000..5596218bd --- /dev/null +++ b/test/e2e/manifest/nsx_staticroute_test.go @@ -0,0 +1,45 @@ +// This file is for e2e StaticRoute tests. + +package e2e + +import ( + "path/filepath" + "testing" + + "github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/common" +) + +const ( + StaticRoute = "StaticRoute" +) + +// TestStaticRouteBasic verifies that it could successfully realize StaticRoute. +func TestStaticRouteBasic(t *testing.T) { + ns := "sc-a" + name := "guestcluster-staticroute-2" + setupTest(t, ns) + defer teardownTest(t, ns, defaultTimeout) + + // Create StaticRoute + StaticRoutePath, _ := filepath.Abs("./manifest/testStaticRoute/staticroute.yaml") + err := applyYAML(StaticRoutePath, ns) + if err != nil { + t.Fatalf("Failed to apply StaticRoute YAML file: %v", err) + } + assertNil(t, err) + + // Check StaticRoute status + err = testData.waitForCRReadyOrDeleted(defaultTimeout, StaticRoute, ns, name, Ready) + assertNil(t, err, "Error when waiting for Static Route %s", name) + + // Check nsx-t resource existing + err = testData.waitForResourceExistOrNot(ns, common.ResourceTypeStaticRoute, name, true) + assertNil(t, err) + + // Delete StaticRoute + _ = deleteYAML(StaticRoutePath, ns) + + // Check nsx-t resource not existing + err = testData.waitForResourceExistOrNot(ns, common.ResourceTypeStaticRoute, name, false) + assertNil(t, err) +} diff --git a/test/e2e/manifest/testStaticRoute/staticroute.yaml b/test/e2e/manifest/testStaticRoute/staticroute.yaml new file mode 100644 index 000000000..629cbf4b6 --- /dev/null +++ b/test/e2e/manifest/testStaticRoute/staticroute.yaml @@ -0,0 +1,8 @@ +apiVersion: nsx.vmware.com/v1alpha1 +kind: StaticRoute +metadata: + name: guestcluster-staticroute-2 +spec: + network: 45.1.2.0/24 + nextHops: + - ipAddress: 172.10.0.2