blob: f1688527dfe0d37bcfede058be714ad6db785e80 [file] [log] [blame]
Jamie Hannaford05d200d2015-02-20 14:49:05 +01001// +build acceptance db
2
3package v1
4
5import (
6 "os"
7 "testing"
8
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02009 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Krzysztof Szukiełojć24a29ce2017-05-07 14:24:02 +020010 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack"
11 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/db/v1/instances"
12 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
Jamie Hannaford05d200d2015-02-20 14:49:05 +010013)
14
15func newClient(t *testing.T) *gophercloud.ServiceClient {
16 ao, err := openstack.AuthOptionsFromEnv()
17 th.AssertNoErr(t, err)
18
19 client, err := openstack.AuthenticatedClient(ao)
20 th.AssertNoErr(t, err)
21
22 c, err := openstack.NewDBV1(client, gophercloud.EndpointOpts{
23 Region: os.Getenv("OS_REGION_NAME"),
24 })
25 th.AssertNoErr(t, err)
26
27 return c
28}
29
30type context struct {
31 test *testing.T
32 client *gophercloud.ServiceClient
33 instanceID string
34 DBIDs []string
Jamie Hannaford11108402015-02-23 10:31:41 +010035 users []string
Jamie Hannaford05d200d2015-02-20 14:49:05 +010036}
37
38func newContext(t *testing.T) context {
39 return context{
40 test: t,
41 client: newClient(t),
42 }
43}
44
45func (c context) Logf(msg string, args ...interface{}) {
Jamie Hannaford99eced52015-03-02 15:24:22 +010046 if len(args) > 0 {
47 c.test.Logf(msg, args...)
48 } else {
49 c.test.Log(msg)
50 }
Jamie Hannaford05d200d2015-02-20 14:49:05 +010051}
52
53func (c context) AssertNoErr(err error) {
54 th.AssertNoErr(c.test, err)
55}
56
57func (c context) WaitUntilActive(id string) {
58 err := gophercloud.WaitFor(60, func() (bool, error) {
59 inst, err := instances.Get(c.client, id).Extract()
60 if err != nil {
61 return false, err
62 }
63 if inst.Status == "ACTIVE" {
64 return true, nil
65 }
66 return false, nil
67 })
Jamie Hannaford11108402015-02-23 10:31:41 +010068
69 c.AssertNoErr(err)
Jamie Hannaford05d200d2015-02-20 14:49:05 +010070}