Skip to content

Commit 3f1886a

Browse files
committed
code refactoring and, Postbackup-restore varify for MSSQL
1 parent 02eb622 commit 3f1886a

File tree

3 files changed

+78
-59
lines changed

3 files changed

+78
-59
lines changed

tests/e2e/apps.go

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import (
77
"os"
88

99
"github.com/onsi/ginkgo"
10-
appsv1 "github.com/openshift/api/apps/v1"
10+
ocpappsv1 "github.com/openshift/api/apps/v1"
11+
appsv1 "k8s.io/api/apps/v1"
12+
1113
security "github.com/openshift/api/security/v1"
1214
corev1 "k8s.io/api/core/v1"
1315
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -102,7 +104,7 @@ func areApplicationPodsRunning(namespace string) wait.ConditionFunc {
102104
if len(condition.Message) > 0 {
103105
ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("Pod not running with condition: %s\n", condition.Message)))
104106
}
105-
}
107+
}
106108
return false, nil
107109
}
108110
}
@@ -112,7 +114,7 @@ func areApplicationPodsRunning(namespace string) wait.ConditionFunc {
112114

113115
func isDCReady(ocClient client.Client, namespace, dcName string) wait.ConditionFunc {
114116
return func() (bool, error) {
115-
dc := appsv1.DeploymentConfig{}
117+
dc := ocpappsv1.DeploymentConfig{}
116118
err := ocClient.Get(context.Background(), client.ObjectKey{
117119
Namespace: namespace,
118120
Name: dcName,
@@ -131,3 +133,25 @@ func isDCReady(ocClient client.Client, namespace, dcName string) wait.ConditionF
131133
return true, nil
132134
}
133135
}
136+
137+
func isDeploymentReady(ocClient client.Client, namespace, dName string) wait.ConditionFunc {
138+
return func() (bool, error) {
139+
deployment := appsv1.Deployment{}
140+
err := ocClient.Get(context.Background(), client.ObjectKey{
141+
Namespace: namespace,
142+
Name: dName,
143+
}, &deployment)
144+
if err != nil {
145+
return false, err
146+
}
147+
if deployment.Status.AvailableReplicas != deployment.Status.Replicas || deployment.Status.Replicas == 0 {
148+
for _, condition := range deployment.Status.Conditions {
149+
if len(condition.Message) > 0 {
150+
ginkgo.GinkgoWriter.Write([]byte(fmt.Sprintf("deployment not available with condition: %s\n", condition.Message)))
151+
}
152+
}
153+
return false, errors.New("deployment is not in a ready state")
154+
}
155+
return true, nil
156+
}
157+
}

tests/e2e/backup_restore_suite_test.go

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ import (
1313
"sigs.k8s.io/controller-runtime/pkg/client"
1414
)
1515

16+
type BackupRestoreType string
17+
18+
const (
19+
csi BackupRestoreType = "csi"
20+
restic BackupRestoreType = "restic"
21+
)
22+
23+
type VerificationFunction func(client.Client, string) error
24+
1625
var _ = Describe("AWS backup restore tests", func() {
1726
var _ = BeforeEach(func() {
1827
testSuiteInstanceName := "ts-" + instanceName
@@ -31,19 +40,35 @@ var _ = Describe("AWS backup restore tests", func() {
3140

3241
})
3342

34-
type VerificationFunction func(client.Client, string) error
35-
3643
type BackupRestoreCase struct {
3744
ApplicationTemplate string
3845
ApplicationNamespace string
3946
Name string
40-
BackupRestoreType string
47+
BackupRestoreType BackupRestoreType
4148
PreBackupVerify VerificationFunction
4249
PostRestoreVerify VerificationFunction
4350
MaxK8SVersion *k8sVersion
4451
MinK8SVersion *k8sVersion
4552
}
4653

54+
parksAppReady := VerificationFunction(func(ocClient client.Client, namespace string) error {
55+
Eventually(isDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
56+
return nil
57+
})
58+
mssqlReady := VerificationFunction(func(ocClient client.Client, namespace string) error {
59+
// This test confirms that SCC restore logic in our plugin is working
60+
Eventually(isDCReady(ocClient, "mssql-persistent", "mssql-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
61+
Eventually(isDeploymentReady(ocClient, "mssql-persistent", "mssql-app-deployment"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
62+
exists, err := doesSCCExist(ocClient, "mssql-persistent-scc")
63+
if err != nil {
64+
return err
65+
}
66+
if !exists {
67+
return errors.New("did not find MSSQL scc")
68+
}
69+
return nil
70+
})
71+
4772
DescribeTable("backup and restore applications",
4873
func(brCase BackupRestoreCase, expectedErr error) {
4974

@@ -56,13 +81,13 @@ var _ = Describe("AWS backup restore tests", func() {
5681
log.Printf("Waiting for velero pod to be running")
5782
Eventually(isVeleroPodRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
5883

59-
if brCase.BackupRestoreType == "restic" {
84+
if brCase.BackupRestoreType == restic {
6085
if vel.CustomResource.Spec.EnableRestic == nil || *vel.CustomResource.Spec.EnableRestic {
6186
log.Printf("Waiting for restic pods to be running")
6287
Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
6388
}
6489
}
65-
if brCase.BackupRestoreType == "csi" {
90+
if brCase.BackupRestoreType == csi {
6691
log.Printf("Creating VolumeSnapshot for CSI backuprestore of %s", brCase.Name)
6792
err = installApplication(vel.Client, "./sample-applications/mssql-persistent/volumeSnapshotClass.yaml")
6893
Expect(err).ToNot(HaveOccurred())
@@ -140,79 +165,49 @@ var _ = Describe("AWS backup restore tests", func() {
140165
err = uninstallApplication(vel.Client, brCase.ApplicationTemplate)
141166
Expect(err).ToNot(HaveOccurred())
142167

143-
if brCase.BackupRestoreType == "csi" {
168+
// Wait for namespace to be deleted
169+
Eventually(isNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue())
170+
171+
if brCase.BackupRestoreType == csi {
144172
log.Printf("Deleting VolumeSnapshot for CSI backuprestore of %s", brCase.Name)
145173
err = uninstallApplication(vel.Client, "./sample-applications/mssql-persistent/volumeSnapshotClass.yaml")
146174
Expect(err).ToNot(HaveOccurred())
147175
}
176+
148177
},
149178
Entry("MSSQL application CSI", BackupRestoreCase{
150179
ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-csi-template.yaml",
151180
ApplicationNamespace: "mssql-persistent",
152181
Name: "mssql-e2e",
153-
BackupRestoreType: "csi",
154-
PreBackupVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
155-
return nil
156-
}),
157-
PostRestoreVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
158-
// This test confirms that SCC restore logic in our plugin is working
159-
exists, err := doesSCCExist(ocClient, "mssql-persistent-scc")
160-
if err != nil {
161-
return err
162-
}
163-
if !exists {
164-
return errors.New("did not find MSSQL scc after restore")
165-
}
166-
return nil
167-
}),
182+
BackupRestoreType: csi,
183+
PreBackupVerify: mssqlReady,
184+
PostRestoreVerify: mssqlReady,
168185
}, nil),
169186
Entry("Parks application <4.8.0", BackupRestoreCase{
170187
ApplicationTemplate: "./sample-applications/parks-app/manifest.yaml",
171188
ApplicationNamespace: "parks-app",
172189
Name: "parks-e2e",
173-
BackupRestoreType: "restic",
174-
PreBackupVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
175-
Eventually(isDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
176-
return nil
177-
}),
178-
PostRestoreVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
179-
return nil
180-
}),
181-
MaxK8SVersion: &k8sVersionOcp47,
190+
BackupRestoreType: restic,
191+
PreBackupVerify: parksAppReady,
192+
PostRestoreVerify: parksAppReady,
193+
MaxK8SVersion: &k8sVersionOcp47,
182194
}, nil),
183195
Entry("MSSQL application", BackupRestoreCase{
184196
ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-template.yaml",
185197
ApplicationNamespace: "mssql-persistent",
186198
Name: "mssql-e2e",
187-
BackupRestoreType: "restic",
188-
PreBackupVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
189-
return nil
190-
}),
191-
PostRestoreVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
192-
// This test confirms that SCC restore logic in our plugin is working
193-
exists, err := doesSCCExist(ocClient, "mssql-persistent-scc")
194-
if err != nil {
195-
return err
196-
}
197-
if !exists {
198-
return errors.New("did not find MSSQL scc after restore")
199-
}
200-
return nil
201-
}),
199+
BackupRestoreType: restic,
200+
PreBackupVerify: mssqlReady,
201+
PostRestoreVerify: mssqlReady,
202202
}, nil),
203203
Entry("Parks application >=4.8.0", BackupRestoreCase{
204204
ApplicationTemplate: "./sample-applications/parks-app/manifest4.8.yaml",
205205
ApplicationNamespace: "parks-app",
206206
Name: "parks-e2e",
207-
BackupRestoreType: "restic",
208-
PreBackupVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
209-
Eventually(isDCReady(ocClient, "parks-app", "restify"), timeoutMultiplier*time.Minute*10, time.Second*10).Should(BeTrue())
210-
return nil
211-
}),
212-
PostRestoreVerify: VerificationFunction(func(ocClient client.Client, namespace string) error {
213-
return nil
214-
}),
215-
MinK8SVersion: &k8sVersionOcp48,
207+
BackupRestoreType: restic,
208+
PreBackupVerify: parksAppReady,
209+
PostRestoreVerify: parksAppReady,
210+
MinK8SVersion: &k8sVersionOcp48,
216211
}, nil),
217212
)
218213
})

tests/e2e/velero_helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ type veleroCustomResource struct {
3030
Bucket string
3131
Region string
3232
Provider string
33-
backupRestoreType string
33+
backupRestoreType BackupRestoreType
3434
CustomResource *oadpv1alpha1.Velero
3535
Client client.Client
3636
}
3737

3838
var veleroPrefix = "velero-e2e-" + string(uuid.NewUUID())
3939

40-
func (v *veleroCustomResource) Build(backupRestoreType string) error {
40+
func (v *veleroCustomResource) Build(backupRestoreType BackupRestoreType) error {
4141
// Velero Instance creation spec with backupstorage location default to AWS. Would need to parameterize this later on to support multiple plugins.
4242
veleroSpec := oadpv1alpha1.Velero{
4343
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)