Skip to content

Commit

Permalink
Merge pull request kubevirt#2067 from cynepco3hahue/bazel_fix_tests
Browse files Browse the repository at this point in the history
Bring cirros images to the sandbox where the test runs
  • Loading branch information
rmohr authored Mar 1, 2019
2 parents 0c5ec78 + 149b473 commit 6f1f653
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ tools/vms-generator/vms-generator
coverage.html
manifests/**/*.tmp
bazel-*
.bazelrc
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ script:
- make build
- if [[ -n "$(git status --porcelain)" ]] ; then echo "It seems like you need to run
`make`. Please run it and commit the changes"; git status --porcelain; false; fi
- if [[ $TRAVIS_REPO_SLUG == "kubevirt/kubevirt" ]]; then make goveralls; else make test; fi
- if [[ $TRAVIS_REPO_SLUG == "kubevirt/kubevirt" ]]; then make goveralls; else make bazel-tests; fi
- make apidocs
- make client-python
- make manifests DOCKER_PREFIX="docker.io/kubevirt" DOCKER_TAG=$TRAVIS_TAG # falls back to latest if not on a tag
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ bazel-push-images:
--define container_tag=${CONTAINER_TAG} \
//:push-images"

bazel-tests:
hack/dockerized "bazel test --test_output=errors -- //pkg/... "

generate: bazel-generate
hack/dockerized "DOCKER_PREFIX=${DOCKER_PREFIX} DOCKER_TAG=${DOCKER_TAG} IMAGE_PULL_POLICY=${IMAGE_PULL_POLICY} VERBOSITY=${VERBOSITY} ./hack/generate.sh"

Expand Down Expand Up @@ -115,8 +118,8 @@ builder-publish:
.PHONY: \
bazel-generate \
bazel-build \
bazel-build-images \
bazel-push-images \
bazel-tests \
build \
test \
clean \
Expand Down
8 changes: 7 additions & 1 deletion hack/dockerized
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ SYNC_VENDOR=${SYNC_VENDOR:-false}

TEMPFILE=".rsynctemp"

# Reduce verbosity if an automated build
BUILDER_EXTRA_ARGS=""
if [ -n "${KUBEVIRT_CACHE_FROM}" ]; then
BUILDER_EXTRA_ARGS="${BUILDER_EXTRA_ARGS} --cache-from kubevirt/builder-cache:${KUBEVIRT_CACHE_FROM}"
Expand All @@ -23,6 +22,13 @@ if [ -n "${KUBEVIRT_UPDATE_CACHE_FROM}" ]; then
BUILDER_EXTRA_ARGS="${BUILDER_EXTRA_ARGS} -t kubevirt/builder-cache:${KUBEVIRT_UPDATE_CACHE_FROM}"
fi

# Be less verbose with bazel
if [ -n "${TRAVIS_JOB_ID}" ]; then
cat >.bazelrc <<EOF
common --noshow_progress --noshow_loading_progress
EOF
fi

# Build the build container
(cd ${DOCKER_DIR} && docker build . ${BUILDER_EXTRA_ARGS} -t ${BUILDER})

Expand Down
5 changes: 5 additions & 0 deletions pkg/virtctl/imageupload/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ go_test(
"imageupload_suite_test.go",
"imageupload_test.go",
],
args = [
"--cirros-image-path",
"$(location @cirros_image//file)",
],
data = ["@cirros_image//file"],
embed = [":go_default_library"],
deps = [
"//pkg/kubecli:go_default_library",
Expand Down
27 changes: 19 additions & 8 deletions pkg/virtctl/imageupload/imageupload_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package imageupload_test

import (
"flag"
"fmt"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"time"

"github.com/golang/mock/gomock"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -30,14 +32,22 @@ const (
podPhaseAnnotation = "cdi.kubevirt.io/storage.pod.phase"
)

var _ = Describe("ImageUpload", func() {
const (
pvcNamespace = "default"
pvcName = "test-pvc"
pvcSize = "500Mi"
)

const (
pvcNamespace = "default"
pvcName = "test-pvc"
pvcSize = "500Mi"
imagePath = "../../../vendor/kubevirt.io/containerized-data-importer/tests/images/cirros-qcow2.img"
)
var imagePath string

func init() {
// how could this ever happen that we have a 13MB blob in our repo?
flag.StringVar(&imagePath, "cirros-image-path", "vendor/kubevirt.io/containerized-data-importer/tests/images/cirros-qcow2.img", "path to cirros test image")
flag.Parse()
imagePath = filepath.Join("../../../", imagePath)
}

var _ = Describe("ImageUpload", func() {

var (
ctrl *gomock.Controller
Expand All @@ -60,6 +70,7 @@ var _ = Describe("ImageUpload", func() {
})

addPodPhaseAnnotation := func() {
defer GinkgoRecover()
time.Sleep(10 * time.Millisecond)
pvc, err := kubeClient.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(pvcName, metav1.GetOptions{})
Expect(err).To(BeNil())
Expand Down

0 comments on commit 6f1f653

Please sign in to comment.