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

Add OCP tests extention #2461

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ WORKDIR /go/src/github.com/openshift/ovn-kubernetes
COPY . .
RUN cd go-controller; CGO_ENABLED=1 make
RUN cd go-controller; CGO_ENABLED=0 make windows
RUN cd openshift-hack; CGO_ENABLED=0 ./e2e/scripts/build-tests-ext.sh && \
gzip ./e2e/bin/ovnk-tests-ext

# Build RHEL-8 binaries (for upgrades from 4.12 and earlier)
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.22-openshift-4.17 AS rhel8
Expand Down Expand Up @@ -58,6 +60,7 @@ COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_o
COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_output/go/bin/ovnkube-trace /usr/bin/
COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_output/go/bin/hybrid-overlay-node /usr/bin/
COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/go-controller/_output/go/bin/ovnkube-observ /usr/bin/
COPY --from=builder /go/src/github.com/openshift/ovn-kubernetes/openshift-hack/e2e/bin/ovnk-tests-ext.gz /usr/bin/

# Copy RHEL-8 and RHEL-9 shim binaries where the CNO's ovnkube-node container startup script can find them
RUN mkdir -p /usr/libexec/cni/rhel9
Expand All @@ -73,7 +76,7 @@ RUN stat /usr/bin/oc
LABEL io.k8s.display-name="ovn kubernetes" \
io.k8s.description="This is a component of OpenShift Container Platform that provides an overlay network using ovn." \
summary="This is a component of OpenShift Container Platform that provides an overlay network using ovn." \
io.openshift.tags="openshift" \
io.openshift.tags="openshift,ovn-kubernetes" \
maintainer="Tim Rozet <[email protected]>"

WORKDIR /root
Expand Down
9 changes: 9 additions & 0 deletions openshift-hack/e2e/cmd/annotate/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
annotate "github.com/openshift/ovn-kubernetes/openshift-hack/e2e/pkg/annotate"
)

func main() {
annotate.Run(annotate.TestMaps, func(name string) bool { return false })
}
67 changes: 67 additions & 0 deletions openshift-hack/e2e/cmd/ovnk-tests-ext/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"os"

"github.com/openshift-eng/openshift-tests-extension/pkg/cmd"
e "github.com/openshift-eng/openshift-tests-extension/pkg/extension"
"github.com/openshift-eng/openshift-tests-extension/pkg/extension/extensiontests"
g "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo"
"github.com/openshift/ovn-kubernetes/openshift-hack/e2e/pkg/generated"
"github.com/spf13/cobra"

_ "github.com/ovn-org/ovn-kubernetes/test/e2e"
)

func main() {
// Create our registry of openshift-tests extensions
extensionRegistry := e.NewRegistry()
ovnTestsExtension := e.NewExtension("openshift", "payload", "ovn-kubernetes")
extensionRegistry.Register(ovnTestsExtension)
// add ovn-kubernetes tests into openshift suites
//TODO: figure out what additional test suites we want to contribute tests to
ovnTestsExtension.AddSuite(e.Suite{
Name: "ovn-kubernetes/conformance/serial",
Parents: []string{
"openshift/conformance/serial",
},
Qualifiers: []string{`!labels.exists(l, l == "Serial") && labels.exists(l, l == "Conformance")`},
})

specs, err := g.BuildExtensionTestSpecsFromOpenShiftGinkgoSuite()
if err != nil {
panic(err)
}
// Initialization for kube ginkgo test framework needs to run before all tests execute
specs.AddBeforeAll(func() {
if err := initializeTestFramework(os.Getenv("TEST_PROVIDER")); err != nil {
panic(err)
}
})
// Annotations get prepended to test names, these are additions to upstream
// tests for controlling skips, suite membership, etc.
//
// TODO:
// - Remove this annotation code, and migrate to Labels/Tags and
// the environmental skip code from the enhancement once its implemented.
// - Make sure to account for test renames that occur because of removal of these
// annotations
specs.Walk(func(spec *extensiontests.ExtensionTestSpec) {
if annotations, ok := generated.Annotations[spec.Name]; ok {
spec.Name += annotations
}
})
ovnTestsExtension.AddSpecs(specs)
// Cobra stuff
root := &cobra.Command{
Long: "OVN-Kubernetes tests extension for OpenShift",
}
root.AddCommand(
cmd.DefaultExtensionCommands(extensionRegistry)...,
)
if err := func() error {
return root.Execute()
}(); err != nil {
os.Exit(1)
}
}
101 changes: 101 additions & 0 deletions openshift-hack/e2e/cmd/ovnk-tests-ext/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package main

