github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/dcs/v1/backup_test.go (about) 1 package v1 2 3 import ( 4 "testing" 5 6 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 7 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 8 "github.com/opentelekomcloud/gophertelekomcloud/openstack/dcs/v1/backups" 9 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 10 ) 11 12 func TestDcsBackupLifeCycle(t *testing.T) { 13 client, err := clients.NewDcsV1Client() 14 th.AssertNoErr(t, err) 15 16 dcsInstance := createDCSInstance(t, client) 17 backupId, err := backups.BackupInstance(client, dcsInstance.InstanceID, backups.BackupInstanceOpts{Remark: "test"}) 18 t.Cleanup(func() { 19 err := backups.DeleteBackupFile(client, dcsInstance.InstanceID, backupId) 20 th.AssertNoErr(t, err) 21 }) 22 23 th.AssertNoErr(t, err) 24 t.Logf("Created DCSv1 backup: %s", backupId) 25 26 err = golangsdk.WaitFor(100, func() (bool, error) { 27 backupList, err := backups.ListBackupRecords(client, dcsInstance.InstanceID, backups.ListBackupOpts{}) 28 if err != nil { 29 return false, err 30 } 31 th.AssertEquals(t, backupList.TotalNum, 1) 32 33 if backupList.BackupRecordResponse[0].Status == "succeed" { 34 return true, nil 35 } 36 return false, nil 37 }) 38 th.AssertNoErr(t, err) 39 40 restoreId, err := backups.RestoreInstance(client, dcsInstance.InstanceID, backups.RestoreInstanceOpts{BackupId: backupId, Remark: "test"}) 41 th.AssertNoErr(t, err) 42 t.Logf("Restored DCSv1 backup: %s", restoreId) 43 44 restoreList, err := backups.ListRestoreRecords(client, dcsInstance.InstanceID, backups.ListBackupOpts{}) 45 th.AssertNoErr(t, err) 46 th.AssertEquals(t, restoreList.TotalNum, 1) 47 48 err = waitForInstanceAvailable(client, 100, dcsInstance.InstanceID) 49 th.AssertNoErr(t, err) 50 }