Merge pull request #4474 from medyagh/4418_fixTestVersionUpgrade

adding retriable http get
pull/4491/head
Sharif Elgamal 2019-06-14 10:09:46 -07:00 committed by GitHub
commit 44856928f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 20 deletions

View File

@ -23,9 +23,9 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http"
"testing" "testing"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/notify" "k8s.io/minikube/pkg/minikube/notify"
"k8s.io/minikube/pkg/util" "k8s.io/minikube/pkg/util"
@ -33,7 +33,7 @@ import (
func getSHAFromURL(url string) (string, error) { func getSHAFromURL(url string) (string, error) {
fmt.Println("Downloading: ", url) fmt.Println("Downloading: ", url)
r, err := http.Get(url) r, err := retryablehttp.Get(url)
if err != nil { if err != nil {
return "", err return "", err
} }

1
go.mod
View File

@ -31,6 +31,7 @@ require (
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect
github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604 // indirect github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604 // indirect
github.com/hashicorp/go-retryablehttp v0.5.4
github.com/hashicorp/go-version v1.1.0 // indirect github.com/hashicorp/go-version v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880 // indirect github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880 // indirect
github.com/hashicorp/hcl v0.0.0-20160711231752-d8c773c4cba1 // indirect github.com/hashicorp/hcl v0.0.0-20160711231752-d8c773c4cba1 // indirect

4
go.sum
View File

@ -64,8 +64,12 @@ github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWet
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce h1:prjrVgOk2Yg6w+PflHoszQNLTUh4kaByUcEWM/9uin4= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce h1:prjrVgOk2Yg6w+PflHoszQNLTUh4kaByUcEWM/9uin4=
github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604 h1:VIq8E7fMiC4h3agg0ya56L0jHn7QisZZcWZXVKJb9jQ= github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604 h1:VIq8E7fMiC4h3agg0ya56L0jHn7QisZZcWZXVKJb9jQ=
github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= github.com/hashicorp/go-multierror v0.0.0-20160811015721-8c5f0ad93604/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I=
github.com/hashicorp/go-retryablehttp v0.5.4 h1:1BZvpawXoJCWX6pNtow9+rpEj+3itIlutiqnntI6jOE=
github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0= github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880 h1:OaRuzt9oCKNui8cCskZijoKUwe+aCuuCwvx1ox8FNyw= github.com/hashicorp/golang-lru v0.0.0-20160207214719-a0d98a5f2880 h1:OaRuzt9oCKNui8cCskZijoKUwe+aCuuCwvx1ox8FNyw=

View File

@ -32,6 +32,7 @@ import (
units "github.com/docker/go-units" units "github.com/docker/go-units"
"github.com/golang/glog" "github.com/golang/glog"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -130,7 +131,7 @@ func RetryAfter(attempts int, callback func() error, d time.Duration) (err error
// ParseSHAFromURL downloads and reads a SHA checksum from an URL // ParseSHAFromURL downloads and reads a SHA checksum from an URL
func ParseSHAFromURL(url string) (string, error) { func ParseSHAFromURL(url string) (string, error) {
r, err := http.Get(url) r, err := retryablehttp.Get(url)
if err != nil { if err != nil {
return "", errors.Wrap(err, "Error downloading checksum.") return "", errors.Wrap(err, "Error downloading checksum.")
} else if r.StatusCode != http.StatusOK { } else if r.StatusCode != http.StatusOK {

View File

@ -32,6 +32,7 @@ import (
"time" "time"
"github.com/docker/machine/libmachine/state" "github.com/docker/machine/libmachine/state"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
pkgutil "k8s.io/minikube/pkg/util" pkgutil "k8s.io/minikube/pkg/util"
"k8s.io/minikube/test/integration/util" "k8s.io/minikube/test/integration/util"
@ -105,7 +106,7 @@ func testDashboard(t *testing.T) {
t.Errorf("got host %s, expected 127.0.0.1", host) t.Errorf("got host %s, expected 127.0.0.1", host)
} }
resp, err := http.Get(u.String()) resp, err := retryablehttp.Get(u.String())
if err != nil { if err != nil {
t.Fatalf("failed get: %v", err) t.Fatalf("failed get: %v", err)
} }

View File

@ -31,6 +31,7 @@ import (
"net/url" "net/url"
"github.com/elazarl/goproxy" "github.com/elazarl/goproxy"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/phayes/freeport" "github.com/phayes/freeport"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -148,7 +149,8 @@ func testProxyDashboard(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("failed to parse %q: %v", s, err) t.Fatalf("failed to parse %q: %v", s, err)
} }
resp, err := http.Get(u.String())
resp, err := retryablehttp.Get(u.String())
if err != nil { if err != nil {
t.Fatalf("failed get: %v", err) t.Fatalf("failed get: %v", err)
} }

View File

@ -20,49 +20,59 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http"
"os" "os"
"runtime" "runtime"
"testing" "testing"
"github.com/docker/machine/libmachine/state" "github.com/docker/machine/libmachine/state"
retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/constants"
pkgutil "k8s.io/minikube/pkg/util" pkgutil "k8s.io/minikube/pkg/util"
) )
func TestVersionUpgrade(t *testing.T) { func downloadMinikubeBinary(version string) (*os.File, error) {
currentRunner := NewMinikubeRunner(t)
currentRunner.RunCommand("delete", true)
currentRunner.CheckStatus(state.None.String())
// Grab latest release binary // Grab latest release binary
url := pkgutil.GetBinaryDownloadURL("latest", runtime.GOOS) url := pkgutil.GetBinaryDownloadURL(version, runtime.GOOS)
resp, err := http.Get(url) resp, err := retryablehttp.Get(url)
if err != nil { if err != nil {
t.Fatal(errors.Wrap(err, "Failed to get latest release binary")) return nil, errors.Wrap(err, "Failed to get latest release binary")
} }
defer resp.Body.Close() defer resp.Body.Close()
tf, err := ioutil.TempFile("", "minikube") tf, err := ioutil.TempFile("", "minikube")
if err != nil { if err != nil {
t.Fatal(errors.Wrap(err, "Failed to create binary file")) return nil, errors.Wrap(err, "Failed to create binary file")
} }
defer os.Remove(tf.Name())
_, err = io.Copy(tf, resp.Body) _, err = io.Copy(tf, resp.Body)
if err != nil { if err != nil {
t.Fatal(errors.Wrap(err, "Failed to populate temp file")) return nil, errors.Wrap(err, "Failed to populate temp file")
} }
if err := tf.Close(); err != nil { if err := tf.Close(); err != nil {
t.Fatal(errors.Wrap(err, "Failed to close temp file")) return nil, errors.Wrap(err, "Failed to close temp file")
} }
if runtime.GOOS != "windows" { if runtime.GOOS != "windows" {
if err := os.Chmod(tf.Name(), 0700); err != nil { if err := os.Chmod(tf.Name(), 0700); err != nil {
t.Fatal(errors.Wrap(err, "Failed to make binary executable.")) return nil, err
// t.Fatal(errors.Wrap(err, "Failed to make binary executable."))
} }
} }
return tf, err
}
// TestVersionUpgrade downloads latest version of minikube and runs with
// the odlest supported k8s version and then runs the current head minikube
// and it tries to upgrade from the older supported k8s to news supported k8s
func TestVersionUpgrade(t *testing.T) {
currentRunner := NewMinikubeRunner(t)
currentRunner.RunCommand("delete", true)
currentRunner.CheckStatus(state.None.String())
tf, err := downloadMinikubeBinary("latest")
if err != nil || tf == nil {
t.Fatal(errors.Wrap(err, "Failed to download minikube binary."))
}
defer os.Remove(tf.Name())
releaseRunner := NewMinikubeRunner(t) releaseRunner := NewMinikubeRunner(t)
releaseRunner.BinaryPath = tf.Name() releaseRunner.BinaryPath = tf.Name()