Skip to content

Commit

Permalink
ibu mgmt: add missing dpa test (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
trewest authored Jun 21, 2024
1 parent d6a58c7 commit 661f013
Show file tree
Hide file tree
Showing 14 changed files with 1,618 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func Do(req Request) error {
continue
case strings.Contains(errorStatus, "connection refused"):
continue
case strings.Contains(errorStatus,
"Operation cannot be fulfilled on imagebasedupgrades.lca.openshift.io \"upgrade\": "+
"the object has been modified; please apply your changes to the latest version and try again"):
continue
default:
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ const (

// LabelStageTransition represents stage-transition label that can be used for test cases selection.
LabelStageTransition = "stage-transition"

// LabelMissingBackupLocation missing-backup-location represents immutable-seed-image
// label that can be used for test cases selection.
LabelMissingBackupLocation = "missing-backup-location"
)
45 changes: 45 additions & 0 deletions tests/lca/imagebasedupgrade/mgmt/negative/negative_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ package negative_test
import (
"runtime"
"testing"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/openshift-kni/eco-goinfra/pkg/clients"
"github.com/openshift-kni/eco-goinfra/pkg/lca"
"github.com/openshift-kni/eco-goinfra/pkg/reportxml"
"github.com/openshift-kni/eco-gotests/tests/internal/reporter"
. "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"

"github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/internal/safeapirequest"
"github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/internal/seedimage"
_ "github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/negative/tests"
)
Expand All @@ -35,6 +38,48 @@ var _ = BeforeSuite(func() {
MGMTConfig.SeedClusterInfo = seedClusterInfo
})

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

if ibu.Object.Spec.Stage != "Idle" {
err = safeapirequest.Do(func() error {
ibu, err = lca.PullImageBasedUpgrade(APIClient)
if err != nil {
return err
}

_, err = ibu.WithStage("Idle").Update()
if err != nil {
return err
}

return nil
})

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")
}

Eventually(func() (bool, error) {
ibu.Object, err = ibu.Get()
if err != nil {
return false, err
}

return len(ibu.Object.Status.Conditions) == 1 &&
ibu.Object.Status.Conditions[0].Type == "Idle" &&
ibu.Object.Status.Conditions[0].Status == "True", nil
}).WithTimeout(time.Second*60).WithPolling(time.Second*2).Should(
BeTrue(), "error waiting for image based upgrade to become idle")

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

var _ = ReportAfterSuite("", func(report Report) {
reportxml.Create(
report, MGMTConfig.GetReportPath(), MGMTConfig.TCPrefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,6 @@ var _ = Describe(
Expect(err).NotTo(HaveOccurred(), "error updating ibu with image and version")
})

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

if ibu.Object.Spec.Stage != "Idle" {
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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
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"
lcav1 "github.com/openshift-kni/lifecycle-agent/api/imagebasedupgrade/v1"
"golang.org/x/exp/slices"
)

var _ = Describe(
Expand All @@ -38,39 +34,6 @@ var _ = Describe(
Expect(err).NotTo(HaveOccurred(), "error updating ibu resource with empty values")
})

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 seedImageRef is immutable while progressing", reportxml.ID("71383"), func() {
ibu, err = ibu.WithSeedImage(MGMTConfig.SeedImage).
WithSeedImageVersion(MGMTConfig.SeedClusterInfo.SeedClusterOCPVersion).Update()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package negative_test

import (
"fmt"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/openshift-kni/eco-goinfra/pkg/configmap"
"github.com/openshift-kni/eco-goinfra/pkg/lca"
"github.com/openshift-kni/eco-goinfra/pkg/oadp"
"github.com/openshift-kni/eco-goinfra/pkg/reportxml"
"github.com/openshift-kni/eco-goinfra/pkg/velero"
"github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/internal/brutil"
. "github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/internal/mgmtinittools"
"github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/internal/mgmtparams"
"github.com/openshift-kni/eco-gotests/tests/lca/imagebasedupgrade/mgmt/negative/internal/tsparams"
lcav1 "github.com/openshift-kni/lifecycle-agent/api/imagebasedupgrade/v1"
)

var _ = Describe(
"Starting imagebasedupgrade with missing dataprotectionlocation",
Ordered,
Label(tsparams.LabelMissingBackupLocation), func() {
var (
ibu *lca.ImageBasedUpgradeBuilder
err error

originalDPA *oadp.DPABuilder
oadpConfigmap *configmap.Builder
)

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 values are empty")
ibu.Definition.Spec.ExtraManifests = []lcav1.ConfigMapRef{}
ibu.Definition.Spec.OADPContent = []lcav1.ConfigMapRef{}
_, err = ibu.Update()
Expect(err).NotTo(HaveOccurred(), "error updating ibu resource with empty values")

By("Get configured dataprotection application")
dpaBuilders, err := oadp.ListDataProtectionApplication(APIClient, mgmtparams.LCAOADPNamespace)
Expect(err).NotTo(HaveOccurred(), "error listing dataprotectionapplications")
Expect(len(dpaBuilders)).To(Equal(1), "error: receieved multiple dataprotectionapplication resources")

originalDPA = dpaBuilders[0]

err = originalDPA.Delete()
Expect(err).NotTo(HaveOccurred(), "error deleting original dataprotectionapplication")

By("Get klusterlet backup string")
klusterletBackup, err := brutil.KlusterletBackup.String()
Expect(err).NotTo(HaveOccurred(), "error creating configmap data for klusterlet backup")

By("Get klusterlet restore string")
klusterletRestore, err := brutil.KlusterletRestore.String()
Expect(err).NotTo(HaveOccurred(), "error creating configmap data for klusterlet restore")

oadpConfigmap, err = configmap.NewBuilder(
APIClient, "oadp-configmap", mgmtparams.LCAOADPNamespace).WithData(map[string]string{
"klusterlet_backup.yaml": klusterletBackup,
"klusterlet_restore.yaml": klusterletRestore,
}).Create()
Expect(err).NotTo(HaveOccurred(), "error creating oadp configmap")
})

AfterAll(func() {

if originalDPA != nil && !originalDPA.Exists() {
By("Restoring data protection application")
originalDPA.Definition.ResourceVersion = ""
_, err := originalDPA.Create()
Expect(err).NotTo(HaveOccurred(), "error restoring original dataprotection application")
}

var backupStorageLocations []*velero.BackupStorageLocationBuilder

Eventually(func() (bool, error) {
backupStorageLocations, err = velero.ListBackupStorageLocationBuilder(APIClient, mgmtparams.LCAOADPNamespace)
if err != nil {
return false, err
}

if len(backupStorageLocations) > 0 {
return backupStorageLocations[0].Object.Status.Phase == "Available", nil
}

return false, nil
}).WithTimeout(time.Second*60).WithPolling(time.Second*2).Should(
BeTrue(), "error waiting for backupstoragelocation to be created")

})

It("fails oadp operator availability check", reportxml.ID("71478"), func() {
ibu, err = ibu.WithSeedImage(MGMTConfig.SeedImage).
WithSeedImageVersion(MGMTConfig.SeedClusterInfo.SeedClusterOCPVersion).WithOadpContent(
oadpConfigmap.Definition.Name,
oadpConfigmap.Definition.Namespace).Update()
Expect(err).NotTo(HaveOccurred(), "error updating ibu with image and version")

By("Setting the IBU stage to Prep")
_, err = ibu.WithStage("Prep").Update()
Expect(err).NotTo(HaveOccurred(), "error setting ibu to prep stage")

ibu.Object, err = ibu.Get()
Expect(err).To(BeNil(), "error: getting updated ibu")

Eventually(func() (string, error) {
ibu.Object, err = ibu.Get()
if err != nil {
return "", err
}

for _, condition := range ibu.Object.Status.Conditions {
if condition.Type == "PrepInProgress" {
return condition.Message, nil
}
}

return "", nil
}).WithTimeout(time.Second * 30).WithPolling(time.Second * 2).Should(
Equal(fmt.Sprintf("failed to validate IBU spec: failed to check oadp operator availability: "+
"No DataProtectionApplication CR found in the %s",
mgmtparams.LCAOADPNamespace)))
})
})
10 changes: 10 additions & 0 deletions vendor/github.com/openshift-kni/eco-goinfra/pkg/oadp/const.go

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

Loading

0 comments on commit 661f013

Please sign in to comment.