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