Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #25 from parul5sahoo/logging
Browse files Browse the repository at this point in the history
Added granular logging for the existing provider upgrade test
  • Loading branch information
jbw976 authored Aug 19, 2022
2 parents e4a5fd7 + 99e5c89 commit 40a60b1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
11 changes: 5 additions & 6 deletions config/provider/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ providers:
upgrade:
- initial: "v0.21.0"
final: "master"
- package: crossplane/provider-aws
upgrade:
- initial: "v0.29.0"
final: "master"
- package: crossplane/provider-azure
upgrade:
- initial: "v0.19.0"
final: "master"

final: "master"
- package: crossplane/provider-aws
upgrade:
- initial: "v0.29.0"
final: "master"
42 changes: 32 additions & 10 deletions test/framework/provider/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package provider

import (
"context"
"testing"
"time"

v1 "github.com/crossplane/crossplane/apis/pkg/v1"
Expand All @@ -27,20 +28,28 @@ import (
)

// Wait for Provider to be successfully installed.
func WaitForAllProvidersInstalled(ctx context.Context, c client.Client, interval time.Duration, timeout time.Duration) error {
func WaitForAllProvidersInstalled(ctx context.Context, c client.Client, interval time.Duration, timeout time.Duration, t *testing.T) error {
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
l := &v1.ProviderList{}
if err := c.List(ctx, l); err != nil {
return false, err
}

if len(l.Items) != 1 {
t.Log("The no. of providers installed is not equal to 1")
for i, item := range l.Items{
t.Logf("Provider %v : %v", i, item.Name)
}
return false, nil
}
for _, p := range l.Items {
if p.GetCondition(v1.TypeInstalled).Status != corev1.ConditionTrue {

for _, item := range l.Items {
if item.GetCondition(v1.TypeInstalled).Status != corev1.ConditionTrue {
t.Logf("The type of provider %v installed is %v", item.Name, item.TypeMeta)
return false, nil
}
if p.GetCondition(v1.TypeHealthy).Status != corev1.ConditionTrue {
if item.GetCondition(v1.TypeHealthy).Status != corev1.ConditionTrue {
t.Logf("The status of provider %v installed is %v", item.Name, item.Status)
return false, nil
}
}
Expand All @@ -52,27 +61,35 @@ func WaitForAllProvidersInstalled(ctx context.Context, c client.Client, interval
}

// Wait for Provider to be successfully updated.
func WaitForRevisionTransition(ctx context.Context, c client.Client, p2 string, p1 string, interval time.Duration, timeout time.Duration) error {
func WaitForRevisionTransition(ctx context.Context, c client.Client, p2 string, p1 string, interval time.Duration, timeout time.Duration, t *testing.T) error {
if err := wait.PollImmediate(interval, timeout, func() (bool, error) {
l := &v1.ProviderRevisionList{}
if err := c.List(ctx, l); err != nil {
return false, err
}

// There should be a revision present for the initial revision and the upgrade.
if len(l.Items) != 2 {
t.Log("The no. of provider revisions is not equal to 2")
for i, item := range l.Items{
t.Logf("Provider revision %v : %v uses package %v", i, item.Name, item.Spec.Package)
}
return false, nil
}
for _, p := range l.Items {
for _, item := range l.Items {
// New ProviderRevision should be Active.
if p.Spec.Package == p2 && p.GetDesiredState() != v1.PackageRevisionActive {
if item.Spec.Package == p2 && item.GetDesiredState() != v1.PackageRevisionActive {
t.Logf("The state of new provider revision %v built from package %v and having version %v is %v", item.Name, item.Spec.Package, item.Spec.Revision, item.Status)
return false, nil
}
// Old ProviderRevision should be Inactive.
if p.Spec.Package == p1 && p.GetDesiredState() != v1.PackageRevisionInactive {
if item.Spec.Package == p1 && item.GetDesiredState() != v1.PackageRevisionInactive {
t.Logf("The state of old provider revision %v built from package %v and having version %v is %v", item.Name, item.Spec.Package, item.Spec.Revision, item.Status)
return false, nil
}
// Both ProviderRevisions should be healthy.
if p.GetCondition(v1.TypeHealthy).Status != corev1.ConditionTrue {
if item.GetCondition(v1.TypeHealthy).Status != corev1.ConditionTrue {
t.Logf("The condition of provider revision %v built from package %v and having version %v is %v", item.Name, item.Spec.Package, item.Spec.Revision, item.Status.ConditionedStatus)
return false, nil
}
}
Expand All @@ -84,12 +101,17 @@ func WaitForRevisionTransition(ctx context.Context, c client.Client, p2 string,
}

// Wait for Provider to be successfully deleted.
func WaitForAllProvidersDeleted(ctx context.Context, c client.Client, interval time.Duration, timeout time.Duration) error {
func WaitForAllProvidersDeleted(ctx context.Context, c client.Client, interval time.Duration, timeout time.Duration, t *testing.T) error {
return wait.PollImmediate(interval, timeout, func() (bool, error) {
l := &v1.ProviderList{}
if err := c.List(ctx, l); err != nil {
return false, err
}
for _, item := range l.Items {
t.Log("Undeleted providers :")
t.Logf("Name: %v \t Type: %v \t Uses Package: %v", item.Name, item.Kind, item.Spec.Package)
}

return len(l.Items) == 0, nil
})
}
6 changes: 3 additions & 3 deletions test/provider/upgrade/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestProviderUpgrade(t *testing.T) {
}

// Wait for Provider to be successfully installed.
if err := provider.WaitForAllProvidersInstalled(ctx, c, 5*time.Second, 2*time.Minute); err != nil {
if err := provider.WaitForAllProvidersInstalled(ctx, c, 5*time.Second, 2*time.Minute, t); err != nil {
return err
}

Expand All @@ -89,7 +89,7 @@ func TestProviderUpgrade(t *testing.T) {
}

// Wait for Provider to be successfully updated.
if err := provider.WaitForRevisionTransition(ctx, c, upgradeProviderPackage, initialProviderPackage, 5*time.Second, 2*time.Minute); err != nil {
if err := provider.WaitForRevisionTransition(ctx, c, upgradeProviderPackage, initialProviderPackage, 5*time.Second, 2*time.Minute, t); err != nil {
return err
}

Expand All @@ -99,7 +99,7 @@ func TestProviderUpgrade(t *testing.T) {
}

// Wait for Provider to be successfully deleted.
return provider.WaitForAllProvidersDeleted(ctx, c, 5*time.Second, 30*time.Second)
return provider.WaitForAllProvidersDeleted(ctx, c, 5*time.Second, 30*time.Second, t)
},
},
}
Expand Down

0 comments on commit 40a60b1

Please sign in to comment.