-
Notifications
You must be signed in to change notification settings - Fork 80
/
upgrade_test_configuration.go
109 lines (92 loc) · 3.94 KB
/
upgrade_test_configuration.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
/*
* upgrade_test_configuration.go
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2023 Apple Inc. and the FoundationDB project authors
*
* 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 fixtures
import (
"log"
"strings"
fdbv1beta2 "github.com/FoundationDB/fdb-kubernetes-operator/api/v1beta2"
"github.com/onsi/ginkgo/v2"
)
// UpgradeTestConfiguration represents the configuration for an upgrade test. This includes the initial FoundationDB version
// and the target FoundationDB version to upgrade the cluster to.
type UpgradeTestConfiguration struct {
// InitialVersion represents the version before the upgrade.
InitialVersion fdbv1beta2.Version
// TargetVersion represents the version to upgrade to.
TargetVersion fdbv1beta2.Version
}
func parseUpgradeVersionPair(upgradeConfig string) UpgradeTestConfiguration {
versions := strings.Split(upgradeConfig, ":")
if len(versions) != 2 {
log.Fatalf(
"expected to have two versions for upgrade string separated by \":\" got: \"%s\"",
upgradeConfig,
)
}
initialVersion, err := fdbv1beta2.ParseFdbVersion(versions[0])
if err != nil {
log.Fatalf("\"%s\" is not a valid FDB version", versions[0])
}
targetVersion, err := fdbv1beta2.ParseFdbVersion(versions[1])
if err != nil {
log.Fatalf("\"%s\" is not a valid FDB version", versions[1])
}
if initialVersion.IsAtLeast(targetVersion) {
log.Fatalf("downgrade from \"%s\" to \"%s\" is not supported", versions[0], versions[1])
}
return UpgradeTestConfiguration{
InitialVersion: initialVersion,
TargetVersion: targetVersion,
}
}
// GetUpgradeVersions returns the upgrade versions as a string slice based on the command line flag. Each entry will be
// a FoundationDB version. This slice can contain duplicate entries. For upgrade tests it's expected that two versions
// form one test, e.g. where the odd number is the initial version and the even number is the
func (factory *Factory) GetUpgradeVersions() []UpgradeTestConfiguration {
return getUpgradeVersions(factory.options.upgradeString)
}
// getUpgradeVersions returns the upgrade versions as a string slice based on the command line flag. Each entry will be
// a FoundationDB version. This slice can contain duplicate entries. For upgrade tests it's expected that two versions
// form one test, e.g. where the odd number is the initial version and the even number is the
// This method is only internally used. Users that import this test suite should use the factory method.
func getUpgradeVersions(upgradeString string) []UpgradeTestConfiguration {
if upgradeString == "" {
return nil
}
upgradeVersionStrings := strings.Split(upgradeString, ",")
upgradeVersions := make([]UpgradeTestConfiguration, 0, len(upgradeVersionStrings))
for _, upgradeTest := range upgradeVersionStrings {
upgradeVersions = append(upgradeVersions, parseUpgradeVersionPair(upgradeTest))
}
return upgradeVersions
}
// GenerateUpgradeTableEntries creates the ginkgo.TableEntry slice based of the provided options.
func GenerateUpgradeTableEntries(options *FactoryOptions) []ginkgo.TableEntry {
upgradeString := options.upgradeString
if upgradeString == "" {
return nil
}
upgradeTests := strings.Split(upgradeString, ",")
tests := make([]ginkgo.TableEntry, 0, len(upgradeTests))
for _, upgradeTest := range getUpgradeVersions(upgradeString) {
tests = append(tests, ginkgo.Entry(nil, upgradeTest.InitialVersion.String(), upgradeTest.TargetVersion.String()))
}
return tests
}