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

Run unit tests on travis #56

Merged
merged 1 commit into from Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

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

it should be the other way around - docker-test runs hack/tests.sh

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

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 {
Copy link
Member

Choose a reason for hiding this comment

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

i don't like the fact that we use docker-builder to run tests, but i guess we can live with it if it saves us from another container

Copy link
Collaborator Author

@SchSeba SchSeba Dec 6, 2018

Choose a reason for hiding this comment

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

Yeah I don't think we need to create another container for that. I will be much more complex with volumes and mounts

/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