Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit defa84a

Browse files
author
Kirill Shirinkin
committed
Merge branch 'master' into add-router-type
2 parents 2e84b74 + f3d0534 commit defa84a

File tree

19 files changed

+364
-56
lines changed

19 files changed

+364
-56
lines changed

.travis.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
language: go
2+
sudo: false
23
install:
4+
- go get golang.org/x/crypto/ssh
35
- go get -v -tags 'fixtures acceptance' ./...
46
go:
5-
- 1.2
6-
- 1.3
77
- 1.4
88
- 1.5
9-
script: script/cibuild
10-
after_success:
11-
- go get golang.org/x/tools/cmd/cover
9+
- tip
10+
env:
11+
- COVERALLS_TOKEN=2k7PTU3xa474Hymwgdj6XjqenNfGTNkO8
12+
before_install:
1213
- go get github.com/axw/gocov/gocov
1314
- go get github.com/mattn/goveralls
14-
- export PATH=$PATH:$HOME/gopath/bin/
15-
- goveralls 2k7PTU3xa474Hymwgdj6XjqenNfGTNkO8
16-
sudo: false
15+
- go get github.com/pierrre/gotestcover
16+
- if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
17+
script:
18+
- $HOME/gopath/bin/gotestcover -v -tags=fixtures -coverprofile=cover.out ./...
19+
after_success:
20+
- $HOME/gopath/bin/goveralls -service=travis-ci -coverprofile=cover.out

CONTRIBUTING.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ As a contributor you will need to setup your workspace in a slightly different
1111
way than just downloading it. Here are the basic installation instructions:
1212

