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 ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame^] | 6 | "github.com/gophercloud/gophercloud/acceptance/tools" |
| 7 | os "github.com/gophercloud/gophercloud/openstack/db/v1/configurations" |
| 8 | "github.com/gophercloud/gophercloud/pagination" |
| 9 | config "github.com/gophercloud/gophercloud/rackspace/db/v1/configurations" |
| 10 | "github.com/gophercloud/gophercloud/rackspace/db/v1/instances" |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 11 | ) |
| 12 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 13 | func (c *context) createConfigGrp() { |
Jamie Hannaford | d2b755f | 2015-10-07 14:01:57 +0200 | [diff] [blame] | 14 | opts := os.CreateOpts{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 15 | Name: tools.RandomString("config_", 5), |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 16 | Values: map[string]interface{}{ |
| 17 | "connect_timeout": 300, |
| 18 | "join_buffer_size": 900000, |
| 19 | }, |
| 20 | } |
| 21 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 22 | cg, err := config.Create(c.client, opts).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 23 | |
| 24 | c.AssertNoErr(err) |
| 25 | c.Logf("Created config group %#v", cg) |
| 26 | |
| 27 | c.configGroupID = cg.ID |
| 28 | } |
| 29 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 30 | func (c *context) getConfigGrp() { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 31 | cg, err := config.Get(c.client, c.configGroupID).Extract() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 32 | c.Logf("Getting config group: %#v", cg) |
| 33 | c.AssertNoErr(err) |
| 34 | } |
| 35 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 36 | func (c *context) updateConfigGrp() { |
Jamie Hannaford | d2b755f | 2015-10-07 14:01:57 +0200 | [diff] [blame] | 37 | opts := os.UpdateOpts{ |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 38 | Name: tools.RandomString("new_name_", 5), |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 39 | Values: map[string]interface{}{ |
| 40 | "connect_timeout": 250, |
| 41 | }, |
| 42 | } |
| 43 | err := config.Update(c.client, c.configGroupID, opts).ExtractErr() |
| 44 | c.Logf("Updated config group %s", c.configGroupID) |
| 45 | c.AssertNoErr(err) |
| 46 | } |
| 47 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 48 | func (c *context) replaceConfigGrp() { |
Jamie Hannaford | d2b755f | 2015-10-07 14:01:57 +0200 | [diff] [blame] | 49 | opts := os.UpdateOpts{ |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 50 | Values: map[string]interface{}{ |
Jamie Hannaford | d2b755f | 2015-10-07 14:01:57 +0200 | [diff] [blame] | 51 | "big_tables": 1, |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 52 | }, |
| 53 | } |
| 54 | |
| 55 | err := config.Replace(c.client, c.configGroupID, opts).ExtractErr() |
| 56 | c.Logf("Replaced values for config group %s", c.configGroupID) |
| 57 | c.AssertNoErr(err) |
| 58 | } |
| 59 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 60 | func (c *context) associateInstanceWithConfigGrp() { |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 61 | err := instances.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr() |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 62 | c.Logf("Associated instance %s with config group %s", c.instanceID, c.configGroupID) |
| 63 | c.AssertNoErr(err) |
| 64 | } |
| 65 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 66 | func (c *context) listConfigGrpInstances() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 67 | c.Logf("Listing all instances associated with config group %s", c.configGroupID) |
| 68 | |
| 69 | err := config.ListInstances(c.client, c.configGroupID).EachPage(func(page pagination.Page) (bool, error) { |
| 70 | instanceList, err := instances.ExtractInstances(page) |
| 71 | c.AssertNoErr(err) |
| 72 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 73 | for _, instance := range instanceList { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 74 | c.Logf("Instance: %#v", instance) |
| 75 | } |
| 76 | |
| 77 | return true, nil |
| 78 | }) |
| 79 | |
Jamie Hannaford | 1110840 | 2015-02-23 10:31:41 +0100 | [diff] [blame] | 80 | c.AssertNoErr(err) |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 83 | func (c *context) deleteConfigGrp() { |
Jamie Hannaford | 05d200d | 2015-02-20 14:49:05 +0100 | [diff] [blame] | 84 | err := config.Delete(c.client, c.configGroupID).ExtractErr() |
| 85 | c.Logf("Deleted config group %s", c.configGroupID) |
| 86 | c.AssertNoErr(err) |
| 87 | } |
Jamie Hannaford | 99eced5 | 2015-03-02 15:24:22 +0100 | [diff] [blame] | 88 | |
| 89 | func (c *context) detachInstanceFromGrp() { |
| 90 | err := instances.DetachFromConfigGroup(c.client, c.instanceID).ExtractErr() |
| 91 | c.Logf("Detached instance %s from config groups", c.instanceID) |
| 92 | c.AssertNoErr(err) |
| 93 | } |