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