Skip to content

Commit

Permalink
lca: add negative test for patching the stage from idle to rollback.
Browse files Browse the repository at this point in the history
Adding a test per the title.

Signed-off-by: Alexander Chuzhoy <[email protected]>
  • Loading branch information
achuzhoy committed Jun 12, 2024
1 parent 749d822 commit cbf2c6b
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ const (

// LabelImmutableSeedImage represents immutable-seed-image label that can be used for test cases selection.
LabelImmutableSeedImage = "immutable-seed-image"

// LabelStageTransitionIdleToRollback represents stage-transition-idle-to-rollback label that can be used for test cases selection.
LabelStageTransitionIdleToRollback = "stage-transition-idle-to-rollback"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package negative_test

import (
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift-kni/eco-goinfra/pkg/lca"
"github.com/openshift-kni/eco-goinfra/pkg/reportxml"
"github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/internal/nodestate"
. "github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/internal/mgmtinittools"
"github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/negative/internal/tsparams"
"golang.org/x/exp/slices"
)

var _ = Describe(
"Patching ibu stage from Idle to Rollback",
Ordered,
Label(tsparams.LabelStageTransitionIdleToRollback), func() {
var (
ibu *lca.ImageBasedUpgradeBuilder
err error
)

BeforeAll(func() {
By("Pull the imagebasedupgrade from the cluster")
ibu, err = lca.PullImageBasedUpgrade(APIClient)
Expect(err).NotTo(HaveOccurred(), "error pulling ibu resource from cluster")

By("Ensure that imagebasedupgrade stage is set to Idle")
Expect(string(ibu.Object.Spec.Stage)).To(Equal("Idle"), "error: ibu resource contains unexpected state")
})

AfterAll(func() {
By("Revert IBU resource back to Idle stage")
ibu, err = lca.PullImageBasedUpgrade(APIClient)
Expect(err).NotTo(HaveOccurred(), "error pulling imagebasedupgrade resource")

if ibu.Object.Spec.Stage == "Upgrade" {
By("Set IBU stage to Rollback")
_, err = ibu.WithStage("Rollback").Update()
Expect(err).NotTo(HaveOccurred(), "error setting ibu to rollback stage")

By("Wait for IBU resource to be available")
err = nodestate.WaitForIBUToBeAvailable(APIClient, ibu, time.Minute*10)
Expect(err).NotTo(HaveOccurred(), "error waiting for ibu resource to become available")

By("Wait until Rollback stage has completed")
_, err = ibu.WaitUntilStageComplete("Rollback")
Expect(err).NotTo(HaveOccurred(), "error waiting for rollback stage to complete")
}

if slices.Contains([]string{"Prep", "Rollback"}, string(ibu.Object.Spec.Stage)) {
By("Set IBU stage to Idle")
_, err = ibu.WithStage("Idle").Update()
Expect(err).NotTo(HaveOccurred(), "error setting ibu to idle stage")

By("Wait until IBU has become Idle")
_, err = ibu.WaitUntilStageComplete("Idle")
Expect(err).NotTo(HaveOccurred(), "error waiting for idle stage to complete")
}

Expect(string(ibu.Object.Spec.Stage)).To(Equal("Idle"), "error: ibu resource contains unexpected state")

})

It("fails because from Idle it's not possible to move to Rollback stage", reportxml.ID("71738"), func() {

By("Setting the IBU stage to Rollback")

_, err := ibu.WithStage("Rollback").Update()
Expect(err.Error()).To(ContainSubstring("the stage transition is not permitted"),
"error: ibu seedimage updated with wrong next stage")

})
})

0 comments on commit cbf2c6b

Please sign in to comment.