Skip to content

Commit db682e3

Browse files
wadlejitendragabriele-wolfoxphiscofcanovai
authored
test(E2E): Backup and restore with PITR
Co-authored-by: Gabriele Quaresima <gabriele.quaresima@enterprisedb.com> Co-authored-by: Philippe Scorsolini <philippe.scorsolini@enterprisedb.com> Co-authored-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
1 parent 4b8ea05 commit db682e3

8 files changed

+605
-54
lines changed

tests/e2e/asserts_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func AssertCreateTestData(namespace, clusterName, tableName string) {
121121
})
122122
}
123123

124-
// AssertTestDataExistence verifies the test data exists on the given pod
125-
func AssertTestDataExistence(namespace, podName, tableName string) {
124+
// AssertTestDataExpectedCount verifies that an expected amount of rows exist on the table
125+
func AssertTestDataExpectedCount(namespace, podName, tableName string, expectedValue int) {
126126
By(fmt.Sprintf("verifying test data on pod %v", podName), func() {
127127
newPodNamespacedName := types.NamespacedName{
128128
Namespace: namespace,
@@ -137,7 +137,8 @@ func AssertTestDataExistence(namespace, podName, tableName string) {
137137
stdout, _, err := env.ExecCommand(env.Ctx, *Pod, "postgres",
138138
&commandTimeout, "psql", "-U", "postgres", "app", "-tAc", query)
139139
Expect(err).ToNot(HaveOccurred())
140-
Expect(strings.Trim(stdout, "\n"), err).To(BeEquivalentTo("2"))
140+
value, err := strconv.Atoi(strings.Trim(stdout, "\n"))
141+
Expect(value, err).To(BeEquivalentTo(expectedValue))
141142
})
142143
}
143144

tests/e2e/backup_restore_test.go

Lines changed: 484 additions & 49 deletions
Large diffs are not rendered by default.

tests/e2e/fixtures/backup/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ external-clusters-azure-blob-03.yaml
66
external-clusters-minio-03.yaml
77
source-cluster-azure-blob-01.yaml
88
source-cluster-minio-01.yaml
9+
source-cluster-azure-blob-pitr.yaml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: postgresql.k8s.enterprisedb.io/v1
2+
kind: Backup
3+
metadata:
4+
name: cluster-backup
5+
spec:
6+
cluster:
7+
name: backup-azure-blob-pitr
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This resource changes only the name and the barmanObjectStore
2+
# from `cluster-with-backup-azure-blob` in the parent directory.
3+
# This is required because all of them write in the
4+
# same azure blob storage.
5+
apiVersion: postgresql.k8s.enterprisedb.io/v1
6+
kind: Cluster
7+
metadata:
8+
name: backup-azure-blob-pitr
9+
spec:
10+
instances: 3
11+
12+
postgresql:
13+
parameters:
14+
log_checkpoints: "on"
15+
log_line_prefix: '%m [%p]: u=[%u] db=[%d] app=[%a] c=[%h] s=[%c:%l] tx=[%v:%x] '
16+
log_lock_waits: "on"
17+
log_min_duration_statement: '1000'
18+
log_statement: 'ddl'
19+
log_temp_files: '1024'
20+
log_autovacuum_min_duration: '1s'
21+
22+
# Example of rolling update strategy:
23+
# - unsupervised: automated update of the primary once all
24+
# replicas have been upgraded (default)
25+
# - supervised: requires manual supervision to perform
26+
# the switchover of the primary
27+
primaryUpdateStrategy: unsupervised
28+
29+
# Persistent storage configuration
30+
storage:
31+
storageClass: ${E2E_DEFAULT_STORAGE_CLASS}
32+
size: 1Gi
33+
34+
bootstrap:
35+
initdb:
36+
database: app
37+
owner: app
38+
39+
backup:
40+
barmanObjectStore:
41+
destinationPath: https://${AZURE_STORAGE_ACCOUNT}.blob.core.windows.net/backup-azure-blob-pitr/
42+
azureCredentials:
43+
storageAccount:
44+
name: backup-storage-creds
45+
key: ID
46+
storageKey:
47+
name: backup-storage-creds
48+
key: KEY
49+
wal:
50+
compression: gzip
51+
data:
52+
immediateCheckpoint: true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: postgresql.k8s.enterprisedb.io/v1
2+
kind: Backup
3+
metadata:
4+
name: cluster-backup
5+
spec:
6+
cluster:
7+
name: source-cluster-azure-pitr
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: postgresql.k8s.enterprisedb.io/v1
2+
kind: Cluster
3+
metadata:
4+
name: source-cluster-azure-pitr
5+
spec:
6+
instances: 3
7+
8+
postgresql:
9+
parameters:
10+
log_checkpoints: "on"
11+
log_line_prefix: '%m [%p]: u=[%u] db=[%d] app=[%a] c=[%h] s=[%c:%l] tx=[%v:%x] '
12+
log_lock_waits: "on"
13+
log_min_duration_statement: '1000'
14+
log_statement: 'ddl'
15+
log_temp_files: '1024'
16+
log_autovacuum_min_duration: '1s'
17+
18+
# Example of rolling update strategy:
19+
# - unsupervised: automated update of the primary once all
20+
# replicas have been upgraded (default)
21+
# - supervised: requires manual supervision to perform
22+
# the switchover of the primary
23+
primaryUpdateStrategy: unsupervised
24+
25+
# Persistent storage configuration
26+
storage:
27+
storageClass: ${E2E_DEFAULT_STORAGE_CLASS}
28+
size: 1Gi
29+
30+
bootstrap:
31+
initdb:
32+
database: app
33+
owner: app
34+
35+
backup:
36+
barmanObjectStore:
37+
destinationPath: https://${AZURE_STORAGE_ACCOUNT}.blob.core.windows.net/source-cluster-azure-pitr/
38+
azureCredentials:
39+
storageAccount:
40+
name: backup-storage-creds
41+
key: ID
42+
storageKey:
43+
name: backup-storage-creds
44+
key: KEY
45+
wal:
46+
compression: gzip
47+
data:
48+
immediateCheckpoint: true

tests/e2e/pg_data_corruption_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ var _ = Describe("PGDATA Corruption", func() {
163163
return strings.Trim(stdOut, "\n"), err
164164
}, 60, 2).Should(BeEquivalentTo("t"))
165165
// verify test data
166-
AssertTestDataExistence(namespace, newPodName, tableName)
166+
AssertTestDataExpectedCount(namespace, newPodName, tableName, 2)
167167
})
168168
// verify test data on new primary
169169
newPrimaryPodInfo, err = env.GetClusterPrimary(namespace, clusterName)
170170
Expect(err).ToNot(HaveOccurred())
171-
AssertTestDataExistence(namespace, newPrimaryPodInfo.GetName(), tableName)
171+
AssertTestDataExpectedCount(namespace, newPrimaryPodInfo.GetName(), tableName, 2)
172172
assertClusterStandbysAreStreaming(namespace, clusterName)
173173
})
174174
})

0 commit comments

Comments
 (0)