Skip to content

Commit 1de506c

Browse files
committed
update e2e tests for OCL v1 API
1 parent 6c476d9 commit 1de506c

File tree

2 files changed

+56
-76
lines changed

2 files changed

+56
-76
lines changed

test/e2e-ocl/helpers_test.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,22 +205,6 @@ func createSecret(t *testing.T, cs *framework.ClientSet, secret *corev1.Secret)
205205
})
206206
}
207207

208-
// Copies the global pull secret from openshift-config/pull-secret into the MCO
209-
// namespace so that it can be used by the build processes.
210-
func copyGlobalPullSecret(t *testing.T, cs *framework.ClientSet) func() {
211-
src := metav1.ObjectMeta{
212-
Name: "pull-secret",
213-
Namespace: "openshift-config",
214-
}
215-
216-
dst := metav1.ObjectMeta{
217-
Name: globalPullSecretCloneName,
218-
Namespace: ctrlcommon.MCONamespace,
219-
}
220-
221-
return cloneSecret(t, cs, src, dst)
222-
}
223-
224208
// Computes the name of the currently-running MachineOSBuild given a MachineConfigPool and MachineOSConfig.
225209
func getMachineOSBuildNameForPool(cs *framework.ClientSet, poolName, moscName string) (string, error) {
226210
mcp, err := cs.MachineconfigurationV1Interface.MachineConfigPools().Get(context.TODO(), poolName, metav1.GetOptions{})
@@ -863,6 +847,13 @@ func getImagePullspecForFailureTest(ctx context.Context, cs *framework.ClientSet
863847
}
864848
}
865849

850+
func getBadContainerFileForFailureTest() []mcfgv1.MachineOSContainerfile {
851+
return []mcfgv1.MachineOSContainerfile{{
852+
ContainerfileArch: mcfgv1.NoArch,
853+
Content: "THIS IS A BAD CONTAINERFILE",
854+
}}
855+
}
856+
866857
// Talks to an image registry to get the digested image pullspec for the
867858
// supplied image pullspec. Note: Only supports public image registries. This
868859
// is the same as doing:

test/e2e-ocl/onclusterlayering_test.go

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/stretchr/testify/require"
2525

