This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
/
upgrade.go
127 lines (114 loc) · 3.1 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"encoding/json"
"fmt"
"strings"
"time"
"github.com/spf13/pflag"
"k8s.io/kubectl/pkg/util/templates"
"k8s.io/kubernetes/test/e2e/cloud/gcp"
"k8s.io/kubernetes/test/e2e/upgrades"
"github.com/openshift/openshift-tests/pkg/test/ginkgo"
"github.com/openshift/openshift-tests/test/e2e/upgrade"
exutil "github.com/openshift/openshift-tests/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]") && strings.Contains(name, "[Suite:openshift]")
},
Init: func(opt map[string]string) error {
for k, v := range opt {
switch k {
case "abort-at":
if err := upgrade.SetUpgradeAbortAt(v); err != nil {
return err
}
case "disrupt-reboot":
if err := upgrade.SetUpgradeDisruptReboot(v); err != nil {
return err
}
default:
return fmt.Errorf("unrecognized upgrade option: %s", k)
}
}
return filterUpgrade(upgrade.AllTests(), func(name string) bool { return true })
},
TestTimeout: 120 * time.Minute,
},
}
type UpgradeOptions struct {
Suite string
ToImage string
JUnitDir string
TestOptions []string
}
func (o *UpgradeOptions) OptionsMap() (map[string]string, error) {
options := make(map[string]string)
for _, option := range o.TestOptions {
parts := strings.SplitN(option, "=", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("test option %q is not valid, must be KEY=VALUE", option)
}
if len(parts[0]) == 0 {
return nil, fmt.Errorf("test option %q is not valid, must be KEY=VALUE", option)
}
_, exists := options[parts[0]]
if exists {
return nil, fmt.Errorf("option %q declared twice", parts[0])
}
options[parts[0]] = parts[1]
}
return options, nil
}
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 {
gcp.SetUpgradeTarget("")
gcp.SetUpgradeImage(opt.ToImage)
exutil.TestContext.ReportDir = opt.JUnitDir
o, err := opt.OptionsMap()
if err != nil {
return err
}
if suite.Init != nil {
return suite.Init(o)
}
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.")
flags.StringSliceVar(&opt.TestOptions, "options", opt.TestOptions, "A set of KEY=VALUE options to control the test. See the help text.")
}