diff --git a/.travis.yml b/.travis.yml index 38cc59e9..8de37b2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ script: - cd ../.. - mv kubevirt ../kubevirt.io - cd ../kubevirt.io/ovs-cni + - make test deploy: - provider: script diff --git a/Makefile b/Makefile index c72fb9b8..7ec5dc73 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,9 @@ format: go vet ./pkg/... test: + hack/tests.sh + +docker-test: go test ./cmd/... ./pkg/... -v --ginkgo.v test-%: diff --git a/automation/check-patch.sh b/automation/check-patch.sh index 4f6d408a..8d24914d 100755 --- a/automation/check-patch.sh +++ b/automation/check-patch.sh @@ -18,9 +18,6 @@ main() { ln -s $(pwd)/ovs-cni go/src/kubevirt.io/ cd go/src/kubevirt.io/ovs-cni - echo "Run tests" - make build test - echo "Run functional tests" exec automation/test.sh } diff --git a/hack/docker-builder/Dockerfile b/hack/docker-builder/Dockerfile index 5d15fd7a..98bc7ad5 100644 --- a/hack/docker-builder/Dockerfile +++ b/hack/docker-builder/Dockerfile @@ -1,9 +1,9 @@ FROM fedora:28 -RUN dnf -y install make git sudo gcc gradle rsync-daemon rsync && \ +RUN dnf -y install make git sudo gcc gradle rsync-daemon rsync openvswitch hostname && \ dnf -y clean all -ENV GIMME_GO_VERSION=1.9 +ENV GIMME_GO_VERSION=1.10 RUN mkdir -p /gimme && curl -sL https://raw.githubusercontent.com/travis-ci/gimme/master/gimme | HOME=/gimme bash >> /etc/profile.d/gimme.sh diff --git a/hack/docker-builder/entrypoint.sh b/hack/docker-builder/entrypoint.sh index 00e6ce26..d426e297 100755 --- a/hack/docker-builder/entrypoint.sh +++ b/hack/docker-builder/entrypoint.sh @@ -4,4 +4,12 @@ set -o pipefail source /etc/profile.d/gimme.sh export GOPATH="/root/go" + +# launch OVS +function quit { + /usr/share/openvswitch/scripts/ovs-ctl stop + exit 0 +} +trap quit SIGTERM +/usr/share/openvswitch/scripts/ovs-ctl start --system-id=random eval "$@" diff --git a/hack/tests.sh b/hack/tests.sh new file mode 100755 index 00000000..0cbfbf42 --- /dev/null +++ b/hack/tests.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# +# This file is part of the KubeVirt project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Copyright 2017 Red Hat, Inc. +# + +set -e +source $(dirname "$0")/common.sh + +DOCKER_DIR=${KUBEVIRT_DIR}/hack/docker-builder + +SYNC_OUT=${SYNC_OUT:-true} + +BUILDER=${job_prefix} + +SYNC_VENDOR=${SYNC_VENDOR:-false} + +TEMPFILE=".rsynctemp" + +# Reduce verbosity if an automated build +BUILD_QUIET= +if [ -n "$JOB_NAME" -o -n "$TRAVIS_BUILD_ID" ]; then + BUILD_QUIET="-q" +fi + +# Build the build container +(cd ${DOCKER_DIR} && docker build . ${BUILD_QUIET} -t ${BUILDER}) + +docker run --rm -it --privileged --network host --cap-add ALL -v /lib/modules:/lib/modules -v `pwd`:/root/go/src/kubevirt.io/ovs-cni -w "/root/go/src/kubevirt.io/ovs-cni" kubevirt make docker-test diff --git a/pkg/plugin/plugin_test.go b/pkg/plugin/plugin_test.go index b63ef336..2ea786a6 100644 --- a/pkg/plugin/plugin_test.go +++ b/pkg/plugin/plugin_test.go @@ -16,17 +16,16 @@ package plugin import ( "fmt" - "net" - "os/exec" - "strconv" - "strings" - "github.com/containernetworking/cni/pkg/skel" "github.com/containernetworking/cni/pkg/types" "github.com/containernetworking/cni/pkg/types/current" "github.com/containernetworking/plugins/pkg/ns" "github.com/containernetworking/plugins/pkg/testutils" "github.com/vishvananda/netlink" + "net" + "os/exec" + "strconv" + "strings" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" diff --git a/tests/temp_test.go b/tests/ovs_test.go similarity index 79% rename from tests/temp_test.go rename to tests/ovs_test.go index f32185cd..fa5fc7aa 100644 --- a/tests/temp_test.go +++ b/tests/ovs_test.go @@ -17,7 +17,6 @@ package tests_test import ( "flag" - . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -25,13 +24,20 @@ import ( "k8s.io/client-go/tools/clientcmd" ) -var _ = Describe("ovs-cni tests", func() { - Describe("pod availability tests", func() { - var kubeconfig *string +var _ = Describe("ovs-cni", func() { + var kubeconfig *string + var clientset *kubernetes.Clientset + + BeforeSuite(func() { kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file") flag.Parse() - config, _ := clientcmd.BuildConfigFromFlags("", *kubeconfig) - clientset, _ := kubernetes.NewForConfig(config) + config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig) + Expect(err).ToNot(HaveOccurred()) + clientset, err = kubernetes.NewForConfig(config) + Expect(err).ToNot(HaveOccurred()) + }) + + Describe("pod availability tests", func() { pods, _ := clientset.CoreV1().Pods("").List(v1.ListOptions{}) Context("pod availability tests", func() { It("assert pods exists", func() {