blob: 81bd40abcf9f7ff5cd502be9fcaa5fc1a104aae9 [file] [log] [blame]
Jamie Hannaford80c70672015-10-06 16:09:33 +02001// +build acceptance db rackspace
Jamie Hannaford05d200d2015-02-20 14:49:05 +01002
3package v1
4
5import (
Jamie Hannaford11108402015-02-23 10:31:41 +01006 "github.com/rackspace/gophercloud/acceptance/tools"
Jamie Hannafordd2b755f2015-10-07 14:01:57 +02007 os "github.com/rackspace/gophercloud/openstack/db/v1/configurations"
Jamie Hannaford05d200d2015-02-20 14:49:05 +01008 "github.com/rackspace/gophercloud/pagination"
Jamie Hannaford11108402015-02-23 10:31:41 +01009 config "github.com/rackspace/gophercloud/rackspace/db/v1/configurations"
10 "github.com/rackspace/gophercloud/rackspace/db/v1/instances"
Jamie Hannaford05d200d2015-02-20 14:49:05 +010011)
12
Jamie Hannaford99eced52015-03-02 15:24:22 +010013func (c *context) createConfigGrp() {
Jamie Hannafordd2b755f2015-10-07 14:01:57 +020014 opts := os.CreateOpts{
Jamie Hannaford11108402015-02-23 10:31:41 +010015 Name: tools.RandomString("config_", 5),
Jamie Hannaford05d200d2015-02-20 14:49:05 +010016 Values: map[string]interface{}{
17 "connect_timeout": 300,
18 "join_buffer_size": 900000,
19 },
20 }
21
Jamie Hannaford11108402015-02-23 10:31:41 +010022 cg, err := config.Create(c.client, opts).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010023
24 c.AssertNoErr(err)
25 c.Logf("Created config group %#v", cg)
26
27 c.configGroupID = cg.ID
28}
29
Jamie Hannaford99eced52015-03-02 15:24:22 +010030func (c *context) getConfigGrp() {
Jamie Hannaford11108402015-02-23 10:31:41 +010031 cg, err := config.Get(c.client, c.configGroupID).Extract()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010032 c.Logf("Getting config group: %#v", cg)
33 c.AssertNoErr(err)
34}
35
Jamie Hannaford99eced52015-03-02 15:24:22 +010036func (c *context) updateConfigGrp() {
Jamie Hannafordd2b755f2015-10-07 14:01:57 +020037 opts := os.UpdateOpts{
Jamie Hannaford11108402015-02-23 10:31:41 +010038 Name: tools.RandomString("new_name_", 5),
Jamie Hannaford05d200d2015-02-20 14:49:05 +010039 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 Hannaford99eced52015-03-02 15:24:22 +010048func (c *context) replaceConfigGrp() {
Jamie Hannafordd2b755f2015-10-07 14:01:57 +020049 opts := os.UpdateOpts{
Jamie Hannaford05d200d2015-02-20 14:49:05 +010050 Values: map[string]interface{}{
Jamie Hannafordd2b755f2015-10-07 14:01:57 +020051 "big_tables": 1,
Jamie Hannaford05d200d2015-02-20 14:49:05 +010052 },
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 Hannaford99eced52015-03-02 15:24:22 +010060func (c *context) associateInstanceWithConfigGrp() {
Jamie Hannaford11108402015-02-23 10:31:41 +010061 err := instances.AssociateWithConfigGroup(c.client, c.instanceID, c.configGroupID).ExtractErr()
Jamie Hannaford05d200d2015-02-20 14:49:05 +010062 c.Logf("Associated instance %s with config group %s", c.instanceID, c.configGroupID)
63 c.AssertNoErr(err)
64}
65
Jamie Hannaford99eced52015-03-02 15:24:22 +010066func (c *context) listConfigGrpInstances() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010067 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 Hannaford11108402015-02-23 10:31:41 +010073 for _, instance := range instanceList {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010074 c.Logf("Instance: %#v", instance)
75 }
76
77 return true, nil
78 })
79
Jamie Hannaford11108402015-02-23 10:31:41 +010080 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010081}
82
Jamie Hannaford99eced52015-03-02 15:24:22 +010083func (c *context) deleteConfigGrp() {
Jamie Hannaford05d200d2015-02-20 14:49:05 +010084 err := config.Delete(c.client, c.configGroupID).ExtractErr()
85 c.Logf("Deleted config group %s", c.configGroupID)
86 c.AssertNoErr(err)
87}
Jamie Hannaford99eced52015-03-02 15:24:22 +010088
89func (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}