/
upgrade.go
82 lines (71 loc) · 1.87 KB
/
upgrade.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"encoding/json"
"fmt"
"strings"
"time"
"github.com/spf13/pflag"
"k8s.io/kubernetes/pkg/kubectl/util/templates"
"k8s.io/kubernetes/test/e2e/upgrades"
"github.com/openshift/origin/pkg/test/ginkgo"
"github.com/openshift/origin/test/e2e/upgrade"
exutil "github.com/openshift/origin/test/extended/util"
)
// upgradeSuites are all known upgade test suites this binary should run
var upgradeSuites = []*ginkgo.TestSuite{
{
Name: "all",
Description: templates.LongDesc(`
Run all tests.
`),
Matches: func(name string) bool { return strings.Contains(name, "[Feature:ClusterUpgrade]") },
Init: func() error { return filterUpgrade(upgrade.AllTests(), func(name string) bool { return true }) },
TestTimeout: 120 * time.Minute,
},
}
type UpgradeOptions struct {
Suite string
ToImage string
JUnitDir string
}
func (o *UpgradeOptions) ToEnv() string {
out, err := json.Marshal(o)
if err != nil {
panic(err)
}
return string(out)
}
func initUpgrade(value string) error {
if len(value) == 0 {
return nil
}
var opt UpgradeOptions
if err := json.Unmarshal([]byte(value), &opt); err != nil {
return err
}
for _, suite := range upgradeSuites {
if suite.Name == opt.Suite {
exutil.TestContext.UpgradeTarget = ""
exutil.TestContext.UpgradeImage = opt.ToImage
exutil.TestContext.ReportDir = opt.JUnitDir
if suite.Init != nil {
return suite.Init()
}
return nil
}
}
return fmt.Errorf("unrecognized upgrade info")
}
func filterUpgrade(tests []upgrades.Test, match func(string) bool) error {
var scope []upgrades.Test
for _, test := range tests {
if match(test.Name()) {
scope = append(scope, test)
}
}
upgrade.SetTests(scope)
return nil
}
func bindUpgradeOptions(opt *UpgradeOptions, flags *pflag.FlagSet) {
flags.StringVar(&opt.ToImage, "to-image", opt.ToImage, "Specify the image to test an upgrade to.")
}