-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
499 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package accelparams | ||
|
||
const ( | ||
// Label represents cnf label that can be used for test cases selection. | ||
// Label represents accel label that can be used for test cases selection. | ||
Label = "accel" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package accelparams | ||
|
||
const ( | ||
// Label represents accel label that can be used for test cases selection. | ||
Label = "accel-upgrade" | ||
// Y stream. | ||
Y = "Y" | ||
// Z stream. | ||
Z = "Z" | ||
// X stream. | ||
X = "X" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package accelparams | ||
|
||
import ( | ||
"fmt" | ||
"slices" | ||
"time" | ||
|
||
"github.com/openshift-kni/eco-gotests/tests/accel/internal/accelparams" | ||
"github.com/openshift-kni/k8sreporter" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var ( | ||
// Labels represents the range of labels that can be used for test cases selection. | ||
Labels = []string{accelparams.Label, Label} | ||
// IbuWorkloadImage is the test workload image. | ||
IbuWorkloadImage = `registry.redhat.io/openshift4/ose-hello-openshift-rhel8@sha256:10dca31348f07e1bfb56ee93c324525cceefe27cb7076b23e42ac181e4d1863e` | ||
// DeploymentName is the name of the test workload. | ||
DeploymentName = "test-workload" | ||
// DefaultTimeout represents the default timeout for most of Eventually/PollImmediate functions. | ||
DefaultTimeout = 300 * time.Second | ||
// ContainerCmdBash start a container command with bash. | ||
ContainerCmdBash = []string{"/bin/bash", "-c"} | ||
// ContainerCmdSleep start a container with a sleep, later execute the needed | ||
// command in the container. | ||
ContainerCmdSleep = append(slices.Clone(ContainerCmdBash), "sleep infinity") | ||
// TestNamespaceName is the namespace where the workload is deployed. | ||
TestNamespaceName = "test-ns" | ||
// containerLabelKey is the test container label key. | ||
containerLabelKey = "app" | ||
// containerLabelVal is the test container label value. | ||
containerLabelVal = "test-workload" | ||
// ContainerLabelsMap labels in an map used when creating the workload container. | ||
ContainerLabelsMap = map[string]string{containerLabelKey: containerLabelVal} | ||
// ContainerLabelsStr labels in a str used when creating the workload container. | ||
ContainerLabelsStr = fmt.Sprintf("%s=%s", containerLabelKey, containerLabelVal) | ||
// ServicePort is the workload service port. | ||
ServicePort int32 = 8080 | ||
// ReporterNamespacesToDump tells to the reporter from where to collect logs. | ||
ReporterNamespacesToDump = map[string]string{"accel-test": "accel-test"} | ||
// ReporterCRDsToDump tells to the reporter what CRs to dump. | ||
ReporterCRDsToDump = []k8sreporter.CRData{ | ||
{Cr: &corev1.PodList{}}, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
package upgrade | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/golang/glog" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
|
||
"github.com/openshift-kni/eco-goinfra/pkg/clusteroperator" | ||
"github.com/openshift-kni/eco-goinfra/pkg/clusterversion" | ||
"github.com/openshift-kni/eco-goinfra/pkg/namespace" | ||
"github.com/openshift-kni/eco-goinfra/pkg/pod" | ||
|
||
"github.com/openshift-kni/eco-goinfra/pkg/reportxml" | ||
"github.com/openshift-kni/eco-goinfra/pkg/route" | ||
"github.com/openshift-kni/eco-gotests/tests/accel/internal/accelconfig" | ||
accelinittools "github.com/openshift-kni/eco-gotests/tests/accel/internal/accelinittools" | ||
"github.com/openshift-kni/eco-gotests/tests/accel/upgrade/internal/accelparams" | ||
|
||
"github.com/openshift-kni/eco-gotests/tests/internal/url" | ||
) | ||
|
||
var ( | ||
waitToUpgradeStart = 5 * time.Minute | ||
waitToUpgradeCompleted = 130 * time.Minute | ||
desiredUpgradeChannel = "stable-" + accelinittools.AccelConfig.HubMinorVersion | ||
stream = accelparams.Z | ||
) | ||
|
||
var _ = Describe("OCP_UPGRADE", Ordered, Label("minor"), func() { | ||
Context("OCP", func() { | ||
|
||
AfterAll(func() { | ||
By("Delete workload test namespace") | ||
glog.V(90).Infof("Deleting test deployments") | ||
deleteWorkloadNamespace() | ||
}) | ||
|
||
It("should upgrade successfully", reportxml.ID("72245"), func() { | ||
By("Get the clusterversion struct") | ||
version, err := clusterversion.Pull(accelinittools.HubAPIClient) | ||
Expect(err).ToNot(HaveOccurred(), "error retrieving clusterversion") | ||
glog.V(90).Infof("got the clusterversion struct %+v", version) | ||
|
||
By("Deploy a workload in the cluster, expose a service and create a route") | ||
workloadRoute := startTestWorkloadAndGetRoute() | ||
|
||
By("Patch the clusterversion with the desired upgrade channel") | ||
if desiredUpgradeChannel == "stable-" { | ||
desiredUpgradeChannel = version.Object.Spec.Channel | ||
glog.V(90).Infof("clusterversion channel %s", desiredUpgradeChannel) | ||
} | ||
version, err = version.WithDesiredUpdateChannel(desiredUpgradeChannel).Update() | ||
Expect(err).ToNot(HaveOccurred(), "error patching the desired upgrade channel") | ||
glog.V(90).Infof("patched the clusterversion channel %s", desiredUpgradeChannel) | ||
|
||
By("Get the desired update image") | ||
config := accelconfig.NewAccelConfig() | ||
desiredImage := config.UpgradeTargetVersion | ||
if config.UpgradeTargetVersion == "" { | ||
desiredImage, err = version.GetNextUpdateVersionImage(stream, false) | ||
Expect(err).ToNot(HaveOccurred(), "error getting the next update image") | ||
} | ||
glog.V(90).Infof("got the desired update image in %s stream %s", stream, desiredImage) | ||
|
||
By("Patch the clusterversion with the desired upgrade image") | ||
version, err = version.WithDesiredUpdateImage(desiredImage, true).Update() | ||
Expect(err).ToNot(HaveOccurred(), "error patching the desired image") | ||
Expect(version.Object.Spec.DesiredUpdate.Image).To(Equal(desiredImage)) | ||
glog.V(90).Infof("patched the clusterversion with desired image %s", desiredImage) | ||
|
||
By("Wait until upgrade starts") | ||
err = version.WaitUntilUpdateIsStarted(waitToUpgradeStart) | ||
Expect(err).ToNot(HaveOccurred(), "the upgrade didn't start after %s", waitToUpgradeStart) | ||
glog.V(90).Infof("upgrade has started") | ||
|
||
By("Wait until upgrade completes") | ||
err = version.WaitUntilUpdateIsCompleted(waitToUpgradeCompleted) | ||
Expect(err).ToNot(HaveOccurred(), "the upgrade didn't complete after %s", waitToUpgradeCompleted) | ||
glog.V(90).Infof("upgrade has completed") | ||
|
||
By("Check that the clusterversion is updated to the desired version") | ||
Expect(version.Object.Status.Desired.Image).To(Equal(desiredImage)) | ||
glog.V(90).Infof("upgrade to image %s has completed successfully", desiredImage) | ||
|
||
By("Check that all the operators version is the desired version") | ||
clusteroperatorList, err := clusteroperator.List(accelinittools.HubAPIClient) | ||
Expect(err).ToNot(HaveOccurred(), "failed to get the clusteroperators list %v", err) | ||
hasVersion, err := clusteroperator.VerifyClusterOperatorsVersion(version.Object.Status.Desired.Version, | ||
clusteroperatorList) | ||
Expect(err).NotTo(HaveOccurred(), "error while checking operators version") | ||
Expect(hasVersion).To(BeTrue()) | ||
|
||
By("Check that no cluster operator is progressing") | ||
cosStoppedProgressing, err := clusteroperator. | ||
WaitForAllClusteroperatorsStopProgressing(accelinittools.HubAPIClient, time.Minute*5) | ||
Expect(err).NotTo(HaveOccurred(), "error while waiting for cluster operators to stop progressing") | ||
Expect(cosStoppedProgressing).To(BeTrue(), "error: some cluster operators are still progressing") | ||
|
||
By("Check that all cluster operators are available") | ||
cosAvailable, err := clusteroperator. | ||
WaitForAllClusteroperatorsAvailable(accelinittools.HubAPIClient, time.Minute*5) | ||
Expect(err).NotTo(HaveOccurred(), "error while waiting for cluster operators to become available") | ||
Expect(cosAvailable).To(BeTrue(), "error: some cluster operators are not available") | ||
|
||
By("Check that all pods are running in workload namespace") | ||
workloadPods, err := pod.List(accelinittools.HubAPIClient, accelparams.TestNamespaceName) | ||
Expect(err).NotTo(HaveOccurred(), "error listing pods in workload namespace %s", accelparams.TestNamespaceName) | ||
Expect(len(workloadPods) > 0).To(BeTrue(), | ||
"error: found no running pods in workload namespace %s", accelparams.TestNamespaceName) | ||
|
||
for _, workloadPod := range workloadPods { | ||
err := workloadPod.WaitUntilReady(time.Minute * 2) | ||
Expect(err).To(BeNil(), "error waiting for workload pod to become ready") | ||
} | ||
|
||
verifyWorkloadReachable(workloadRoute) | ||
}) | ||
}) | ||
}) | ||
|
||
func startTestWorkloadAndGetRoute() *route.Builder { | ||
By("Check if workload app namespace exists") | ||
|
||
if _, err := namespace.Pull(accelinittools.HubAPIClient, accelparams.TestNamespaceName); err == nil { | ||
deleteWorkloadNamespace() | ||
} | ||
|
||
By("Create workload app namespace") | ||
|
||
_, err := namespace.NewBuilder(accelinittools.HubAPIClient, accelparams.TestNamespaceName).Create() | ||
Expect(err).NotTo(HaveOccurred(), "error creating namespace for workload app") | ||
|
||
By("Create workload app deployment") | ||
|
||
_, err = CreateWorkload(accelinittools.HubAPIClient, accelparams.IbuWorkloadImage) | ||
Expect(err).ToNot(HaveOccurred(), "error creating workload application") | ||
|
||
By("Create workload app service") | ||
|
||
_, err = CreateService(accelinittools.HubAPIClient, accelparams.ServicePort) | ||
Expect(err).ToNot(HaveOccurred(), "error creating workload service %v", err) | ||
|
||
By("Create workload app route") | ||
|
||
workloadRoute, err := CreateWorkloadRoute(accelinittools.HubAPIClient) | ||
Expect(err).ToNot(HaveOccurred(), "error creating workload route %v", err) | ||
|
||
verifyWorkloadReachable(workloadRoute) | ||
|
||
return workloadRoute | ||
} | ||
|
||
func deleteWorkloadNamespace() { | ||
By("Delete workload") | ||
|
||
err := DeleteNamespace(accelinittools.HubAPIClient) | ||
Expect(err).NotTo(HaveOccurred(), "error deleting workload namespace %v", err) | ||
} | ||
|
||
func verifyWorkloadReachable(workloadRoute *route.Builder) { | ||
By("Verify workload is reachable") | ||
|
||
err := wait.PollUntilContextTimeout( | ||
context.TODO(), time.Second*2, time.Second*10, true, func(ctx context.Context) (bool, error) { | ||
_, rc, _ := url.Fetch(fmt.Sprintf("http://%s", workloadRoute.Object.Spec.Host), "get", true) | ||
|
||
return rc == 200, nil | ||
}, | ||
) | ||
|
||
Expect(err).NotTo(HaveOccurred(), "error reaching the workload") | ||
} |
Oops, something went wrong.