1313
1. Configure your `$GOPATH` and run `go get` as described in the main
14-
[README](/README.md#how-to-install).
14+
[README](/README.md#how-to-install) but add `-tags "fixtures acceptance"` to
15+
get dependencies for unit and acceptance tests.
1516

1617
2. Move into the directory that houses your local repository:
1718

@@ -158,25 +159,25 @@ deleted after the test suite finishes.
158159
To run all tests:
159160

160161
```bash
161-
go test ./...
162+
go test -tags fixtures ./...
162163
```
163164

164165
To run all tests with verbose output:
165166

166167
```bash
167-
go test -v ./...
168+
go test -v -tags fixtures ./...
168169
```
169170

170171
To run tests that match certain [build tags]():
171172

172173
```bash
173-
go test -tags "foo bar" ./...
174+
go test -tags "fixtures foo bar" ./...
174175
```
175176

176177
To run tests for a particular sub-package:
177178

178179
```bash
179-
cd ./path/to/package && go test .
180+
cd ./path/to/package && go test -tags fixtures .
180181
```
181182

182183
## Basic style guide

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Gophercloud: an OpenStack SDK for Go
2-
[![Build Status](https://travis-ci.org/rackspace/gophercloud.svg?branch=master)](https://travis-ci.org/rackspace/gophercloud)
2+
[![Build Status](https://travis-ci.org/rackspace/gophercloud.svg?branch=master)](https://travis-ci.org/rackspace/gophercloud) [![Coverage Status](https://coveralls.io/repos/rackspace/gophercloud/badge.png)](https://coveralls.io/r/rackspace/gophercloud)
33

44
Gophercloud is a flexible SDK that allows you to consume and work with OpenStack
55
clouds in a simple and idiomatic way using golang. Many services are supported,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// The v1 package contains acceptance tests for the Openstack Cinder V1 service.
2+
3+
package v1

acceptance/openstack/compute/v2/secgroup_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,24 @@ func addRemoveRules(t *testing.T, client *gophercloud.ServiceClient, id string)
107107
th.AssertNoErr(t, err)
108108

109109
t.Logf("Deleted rule %s from group %s", rule.ID, id)
110+
111+
icmpOpts := secgroups.CreateRuleOpts{
112+
ParentGroupID: id,
113+
FromPort: 0,
114+
ToPort: 0,
115+
IPProtocol: "ICMP",
116+
CIDR: "0.0.0.0/0",
117+
}
118+
119+
icmpRule, err := secgroups.CreateRule(client, icmpOpts).Extract()
120+
th.AssertNoErr(t, err)
121+
122+
t.Logf("Adding ICMP rule %s to group %s", icmpRule.ID, id)
123+
124+
err = secgroups.DeleteRule(client, icmpRule.ID).ExtractErr()
125+
th.AssertNoErr(t, err)
126+
127+
t.Logf("Deleted ICMP rule %s from group %s", icmpRule.ID, id)
110128
}
111129

112130
func findServer(t *testing.T, client *gophercloud.ServiceClient) (string, bool) {

acceptance/rackspace/identity/v2/tokens_test.go

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,10 @@ import (
66
"os"
77
"testing"
88

9-
"github.com/rackspace/gophercloud"
10-
"github.com/rackspace/gophercloud/acceptance/tools"
11-
"github.com/rackspace/gophercloud/rackspace"
129
"github.com/rackspace/gophercloud/rackspace/identity/v2/tokens"
1310
th "github.com/rackspace/gophercloud/testhelper"
1411
)
1512

16-
func rackspaceAuthOptions(t *testing.T) gophercloud.AuthOptions {
17-
// Obtain credentials from the environment.
18-
options, err := rackspace.AuthOptionsFromEnv()
19-
th.AssertNoErr(t, err)
20-
options = tools.OnlyRS(options)
21-
22-
if options.Username == "" {
23-
t.Fatal("Please provide a Rackspace username as RS_USERNAME.")
24-
}
25-
if options.APIKey == "" {
26-
t.Fatal("Please provide a Rackspace API key as RS_API_KEY.")
27-
}
28-
29-
return options
30-
}
31-
32-
func createClient(t *testing.T, auth bool) *gophercloud.ServiceClient {
33-
ao := rackspaceAuthOptions(t)
34-
35-
provider, err := rackspace.NewClient(ao.IdentityEndpoint)
36-
th.AssertNoErr(t, err)
37-
38-
if auth {
39-
err = rackspace.Authenticate(provider, ao)
40-
th.AssertNoErr(t, err)
41-
}
42-
43-
return rackspace.NewIdentityV2(provider)
44-
}
45-
4613
func TestTokenAuth(t *testing.T) {
4714
authedClient := createClient(t, true)
4815
token := authedClient.TokenID
@@ -54,7 +21,7 @@ func TestTokenAuth(t *testing.T) {
5421

5522
authOpts := tokens.AuthOptions{}
5623
authOpts.TenantID = tenantID
57-
authOpts.Token = token
24+
authOpts.TokenID = token
5825

5926
_, err := tokens.Create(authedClient, authOpts).ExtractToken()
6027
th.AssertNoErr(t, err)

openstack/compute/v2/extensions/defsecrules/fixtures.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,41 @@ func mockCreateRuleResponse(t *testing.T) {
7272
})
7373
}
7474

75+
func mockCreateRuleResponseICMPZero(t *testing.T) {
76+
th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) {
77+
th.TestMethod(t, r, "POST")
78+
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
79+
80+
th.TestJSONRequest(t, r, `
81+
{
82+
"security_group_default_rule": {
83+
"ip_protocol": "ICMP",
84+
"from_port": 0,
85+
"to_port": 0,
86+
"cidr": "10.10.12.0/24"
87+
}
88+
}
89+
`)
90+
91+
w.Header().Add("Content-Type", "application/json")
92+
w.WriteHeader(http.StatusOK)
93+
94+
fmt.Fprintf(w, `
95+
{
96+
"security_group_default_rule": {
97+
"from_port": 0,
98+
"id": "{ruleID}",
99+
"ip_protocol": "ICMP",
100+
"ip_range": {
101+
"cidr": "10.10.12.0/24"
102+
},
103+
"to_port": 0
104+
}
105+
}
106+
`)
107+
})
108+
}
109+
75110
func mockGetRuleResponse(t *testing.T, ruleID string) {
76111
url := rootPath + "/" + ruleID
77112
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {

openstack/compute/v2/extensions/defsecrules/requests.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package defsecrules
22

33
import (
44
"errors"
5+
"strings"
56

67
"github.com/rackspace/gophercloud"
78
"github.com/rackspace/gophercloud/pagination"
@@ -42,10 +43,10 @@ type CreateOptsBuilder interface {
4243
func (opts CreateOpts) ToRuleCreateMap() (map[string]interface{}, error) {
4344
rule := make(map[string]interface{})
4445

45-
if opts.FromPort == 0 {
46+
if opts.FromPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
4647
return rule, errors.New("A FromPort must be set")
4748
}
48-
if opts.ToPort == 0 {
49+
if opts.ToPort == 0 && strings.ToUpper(opts.IPProtocol) != "ICMP" {
4950
return rule, errors.New("A ToPort must be set")
5051
}
5152
if opts.IPProtocol == "" {

openstack/compute/v2/extensions/defsecrules/requests_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ func TestCreate(t *testing.T) {
6969
th.AssertDeepEquals(t, expected, group)
7070
}
7171

72+
func TestCreateICMPZero(t *testing.T) {
73+
th.SetupHTTP()
74+
defer th.TeardownHTTP()
75+
76+
mockCreateRuleResponseICMPZero(t)
77+
78+
opts := CreateOpts{
79+
IPProtocol: "ICMP",
80+
FromPort: 0,
81+
ToPort: 0,
82+
CIDR: "10.10.12.0/24",
83+
}
84+
85+
group, err := Create(client.ServiceClient(), opts).Extract()
86+
th.AssertNoErr(t, err)
87+
88+
expected := &DefaultRule{
89+
ID: ruleID,
90+
FromPort: 0,
91+
ToPort: 0,
92+
IPProtocol: "ICMP",
93+
IPRange: secgroups.IPRange{CIDR: "10.10.12.0/24"},
94+
}
95+
th.AssertDeepEquals(t, expected, group)
96+
}
97+
7298
func TestGet(t *testing.T) {
7399
th.SetupHTTP()
74100
defer th.TeardownHTTP()

openstack/compute/v2/extensions/secgroups/fixtures.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,42 @@ func mockAddRuleResponse(t *testing.T) {
216216
})
217217
}
218218

219+
func mockAddRuleResponseICMPZero(t *testing.T) {
220+
th.Mux.HandleFunc("/os-security-group-rules", func(w http.ResponseWriter, r *http.Request) {
221+
th.TestMethod(t, r, "POST")
222+
th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
223+
224+
th.TestJSONRequest(t, r, `
225+
{
226+
"security_group_rule": {
227+
"from_port": 0,
228+
"ip_protocol": "ICMP",
229+
"to_port": 0,
230+
"parent_group_id": "{groupID}",
231+
"cidr": "0.0.0.0/0"
232+
}
233+
} `)
234+
235+
w.Header().Add("Content-Type", "application/json")
236+
w.WriteHeader(http.StatusOK)
237+
238+
fmt.Fprintf(w, `
239+
{
240+
"security_group_rule": {
241+
"from_port": 0,
242+
"group": {},
243+
"ip_protocol": "ICMP",
244+
"to_port": 0,
245+
"parent_group_id": "{groupID}",
246+
"ip_range": {
247+
"cidr": "0.0.0.0/0"
248+
},
249+
"id": "{ruleID}"
250+
}
251+
}`)
252+
})
253+
}
254+
219255
func mockDeleteRuleResponse(t *testing.T, ruleID string) {
220256
url := fmt.Sprintf("/os-security-group-rules/%s", ruleID)
221257
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)