Skip to content

Commit f16bb38

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

File tree

4 files changed

+84
-67
lines changed

4 files changed

+84
-67
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: 53 additions & 60 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,15 +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" {
60-
if vel.CustomResource.Spec.EnableRestic == nil || *vel.CustomResource.Spec.EnableRestic {
61-
log.Printf("Waiting for restic pods to be running")
62-
Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
63-
}
84+
if brCase.BackupRestoreType == restic {
85+
log.Printf("Waiting for restic pods to be running")
86+
Eventually(areResticPodsRunning(namespace), timeoutMultiplier*time.Minute*3, time.Second*5).Should(BeTrue())
6487
}
65-
if brCase.BackupRestoreType == "csi" {
88+
if brCase.BackupRestoreType == csi {
6689
log.Printf("Creating VolumeSnapshot for CSI backuprestore of %s", brCase.Name)
67-
err = installApplication(vel.Client, "./sample-applications/mssql-persistent/volumeSnapshotClass.yaml")
90+
err = installApplication(vel.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml")
6891
Expect(err).ToNot(HaveOccurred())
6992
}
7093

@@ -140,79 +163,49 @@ var _ = Describe("AWS backup restore tests", func() {
140163
err = uninstallApplication(vel.Client, brCase.ApplicationTemplate)
141164
Expect(err).ToNot(HaveOccurred())
142165

143-
if brCase.BackupRestoreType == "csi" {
166+
// Wait for namespace to be deleted
167+
Eventually(isNamespaceDeleted(brCase.ApplicationNamespace), timeoutMultiplier*time.Minute*2, time.Second*5).Should(BeTrue())
168+
169+
if brCase.BackupRestoreType == csi {
144170
log.Printf("Deleting VolumeSnapshot for CSI backuprestore of %s", brCase.Name)
145-
err = uninstallApplication(vel.Client, "./sample-applications/mssql-persistent/volumeSnapshotClass.yaml")
171+
err = uninstallApplication(vel.Client, "./sample-applications/gp2-csi/volumeSnapshotClass.yaml")
146172
Expect(err).ToNot(HaveOccurred())
147173
}
174+
148175
},
149176
Entry("MSSQL application CSI", BackupRestoreCase{
150177
ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-csi-template.yaml",
151178
ApplicationNamespace: "mssql-persistent",
152179
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-
}),
180+
BackupRestoreType: csi,
181+
PreBackupVerify: mssqlReady,
182+
PostRestoreVerify: mssqlReady,
168183
}, nil),
169184
Entry("Parks application <4.8.0", BackupRestoreCase{
170185
ApplicationTemplate: "./sample-applications/parks-app/manifest.yaml",
171186
ApplicationNamespace: "parks-app",
172187
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,
188+
BackupRestoreType: restic,
189+
PreBackupVerify: parksAppReady,
190+
PostRestoreVerify: parksAppReady,
191+
MaxK8SVersion: &k8sVersionOcp47,
182192
}, nil),
183193
Entry("MSSQL application", BackupRestoreCase{
184194
ApplicationTemplate: "./sample-applications/mssql-persistent/mssql-persistent-template.yaml",
185195
ApplicationNamespace: "mssql-persistent",
186196
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-
}),
197+
BackupRestoreType: restic,
198+
PreBackupVerify: mssqlReady,
199+
PostRestoreVerify: mssqlReady,
202200
}, nil),
203201
Entry("Parks application >=4.8.0", BackupRestoreCase{
204202
ApplicationTemplate: "./sample-applications/parks-app/manifest4.8.yaml",
205203
ApplicationNamespace: "parks-app",
206204
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,
205+
BackupRestoreType: restic,
206+
PreBackupVerify: parksAppReady,
207+
PostRestoreVerify: parksAppReady,
208+
MinK8SVersion: &k8sVersionOcp48,
216209
}, nil),
217210
)
218211
})

tests/e2e/velero_helpers.go

Lines changed: 4 additions & 4 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{
@@ -69,9 +69,9 @@ func (v *veleroCustomResource) Build(backupRestoreType string) error {
6969
}
7070
v.backupRestoreType = backupRestoreType
7171
switch backupRestoreType {
72-
case "restic":
72+
case restic:
7373
veleroSpec.Spec.EnableRestic = pointer.Bool(true)
74-
case "csi":
74+
case csi:
7575
veleroSpec.Spec.EnableRestic = pointer.Bool(false)
7676
veleroSpec.Spec.DefaultVeleroPlugins = append(veleroSpec.Spec.DefaultVeleroPlugins, oadpv1alpha1.DefaultPluginCSI)
7777
veleroSpec.Spec.VeleroFeatureFlags = append(veleroSpec.Spec.VeleroFeatureFlags, "EnableCSI")

0 commit comments

Comments
 (0)