Skip to content

Commit

Permalink
Use ginkgo's context in e2e
Browse files Browse the repository at this point in the history
Use ginkgo contexts instead and let ginkgo handle them, instead of
creating our on contexts.

Signed-off-by: Nahshon Unna-Tsameret <nunnatsa@redhat.com>
  • Loading branch information
nunnatsa committed Jun 13, 2024
1 parent 6b52373 commit 1880409
Show file tree
Hide file tree
Showing 19 changed files with 274 additions and 294 deletions.
20 changes: 10 additions & 10 deletions tests/func-tests/aaq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,33 @@ var _ = Describe("Test AAQ", Label("AAQ"), Serial, Ordered, func() {
tests.FlagParse()
var (
k8scli client.Client
ctx context.Context
)

BeforeEach(func() {
BeforeEach(func(ctx context.Context) {
k8scli = tests.GetControllerRuntimeClient()

ctx = context.Background()

disableAAQFeatureGate(ctx, k8scli)
})

AfterAll(func() {
AfterAll(func(ctx context.Context) {
disableAAQFeatureGate(ctx, k8scli)
})

When("set the applicationAwareConfig exists", func() {
It("should create the AAQ CR and all the pods", func() {
It("should create the AAQ CR and all the pods", func(ctx context.Context) {

enableAAQFeatureGate(ctx, k8scli)

By("check the AAQ CR")
Eventually(func(g Gomega) bool {
Eventually(func(g Gomega, ctx context.Context) bool {
aaq, err := getAAQ(ctx, k8scli)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(aaq.Status.Conditions).ToNot(BeEmpty())
return conditionsv1.IsStatusConditionTrue(aaq.Status.Conditions, conditionsv1.ConditionAvailable)
}).WithTimeout(5 * time.Minute).WithPolling(time.Second).ShouldNot(BeTrue())
}).WithTimeout(5 * time.Minute).WithPolling(time.Second).WithContext(ctx).ShouldNot(BeTrue())

By("check AAQ pods")
Eventually(func(g Gomega) {
Eventually(func(g Gomega, ctx context.Context) {
deps := &appsv1.DeploymentList{}
Expect(
k8scli.List(ctx, deps, client.MatchingLabels{"app.kubernetes.io/managed-by": "aaq-operator"}),
Expand All @@ -78,6 +75,7 @@ var _ = Describe("Test AAQ", Label("AAQ"), Serial, Ordered, func() {
g.Expect(pods.Items).To(HaveLen(int(expectedPods)))
}).WithTimeout(5 * time.Minute).
WithPolling(time.Second).
WithContext(ctx).
Should(Succeed())
})
})
Expand Down Expand Up @@ -105,12 +103,13 @@ func disableAAQFeatureGate(ctx context.Context, cli client.Client) {
setAAQFeatureGate(ctx, cli, false)

By("make sure the AAQ CR was removed")
Eventually(func() error {
Eventually(func(ctx context.Context) error {
_, err := getAAQ(ctx, cli)
return err
}).WithTimeout(5 * time.Minute).
WithPolling(100 * time.Millisecond).
WithOffset(1).
WithContext(ctx).
Should(MatchError(errors.IsNotFound, "not found error"))
}

Expand All @@ -121,6 +120,7 @@ func setAAQFeatureGate(ctx context.Context, cli client.Client, fgState bool) {
WithArguments(ctx, cli, patchBytes).
WithTimeout(10 * time.Second).
WithPolling(100 * time.Millisecond).
WithContext(ctx).
WithOffset(2).
Should(Succeed())
}
8 changes: 3 additions & 5 deletions tests/func-tests/cli_download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ var _ = Describe("[rfe_id:5100][crit:medium][vendor:cnv-qe@redhat.com][level:sys

var (
cli client.Client
ctx context.Context
)

BeforeEach(func() {
tests.BeforeEach()
BeforeEach(func(ctx context.Context) {
tests.BeforeEach(ctx)
cfg, err := config.GetConfig()
Expect(err).ToNot(HaveOccurred())

Expand All @@ -36,11 +35,10 @@ var _ = Describe("[rfe_id:5100][crit:medium][vendor:cnv-qe@redhat.com][level:sys
cli, err = client.New(cfg, client.Options{Scheme: s})
Expect(err).ToNot(HaveOccurred())

ctx = context.Background()
tests.FailIfNotOpenShift(ctx, cli, "ConsoleCliDownload")
})

It("[test_id:6956]should create ConsoleCliDownload objects with expected spec", Label("test_id:6956"), func() {
It("[test_id:6956]should create ConsoleCliDownload objects with expected spec", Label("test_id:6956"), func(ctx context.Context) {
By("Checking existence of ConsoleCliDownload")

ccd := &consolev1.ConsoleCLIDownload{
Expand Down
13 changes: 5 additions & 8 deletions tests/func-tests/cluster_eviction_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,30 @@ var _ = Describe("Cluster level evictionStrategy default value", Serial, Ordered
tests.FlagParse()
var (
cli client.Client
ctx context.Context

initialEvictionStrategy *v1.EvictionStrategy
singleWorkerCluster bool
)

BeforeEach(func() {
BeforeEach(func(ctx context.Context) {
cli = tests.GetControllerRuntimeClient()

ctx = context.Background()

var err error
singleWorkerCluster, err = isSingleWorkerCluster(ctx, cli)
Expect(err).ToNot(HaveOccurred())

tests.BeforeEach()
tests.BeforeEach(ctx)
hc := tests.GetHCO(ctx, cli)
initialEvictionStrategy = hc.Spec.EvictionStrategy
})

AfterEach(func() {
AfterEach(func(ctx context.Context) {
hc := tests.GetHCO(ctx, cli)
hc.Spec.EvictionStrategy = initialEvictionStrategy
tests.UpdateHCORetry(ctx, cli, hc)
})

It("Should set spec.evictionStrategy = None by default on single worker clusters", Label(tests.SingleNodeLabel), func() {
It("Should set spec.evictionStrategy = None by default on single worker clusters", Label(tests.SingleNodeLabel), func(ctx context.Context) {
Expect(singleWorkerCluster).To(BeTrue(), "this test requires single worker cluster; use the %q label to skip this test", tests.SingleNodeLabel)

hco := tests.GetHCO(ctx, cli)
Expand All @@ -54,7 +51,7 @@ var _ = Describe("Cluster level evictionStrategy default value", Serial, Ordered
Expect(hco.Spec.EvictionStrategy).To(Equal(&noneEvictionStrategy))
})

It("Should set spec.evictionStrategy = LiveMigrate by default with multiple worker node", Label(tests.HighlyAvailableClusterLabel), func() {
It("Should set spec.evictionStrategy = LiveMigrate by default with multiple worker node", Label(tests.HighlyAvailableClusterLabel), func(ctx context.Context) {
tests.FailIfSingleNode(singleWorkerCluster)
hco := tests.GetHCO(ctx, cli)
hco.Spec.EvictionStrategy = nil
Expand Down
29 changes: 16 additions & 13 deletions tests/func-tests/console_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,27 @@ var _ = Describe("kubevirt console plugin", Label(tests.OpenshiftLabel, "console
var (
cli client.Client
k8sClientSet *kubernetes.Clientset
ctx context.Context
)

tests.FlagParse()

BeforeEach(func() {
BeforeEach(func(ctx context.Context) {
cli = tests.GetControllerRuntimeClient()

ctx = context.Background()
tests.FailIfNotOpenShift(ctx, cli, "kubevirt console plugin")

hco := tests.GetHCO(ctx, cli)
originalInfra := hco.Spec.Infra

k8sClientSet = tests.GetK8sClientSet()

DeferCleanup(func() {
DeferCleanup(func(ctx context.Context) {
hco.Spec.Infra = originalInfra
tests.UpdateHCORetry(ctx, cli, hco)
})

})

It("console should reach kubevirt-plugin manifests", func() {
It("console should reach kubevirt-plugin manifests", func(ctx context.Context) {
kubevirtPlugin := &consolev1.ConsolePlugin{
ObjectMeta: metav1.ObjectMeta{
Name: expectedKubevirtConsolePluginName,
Expand Down Expand Up @@ -93,7 +90,7 @@ var _ = Describe("kubevirt console plugin", Label(tests.OpenshiftLabel, "console
Expect(pluginName).To(Equal(expectedKubevirtConsolePluginName))
})

It("nodePlacement should be propagated from HyperConverged CR to console-plugin and apiserver-proxy Deployments", Serial, func() {
It("nodePlacement should be propagated from HyperConverged CR to console-plugin and apiserver-proxy Deployments", Serial, func(ctx context.Context) {

expectedNodeSelector := map[string]string{
"foo": "bar",
Expand All @@ -103,14 +100,15 @@ var _ = Describe("kubevirt console plugin", Label(tests.OpenshiftLabel, "console
expectedNodeSelectorStr := string(expectedNodeSelectorBytes)
addNodeSelectorPatch := []byte(fmt.Sprintf(`[{"op": "add", "path": "/spec/infra", "value": {"nodePlacement": {"nodeSelector": %s}}}]`, expectedNodeSelectorStr))

Eventually(func() error {
Eventually(func(ctx context.Context) error {
err = tests.PatchHCO(ctx, cli, addNodeSelectorPatch)
return err
}).WithTimeout(1 * time.Minute).
WithPolling(1 * time.Millisecond).
WithContext(ctx).
Should(Succeed())

Eventually(func(g Gomega) {
Eventually(func(g Gomega, ctx context.Context) {
consoleUIDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: string(hcoutil.AppComponentUIPlugin),
Expand All @@ -123,9 +121,10 @@ var _ = Describe("kubevirt console plugin", Label(tests.OpenshiftLabel, "console
g.Expect(consoleUIDeployment.Spec.Template.Spec.NodeSelector).To(Equal(expectedNodeSelector))
}).WithTimeout(1 * time.Minute).
WithPolling(100 * time.Millisecond).
WithContext(ctx).
Should(Succeed())

Eventually(func(g Gomega) {
Eventually(func(g Gomega, ctx context.Context) {
proxyUIDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: string(hcoutil.AppComponentUIProxy),
Expand All @@ -136,18 +135,20 @@ var _ = Describe("kubevirt console plugin", Label(tests.OpenshiftLabel, "console
g.Expect(proxyUIDeployment.Spec.Template.Spec.NodeSelector).To(Equal(expectedNodeSelector))
}).WithTimeout(1 * time.Minute).
WithPolling(100 * time.Millisecond).
WithContext(ctx).
Should(Succeed())

// clear node placement from HyperConverged CR and verify the nodeSelector has been cleared as well from the UI Deployments
removeNodeSelectorPatch := []byte(`[{"op": "replace", "path": "/spec/infra", "value": {}}]`)
Eventually(func() error {
Eventually(func(ctx context.Context) error {
err = tests.PatchHCO(ctx, cli, removeNodeSelectorPatch)
return err
}).WithTimeout(1 * time.Minute).
WithPolling(1 * time.Millisecond).
WithContext(ctx).
Should(Succeed())

Eventually(func(g Gomega) {
Eventually(func(g Gomega, ctx context.Context) {
consoleUIDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: string(hcoutil.AppComponentUIPlugin),
Expand All @@ -159,9 +160,10 @@ var _ = Describe("kubevirt console plugin", Label(tests.OpenshiftLabel, "console
g.Expect(consoleUIDeployment.Spec.Template.Spec.NodeSelector).To(BeEmpty())
}).WithTimeout(1 * time.Minute).
WithPolling(100 * time.Millisecond).
WithContext(ctx).
Should(Succeed())

Eventually(func(g Gomega) {
Eventually(func(g Gomega, ctx context.Context) {
proxyUIDeployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: string(hcoutil.AppComponentUIProxy),
Expand All @@ -172,6 +174,7 @@ var _ = Describe("kubevirt console plugin", Label(tests.OpenshiftLabel, "console
g.Expect(proxyUIDeployment.Spec.Template.Spec.NodeSelector).To(BeEmpty())
}).WithTimeout(1 * time.Minute).
WithPolling(100 * time.Millisecond).
WithContext(ctx).
Should(Succeed())
})
})
Expand Down
12 changes: 4 additions & 8 deletions tests/func-tests/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ import (
var _ = Describe("[rfe_id:5108][crit:medium][vendor:cnv-qe@redhat.com][level:system]Dashboard configmaps", Label(tests.OpenshiftLabel), func() {
flag.Parse()

var (
cli *kubernetes.Clientset
ctx context.Context
)
var cli *kubernetes.Clientset

BeforeEach(func() {
tests.BeforeEach()
BeforeEach(func(ctx context.Context) {
tests.BeforeEach(ctx)

k8sCli := tests.GetControllerRuntimeClient()
ctx = context.Background()

tests.FailIfNotOpenShift(ctx, k8sCli, "Dashboard configmaps")

cli = tests.GetK8sClientSet()
})

It("[test_id:5919]should create configmaps for OCP Dashboard", Label("test_id:5919"), func() {
It("[test_id:5919]should create configmaps for OCP Dashboard", Label("test_id:5919"), func(ctx context.Context) {
By("Checking expected configmaps")
items := tests.GetConfig().Dashboard.TestItems

Expand Down
Loading

0 comments on commit 1880409

Please sign in to comment.