Jamie Hannaford | 80c7067 | 2015-10-06 16:09:33 +0200 | [diff] [blame^] | 1 | // +build acceptance db rackspace |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 2 | |
| 3 | package v1 |
| 4 | |
| 5 | import ( |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 6 | "testing" |
| 7 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 8 | "github.com/rackspace/gophercloud" |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/acceptance/tools" |
| 10 | "github.com/rackspace/gophercloud/pagination" |
| 11 | "github.com/rackspace/gophercloud/rackspace/db/v1/instances" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 15 | func TestRunner(t *testing.T) { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 16 | c := newContext(t) |
| 17 | |
| 18 | // FLAVOR tests |
| 19 | c.listFlavors() |
| 20 | c.getFlavor() |
| 21 | |
| 22 | // INSTANCE tests |
| 23 | c.createInstance() |
| 24 | c.listInstances() |
| 25 | c.getInstance() |
| 26 | c.isRootEnabled() |
| 27 | c.enableRootUser() |
| 28 | c.isRootEnabled() |
| 29 | c.restartInstance() |
| 30 | c.resizeInstance() |
| 31 | c.resizeVol() |
| 32 | c.getDefaultConfig() |
| 33 | |
| 34 | // REPLICA tests |
| 35 | c.createReplica() |
| 36 | c.detachReplica() |
| 37 | |
| 38 | // BACKUP tests |
| 39 | c.createBackup() |
| 40 | c.getBackup() |
| 41 | c.listAllBackups() |
| 42 | c.listInstanceBackups() |
| 43 | c.deleteBackup() |
| 44 | |
| 45 | // CONFIG GROUP tests |
| 46 | c.createConfigGrp() |
| 47 | c.getConfigGrp() |
| 48 | c.updateConfigGrp() |
| 49 | c.replaceConfigGrp() |
| 50 | c.associateInstanceWithConfigGrp() |
| 51 | c.listConfigGrpInstances() |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 52 | c.detachInstanceFromGrp() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 53 | c.deleteConfigGrp() |
| 54 | |
| 55 | // DATABASE tests |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 56 | c.createDBs() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 57 | c.listDBs() |
| 58 | |
| 59 | // USER tests |
| 60 | c.createUsers() |
| 61 | c.listUsers() |
| 62 | c.changeUserPwd() |
| 63 | c.getUser() |
| 64 | c.updateUser() |
| 65 | c.listUserAccess() |
| 66 | c.revokeUserAccess() |
| 67 | c.grantUserAccess() |
| 68 | |
| 69 | // TEARDOWN |
| 70 | c.deleteUsers() |
| 71 | c.deleteDBs() |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 72 | c.detachAndDeleteReplica() |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 73 | c.deleteInstance() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 76 | func (c *context) createInstance() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 77 | opts := instances.CreateOpts{ |
| 78 | FlavorRef: "1", |
| 79 | Size: 1, |
| 80 | Name: tools.RandomString("gopher_db", 5), |
| 81 | } |
| 82 | |
| 83 | instance, err := instances.Create(c.client, opts).Extract() |
| 84 | th.AssertNoErr(c.test, err) |
| 85 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 86 | c.Logf("Creating %s. Waiting...", instance.ID) |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 87 | c.WaitUntilActive(instance.ID) |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 88 | c.Logf("Created instance %s", instance.ID) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 89 | |
| 90 | c.instanceID = instance.ID |
| 91 | } |
| 92 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 93 | func (c *context) listInstances() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 94 | c.Logf("Listing instances") |
| 95 | |
| 96 | err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) { |
| 97 | instanceList, err := instances.ExtractInstances(page) |
| 98 | c.AssertNoErr(err) |
| 99 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 100 | for _, i := range instanceList { |
| 101 | c.Logf("Instance: ID [%s] Name [%s] Status [%s] VolSize [%d] Datastore Type [%s]", |
| 102 | i.ID, i.Name, i.Status, i.Volume.Size, i.Datastore.Type) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | return true, nil |
| 106 | }) |
| 107 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 108 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 111 | func (c *context) getInstance() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 112 | instance, err := instances.Get(c.client, c.instanceID).Extract() |
| 113 | c.AssertNoErr(err) |
| 114 | c.Logf("Getting instance: %#v", instance) |
| 115 | } |
| 116 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 117 | func (c *context) deleteInstance() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 118 | err := instances.Delete(c.client, c.instanceID).ExtractErr() |
| 119 | c.AssertNoErr(err) |
| 120 | c.Logf("Deleted instance %s", c.instanceID) |
| 121 | } |
| 122 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 123 | func (c *context) enableRootUser() { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 124 | _, err := instances.EnableRootUser(c.client, c.instanceID).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 125 | c.AssertNoErr(err) |
| 126 | c.Logf("Enabled root user on %s", c.instanceID) |
| 127 | } |
| 128 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 129 | func (c *context) isRootEnabled() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 130 | enabled, err := instances.IsRootEnabled(c.client, c.instanceID) |
| 131 | c.AssertNoErr(err) |
| 132 | c.Logf("Is root enabled? %s", enabled) |
| 133 | } |
| 134 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 135 | func (c *context) restartInstance() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 136 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 137 | err := instances.RestartService(c.client, id).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 138 | c.AssertNoErr(err) |
| 139 | c.Logf("Restarting %s. Waiting...", id) |
| 140 | c.WaitUntilActive(id) |
| 141 | c.Logf("Restarted %s", id) |
| 142 | } |
| 143 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 144 | func (c *context) resizeInstance() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 145 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 146 | err := instances.ResizeInstance(c.client, id, "2").ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 147 | c.AssertNoErr(err) |
| 148 | c.Logf("Resizing %s. Waiting...", id) |
| 149 | c.WaitUntilActive(id) |
| 150 | c.Logf("Resized %s with flavorRef %s", id, "2") |
| 151 | } |
| 152 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 153 | func (c *context) resizeVol() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 154 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 155 | err := instances.ResizeVolume(c.client, id, 2).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 156 | c.AssertNoErr(err) |
| 157 | c.Logf("Resizing volume of %s. Waiting...", id) |
| 158 | c.WaitUntilActive(id) |
| 159 | c.Logf("Resized the volume of %s to %d GB", id, 2) |
| 160 | } |
| 161 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 162 | func (c *context) getDefaultConfig() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 163 | config, err := instances.GetDefaultConfig(c.client, c.instanceID).Extract() |
| 164 | c.Logf("Default config group for instance %s: %#v", c.instanceID, config) |
| 165 | c.AssertNoErr(err) |
| 166 | } |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 167 | |
| 168 | func (c *context) detachAndDeleteReplica() { |
| 169 | err := instances.DetachReplica(c.client, c.replicaID).ExtractErr() |
| 170 | c.AssertNoErr(err) |
| 171 | c.Logf("Detached replica %s from instance %s", c.replicaID, c.instanceID) |
| 172 | |
| 173 | err = instances.Delete(c.client, c.replicaID).ExtractErr() |
| 174 | c.AssertNoErr(err) |
| 175 | c.Logf("Deleted replica %s", c.replicaID) |
| 176 | |
| 177 | // Check that it's deleted |
| 178 | err = gophercloud.WaitFor(60, func() (bool, error) { |
| 179 | _, err := instances.Get(c.client, c.replicaID).Extract() |
| 180 | if casted, ok := err.(*gophercloud.UnexpectedResponseCodeError); ok && casted.Actual == 404 { |
| 181 | return true, nil |
| 182 | } |
| 183 | if err != nil { |
| 184 | return false, err |
| 185 | } |
| 186 | return false, nil |
| 187 | }) |
| 188 | } |