blob: 16c43f4c7522743281eccacdef94de2e7560b0d5 [file] [log] [blame]
Joe Topjianaa8aff12016-07-25 19:43:52 +00001// +build acceptance compute defsecrules
2
3package v2
4
5import (
6 "testing"
7
Joe Topjian1c15e3f2016-08-08 10:48:38 -06008 "github.com/gophercloud/gophercloud/acceptance/clients"
Joe Topjian66a046c2017-01-19 22:07:26 -07009 "github.com/gophercloud/gophercloud/acceptance/tools"
Joe Topjianaa8aff12016-07-25 19:43:52 +000010 dsr "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/defsecrules"
11)
12
13func TestDefSecRulesList(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060014 client, err := clients.NewComputeV2Client()
Joe Topjianaa8aff12016-07-25 19:43:52 +000015 if err != nil {
16 t.Fatalf("Unable to create a compute client: %v", err)
17 }
18
19 allPages, err := dsr.List(client).AllPages()
20 if err != nil {
21 t.Fatalf("Unable to list default rules: %v", err)
22 }
23
24 allDefaultRules, err := dsr.ExtractDefaultRules(allPages)
25 if err != nil {
26 t.Fatalf("Unable to extract default rules: %v", err)
27 }
28
29 for _, defaultRule := range allDefaultRules {
Joe Topjian66a046c2017-01-19 22:07:26 -070030 tools.PrintResource(t, defaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000031 }
32}
33
34func TestDefSecRulesCreate(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060035 client, err := clients.NewComputeV2Client()
Joe Topjianaa8aff12016-07-25 19:43:52 +000036 if err != nil {
37 t.Fatalf("Unable to create a compute client: %v", err)
38 }
39
Joe Topjian1c15e3f2016-08-08 10:48:38 -060040 defaultRule, err := CreateDefaultRule(t, client)
Joe Topjianaa8aff12016-07-25 19:43:52 +000041 if err != nil {
42 t.Fatalf("Unable to create default rule: %v", err)
43 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060044 defer DeleteDefaultRule(t, client, defaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000045
Joe Topjian66a046c2017-01-19 22:07:26 -070046 tools.PrintResource(t, defaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000047}
48
49func TestDefSecRulesGet(t *testing.T) {
Joe Topjian1c15e3f2016-08-08 10:48:38 -060050 client, err := clients.NewComputeV2Client()
Joe Topjianaa8aff12016-07-25 19:43:52 +000051 if err != nil {
52 t.Fatalf("Unable to create a compute client: %v", err)
53 }
54
Joe Topjian1c15e3f2016-08-08 10:48:38 -060055 defaultRule, err := CreateDefaultRule(t, client)
Joe Topjianaa8aff12016-07-25 19:43:52 +000056 if err != nil {
57 t.Fatalf("Unable to create default rule: %v", err)
58 }
Joe Topjian1c15e3f2016-08-08 10:48:38 -060059 defer DeleteDefaultRule(t, client, defaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000060
61 newDefaultRule, err := dsr.Get(client, defaultRule.ID).Extract()
62 if err != nil {
63 t.Fatalf("Unable to get default rule %s: %v", defaultRule.ID, err)
64 }
65
Joe Topjian66a046c2017-01-19 22:07:26 -070066 tools.PrintResource(t, newDefaultRule)
Joe Topjianaa8aff12016-07-25 19:43:52 +000067}