Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/default_os_images.json
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,4 @@
"url": "https://mirror.openshift.com/pub/openshift-v4/s390x/dependencies/rhcos/pre-release/4.22.0-ec.5/rhcos-4.22.0-ec.5-s390x-live-iso.s390x.iso",
"version": "9.6.20251023-0"
}
]
]
2 changes: 1 addition & 1 deletion data/default_release_images.json
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@
"support_level": "beta",
"version": "5.0.0-ec.1-multi"
}
]
]
5 changes: 4 additions & 1 deletion hack/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ generate-events:
validate-swagger-file:
./hack/generate.sh validate_swagger_file

generate-test-versions:
./hack/generate.sh generate_test_versions

generate-configuration:
./hack/generate.sh generate_configuration

Expand All @@ -61,4 +64,4 @@ generate-go:
# because the latter copies around files that need to be generated by the
# former. Without doing it in this order, the `generate` target will not be
# idempotent and would have to be executed twice to achieve the desired result.
generate: generate-from-swagger generate-go generate-events generate-mocks generate-configuration generate-bundle
generate: generate-from-swagger generate-go generate-events generate-mocks generate-configuration generate-test-versions generate-bundle
Comment thread
bluesort marked this conversation as resolved.
38 changes: 38 additions & 0 deletions hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,44 @@ function generate_bundle() {
operator-sdk bundle validate ${BUNDLE_OUTPUT_DIR}
}

function generate_test_versions() {
local data_file="${__root}/data/default_release_images.json"
local output_file="${__root}/internal/common/test_versions_generated.go"

python3 -c '
import json, re
from collections import defaultdict

with open("'"${data_file}"'") as f:
data = json.load(f)

arch_versions = defaultdict(set)
for entry in data:
version = re.sub(r"-multi$", "", entry["openshift_version"])
parts = version.split(".")
version = "%s.%s" % (parts[0], parts[1])
arch_versions[entry["cpu_architecture"]].add(version)

def sort_key(v):
return tuple(int(p) for p in v.split(".") if p.isdigit())

lines = []
for arch in sorted(arch_versions):
versions = sorted(arch_versions[arch], key=sort_key)
quoted = ", ".join("\"%s\"" % v for v in versions)
lines.append("\t\"%s\": {%s}," % (arch, quoted))

print("""// Code generated by hack/generate.sh generate_test_versions; DO NOT EDIT.
package common

var testVersionsByArch = map[string][]string{
%s
}""" % "\n".join(lines))
' > "$output_file"

gofmt -w "$output_file"
}

function print_help() {
echo "The available functions are:"
compgen -A function | grep "^generate" | awk '{print "\t" $1}'
Expand Down
24 changes: 19 additions & 5 deletions internal/bminventory/inventory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5209,6 +5209,17 @@ var _ = Describe("cluster", func() {
})

Context("Multiple VIPs forbidden in update for pre-4.12", func() {
var pre412Version string

BeforeEach(func() {
v, ok := common.TestVersion().LessThan("4.12").Latest().TryVersion()
if !ok {
Skip("no test version available below 4.12")
}
pre412Version = v
Expect(db.Model(&common.Cluster{}).Where("id = ?", clusterID).Update("openshift_version", pre412Version).Error).ShouldNot(HaveOccurred())
})

It("2 APIVips and 2 IngressVips", func() {
apiVip := "8.8.8.7"
ingressVip := "8.8.8.1"
Expand All @@ -5223,7 +5234,7 @@ var _ = Describe("cluster", func() {
},
})

verifyApiErrorString(reply, http.StatusBadRequest, "dual-stack VIPs are not supported in OpenShift 4.6")
verifyApiErrorString(reply, http.StatusBadRequest, "dual-stack VIPs are not supported in OpenShift "+pre412Version)
})

It("2 APIVips and 1 IngressVips", func() {
Expand All @@ -5240,7 +5251,7 @@ var _ = Describe("cluster", func() {
},
})

verifyApiErrorString(reply, http.StatusBadRequest, "dual-stack VIPs are not supported in OpenShift 4.6")
verifyApiErrorString(reply, http.StatusBadRequest, "dual-stack VIPs are not supported in OpenShift "+pre412Version)
})

It("1 APIVip and 2 IngressVips", func() {
Expand All @@ -5257,7 +5268,7 @@ var _ = Describe("cluster", func() {
},
})

verifyApiErrorString(reply, http.StatusBadRequest, "dual-stack VIPs are not supported in OpenShift 4.6")
verifyApiErrorString(reply, http.StatusBadRequest, "dual-stack VIPs are not supported in OpenShift "+pre412Version)
})
})
})
Expand Down Expand Up @@ -5355,6 +5366,7 @@ var _ = Describe("cluster", func() {
ID: &clusterID,
APIVips: []*models.APIVip{{IP: "10.11.12.13"}},
IngressVips: []*models.IngressVip{{IP: "10.11.20.50"}},
CPUArchitecture: common.DefaultCPUArchitecture,
OpenshiftVersion: common.TestDefaultConfig.OpenShiftVersion,
Status: swag.String(models.ClusterStatusReady),
}}
Expand All @@ -5363,6 +5375,7 @@ var _ = Describe("cluster", func() {
ID: &clusterID,
APIVips: []*models.APIVip{{IP: "10.11.12.13"}},
IngressVips: []*models.IngressVip{{IP: "10.11.20.50"}},
CPUArchitecture: common.DefaultCPUArchitecture,
OpenshiftVersion: common.TestDefaultConfig.OpenShiftVersion,
Status: swag.String(models.ClusterStatusInstalling),
},
Expand Down Expand Up @@ -15102,8 +15115,8 @@ var _ = Describe("RegisterCluster", func() {
Expect(result.Platform.None).Should(BeNil())
Expect(result.Platform.Baremetal).Should(BeNil())

Expect(result.Platform.Vsphere.DeprecatedAPIVIP).Should(Equal(apiVip))
Expect(result.Platform.Vsphere.DeprecatedIngressVIP).Should(Equal(ingressVip))
Expect(result.Platform.Vsphere.APIVIPs).Should(ContainElement(apiVip))
Expect(result.Platform.Vsphere.IngressVIPs).Should(ContainElement(ingressVip))
})
})