2626
"github.com/openshift/machine-config-operator/pkg/controller/build/buildrequest"
27-
"github.com/openshift/machine-config-operator/pkg/controller/build/constants"
2827
"github.com/openshift/machine-config-operator/pkg/controller/build/utils"
2928
ctrlcommon "github.com/openshift/machine-config-operator/pkg/controller/common"
3029
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -109,8 +108,6 @@ func TestOnClusterLayeringOnOKD(t *testing.T) {
109108

110109
// Tests that an on-cluster build can be performed with the Custom Pod Builder.
111110
func TestOnClusterLayering(t *testing.T) {
112-
ctx, cancel := context.WithCancel(context.Background())
113-
t.Cleanup(cancel)
114111

115112
runOnClusterLayeringTest(t, onClusterLayeringTestOpts{
116113
poolName: layeredMCPName,
@@ -119,6 +116,11 @@ func TestOnClusterLayering(t *testing.T) {
119116
},
120117
})
121118

119+
/* Removing this portion of this test - update when https://issues.redhat.com/browse/OCPBUGS-46421 fixed.
120+
121+
ctx, cancel := context.WithCancel(context.Background())
122+
t.Cleanup(cancel)
123+
122124
t.Logf("Applying rebuild annotation (%q) to MachineOSConfig (%q) to cause a rebuild", constants.RebuildMachineOSConfigAnnotationKey, layeredMCPName)
123125
124126
cs := framework.NewClientSet("")
@@ -132,6 +134,7 @@ func TestOnClusterLayering(t *testing.T) {
132134
require.NoError(t, err)
133135
134136
waitForBuildToStartForPoolAndConfig(t, cs, layeredMCPName, layeredMCPName)
137+
*/
135138
}
136139

137140
// Tests that an on-cluster build can be performed and that the resulting image
@@ -313,75 +316,67 @@ func TestMachineConfigPoolChangeRestartsBuild(t *testing.T) {
313316
require.NoError(t, err)
314317
}
315318

316-
// This test starts a build with an image that is known to fail because it does
317-
// not have the necessary binaries within it. After failure, it edits the
318-
// MachineOSConfig with the expectation that the failed build and its objects
319-
// will be deleted and a new build will start in its place.
319+
// This test starts a build with an image that is known to fail because it uses
320+
// an invalid containerfile. After failure, it edits the MachineOSConfig
321+
// with the expectation that the failed build and its will be deleted and a new
322+
// build will start in its place.
320323
func TestGracefulBuildFailureRecovery(t *testing.T) {
321324

322-
//TODO: Update this test to use a bad container file
323-
/*
324-
ctx, cancel := context.WithCancel(context.Background())
325-
t.Cleanup(cancel)
326-
327-
cs := framework.NewClientSet("")
328-
329-
mosc := prepareForOnClusterLayeringTest(t, cs, onClusterLayeringTestOpts{
330-
poolName: layeredMCPName,
331-
customDockerfiles: map[string]string{
332-
layeredMCPName: cowsayDockerfile,
333-
},
334-
})
325+
ctx, cancel := context.WithCancel(context.Background())
326+
t.Cleanup(cancel)
335327

336-
// Override the base OS container image to pull an invalid (and smaller)
337-
// image that should produce a failure faster.
328+
cs := framework.NewClientSet("")
338329

339-
pullspec, err := getImagePullspecForFailureTest(ctx, cs)
340-
require.NoError(t, err)
330+
mosc := prepareForOnClusterLayeringTest(t, cs, onClusterLayeringTestOpts{
331+
poolName: layeredMCPName,
332+
customDockerfiles: map[string]string{
333+
layeredMCPName: cowsayDockerfile,
334+
},
335+
})
341336

342-
t.Logf("Overriding BaseImagePullspec for MachineOSConfig %s with %q to cause a build failure", mosc.Name, pullspec)
337+
// Add a bad containerfile so that we can cause a build failure
338+
t.Logf("Adding a bad containerfile for MachineOSConfig %s to cause a build failure", mosc.Name)
343339

344-
mosc.Spec.BuildInputs.BaseOSImagePullspec = pullspec
340+
mosc.Spec.Containerfile = getBadContainerFileForFailureTest()
345341

346-
createMachineOSConfig(t, cs, mosc)
342+
createMachineOSConfig(t, cs, mosc)
347343

348-
// Wait for the build to start.
349-
firstMosb := waitForBuildToStartForPoolAndConfig(t, cs, layeredMCPName, mosc.Name)
344+
// Wait for the build to start.
345+
firstMosb := waitForBuildToStartForPoolAndConfig(t, cs, layeredMCPName, mosc.Name)
350346

351-
t.Logf("Waiting for MachineOSBuild %s to fail", firstMosb.Name)
347+
t.Logf("Waiting for MachineOSBuild %s to fail", firstMosb.Name)
352348

353-
// Wait for the build to fail.
354-
kubeassert := helpers.AssertClientSet(t, cs).WithContext(ctx)
355-
kubeassert.Eventually().MachineOSBuildIsFailure(firstMosb)
349+
// Wait for the build to fail.
350+
kubeassert := helpers.AssertClientSet(t, cs).WithContext(ctx)
351+
kubeassert.Eventually().MachineOSBuildIsFailure(firstMosb)
356352

357-
// Clear the overridden image pullspec.
358-
apiMosc, err := cs.MachineconfigurationV1Interface.MachineOSConfigs().Get(ctx, mosc.Name, metav1.GetOptions{})
359-
require.NoError(t, err)
353+
// Clear the overridden image pullspec.
354+
apiMosc, err := cs.MachineconfigurationV1Interface.MachineOSConfigs().Get(ctx, mosc.Name, metav1.GetOptions{})
355+
require.NoError(t, err)
360356

361-
apiMosc.Spec.BaseOSImagePullspec = ""
357+
apiMosc.Spec.Containerfile = []mcfgv1.MachineOSContainerfile{}
362358

363-
updated, err := cs.MachineconfigurationV1Interface.MachineOSConfigs().Update(ctx, apiMosc, metav1.UpdateOptions{})
364-
require.NoError(t, err)
359+
updated, err := cs.MachineconfigurationV1Interface.MachineOSConfigs().Update(ctx, apiMosc, metav1.UpdateOptions{})
360+
require.NoError(t, err)
365361

366-
t.Logf("Cleared BaseImagePullspec to use default value")
362+
t.Logf("Cleared out bad containerfile")
367363

368-
mcp, err := cs.MachineconfigurationV1Interface.MachineConfigPools().Get(ctx, layeredMCPName, metav1.GetOptions{})
369-
require.NoError(t, err)
364+
mcp, err := cs.MachineconfigurationV1Interface.MachineConfigPools().Get(ctx, layeredMCPName, metav1.GetOptions{})
365+
require.NoError(t, err)
370366

371-
// Compute the new MachineOSBuild image name.
372-
moscChangeMosb := buildrequest.NewMachineOSBuildFromAPIOrDie(ctx, cs.GetKubeclient(), updated, mcp)
367+
// Compute the new MachineOSBuild image name.
368+
moscChangeMosb := buildrequest.NewMachineOSBuildFromAPIOrDie(ctx, cs.GetKubeclient(), updated, mcp)
373369

374-
// Wait for the second build to start.
375-
secondMosb := waitForBuildToStart(t, cs, moscChangeMosb)
370+
// Wait for the second build to start.
371+
secondMosb := waitForBuildToStart(t, cs, moscChangeMosb)
376372

377-
// Ensure that the first build is eventually cleaned up.
378-
kubeassert.Eventually().MachineOSBuildDoesNotExist(firstMosb)
379-
assertBuildObjectsAreDeleted(t, kubeassert.Eventually(), firstMosb)
373+
// Ensure that the first build is eventually cleaned up.
374+
kubeassert.Eventually().MachineOSBuildDoesNotExist(firstMosb)
375+
assertBuildObjectsAreDeleted(t, kubeassert.Eventually(), firstMosb)
380376

381-
// Ensure that the second build is still running.
382-
kubeassert.MachineOSBuildExists(secondMosb)
383-
assertBuildObjectsAreCreated(t, kubeassert, secondMosb)
384-
*/
377+
// Ensure that the second build is still running.
378+
kubeassert.MachineOSBuildExists(secondMosb)
379+
assertBuildObjectsAreCreated(t, kubeassert, secondMosb)
385380

386381
}
387382

@@ -811,14 +806,11 @@ func prepareForOnClusterLayeringTest(t *testing.T, cs *framework.ClientSet, test
811806
})
812807

813808
imagestreamObjMeta := metav1.ObjectMeta{
814-
Name: "os-image",
815-
Namespace: strings.ToLower(t.Name()),
809+
Name: "os-image",
816810
}
817811

818812
pushSecretName, finalPullspec, _ := setupImageStream(t, cs, imagestreamObjMeta)
819813

820-
copyGlobalPullSecret(t, cs)
821-
822814
if testOpts.targetNode != nil {
823815
makeIdempotentAndRegister(t, helpers.CreatePoolWithNode(t, cs, testOpts.poolName, *testOpts.targetNode))
824816
} else {
@@ -860,9 +852,6 @@ func prepareForOnClusterLayeringTest(t *testing.T, cs *framework.ClientSet, test
860852
MachineConfigPool: mcfgv1.MachineConfigPoolReference{
861853
Name: testOpts.poolName,
862854
},
863-
BaseImagePullSecret: &mcfgv1.ImageSecretObjectReference{
864-
Name: globalPullSecretCloneName,
865-
},
866855
RenderedImagePushSecret: mcfgv1.ImageSecretObjectReference{
867856
Name: pushSecretName,
868857
},

0 commit comments

Comments
 (0)