github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/gaussdb/v3/db_test.go (about) 1 package v3 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" 8 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack" 9 "github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools" 10 "github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto" 11 v3 "github.com/opentelekomcloud/gophertelekomcloud/openstack/gaussdb/v3" 12 "github.com/opentelekomcloud/gophertelekomcloud/openstack/gaussdb/v3/backup" 13 "github.com/opentelekomcloud/gophertelekomcloud/openstack/gaussdb/v3/instance" 14 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 15 ) 16 17 func TestGaussDBLifecycle(t *testing.T) { 18 if os.Getenv("RUN_GAUSS") == "" { 19 t.Skip("long test") 20 } 21 client, err := clients.NewGaussDBClient() 22 th.AssertNoErr(t, err) 23 createOpts := openstack.GetCloudServerCreateOpts(t) 24 25 // API is not registered in the backend 26 // flavors, err := v3.ShowGaussMySqlFlavors(client, v3.ShowGaussMySqlFlavorsOpts{}) 27 // th.AssertNoErr(t, err) 28 // flav := flavors[0] 29 30 name := tools.RandomString("gaussdb-test-", 5) 31 32 ins, err := instance.CreateInstance(client, instance.CreateInstanceOpts{ 33 Region: "eu-de", 34 Name: name, 35 AvailabilityZoneMode: "multi", 36 MasterAvailabilityZone: "eu-de-01", 37 Datastore: instance.Datastore{ 38 Type: "gaussdb-mysql", 39 Version: "8.0", 40 }, 41 Mode: "Cluster", 42 FlavorRef: "gaussdb.mysql.xlarge.x86.8", 43 VpcId: createOpts.VpcId, 44 SubnetId: createOpts.Nics[0].SubnetId, 45 Password: "gaussdb1!-test", 46 SlaveCount: pointerto.Int(1), 47 SecurityGroupId: openstack.DefaultSecurityGroup(t), 48 }) 49 id := ins.Instance.Id 50 51 t.Cleanup(func() { 52 _, err = instance.DeleteInstance(client, ins.Instance.Id) 53 th.AssertNoErr(t, err) 54 }) 55 th.AssertNoErr(t, err) 56 _, err = v3.WaitForGaussJob(client, ins.JobId, 600) 57 th.AssertNoErr(t, err) 58 59 getInstance, err := instance.GetInstance(client, ins.Instance.Id) 60 th.AssertNoErr(t, err) 61 th.AssertEquals(t, getInstance.Name, name) 62 63 list, err := instance.ListInstances(client, instance.ListInstancesOpts{ 64 Id: ins.Instance.Id, 65 }) 66 th.AssertNoErr(t, err) 67 th.AssertEquals(t, list.Instances[0].Id, ins.Instance.Id) 68 tools.PrintResource(t, list) 69 70 nameOpts := instance.UpdateNameOpts{ 71 InstanceId: id, 72 Name: name + "_updated", 73 } 74 75 jobId, err := instance.UpdateName(client, nameOpts) 76 th.AssertNoErr(t, err) 77 78 _, err = v3.WaitForGaussJob(client, *jobId, 600) 79 th.AssertNoErr(t, err) 80 81 passwdOpts := instance.ResetPwdOpts{ 82 InstanceId: id, 83 Password: "gaussdb1!-test-2", 84 } 85 err = instance.ResetPassword(client, passwdOpts) 86 87 updateOpts := instance.UpdateSpecOpts{ 88 InstanceId: id, 89 ResizeFlavor: instance.ResizeFlavor{ 90 SpecCode: "gaussdb.mysql.2xlarge.x86.8", 91 }, 92 } 93 94 updateResp, err := instance.UpdateInstance(client, updateOpts) 95 th.AssertNoErr(t, err) 96 tools.PrintResource(t, updateResp) 97 98 _, err = v3.WaitForGaussJob(client, updateResp.JobId, 1200) 99 th.AssertNoErr(t, err) 100 101 getInstance, err = instance.GetInstance(client, ins.Instance.Id) 102 th.AssertNoErr(t, err) 103 th.AssertEquals(t, getInstance.Name, name) 104 105 } 106 107 func TestGaussDBReplicationLifecycle(t *testing.T) { 108 if os.Getenv("RUN_GAUSS") == "" { 109 t.Skip("long test") 110 } 111 client, err := clients.NewGaussDBClient() 112 th.AssertNoErr(t, err) 113 createOpts := openstack.GetCloudServerCreateOpts(t) 114 115 name := tools.RandomString("gaussdb-test-", 5) 116 117 ins, err := instance.CreateInstance(client, instance.CreateInstanceOpts{ 118 Region: "eu-de", 119 Name: name, 120 AvailabilityZoneMode: "multi", 121 MasterAvailabilityZone: "eu-de-01", 122 Datastore: instance.Datastore{ 123 Type: "gaussdb-mysql", 124 Version: "8.0", 125 }, 126 Mode: "Cluster", 127 FlavorRef: "gaussdb.mysql.xlarge.x86.8", 128 VpcId: createOpts.VpcId, 129 SubnetId: createOpts.Nics[0].SubnetId, 130 Password: "gaussdb1!-test", 131 SlaveCount: pointerto.Int(1), 132 SecurityGroupId: openstack.DefaultSecurityGroup(t), 133 }) 134 id := ins.Instance.Id 135 136 t.Cleanup(func() { 137 _, err = instance.DeleteInstance(client, ins.Instance.Id) 138 th.AssertNoErr(t, err) 139 }) 140 th.AssertNoErr(t, err) 141 _, err = v3.WaitForGaussJob(client, ins.JobId, 600) 142 th.AssertNoErr(t, err) 143 144 replicaOpts := instance.CreateNodeOpts{ 145 InstanceId: id, 146 Priorities: []int{1}, 147 } 148 node, err := instance.CreateReplica(client, replicaOpts) 149 th.AssertNoErr(t, err) 150 151 _, err = v3.WaitForGaussJob(client, node.JobId, 600) 152 th.AssertNoErr(t, err) 153 154 getInstance, err := instance.GetInstance(client, ins.Instance.Id) 155 th.AssertNoErr(t, err) 156 th.AssertEquals(t, getInstance.Name, name) 157 158 nodeElem := *getInstance.Nodes 159 160 job, err := instance.DeleteReplica(client, id, nodeElem[0].Id) 161 th.AssertNoErr(t, err) 162 163 _, err = v3.WaitForGaussJob(client, *job, 600) 164 th.AssertNoErr(t, err) 165 } 166 167 func TestGaussDBBackupLifecycle(t *testing.T) { 168 if os.Getenv("RUN_GAUSS") == "" { 169 t.Skip("long test") 170 } 171 client, err := clients.NewGaussDBClient() 172 th.AssertNoErr(t, err) 173 createOpts := openstack.GetCloudServerCreateOpts(t) 174 175 ins, err := instance.CreateInstance(client, instance.CreateInstanceOpts{ 176 Region: "eu-de", 177 Name: "gaussdb-test", 178 AvailabilityZoneMode: "multi", 179 MasterAvailabilityZone: "eu-de-01", 180 Datastore: instance.Datastore{ 181 Type: "gaussdb-mysql", 182 Version: "8.0", 183 }, 184 Mode: "Cluster", 185 FlavorRef: "gaussdb.mysql.xlarge.x86.8", 186 VpcId: createOpts.VpcId, 187 SubnetId: createOpts.Nics[0].SubnetId, 188 Password: "gaussdb1!-test", 189 SlaveCount: pointerto.Int(1), 190 SecurityGroupId: openstack.DefaultSecurityGroup(t), 191 }) 192 t.Cleanup(func() { 193 jobId, err := instance.DeleteInstance(client, ins.Instance.Id) 194 th.AssertNoErr(t, err) 195 _, err = v3.WaitForGaussJob(client, *jobId, 600) 196 th.AssertNoErr(t, err) 197 }) 198 th.AssertNoErr(t, err) 199 _, err = v3.WaitForGaussJob(client, ins.JobId, 600) 200 th.AssertNoErr(t, err) 201 202 dbBackup, err := backup.CreateBackup(client, backup.CreateBackupOpts{ 203 InstanceId: ins.Instance.Id, 204 Name: "gaussdb-test-backup", 205 }) 206 th.AssertNoErr(t, err) 207 _, err = v3.WaitForGaussJob(client, dbBackup.JobId, 600) 208 th.AssertNoErr(t, err) 209 210 backupList, err := backup.ListBackups(client, backup.BackupListOpts{ 211 InstanceId: ins.Instance.Id, 212 }) 213 th.AssertNoErr(t, err) 214 th.AssertEquals(t, backupList.Backups[0].Id, dbBackup.Backup.Id) 215 }