import (
"fmt"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"k8s.io/client-go/tools/clientcmd"
"os"
"path/filepath"
"strings"

"encoding/json"
"k8s.io/kubernetes/test/e2e/framework"
// these are loading important global flags that we need to get and set
_ "k8s.io/kubernetes/test/e2e"
_ "k8s.io/kubernetes/test/e2e/lifecycle"
)

// copied directly from github.com/openshift/origin/cmd/openshift-tests/provider.go
// and github.com/openshift/origin/test/extended/util/test.go
// but with the following changes:
// - removed CSI driver init
func initializeTestFramework(provider string) error {
if len(provider) == 0 {
return fmt.Errorf("provider must not be empty")
}
providerInfo := &ClusterConfiguration{}
if err := json.Unmarshal([]byte(provider), &providerInfo); err != nil {
return fmt.Errorf("provider must be a JSON object with the 'type' key at a minimum: %v", err)
}
if len(providerInfo.ProviderName) == 0 {
return fmt.Errorf("provider must have a name")
}
config := &ClusterConfiguration{}
if err := json.Unmarshal([]byte(provider), config); err != nil {
return fmt.Errorf("provider must decode into the ClusterConfig object: %v", err)
}

// update testContext with loaded config
testContext := &framework.TestContext
testContext.Provider = config.ProviderName
testContext.CloudConfig = framework.CloudConfig{
ProjectID: config.ProjectID,
Region: config.Region,
Zone: config.Zone,
Zones: config.Zones,
NumNodes: config.NumNodes,
MultiMaster: config.MultiMaster,
MultiZone: config.MultiZone,
ConfigFile: config.ConfigFile,
}
testContext.AllowedNotReadyNodes = 0
testContext.MinStartupPods = -1
testContext.MaxNodesToGather = 0
testContext.KubeConfig = os.Getenv("KUBECONFIG")

if ad := os.Getenv("ARTIFACT_DIR"); len(strings.TrimSpace(ad)) == 0 {
os.Setenv("ARTIFACT_DIR", filepath.Join(os.TempDir(), "artifacts"))
}

testContext.DeleteNamespace = os.Getenv("DELETE_NAMESPACE") != "false"
testContext.VerifyServiceAccount = false
//testfiles.AddFileSource(e2etestingmanifests.GetE2ETestingManifestsFS())
//TODO: do we really need the file systems?

testContext.KubectlPath = "kubectl"
// context.KubeConfig = KubeConfigPath()
testContext.KubeConfig = os.Getenv("KUBECONFIG")

// "debian" is used when not set. At least GlusterFS tests need "custom".
// (There is no option for "rhel" or "centos".)
testContext.NodeOSDistro = "custom"
testContext.MasterOSDistro = "custom"

// load and set the host variable for kubectl
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(&clientcmd.ClientConfigLoadingRules{ExplicitPath: testContext.KubeConfig}, &clientcmd.ConfigOverrides{})
cfg, err := clientConfig.ClientConfig()
if err != nil {
return err
}
testContext.Host = cfg.Host

//testContext.CreateTestingNS = func(ctx context.Context, baseName string, c kclientset.Interface, labels map[string]string) (*corev1.Namespace, error) {
// return e2e.CreateTestingNS(ctx, baseName, c, labels, true)
//}

gomega.RegisterFailHandler(ginkgo.Fail)

framework.AfterReadingAllFlags(testContext)
testContext.DumpLogsOnFailure = true

// these constants are taken from kube e2e and used by tests
testContext.IPFamily = "ipv4"
if config.HasIPv6 && !config.HasIPv4 {
testContext.IPFamily = "ipv6"
}

testContext.ReportDir = os.Getenv("TEST_JUNIT_DIR")

return nil
}
47 changes: 47 additions & 0 deletions openshift-hack/e2e/cmd/ovnk-tests-ext/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

// copied directly from github.com/openshift/origin/test/extended/util/cluster/cluster.go
type ClusterConfiguration struct {
ProviderName string `json:"type"`

// These fields (and the "type" tag for ProviderName) chosen to match
// upstream's e2e.CloudConfig.
ProjectID string
Region string
Zone string
NumNodes int
MultiMaster bool
MultiZone bool
Zones []string
ConfigFile string

// Disconnected is set for test jobs without external internet connectivity
Disconnected bool

// SingleReplicaTopology is set for disabling disruptive tests or tests
// that require high availability
SingleReplicaTopology bool

// NetworkPlugin is the "official" plugin name
NetworkPlugin string
// NetworkPluginMode is an optional sub-identifier for the NetworkPlugin.
// (Currently it is only used for OpenShiftSDN.)
NetworkPluginMode string `json:",omitempty"`

// HasIPv4 and HasIPv6 determine whether IPv4-specific, IPv6-specific,
// and dual-stack-specific tests are run
HasIPv4 bool
HasIPv6 bool

// HasSCTP determines whether SCTP connectivity tests can be run in the cluster
HasSCTP bool

// IsProxied determines whether we are accessing the cluster through an HTTP proxy
IsProxied bool

// IsIBMROKS determines whether the cluster is Managed IBM Cloud (ROKS)
IsIBMROKS bool

// IsNoOptionalCapabilities indicates the cluster has no optional capabilities enabled
HasNoOptionalCapabilities bool
}
127 changes: 127 additions & 0 deletions openshift-hack/e2e/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package e2e

