minikube/test/integration/version_upgrade_test.go

98 lines
3.0 KiB
Go
Raw Normal View History

/*
Copyright 2019 The Kubernetes Authors All rights reserved.
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.
*/
package integration
import (
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"
"runtime"
2019-06-24 03:42:05 +00:00
"strings"
"testing"
2019-07-24 20:32:32 +00:00
"time"
"github.com/docker/machine/libmachine/state"
"k8s.io/minikube/pkg/minikube/constants"
2019-08-14 05:18:47 +00:00
"k8s.io/minikube/pkg/util/retry"
2019-07-26 17:00:51 +00:00
"github.com/hashicorp/go-getter"
pkgutil "k8s.io/minikube/pkg/util"
)
2019-06-12 17:44:04 +00:00
// 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) {
profile := UniqueProfileName("vupgrade")
ctx, cancel := context.WithTimeout(context.Background(), 55*time.Minute)
MaybeSlowParallel(t)
2019-07-26 17:00:51 +00:00
defer CleanupWithLogs(t, profile, cancel)
tf, err := ioutil.TempFile("", "minikube-release.*.exe")
if err != nil {
t.Fatalf("tempfile: %v", err)
}
defer os.Remove(tf.Name())
tf.Close()
url := pkgutil.GetBinaryDownloadURL("latest", runtime.GOOS)
if err := retry.Expo(func() error { return getter.GetFile(tf.Name(), url) }, 3*time.Second, 3*time.Minute); err != nil {
t.Fatalf("get failed: %v", err)
}
if runtime.GOOS != "windows" {
if err := os.Chmod(tf.Name(), 0700); err != nil {
t.Errorf("chmod: %v", err)
}
}
args := append([]string{"start", "-p", profile, fmt.Sprintf("--kubernetes-version=%s", constants.OldestKubernetesVersion), "--alsologtostderr", "-v=1"}, StartArgs()...)
rr := &RunResult{}
releaseStart := func() error {
rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), args...))
return err
}
// Retry to allow flakiness for the previous release
if err := retry.Expo(releaseStart, 1*time.Second, 30*time.Minute, 3); err != nil {
t.Fatalf("release start failed: %v", err)
}
rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), "stop", "-p", profile))
if err != nil {
t.Fatalf("%s failed: %v", rr.Args, err)
}
rr, err = Run(t, exec.CommandContext(ctx, tf.Name(), "-p", profile, "status", "--format={{.Host}}"))
if err != nil {
t.Logf("status error: %v (may be ok)", err)
}
got := strings.TrimSpace(rr.Stdout.String())
if got != state.Stopped.String() {
t.Errorf("status = %q; want = %q", got, state.Stopped.String())
}
2019-09-13 14:42:30 +00:00
args = append([]string{"start", "-p", profile, fmt.Sprintf("--kubernetes-version=%s", constants.NewestKubernetesVersion), "--alsologtostderr", "-v=1"}, StartArgs()...)
rr, err = Run(t, exec.CommandContext(ctx, Target(), args...))
if err != nil {
t.Errorf("%s failed: %v", rr.Args, err)
}
}