Skip to content

Commit

Permalink
fix(tests): Added Backup/Restore test for NFS. (#8551)
Browse files Browse the repository at this point in the history
Change: Added new automated tests for backup/restore (full as well as
incremental ) on NFS.
Test Scenarios covered:-
 - Full+Incremental backup on nfs mounted directory
 - Full+Incremental restore from nfs mounted directory.
  • Loading branch information
shivaji-dgraph authored Feb 1, 2023
1 parent c175edc commit 9739415
Show file tree
Hide file tree
Showing 17 changed files with 739 additions and 25 deletions.
2 changes: 1 addition & 1 deletion graphql/e2e/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ func TestDeleteSchemaAndExport(t *testing.T) {

require.Equal(t, "Success", testutil.JsonGet(data, "export", "response", "code").(string))
taskId := testutil.JsonGet(data, "export", "taskId").(string)
testutil.WaitForTask(t, taskId, false)
testutil.WaitForTask(t, taskId, false, testutil.SockAddrHttp)

// applying a new schema should still work
newSchemaResp := common.AssertUpdateGQLSchemaSuccess(t, groupOneHTTP, schema, nil)
Expand Down
2 changes: 1 addition & 1 deletion systest/acl/restore/acl_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestAclCacheRestore(t *testing.T) {
dg.Login(context.Background(), "groot", "password")

sendRestoreRequest(t, "/backups", "vibrant_euclid5", 1)
testutil.WaitForRestore(t, dg)
testutil.WaitForRestore(t, dg, testutil.SockAddrHttp)

token := testutil.Login(t,
&testutil.LoginParams{UserID: "alice1", Passwd: "password", Namespace: 0})
Expand Down
10 changes: 10 additions & 0 deletions systest/backup/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,13 @@ func CopyToLocalFs(t *testing.T) {
srcPath := testutil.DockerPrefix + "_alpha1_1:/data/backups"
require.NoError(t, testutil.DockerCp(srcPath, copyBackupDir))
}

// to copy files fron nfs server
func CopyToLocalFsFromNFS(t *testing.T, backupDst string, copyBackupDirectory string) {
// The original backup files are not accessible because docker creates all files in
// the shared volume as the root user. This restriction is circumvented by using
// "docker cp" to create a copy that is not owned by the root user.
require.NoError(t, os.RemoveAll(copyBackupDirectory))
srcPath := testutil.DockerPrefix + "_nfs_1:/data" + backupDst
require.NoError(t, testutil.DockerCp(srcPath, copyBackupDirectory))
}
2 changes: 1 addition & 1 deletion systest/backup/encryption/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles,
require.NoError(t, json.NewDecoder(resp.Body).Decode(&data))
require.Equal(t, "Success", testutil.JsonGet(data, "data", "backup", "response", "code").(string))
taskId := testutil.JsonGet(data, "data", "backup", "taskId").(string)
testutil.WaitForTask(t, taskId, true)
testutil.WaitForTask(t, taskId, true, testutil.SockAddrHttp)

// Verify that the right amount of files and directories were created.
copyToLocalFs(t)
Expand Down
8 changes: 4 additions & 4 deletions systest/backup/filesystem/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestBackupOfOldRestore(t *testing.T) {
_ = runBackup(t, 3, 1)

sendRestoreRequest(t, oldBackupDir1)
testutil.WaitForRestore(t, dg)
testutil.WaitForRestore(t, dg, testutil.SockAddrHttp)

resp, err := dg.NewTxn().Query(context.Background(), `{ authors(func: has(Author.name)) { count(uid) } }`)
require.NoError(t, err)
Expand All @@ -115,7 +115,7 @@ func TestBackupOfOldRestore(t *testing.T) {
testutil.DropAll(t, dg)
time.Sleep(2 * time.Second)
sendRestoreRequest(t, alphaBackupDir)
testutil.WaitForRestore(t, dg)
testutil.WaitForRestore(t, dg, testutil.SockAddrHttp)

resp, err = dg.NewTxn().Query(context.Background(), `{ authors(func: has(Author.name)) { count(uid) } }`)
require.NoError(t, err)
Expand All @@ -142,7 +142,7 @@ func TestRestoreOfOldBackup(t *testing.T) {
time.Sleep(2 * time.Second)

sendRestoreRequest(t, dir)
testutil.WaitForRestore(t, dg)
testutil.WaitForRestore(t, dg, testutil.SockAddrHttp)

queryAndCheck := func(pred string, cnt int) {
q := fmt.Sprintf(`{ me(func: has(%s)) { count(uid) } }`, pred)
Expand Down Expand Up @@ -434,7 +434,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles,
require.NoError(t, json.NewDecoder(resp.Body).Decode(&data))
require.Equal(t, "Success", testutil.JsonGet(data, "data", "backup", "response", "code").(string))
taskId := testutil.JsonGet(data, "data", "backup", "taskId").(string)
testutil.WaitForTask(t, taskId, true)
testutil.WaitForTask(t, taskId, true, testutil.SockAddrHttp)

// Verify that the right amount of files and directories were created.
common.CopyToLocalFs(t)
Expand Down
2 changes: 1 addition & 1 deletion systest/backup/minio-large/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func runBackup(t *testing.T) {
require.NoError(t, json.NewDecoder(resp.Body).Decode(&data))
require.Equal(t, "Success", testutil.JsonGet(data, "data", "backup", "response", "code").(string))
taskId := testutil.JsonGet(data, "data", "backup", "taskId").(string)
testutil.WaitForTask(t, taskId, true)
testutil.WaitForTask(t, taskId, true, testutil.SockAddrHttp)

// Verify that the right amount of files and directories were created.
copyToLocalFs(t)
Expand Down
2 changes: 1 addition & 1 deletion systest/backup/minio/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func runBackupInternal(t *testing.T, forceFull bool, numExpectedFiles,
require.NoError(t, json.NewDecoder(resp.Body).Decode(&data))
require.Equal(t, "Success", testutil.JsonGet(data, "data", "backup", "response", "code").(string))
taskId := testutil.JsonGet(data, "data", "backup", "taskId").(string)
testutil.WaitForTask(t, taskId, true)
testutil.WaitForTask(t, taskId, true, testutil.SockAddrHttp)

// Verify that the right amount of files and directories were created.
copyToLocalFs(t)
Expand Down
8 changes: 4 additions & 4 deletions systest/backup/multi-tenancy/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestBackupMultiTenancy(t *testing.T) {
_ = runBackup(t, galaxyToken, 3, 1)
testutil.DropAll(t, dg)
sendRestoreRequest(t, alphaBackupDir, galaxyToken.AccessJwt)
testutil.WaitForRestore(t, dg)
testutil.WaitForRestore(t, dg, testutil.SockAddrHttp)

query := `{ q(func: has(movie)) { count(uid) } }`
expectedResponse := `{ "q": [{ "count": 5 }]}`
Expand All @@ -125,7 +125,7 @@ func TestBackupMultiTenancy(t *testing.T) {
_ = runBackup(t, galaxyToken, 6, 2)
testutil.DropAll(t, dg)
sendRestoreRequest(t, alphaBackupDir, galaxyToken.AccessJwt)
testutil.WaitForRestore(t, dg)
testutil.WaitForRestore(t, dg, testutil.SockAddrHttp)
testutil.VerifyQueryResponse(t, dg, query, expectedResponse)
testutil.VerifyQueryResponse(t, dg1, query, expectedResponse)
testutil.VerifyQueryResponse(t, dg2, query, `{ "q": [{ "count": 0 }]}`)
Expand All @@ -136,7 +136,7 @@ func TestBackupMultiTenancy(t *testing.T) {
_ = runBackup(t, galaxyToken, 9, 3)
testutil.DropAll(t, dg)
sendRestoreRequest(t, alphaBackupDir, galaxyToken.AccessJwt)
testutil.WaitForRestore(t, dg)
testutil.WaitForRestore(t, dg, testutil.SockAddrHttp)
query = `{ q(func: has(movie)) { count(uid) } }`
expectedResponse = `{ "q": [{ "count": 5 }]}`
testutil.VerifyQueryResponse(t, dg, query, expectedResponse)
Expand Down Expand Up @@ -174,7 +174,7 @@ func runBackupInternal(t *testing.T, token *testutil.HttpToken, forceFull bool,
require.NoError(t, json.Unmarshal(resp.Data, &data))
require.Equal(t, "Success", testutil.JsonGet(data, "backup", "response", "code").(string))
taskId := testutil.JsonGet(data, "backup", "taskId").(string)
testutil.WaitForTask(t, taskId, false)
testutil.WaitForTask(t, taskId, false, testutil.SockAddrHttp)

// Verify that the right amount of files and directories were created.
common.CopyToLocalFs(t)
Expand Down
Loading

0 comments on commit 9739415

Please sign in to comment.