import (
"context"
"flag"
"fmt"
"math/rand"
"os"
"strings"
"testing"
"time"

"gopkg.in/yaml.v2"

// Never, ever remove the line with "/ginkgo". Without it,
// the ginkgo test runner will not detect that this
// directory contains a Ginkgo test suite.
// See https://github.com/kubernetes/kubernetes/issues/74827
// "github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2"
"github.com/onsi/ginkgo/v2/types"

"github.com/openshift/ovn-kubernetes/openshift-hack/e2e/pkg/generated"
corev1 "k8s.io/api/core/v1"
kclientset "k8s.io/client-go/kubernetes"
"k8s.io/component-base/version"
conformancetestdata "k8s.io/kubernetes/test/conformance/testdata"
"k8s.io/kubernetes/test/e2e"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework/testfiles"
e2etestingmanifests "k8s.io/kubernetes/test/e2e/testing-manifests"
testfixtures "k8s.io/kubernetes/test/fixtures"
"k8s.io/kubernetes/test/utils/image"

// import OVN-Kubernetes E2Es
_ "github.com/ovn-org/ovn-kubernetes/test/e2e"

// Ensure that logging flags are part of the command line.
_ "k8s.io/component-base/logs/testinit"
)

//go:generate go run -mod vendor ./cmd/annotate -- ./pkg/generated/zz_generated.annotations.go

// This file duplicates most of test/e2e/e2e_test.go but limits the included
// tests (via include.go) to tests that are relevant to openshift.

func TestMain(m *testing.M) {
var versionFlag bool
flag.CommandLine.BoolVar(&versionFlag, "version", false, "Displays version information.")

if framework.TestContext.ListImages {
for _, v := range image.GetImageConfigs() {
fmt.Println(v.GetE2EImage())
}
os.Exit(0)
}
if versionFlag {
fmt.Printf("%s\n", version.Get())
os.Exit(0)
}

// Enable embedded FS file lookup as fallback
testfiles.AddFileSource(e2etestingmanifests.GetE2ETestingManifestsFS())
testfiles.AddFileSource(testfixtures.GetTestFixturesFS())
testfiles.AddFileSource(conformancetestdata.GetConformanceTestdataFS())

if framework.TestContext.ListConformanceTests {
var tests []struct {
Testname string `yaml:"testname"`
Codename string `yaml:"codename"`
Description string `yaml:"description"`
Release string `yaml:"release"`
File string `yaml:"file"`
}

data, err := testfiles.Read("test/conformance/testdata/conformance.yaml")
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := yaml.Unmarshal(data, &tests); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := yaml.NewEncoder(os.Stdout).Encode(tests); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
os.Exit(0)
}

// Ensure the test namespaces have disabled SCCs and label syncer.
framework.TestContext.CreateTestingNS = func(ctx context.Context, baseName string, c kclientset.Interface, labels map[string]string) (*corev1.Namespace, error) {
return CreateTestingNS(ctx, baseName, c, labels, true)
}

framework.AfterReadingAllFlags(&framework.TestContext)

// TODO: Deprecating repo-root over time... instead just use gobindata_util.go , see #23987.
// Right now it is still needed, for example by
// test/e2e/framework/ingress/ingress_utils.go
// for providing the optional secret.yaml file and by
// test/e2e/framework/util.go for cluster/log-dump.
if framework.TestContext.RepoRoot != "" {
testfiles.AddFileSource(testfiles.RootFileSource{Root: framework.TestContext.RepoRoot})
}

rand.Seed(time.Now().UnixNano())
os.Exit(m.Run())
}

func TestE2E(t *testing.T) {
// TODO(soltysh): this is raw copy from end of openshift-hack/e2e/annotate/generated/zz_generated.annotations.go
// https://issues.redhat.com/browse/OCPBUGS-25641
ginkgo.GetSuite().SetAnnotateFn(func(name string, node types.TestSpec) {
if newLabels, ok := generated.Annotations[name]; ok {
node.AppendText(newLabels)
} else {
panic(fmt.Sprintf("unable to find test %s", name))
}
if strings.Contains(name, "Kubectl client Kubectl prune with applyset should apply and prune objects") {
fmt.Printf("Trying to annotate %q\n", name)
}
})

e2e.RunE2ETests(t)
}
Loading