Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
EVEREST-316 backup for not existing cluster (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
oksana-grishchenko authored Sep 13, 2023
1 parent 5ae32af commit 193ec3b
Show file tree
Hide file tree
Showing 7 changed files with 405 additions and 245 deletions.
11 changes: 0 additions & 11 deletions api-tests/tests/backup-storages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ import { expect, test } from '@fixtures';

let req;

test.afterEach(async ({ page }, testInfo) => {
const request = page.context().request;
const result = await request.get('/v1/backup-storages');
const list = await result.json();

for (const storage of list) {
await request.delete(`/v1/backup-storages/${storage.name}`);
}
});

test('add/list/get/delete backup storage success', async ({ request }) => {
req = request;
const payload = {
Expand Down Expand Up @@ -98,7 +88,6 @@ test('add/list/get/delete backup storage success', async ({ request }) => {

// delete
const deleted = await request.delete(`/v1/backup-storages/${name}`);

expect(deleted.ok()).toBeTruthy();
});

Expand Down
276 changes: 153 additions & 123 deletions api-tests/tests/database-cluster-backups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,139 +12,169 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { test, expect } from '@playwright/test'

// testPrefix is used to differentiate between several workers
// running this test to avoid conflicts in instance names
const testPrefix = `${(Math.random() + 1).toString(36).substring(10)}`
import {expect, test} from '@playwright/test'
import * as th from './helpers';

let kubernetesId
const bsName = `${testPrefix}-bs`

test.beforeAll(async ({ request }) => {
const kubernetesList = await request.get('/v1/kubernetes')
kubernetesId = (await kubernetesList.json())[0].id

// Backup storage
const payload = {
type: 's3',
name: bsName,
url: 'http://custom-url',
description: 'Dev storage',
bucketName: 'percona-test-backup-storage',
region: 'us-east-2',
accessKey: 'sdfs',
secretKey: 'sdfsdfsd',
}

const response = await request.post('/v1/backup-storages', { data: payload })
expect(response.ok()).toBeTruthy()
})

test.afterAll(async ({ request }) => {
let res = await request.delete(`/v1/backup-storages/${bsName}`)
expect(res.ok()).toBeTruthy()
})

test('create/delete database cluster backups', async ({ request }) => {
const payload = {
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: 'backup',
},
spec: {
dbClusterName: 'someCluster',
backupStorageName: bsName,
},
}

let response = await request.post(`/v1/kubernetes/${kubernetesId}/database-cluster-backups`, {
data: payload,
})

expect(response.ok()).toBeTruthy()

response = await request.get(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/backup`)
const result = await response.json()

expect(result.spec).toMatchObject(payload.spec)

await request.delete(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/backup`)
response = await request.get(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/backup`)
expect(response.status()).toBe(404)
test.beforeAll(async ({request}) => {
const kubernetesList = await request.get('/v1/kubernetes')
kubernetesId = (await kubernetesList.json())[0].id
})

test('list backups', async ({ request, page }) => {
const payloads = [
{
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: 'backup4',
},
spec: {
dbClusterName: 'cluster1',
backupStorageName: bsName,
},
},
{
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: 'backup41',
},
spec: {
dbClusterName: 'cluster1',
backupStorageName: bsName,
},
},
{
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: 'backup42',
},
spec: {
dbClusterName: 'cluster2',
backupStorageName: bsName,
},
},
{
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: 'backup43',
},
spec: {
dbClusterName: 'cluster2',
backupStorageName: bsName,
},
},
]

for (const payload of payloads) {
const response = await request.post(`/v1/kubernetes/${kubernetesId}/database-cluster-backups`, {
data: payload,
test('create/delete database cluster backups', async ({request}) => {
const bsName = th.suffixedName("storage")
const clName = th.suffixedName("cluster")

await th.createBackupStorage(request, bsName)
await th.createDBCluster(request, kubernetesId, clName)

const backupName = th.suffixedName("backup")

const payload = {
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: backupName,
},
spec: {
dbClusterName: clName,
backupStorageName: bsName,
},
}

let response = await request.post(`/v1/kubernetes/${kubernetesId}/database-cluster-backups`, {
data: payload,
})

expect(response.ok()).toBeTruthy()
}

await page.waitForTimeout(1000)
let response = await request.get(`/v1/kubernetes/${kubernetesId}/database-clusters/cluster1/backups`)
let result = await response.json()
response = await request.get(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/${backupName}`)
const result = await response.json()

expect(result.spec).toMatchObject(payload.spec)

await request.delete(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/${backupName}`)
response = await request.get(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/${backupName}`)
expect(response.status()).toBe(404)

expect(result.items).toHaveLength(2)
await th.deleteDBCluster(request, kubernetesId, clName)
await th.deleteBackupStorage(request, bsName)
})

response = await request.get(`/v1/kubernetes/${kubernetesId}/database-clusters/cluster2/backups`)
result = await response.json()
test('dbcluster not found', async ({request, page}) => {
const bsName = th.suffixedName("storage")
await th.createBackupStorage(request, bsName)

const backupName = th.suffixedName("backup")
const payload = {
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: backupName,
},
spec: {
dbClusterName: "not-existing-cluster",
backupStorageName: bsName,
},
}

let response = await request.post(`/v1/kubernetes/${kubernetesId}/database-cluster-backups`, {
data: payload,
})
expect(response.status()).toBe(400);
expect(await response.text()).toContain(`{"message":"DatabaseCluster 'not-existing-cluster' is not found"}`);

expect(result.items).toHaveLength(2)
await th.deleteBackupStorage(request, bsName)
})

for (const payload of payloads) {
await request.delete(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/${payload.metadata.name}`)
response = await request.get(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/${payload.metadata.name}`)
expect(response.status()).toBe(404)
}

test('list backups', async ({request, page}) => {
const bsName = th.suffixedName("storage")
const clusterName1 = th.suffixedName("cluster1")
const clusterName2 = th.suffixedName("cluster2")

await th.createBackupStorage(request, bsName)
await th.createDBCluster(request, kubernetesId, clusterName1)
await th.createDBCluster(request, kubernetesId, clusterName2)

const backupName1 = th.suffixedName("backup1")
const backupName2 = th.suffixedName("backup2")
const backupName3 = th.suffixedName("backup3")
const backupName4 = th.suffixedName("backup4")

const payloads = [
{
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: backupName1,
},
spec: {
dbClusterName: clusterName1,
backupStorageName: bsName,
},
},
{
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: backupName2,
},
spec: {
dbClusterName: clusterName1,
backupStorageName: bsName,
},
},
{
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: backupName3,
},
spec: {
dbClusterName: clusterName2,
backupStorageName: bsName,
},
},
{
apiVersion: 'everest.percona.com/v1alpha1',
kind: 'DatabaseClusterBackup',
metadata: {
name: backupName4,
},
spec: {
dbClusterName: clusterName2,
backupStorageName: bsName,
},
},
]

for (const payload of payloads) {
const response = await request.post(`/v1/kubernetes/${kubernetesId}/database-cluster-backups`, {
data: payload,
})
expect(response.ok()).toBeTruthy()
}

await page.waitForTimeout(1000)
let response = await request.get(`/v1/kubernetes/${kubernetesId}/database-clusters/${clusterName1}/backups`)
let result = await response.json()

expect(result.items).toHaveLength(2)

response = await request.get(`/v1/kubernetes/${kubernetesId}/database-clusters/${clusterName2}/backups`)
result = await response.json()

expect(result.items).toHaveLength(2)

for (const payload of payloads) {
await request.delete(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/${payload.metadata.name}`)
response = await request.get(`/v1/kubernetes/${kubernetesId}/database-cluster-backups/${payload.metadata.name}`)
expect(response.status()).toBe(404)
}

await th.deleteDBCluster(request, kubernetesId, clusterName1)
await th.deleteDBCluster(request, kubernetesId, clusterName2)
await th.deleteBackupStorage(request, bsName)
})

Loading

0 comments on commit 193ec3b

Please sign in to comment.