Skip to content

Commit f646332

Browse files
committed
baremetal: add WaitForProvisionState and expand tests
1 parent 583d117 commit f646332

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

internal/acceptance/openstack/baremetal/v1/nodes_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func TestNodesCreateDestroy(t *testing.T) {
2121
th.AssertNoErr(t, err)
2222
client.Microversion = "1.38"
2323

24-
node, err := CreateNode(t, client)
24+
node, err := CreateFakeNode(t, client)
2525
th.AssertNoErr(t, err)
2626
defer DeleteNode(t, client, node)
2727

@@ -42,8 +42,17 @@ func TestNodesCreateDestroy(t *testing.T) {
4242
return false, nil
4343
})
4444
th.AssertNoErr(t, err)
45-
4645
th.AssertEquals(t, found, true)
46+
47+
th.AssertEquals(t, node.ProvisionState, string(nodes.Enroll))
48+
49+
err = nodes.ChangeProvisionState(context.TODO(), client, node.UUID, nodes.ProvisionStateOpts{
50+
Target: nodes.TargetManage,
51+
}).ExtractErr()
52+
th.AssertNoErr(t, err)
53+
54+
err = nodes.WaitForProvisionState(context.TODO(), client, node.UUID, nodes.Manageable, 5)
55+
th.AssertNoErr(t, err)
4756
}
4857

4958
func TestNodesFields(t *testing.T) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package nodes
2+
3+
import (
4+
"context"
5+
6+
"github.com/gophercloud/gophercloud/v2"
7+
)
8+
9+
// WaitForProvisionState will continually poll a node until it successfully
10+
// transitions to a specified state. It will do this for at most the number
11+
// of seconds specified.
12+
func WaitForProvisionState(ctx context.Context, c *gophercloud.ServiceClient, id string, state ProvisionState, secs int) error {
13+
return gophercloud.WaitFor(secs, func() (bool, error) {
14+
current, err := Get(ctx, c, id).Extract()
15+
if err != nil {
16+
return false, err
17+
}
18+
19+
if current.ProvisionState == string(state) {
20+
return true, nil
21+
}
22+
23+
return false, nil
24+
})
25+
}

0 commit comments

Comments
 (0)