Skip to content

Commit 5faddcb

Browse files
Merge pull request #9018 from openshift-cherrypick-robot/cherry-pick-8789-to-release-4.17
[release-4.17] OCPBUGS-42051: Fix integration tests
2 parents c378781 + 38b2985 commit 5faddcb

File tree

7 files changed

+91
-77
lines changed

7 files changed

+91
-77
lines changed

cmd/openshift-install/internal_integration_test.go

+78-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/rogpeppe/go-internal/testscript"
2020
"github.com/stretchr/testify/assert"
2121
"github.com/vincent-petithory/dataurl"
22+
"gopkg.in/yaml.v2"
2223

2324
"github.com/openshift/installer/pkg/asset/releaseimage"
2425
)
@@ -103,13 +104,31 @@ func runIntegrationTest(t *testing.T, testFolder string) {
103104
}
104105
}
105106

106-
// Let's get the current release version, so that
107-
// it could be used within the tests
108-
pullspec, err := releaseimage.Default()
109-
if err != nil {
110-
return err
107+
var pullspec string
108+
// If set, let's use $OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE to replace test data
109+
// and also pass it to the testscript environment. It will be usually set in a CI job
110+
// to reference the ephemeral payload release.
111+
if releaseImageOverride, ok := os.LookupEnv("OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE"); ok && releaseImageOverride != "" {
112+
pullspec = releaseImageOverride
113+
e.Vars = append(e.Vars, fmt.Sprintf("OPENSHIFT_INSTALL_RELEASE_IMAGE_OVERRIDE=%s", pullspec))
114+
} else {
115+
// Let's get the current release version, so that
116+
// it could be used within the tests
117+
pullspec, err = releaseimage.Default()
118+
if err != nil {
119+
return err
120+
}
111121
}
112122
e.Vars = append(e.Vars, fmt.Sprintf("RELEASE_IMAGE=%s", pullspec))
123+
// When AUTH_FILE is set in the CI integration-tests job
124+
if authFilePath, ok := os.LookupEnv("AUTH_FILE"); ok && authFilePath != "" {
125+
workDir := e.Getenv("WORK")
126+
err := updatePullSecret(workDir, authFilePath)
127+
if err != nil {
128+
return err
129+
}
130+
t.Log("PullSecret updated successfully")
131+
}
113132

114133
return nil
115134
},
@@ -123,6 +142,7 @@ func runIntegrationTest(t *testing.T, testFolder string) {
123142
"unconfiguredIgnCmp": unconfiguredIgnCmp,
124143
"expandFile": expandFile,
125144
"isoContains": isoContains,
145+
"existsInIso": existsInIso,
126146
},
127147
})
128148
}
@@ -259,6 +279,7 @@ func ignitionStorageCmp(ts *testscript.TestScript, neg bool, args []string) {
259279

260280
workDir := ts.Getenv("WORK")
261281
ignPath, aFilePath, eFilePath := args[0], args[1], args[2]
282+
262283
ignPathAbs := filepath.Join(workDir, ignPath)
263284

264285
config, err := readIgnition(ts, ignPathAbs)
@@ -473,6 +494,25 @@ func isoContains(ts *testscript.TestScript, neg bool, args []string) {
473494
ts.Check(err)
474495
}
475496

497+
// [!] existsInIso `isoPath` `file` check if the specified `file` is stored
498+
// within the ISO `isoPath` image.
499+
func existsInIso(ts *testscript.TestScript, neg bool, args []string) {
500+
if len(args) != 2 {
501+
ts.Fatalf("usage: isoContains isoPath file")
502+
}
503+
504+
workDir := ts.Getenv("WORK")
505+
isoPath, filePath := args[0], args[1]
506+
isoPathAbs := filepath.Join(workDir, isoPath)
507+
508+
archiveFile, ignitionFile, err := archiveFileNames(isoPath)
509+
if err != nil {
510+
ts.Check(err)
511+
}
512+
_, err = readFileFromISO(isoPathAbs, archiveFile, ignitionFile, filePath)
513+
ts.Check(err)
514+
}
515+
476516
func checkFileFromInitrdImg(isoPath string, fileName string) error {
477517
disk, err := diskfs.Open(isoPath, diskfs.WithOpenMode(diskfs.ReadOnly))
478518
if err != nil {
@@ -570,3 +610,36 @@ func lookForCpioFiles(r io.Reader) ([]string, error) {
570610

571611
return files, nil
572612
}
613+
614+
func updatePullSecret(workDir, authFilePath string) error {
615+
authFile, err := os.ReadFile(authFilePath)
616+
if err != nil {
617+
return err
618+
}
619+
ciPullSecret := string(authFile)
620+
expectedInstallConfigPathAbs := filepath.Join(workDir, "install-config.yaml")
621+
_, err = os.Stat(expectedInstallConfigPathAbs)
622+
if err == nil {
623+
installConfigFile, err := os.ReadFile(expectedInstallConfigPathAbs)
624+
if err != nil {
625+
return err
626+
}
627+
var config map[string]interface{}
628+
if err := yaml.Unmarshal(installConfigFile, &config); err != nil {
629+
return err
630+
}
631+
632+
config["pullSecret"] = ciPullSecret
633+
634+
updatedConfig, err := yaml.Marshal(&config)
635+
if err != nil {
636+
return err
637+
}
638+
if err := os.WriteFile(expectedInstallConfigPathAbs, updatedConfig, 0600); err != nil {
639+
return err
640+
}
641+
} else if !os.IsNotExist(err) {
642+
return err
643+
}
644+
return nil
645+
}

cmd/openshift-install/testdata/agent/configimage/manifests/default_manifests.txt

+2-17
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ exists $WORK/agentconfig.noarch.iso
66

77
isocmp agentconfig.noarch.iso /etc/assisted/manifests/agent-cluster-install.yaml expected/agent-cluster-install.yaml
88
isocmp agentconfig.noarch.iso /etc/assisted/manifests/cluster-image-set.yaml expected/cluster-image-set.yaml
9-
isocmp agentconfig.noarch.iso /etc/assisted/manifests/pull-secret.yaml expected/pull-secret.yaml
109
isocmp agentconfig.noarch.iso /etc/assisted/manifests/cluster-deployment.yaml expected/cluster-deployment.yaml
1110

11+
existsInIso agentconfig.noarch.iso /etc/assisted/manifests/pull-secret.yaml
12+
1213
-- install-config.yaml --
1314
apiVersion: v1
1415
baseDomain: test.metalkube.org
@@ -106,19 +107,3 @@ metadata:
106107
spec:
107108
releaseImage: $RELEASE_IMAGE
108109
status: {}
109-
-- expected/pull-secret.yaml --
110-
apiVersion: v1
111-
kind: Secret
112-
metadata:
113-
creationTimestamp: null
114-
name: ostest-pull-secret
115-
namespace: cluster0
116-
stringData:
117-
.dockerconfigjson: |-
118-
{
119-
"auths": {
120-
"quay.io": {
121-
"auth": "c3VwZXItc2VjcmV0Cg=="
122-
}
123-
}
124-
}

cmd/openshift-install/testdata/agent/image/manifests/default_manifests.txt

+2-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ isocmp agent.x86_64.iso /etc/assisted/manifests/agent-cluster-install.yaml expec
88
isocmp agent.x86_64.iso /etc/assisted/manifests/cluster-deployment.yaml expected/cluster-deployment.yaml
99
isocmp agent.x86_64.iso /etc/assisted/manifests/cluster-image-set.yaml expected/cluster-image-set.yaml
1010
isocmp agent.x86_64.iso /etc/assisted/manifests/infraenv.yaml expected/infraenv.yaml
11-
isocmp agent.x86_64.iso /etc/assisted/manifests/pull-secret.yaml expected/pull-secret.yaml
11+
12+
existsInIso agent.x86_64.iso /etc/assisted/manifests/pull-secret.yaml
1213

1314
-- install-config.yaml --
1415
apiVersion: v1
@@ -135,19 +136,3 @@ status:
135136
rootfs: ""
136137
debugInfo:
137138
eventsURL: ""
138-
-- expected/pull-secret.yaml --
139-
apiVersion: v1
140-
kind: Secret
141-
metadata:
142-
creationTimestamp: null
143-
name: ostest-pull-secret
144-
namespace: cluster0
145-
stringData:
146-
.dockerconfigjson: |-
147-
{
148-
"auths": {
149-
"quay.io": {
150-
"auth": "c3VwZXItc2VjcmV0Cg=="
151-
}
152-
}
153-
}

cmd/openshift-install/testdata/agent/unconfigured-ignition/configurations/from-ztp-manifests.txt

+3-17
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ exec openshift-install agent create unconfigured-ignition --dir $WORK
1010
exists $WORK/unconfigured-agent.ign
1111
! exists $WORK/auth/kubeconfig
1212
! exists $WORK/auth/kubeadmin-password
13+
14+
unconfiguredIgnContains /etc/assisted/manifests/pull-secret.yaml
1315
! unconfiguredIgnContains /etc/assisted/manifests/agent-cluster-install.yaml
1416
! unconfiguredIgnContains /etc/assisted/manifests/cluster-deployment.yaml
17+
1518
unconfiguredIgnCmp /etc/assisted/manifests/cluster-image-set.yaml expected/cluster-image-set.yaml
1619
unconfiguredIgnCmp /etc/assisted/manifests/infraenv.yaml expected/infraenv.yaml
17-
unconfiguredIgnCmp /etc/assisted/manifests/pull-secret.yaml expected/pull-secret.yaml
1820

1921
-- cluster-manifests/infraenv.yaml --
2022
apiVersion: agent-install.openshift.io/v1beta1
@@ -85,19 +87,3 @@ status:
8587
rootfs: ""
8688
debugInfo:
8789
eventsURL: ""
88-
-- expected/pull-secret.yaml --
89-
apiVersion: v1
90-
kind: Secret
91-
metadata:
92-
creationTimestamp: null
93-
name: ostest-pull-secret
94-
namespace: cluster0
95-
stringData:
96-
.dockerconfigjson: |-
97-
{
98-
"auths": {
99-
"quay.io": {
100-
"auth": "c3VwZXItc2VjcmV0Cg=="
101-
}
102-
}
103-
}

cmd/openshift-install/testdata/agent/unconfigured-ignition/manifests/default_manifests.txt

+2-17
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ exists $WORK/unconfigured-agent.ign
88
! exists $WORK/auth/kubeconfig
99
! exists $WORK/auth/kubeadmin-password
1010

11+
unconfiguredIgnContains /etc/assisted/manifests/pull-secret.yaml
1112
! unconfiguredIgnContains /etc/assisted/manifests/agent-cluster-install.yaml
1213
! unconfiguredIgnContains /etc/assisted/manifests/cluster-deployment.yaml
14+
1315
unconfiguredIgnCmp /etc/assisted/manifests/cluster-image-set.yaml expected/cluster-image-set.yaml
1416
unconfiguredIgnCmp /etc/assisted/manifests/infraenv.yaml expected/infraenv.yaml
15-
unconfiguredIgnCmp /etc/assisted/manifests/pull-secret.yaml expected/pull-secret.yaml
1617

1718
-- install-config.yaml --
1819
apiVersion: v1
@@ -85,19 +86,3 @@ status:
8586
rootfs: ""
8687
debugInfo:
8788
eventsURL: ""
88-
-- expected/pull-secret.yaml --
89-
apiVersion: v1
90-
kind: Secret
91-
metadata:
92-
creationTimestamp: null
93-
name: ostest-pull-secret
94-
namespace: cluster0
95-
stringData:
96-
.dockerconfigjson: |-
97-
{
98-
"auths": {
99-
"quay.io": {
100-
"auth": "c3VwZXItc2VjcmV0Cg=="
101-
}
102-
}
103-
}

pkg/asset/agent/manifests/clusterimageset.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (a *ClusterImageSet) validateReleaseVersion(ctx context.Context, workflowTy
189189
}
190190

191191
if a.Config.Spec.ReleaseImage != releaseImage.PullSpec {
192-
allErrs = append(allErrs, field.Forbidden(fieldPath, fmt.Sprintf("value must be equal to %s", releaseImage.PullSpec)))
192+
allErrs = append(allErrs, field.Invalid(fieldPath, a.Config.Spec.ReleaseImage, fmt.Sprintf("value must be equal to %s", releaseImage.PullSpec)))
193193
}
194194

195195
return allErrs

pkg/asset/agent/manifests/clusterimageset_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestClusterImageSet_Generate(t *testing.T) {
6262
getValidOptionalInstallConfig(),
6363
&releaseimage.Image{},
6464
},
65-
expectedError: "invalid ClusterImageSet configuration: Spec.ReleaseImage: Forbidden: value must be equal to " + currentRelease,
65+
expectedError: "invalid ClusterImageSet configuration: Spec.ReleaseImage: Invalid value: \"\": value must be equal to " + currentRelease,
6666
},
6767
{
6868
name: "valid configuration",
@@ -182,7 +182,7 @@ metadata:
182182
name: openshift-v4.10.0
183183
spec:
184184
releaseImage: 99.999`,
185-
expectedError: fmt.Sprintf("invalid ClusterImageSet configuration: Spec.ReleaseImage: Forbidden: value must be equal to %s", currentRelease),
185+
expectedError: fmt.Sprintf("invalid ClusterImageSet configuration: Spec.ReleaseImage: Invalid value: \"99.999\": value must be equal to %s", currentRelease),
186186
},
187187
{
188188
name: "not-yaml",
@@ -192,7 +192,7 @@ spec:
192192
{
193193
name: "empty",
194194
data: "",
195-
expectedError: fmt.Sprintf("invalid ClusterImageSet configuration: Spec.ReleaseImage: Forbidden: value must be equal to %s", currentRelease),
195+
expectedError: fmt.Sprintf("invalid ClusterImageSet configuration: Spec.ReleaseImage: Invalid value: \"\": value must be equal to %s", currentRelease),
196196
},
197197
{
198198
name: "file-not-found",

0 commit comments

Comments
 (0)