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 | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 6 | "os" |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 7 | "testing" |
| 8 | |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 9 | "github.com/rackspace/gophercloud/acceptance/tools" |
| 10 | "github.com/rackspace/gophercloud/openstack/db/v1/instances" |
| 11 | "github.com/rackspace/gophercloud/pagination" |
| 12 | th "github.com/rackspace/gophercloud/testhelper" |
| 13 | ) |
| 14 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 15 | const envDSType = "DATASTORE_TYPE_ID" |
| 16 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 17 | func TestRunner(t *testing.T) { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 18 | c := newContext(t) |
| 19 | |
| 20 | // FLAVOR tests |
| 21 | c.listFlavors() |
| 22 | c.getFlavor() |
| 23 | |
| 24 | // INSTANCE tests |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 25 | //c.createInstance() |
| 26 | c.instanceID = "dbf901f4-fe23-48b7-8c1d-ee60ec85a660" |
| 27 | |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 28 | c.listInstances() |
| 29 | c.getInstance() |
| 30 | c.isRootEnabled() |
| 31 | c.enableRootUser() |
| 32 | c.isRootEnabled() |
| 33 | c.restartInstance() |
| 34 | c.resizeInstance() |
| 35 | c.resizeVol() |
| 36 | |
| 37 | // DATABASE tests |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 38 | c.createDBs() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 39 | c.listDBs() |
| 40 | |
| 41 | // USER tests |
| 42 | c.createUsers() |
| 43 | c.listUsers() |
| 44 | |
| 45 | // TEARDOWN |
| 46 | c.deleteUsers() |
| 47 | c.deleteDBs() |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 48 | c.deleteInstance() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | func (c context) createInstance() { |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 52 | if os.Getenv(envDSType) == "" { |
| 53 | c.test.Fatalf("%s must be set as an environment var", envDSType) |
| 54 | } |
| 55 | |
| 56 | opts := instances.CreateOpts{ |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 57 | FlavorRef: "1", |
| 58 | Size: 1, |
| 59 | Name: tools.RandomString("gopher_db", 5), |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 60 | Datastore: &instances.DatastoreOpts{Type: os.Getenv(envDSType)}, |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | instance, err := instances.Create(c.client, opts).Extract() |
| 64 | th.AssertNoErr(c.test, err) |
| 65 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 66 | c.Logf("Restarting %s. Waiting...", instance.ID) |
| 67 | c.WaitUntilActive(instance.ID) |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 68 | c.Logf("Created Instance %s", instance.ID) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 69 | |
| 70 | c.instanceID = instance.ID |
| 71 | } |
| 72 | |
| 73 | func (c context) listInstances() { |
| 74 | c.Logf("Listing instances") |
| 75 | |
| 76 | err := instances.List(c.client).EachPage(func(page pagination.Page) (bool, error) { |
| 77 | instanceList, err := instances.ExtractInstances(page) |
| 78 | c.AssertNoErr(err) |
| 79 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 80 | for _, i := range instanceList { |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 81 | c.Logf("Instance: ID [%s] Name [%s] Status [%s] VolSize [%d] Datastore Type [%s]", |
| 82 | i.ID, i.Name, i.Status, i.Volume.Size, i.Datastore.Type) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | return true, nil |
| 86 | }) |
| 87 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 88 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | func (c context) getInstance() { |
| 92 | instance, err := instances.Get(c.client, c.instanceID).Extract() |
| 93 | c.AssertNoErr(err) |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 94 | c.Logf("Getting instance: %s", instance.ID) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | func (c context) deleteInstance() { |
| 98 | err := instances.Delete(c.client, c.instanceID).ExtractErr() |
| 99 | c.AssertNoErr(err) |
| 100 | c.Logf("Deleted instance %s", c.instanceID) |
| 101 | } |
| 102 | |
| 103 | func (c context) enableRootUser() { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 104 | _, err := instances.EnableRootUser(c.client, c.instanceID).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 105 | c.AssertNoErr(err) |
| 106 | c.Logf("Enabled root user on %s", c.instanceID) |
| 107 | } |
| 108 | |
| 109 | func (c context) isRootEnabled() { |
| 110 | enabled, err := instances.IsRootEnabled(c.client, c.instanceID) |
| 111 | c.AssertNoErr(err) |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 112 | c.Logf("Is root enabled? %d", enabled) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | func (c context) restartInstance() { |
| 116 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 117 | err := instances.RestartService(c.client, id).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 118 | c.AssertNoErr(err) |
| 119 | c.Logf("Restarting %s. Waiting...", id) |
| 120 | c.WaitUntilActive(id) |
| 121 | c.Logf("Restarted %s", id) |
| 122 | } |
| 123 | |
| 124 | func (c context) resizeInstance() { |
| 125 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 126 | err := instances.ResizeInstance(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 %s. Waiting...", id) |
| 129 | c.WaitUntilActive(id) |
| 130 | c.Logf("Resized %s with flavorRef %s", id, "2") |
| 131 | } |
| 132 | |
| 133 | func (c context) resizeVol() { |
| 134 | id := c.instanceID |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 135 | err := instances.ResizeVolume(c.client, id, 2).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 136 | c.AssertNoErr(err) |
| 137 | c.Logf("Resizing volume of %s. Waiting...", id) |
| 138 | c.WaitUntilActive(id) |
| 139 | c.Logf("Resized the volume of %s to %d GB", id, 2) |
| 140 | } |