test: Allow sequential upgrades to be passed to upgrade test
Upgrade test now accepts comma-delimited images or versions in
`openshift-tests run-upgrade --image A,B`. This simplifies bulk
testing of upgrades and will allow us to test existing upgrade
paths.
@@ -6,6 +6,7 @@ import (
"math/rand"
"os"
"strconv"
+ "strings"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -61,7 +62,8 @@ func SetTests(tests []upgrades.Test) {
upgradeTests = tests
}
-// SetToImage sets the image that will be upgraded to.
+// SetToImage sets the image that will be upgraded to. This may be a comma delimited list
+// of sequential upgrade attempts.
func SetToImage(image string) {
upgradeToImage = image
}
@@ -116,7 +118,7 @@ var _ = g.Describe("[Disruptive]", func() {
client := configv1client.NewForConfigOrDie(config)
dynamicClient := dynamic.NewForConfigOrDie(config)
- upgCtx, err := getUpgradeContext(client, "", upgradeToImage)
+ upgCtx, err := getUpgradeContext(client, upgradeToImage)
framework.ExpectNoError(err, "determining what to upgrade to version=%s image=%s", "", upgradeToImage)
disruption.Run(
@@ -128,7 +130,9 @@ var _ = g.Describe("[Disruptive]", func() {
},
upgradeTests,
func() {
- framework.ExpectNoError(clusterUpgrade(client, dynamicClient, config, upgCtx.Versions[1]), "during upgrade")
+ for i := 1; i < len(upgCtx.Versions); i++ {
+ framework.ExpectNoError(clusterUpgrade(client, dynamicClient, config, upgCtx.Versions[i]), fmt.Sprintf("during upgrade to %s", upgCtx.Versions[i].NodeImage))
+ }
},
)
})
@@ -151,8 +155,8 @@ func latestCompleted(history []configv1.UpdateHistory) (*configv1.Update, bool)
return nil, false
}
-func getUpgradeContext(c configv1client.Interface, upgradeTarget, upgradeImage string) (*upgrades.UpgradeContext, error) {
- if upgradeTarget == "[pause]" {
+func getUpgradeContext(c configv1client.Interface, upgradeImage string) (*upgrades.UpgradeContext, error) {
+ if upgradeImage == "[pause]" {
return &upgrades.UpgradeContext{
Versions: []upgrades.VersionContext{
{Version: *version.MustParseSemantic("0.0.1"), NodeImage: "[pause]"},
@@ -206,24 +210,23 @@ func getUpgradeContext(c configv1client.Interface, upgradeTarget, upgradeImage s
},
}
- if len(upgradeTarget) == 0 && len(upgradeImage) == 0 {
+ if len(upgradeImage) == 0 {
return upgCtx, nil
}
- if (len(upgradeImage) > 0 && upgradeImage == current.Image) || (len(upgradeTarget) > 0 && upgradeTarget == current.Version) {
+ upgradeImages := strings.Split(upgradeImage, ",")
+ if (len(upgradeImages[0]) > 0 && upgradeImages[0] == current.Image) || (len(upgradeImages[0]) > 0 && upgradeImages[0] == current.Version) {
return nil, fmt.Errorf("cluster is already at version %s", versionString(*current))
}
-
+ for _, upgradeImage := range upgradeImages {
var next upgrades.VersionContext
- next.NodeImage = upgradeImage
- if len(upgradeTarget) > 0 {
- nextVer, err := version.ParseSemantic(upgradeTarget)
- if err != nil {
- return nil, err
- }
+ if nextVer, err := version.ParseSemantic(upgradeImage); err == nil {
next.Version = *nextVer
+ } else {
+ next.NodeImage = upgradeImage
}
upgCtx.Versions = append(upgCtx.Versions, next)
+ }
return upgCtx, nil
}