Expand Down Expand Up @@ -17815,6 +17828,7 @@ var _ = Describe("AMS subscriptions", func() {
err := db.Create(&common.Cluster{Cluster: models.Cluster{
ID: &clusterID,
OpenshiftVersion: common.TestDefaultConfig.OpenShiftVersion,
CPUArchitecture: common.DefaultCPUArchitecture,
Status: swag.String(models.ClusterStatusReady),
}}).Error
Expect(err).ShouldNot(HaveOccurred())
Expand Down
15 changes: 8 additions & 7 deletions internal/common/test_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ const TestDiskPath = "/dev/test-disk"
const MinimalVersionForNmstatectl = "4.18"

var (
OpenShiftVersion string = "4.6"
ReleaseVersion = "4.6.0"
ReleaseImageURL = "quay.io/openshift-release-dev/ocp-release:4.6.16-x86_64"
RhcosImage = "rhcos_4.6.0"
RhcosVersion = "version-46.123-0"
SupportLevel = "beta"
CPUArchitecture = DefaultCPUArchitecture
DefaultTestVersion = TestVersion().Latest()
OpenShiftVersion = DefaultTestVersion.Version()
ReleaseVersion = DefaultTestVersion.ReleaseVersion()
ReleaseImageURL = DefaultTestVersion.ReleaseImageURL()
RhcosImage = DefaultTestVersion.RhcosImage()
RhcosVersion = DefaultTestVersion.RhcosVersion()
SupportLevel = "beta"
CPUArchitecture = DefaultCPUArchitecture
)

// Defaults to be used by all testing modules
Expand Down
126 changes: 126 additions & 0 deletions internal/common/test_versions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package common

import (
"fmt"
"strings"

"github.com/hashicorp/go-version"
)

type TestVersionBuilder struct {
arch string
oldest bool
constraint func(string) bool
versionsByArch map[string][]string
}

func TestVersion() *TestVersionBuilder {
return &TestVersionBuilder{
arch: DefaultCPUArchitecture,
versionsByArch: testVersionsByArch,
}
}

func (b *TestVersionBuilder) ForArch(arch string) *TestVersionBuilder {
b.arch = arch
return b
}

func (b *TestVersionBuilder) Latest() *TestVersionBuilder {
b.oldest = false
return b
}

func (b *TestVersionBuilder) Oldest() *TestVersionBuilder {
b.oldest = true
return b
}

func (b *TestVersionBuilder) LessThan(threshold string) *TestVersionBuilder {
parsed := b.parseVersion(threshold)
b.constraint = func(v string) bool {
return b.parseVersion(v).LessThan(parsed)
}
return b
}

func (b *TestVersionBuilder) GreaterThan(threshold string) *TestVersionBuilder {
parsed := b.parseVersion(threshold)
b.constraint = func(v string) bool {
return b.parseVersion(v).GreaterThan(parsed)
}
return b
}

func (b *TestVersionBuilder) Exact(target string) *TestVersionBuilder {
parsed := b.parseVersion(target)
b.constraint = func(v string) bool {
return b.parseVersion(v).Equal(parsed)
}
return b
}

func (b *TestVersionBuilder) TryVersion() (string, bool) {
v := b.versions()
if len(v) == 0 {
return "", false
}
if b.oldest {
return v[0], true
}
return v[len(v)-1], true
}

func (b *TestVersionBuilder) Version() string {
v, ok := b.TryVersion()
if !ok {
panic(fmt.Sprintf("no test version found for arch %q with active constraint", b.arch))
}
return v
}

func (b *TestVersionBuilder) ReleaseVersion() string {
return b.Version() + ".0"
}

// Mirrors getReleaseImageReference in internal/releasesources/release_sources.go
func (b *TestVersionBuilder) ReleaseImageURL() string {
suffix := b.arch
if suffix == ARM64CPUArchitecture {
suffix = AARCH64CPUArchitecture
}
return fmt.Sprintf("quay.io/openshift-release-dev/ocp-release:%s-%s", b.ReleaseVersion(), suffix)
}
Comment thread
bluesort marked this conversation as resolved.

func (b *TestVersionBuilder) RhcosImage() string {
return fmt.Sprintf("rhcos_%s", b.ReleaseVersion())
}

func (b *TestVersionBuilder) RhcosVersion() string {
return fmt.Sprintf("version-%s.123-0", strings.ReplaceAll(b.Version(), ".", ""))
}

func (b *TestVersionBuilder) versions() []string {
all, ok := testVersionsByArch[b.arch]
if !ok {
return []string{}
}
if b.constraint == nil || len(all) == 0 {
return all
}
var filtered []string
for _, v := range all {
if b.constraint(v) {
filtered = append(filtered, v)
}
}
return filtered
}

func (b *TestVersionBuilder) parseVersion(v string) *version.Version {
parsed, err := version.NewVersion(v)
if err != nil {
panic(fmt.Sprintf("invalid version %q: %v", v, err))
}
return parsed
}
8 changes: 8 additions & 0 deletions internal/common/test_versions_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading