github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/dws/v1/dws_test.go (about) 1 package v1 2 3 import ( 4 "os" 5 "testing" 6 "time" 7 8 golangsdk "github.com/opentelekomcloud/gophertelekomcloud" 9 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 10 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack" 11 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 12 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" 13 "github.com/opentelekomcloud/gophertelekomcloud/openstack/dws/v1/cluster" 14 "github.com/opentelekomcloud/gophertelekomcloud/openstack/dws/v1/snapshot" 15 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 16 ) 17 18 func TestDWS(t *testing.T) { 19 if os.Getenv("RUN_DWS_LIFECYCLE") == "" { 20 t.Skip("too slow to run in zuul") 21 } 22 23 client, err := clients.NewDWSV1Client() 24 th.AssertNoErr(t, err) 25 26 vpcID := clients.EnvOS.GetEnv("VPC_ID") 27 if vpcID == "" { 28 t.Skip("OS_VPC_ID is missing but DWS test requires using existing network") 29 } 30 31 subnetID := clients.EnvOS.GetEnv("NETWORK_ID") 32 if subnetID == "" { 33 t.Skip("OS_SUBNET_ID env var is missing but DWS test requires using existing network") 34 } 35 36 // clusterId := "57e5b43d-d5a1-47e7-aef1-1f46a9abb3ab" 37 38 t.Log("Creating cluster") 39 name := tools.RandomString("dws-test-", 3) 40 clusterId, err := cluster.CreateCluster(client, cluster.CreateClusterOpts{ 41 NodeType: "dws.m3.xlarge", 42 NumberOfNode: 3, 43 SubnetId: subnetID, 44 SecurityGroupId: openstack.DefaultSecurityGroup(t), 45 VpcId: vpcID, 46 Name: name, 47 UserName: "dbadmin", 48 UserPwd: "#dbadmin123", 49 }) 50 th.AssertNoErr(t, err) 51 t.Cleanup(func() { 52 err = golangsdk.WaitFor(1000, func() (bool, error) { 53 err = cluster.DeleteCluster(client, cluster.DeleteClusterOpts{ 54 ClusterId: clusterId, 55 KeepLastManualSnapshot: pointerto.Int(0), 56 }) 57 if err != nil { 58 t.Error(err) 59 return false, nil 60 } 61 return true, nil 62 }) 63 th.AssertNoErr(t, err) 64 }) 65 66 err = cluster.WaitForCreate(client, clusterId, 1000) 67 th.AssertNoErr(t, err) 68 69 t.Log("ResetPassword") 70 err = cluster.ResetPassword(client, cluster.ResetPasswordOpts{ 71 ClusterId: clusterId, 72 NewPassword: "#SomePassword123", 73 }) 74 th.AssertNoErr(t, err) 75 76 err = cluster.WaitForRestart(client, clusterId, 1000) 77 th.AssertNoErr(t, err) 78 79 t.Log("ResizeCluster") 80 err = cluster.ResizeCluster(client, cluster.ResizeClusterOpts{ 81 ClusterId: clusterId, 82 Count: 1, 83 }) 84 85 err = cluster.WaitForResize(client, clusterId, 1000) 86 th.AssertNoErr(t, err) 87 88 t.Log("RestartCluster") 89 err = cluster.RestartCluster(client, cluster.RestartClusterOpts{ 90 ClusterId: clusterId, 91 Restart: struct{}{}, 92 }) 93 th.AssertNoErr(t, err) 94 95 err = cluster.WaitForRestart(client, clusterId, 1000) 96 th.AssertNoErr(t, err) 97 98 list, err := cluster.ListClusters(client) 99 th.AssertNoErr(t, err) 100 tools.PrintResource(t, list) 101 102 t.Log("CreateSnapshot") 103 snapId, err := snapshot.CreateSnapshot(client, snapshot.Snapshot{ 104 Name: name, 105 ClusterId: clusterId, 106 }) 107 th.AssertNoErr(t, err) 108 t.Cleanup(func() { 109 err = snapshot.DeleteSnapshot(client, snapId) 110 th.AssertNoErr(t, err) 111 }) 112 113 err = snapshot.WaitForSnapshot(client, clusterId, snapId, 1000) 114 th.AssertNoErr(t, err) 115 116 t.Log("RestoreCluster") 117 newName := tools.RandomString("dws-test-", 3) 118 resCId, err := snapshot.RestoreCluster(client, snapshot.RestoreClusterOpts{ 119 SnapshotId: snapId, 120 Name: newName, 121 }) 122 t.Cleanup(func() { 123 err = golangsdk.WaitFor(5000, func() (bool, error) { 124 err = cluster.DeleteCluster(client, cluster.DeleteClusterOpts{ 125 ClusterId: resCId, 126 KeepLastManualSnapshot: pointerto.Int(0), 127 }) 128 if err != nil { 129 t.Error(err) 130 time.Sleep(10 * time.Second) 131 return false, nil 132 } 133 return true, nil 134 }) 135 th.AssertNoErr(t, err) 136 }) 137 138 err = snapshot.WaitForRestore(client, resCId, 2000) 139 th.AssertNoErr(t, err) 140 141 snaps, err := snapshot.ListSnapshot(client) 142 th.AssertNoErr(t, err) 143 tools.PrintResource(t, snaps) 144 }