move file download logic to common.sh

pull/4946/head
Medya Gh 2019-07-26 10:00:51 -07:00
parent 04144ca1d4
commit 25bc27e170
5 changed files with 62 additions and 23 deletions

View File

@ -74,6 +74,12 @@ gsutil -qm cp \
"gs://minikube-builds/${MINIKUBE_LOCATION}/e2e-${OS_ARCH}" out
gsutil -qm cp "gs://minikube-builds/${MINIKUBE_LOCATION}/testdata"/* testdata/
gsutil -qm cp "gs://minikube-builds/${MINIKUBE_LOCATION}/testdata"/* testdata/
# to be used by TestVersionUpgrade
gsutil -qm cp gs://minikube/releases/latest/minikube-${OS_ARCH} testdata/minikube-${OS_ARCH}-latest-stable
chmod +x "testdata/minikube-${OS_ARCH}-latest-stable"
# Set the executable bit on the e2e binary and out binary
export MINIKUBE_BIN="out/minikube-${OS_ARCH}"

View File

@ -32,6 +32,7 @@ func TestFunctional(t *testing.T) {
if !usingNoneDriver(mk) {
t.Parallel()
}
mk.EnsureRunning()
// This one is not parallel, and ensures the cluster comes up
// before we run any other tests.

View File

@ -41,6 +41,7 @@ func TestPersistence(t *testing.T) {
if err != nil {
t.Errorf("Error getting the file path for current directory: %s", curdir)
}
// TODO change all testdata path to get from flag vs hardcode
podPath := path.Join(curdir, "testdata", "busybox.yaml")
// Create a pod and wait for it to be running.

View File

@ -162,6 +162,18 @@ func Retry(t *testing.T, callback func() error, d time.Duration, attempts int) (
return err
}
// Retry2 tries the callback for a number of attempts, with a delay without *testing.T
func Retry2(callback func() error, d time.Duration, attempts int) (err error) {
for i := 0; i < attempts; i++ {
err = callback()
if err == nil {
return nil
}
time.Sleep(d)
}
return err
}
// Logf writes logs to stdout if -v is set.
func Logf(str string, args ...interface{}) {
if !testing.Verbose() {

View File

@ -19,33 +19,51 @@ package integration
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
"github.com/docker/machine/libmachine/state"
"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants"
pkgutil "k8s.io/minikube/pkg/util"
"k8s.io/minikube/test/integration/util"
)
func downloadMinikubeBinary(t *testing.T, dest string, version string) error {
// Grab latest release binary
url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS)
download := func() error {
return getter.GetFile(dest, url)
}
// This is moved to common.sh
// func downloadMinikubeBinary(dest string, version string) error {
// // Grab latest release binary
// url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS)
// download := func() error {
// return getter.GetFile(dest, url)
// }
if err := util.Retry(t, download, 3*time.Second, 13); err != nil {
return errors.Wrap(err, "Failed to get latest release binary")
}
if runtime.GOOS != "windows" {
if err := os.Chmod(dest, 0700); err != nil {
// if err := util.Retry2(download, 3*time.Second, 13); err != nil {
// return errors.Wrap(err, "Failed to get latest release binary")
// }
// if runtime.GOOS != "windows" {
// if err := os.Chmod(dest, 0700); err != nil {
// return err
// }
// }
// return nil
// }
func fileExists(fname string) error {
check := func() error {
info, err := os.Stat(fname)
if os.IsNotExist(err) {
return err
}
if info.IsDir() {
return fmt.Errorf("Error expect file got dir")
}
return nil
}
if err := util.Retry2(check, 1*time.Second, 3); err != nil {
return errors.Wrap(err, fmt.Sprintf("Failed check if file (%q) exists,", fname))
}
return nil
}
@ -55,15 +73,20 @@ func downloadMinikubeBinary(t *testing.T, dest string, version string) error {
// and it tries to upgrade from the older supported k8s to news supported k8s
func TestVersionUpgrade(t *testing.T) {
p := t.Name()
// this gets downloaded by common.sh in the CI
fname := filepath.Join(*testdataDir, fmt.Sprintf("minikube-%s-%s-latest-stable", runtime.GOOS, runtime.GOARCH))
err := fileExists(fname)
if err != nil {
t.Fail()
}
mkCurrent := NewMinikubeRunner(t, p)
if usingNoneDriver(mkCurrent) { // TODO (medyagh@): bring back once soled https://github.com/kubernetes/minikube/issues/4418
t.Skip("skipping test as none driver does not support persistence")
}
mkCurrent.RunCommand("delete", true)
mkCurrent.CheckStatus(state.None.String())
fname := "minikube_latest_binary"
err := downloadMinikubeBinary(t, fname, "latest")
if err != nil {
t.Fatal(errors.Wrap(err, "Failed to download minikube binary."))
}
defer os.Remove(fname)
mkRelease := NewMinikubeRunner(t, p)
@ -74,12 +97,8 @@ func TestVersionUpgrade(t *testing.T) {
mkRelease.RunCommand("stop", true)
mkRelease.CheckStatus(state.Stopped.String())
opts := ""
if usingNoneDriver(mkCurrent) { // to avoid https://github.com/kubernetes/minikube/issues/4418
opts = "--apiserver-port=8444"
}
// Trim the leading "v" prefix to assert that we handle it properly.
mkCurrent.Start(fmt.Sprintf("--kubernetes-version=%s", strings.TrimPrefix(constants.NewestKubernetesVersion, "v")), opts)
mkCurrent.Start(fmt.Sprintf("--kubernetes-version=%s", strings.TrimPrefix(constants.NewestKubernetesVersion, "v")))
mkCurrent.CheckStatus(state.Running.String())
mkCurrent.RunCommand("delete", true)
mkCurrent.CheckStatus(state.None.String())