Skip to content

Commit

Permalink
Fix unit and functional tests for the plugin
Browse files Browse the repository at this point in the history
* unit tests are going to run on travis.
* functional tests are going to run on STD-CI
  • Loading branch information
SchSeba committed Dec 6, 2018
1 parent b0e5bf2 commit b51a243
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -14,6 +14,7 @@ script:
- cd ../..
- mv kubevirt ../kubevirt.io
- cd ../kubevirt.io/ovs-cni
- make docker-test

deploy:
- provider: script
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Expand Up @@ -22,6 +22,9 @@ format:
test:
go test ./cmd/... ./pkg/... -v --ginkgo.v

docker-test:
hack/test-dockerized.sh

test-%:
go test ./$(subst -,/,$*)/... -v --ginkgo.v

Expand Down
6 changes: 0 additions & 6 deletions automation/check-patch.sh
Expand Up @@ -8,19 +8,13 @@ main() {
echo "TARGET=$TARGET"
export TARGET

echo "Start ovs process"
/usr/share/openvswitch/scripts/ovs-ctl --system-id=random start

cd ..
mkdir -p go/src/kubevirt.io
mkdir -p go/pkg
export GOPATH=$(pwd)/go
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
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/ephemeral-provider-common.sh
Expand Up @@ -17,7 +17,7 @@

set -e

_cli="docker run --privileged --net=host --rm ${USE_TTY} -v /var/run/docker.sock:/var/run/docker.sock kubevirtci/gocli@sha256:aa7f295a7908fa333ab5e98ef3af0bfafbabfd3cee2b83f9af47f722e3000f6a"
_cli="docker run --privileged --net=host --rm ${USE_TTY} -v /var/run/docker.sock:/var/run/docker.sock kubevirtci/gocli@sha256:df958c060ca8d90701a1b592400b33852029979ad6d5c1d9b79683033704b690"

function _main_ip() {
echo 127.0.0.1
Expand Down
4 changes: 2 additions & 2 deletions 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

Expand Down
8 changes: 8 additions & 0 deletions hack/docker-builder/entrypoint.sh
Expand Up @@ -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 "$@"
42 changes: 42 additions & 0 deletions hack/test-dockerized.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" ${BUILDER} make test
21 changes: 13 additions & 8 deletions tests/temp_test.go → tests/ovs_test.go
Expand Up @@ -17,24 +17,29 @@ package tests_test

import (
"flag"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

var _ = Describe("ovs-cni tests", func() {
var _ = Describe("ovs-cni", func() {
var clientset *kubernetes.Clientset
kubeconfig := flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
flag.Parse()

BeforeSuite(func() {
config, err := clientcmd.BuildConfigFromFlags("", *kubeconfig)
Expect(err).ToNot(HaveOccurred())
clientset, err = kubernetes.NewForConfig(config)
Expect(err).ToNot(HaveOccurred())
})

Describe("pod availability tests", func() {
var kubeconfig *string
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
flag.Parse()
config, _ := clientcmd.BuildConfigFromFlags("", *kubeconfig)
clientset, _ := kubernetes.NewForConfig(config)
pods, _ := clientset.CoreV1().Pods("").List(v1.ListOptions{})
Context("pod availability tests", func() {
It("assert pods exists", func() {
pods, _ := clientset.CoreV1().Pods("").List(v1.ListOptions{})
Expect(len(pods.Items)).Should(BeNumerically(">", 0))
})
})
Expand Down

0 comments on commit b51a243

Please sign in to comment.