Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 1 | // +build acceptance db |
| 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/openstack/db/v1/instances" |
| 10 | "github.com/rackspace/gophercloud/pagination" |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 11 | rackspaceInst "github.com/rackspace/gophercloud/rackspace/db/v1/instances" |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 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 | |
| 33 | // DATABASE tests |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 34 | c.createDBs() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 35 | c.listDBs() |
| 36 | |
| 37 | // USER tests |
| 38 | c.createUsers() |
| 39 | c.listUsers() |
| 40 | |
| 41 | // TEARDOWN |
| 42 | c.deleteUsers() |
| 43 | c.deleteDBs() |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 44 | c.deleteInstance() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | func (c context) createInstance() { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 48 | opts := rackspaceInst.CreateOpts{ |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 49 | FlavorRef: "1", |
| 50 | Size: 1, |
| 51 | Name: tools.RandomString("gopher_db", 5), |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 52 | Datastore: &rackspaceInst.DatastoreOpts{Version: "5.6", Type: "MySQL"}, |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | instance, err := instances.Create(c.client, opts).Extract() |
| 56 | th.AssertNoErr(c.test, err) |
| 57 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 58 | c.Logf("Restarting %s. Waiting...", instance.ID) |
| 59 | c.WaitUntilActive(instance.ID) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 60 | c.Logf("Created DB %#v", instance) |
| 61 | |
| 62 | c.instanceID = instance.ID |
| 63 | } |
| 64 | |
| 65 | func (c context) listInstances() { |
| 66 | c.Logf("Listing instances") |
| 67 | |
| 68 | err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) { |
| 69 | instanceList, err := instances.ExtractInstances(page) |
| 70 | c.AssertNoErr(err) |
| 71 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 72 | for _, i := range instanceList { |
| 73 | c.Logf("Instance: %#v", i) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | return true, nil |
| 77 | }) |
| 78 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 79 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | func (c context) getInstance() { |
| 83 | instance, err := instances.Get(c.client, c.instanceID).Extract() |
| 84 | c.AssertNoErr(err) |
| 85 | c.Logf("Getting instance: %#v", instance) |
| 86 | } |
| 87 | |
| 88 | func (c context) deleteInstance() { |
| 89 | err := instances.Delete(c.client, c.instanceID).ExtractErr() |
| 90 | c.AssertNoErr(err) |
| 91 | c.Logf("Deleted instance %s", c.instanceID) |
| 92 | } |
| 93 | |
| 94 | func (c context) enableRootUser() { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 95 | _, err := instances.EnableRootUser(c.client, c.instanceID).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 96 | c.AssertNoErr(err) |
| 97 | c.Logf("Enabled root user on %s", c.instanceID) |
| 98 | } |
| 99 | |
| 100 | func (c context) isRootEnabled() { |
| 101 | enabled, err := instances.IsRootEnabled(c.client, c.instanceID) |
| 102 | c.AssertNoErr(err) |
| 103 | c.Logf("Is root enabled? %s", enabled) |
| 104 | } |
| 105 | |
| 106 | func (c context) restartInstance() { |
| 107 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 108 | err := instances.RestartService(c.client, id).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 109 | c.AssertNoErr(err) |
| 110 | c.Logf("Restarting %s. Waiting...", id) |
| 111 | c.WaitUntilActive(id) |
| 112 | c.Logf("Restarted %s", id) |
| 113 | } |
| 114 | |
| 115 | func (c context) resizeInstance() { |
| 116 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 117 | err := instances.ResizeInstance(c.client, id, "2").ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 118 | c.AssertNoErr(err) |
| 119 | c.Logf("Resizing %s. Waiting...", id) |
| 120 | c.WaitUntilActive(id) |
| 121 | c.Logf("Resized %s with flavorRef %s", id, "2") |
| 122 | } |
| 123 | |
| 124 | func (c context) resizeVol() { |
| 125 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame^] | 126 | err := instances.ResizeVolume(c.client, id, 2).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 127 | c.AssertNoErr(err) |
| 128 | c.Logf("Resizing volume of %s. Waiting...", id) |
| 129 | c.WaitUntilActive(id) |
| 130 | c.Logf("Resized the volume of %s to %d GB", id, 2) |
| 131 | } |