Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

Commit f1a0995

Browse files
author
Samuel Ortiz
authored
Merge pull request #305 from markdryan/master
Remove github.com/docker/distribution/uuid dependency
2 parents 2aeade1 + e62dc9b commit f1a0995

File tree

22 files changed

+246
-674
lines changed

22 files changed

+246
-674
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ script:
6060
- go list ./... | grep -v github.com/01org/ciao/vendor | xargs go list -f '{{.Dir}}' | xargs gofmt -s -l | wc -l | xargs -I % bash -c "test % -eq 0"
6161
- sudo mkdir -p /var/lib/ciao/instances
6262
- sudo chmod 0777 /var/lib/ciao/instances
63-
- test-cases -text -coverprofile /tmp/cover.out -short github.com/01org/ciao/ciao-launcher github.com/01org/ciao/ciao-scheduler github.com/01org/ciao/ciao-controller/... github.com/01org/ciao/payloads github.com/01org/ciao/configuration github.com/01org/ciao/testutil
63+
- test-cases -text -coverprofile /tmp/cover.out -short github.com/01org/ciao/ciao-launcher github.com/01org/ciao/ciao-scheduler github.com/01org/ciao/ciao-controller/... github.com/01org/ciao/payloads github.com/01org/ciao/configuration github.com/01org/ciao/testutil github.com/01org/ciao/ssntp/uuid
6464
- export GOROOT=`go env GOROOT` && sudo -E PATH=$PATH:$GOROOT/bin $GOPATH/bin/test-cases -text -coverprofile /tmp/cover.out -append-profile github.com/01org/ciao/ssntp
6565
- export GOROOT=`go env GOROOT` && export SNNET_ENV=198.51.100.0/24 && sudo -E PATH=$PATH:$GOROOT/bin $GOPATH/bin/test-cases -text -short -tags travis -coverprofile /tmp/cover.out -append-profile github.com/01org/ciao/networking/libsnnet
6666

ciao-controller/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"github.com/01org/ciao/ciao-controller/types"
2929
"github.com/01org/ciao/payloads"
3030
"github.com/01org/ciao/ssntp"
31+
"github.com/01org/ciao/ssntp/uuid"
3132
"github.com/01org/ciao/testutil"
32-
"github.com/docker/distribution/uuid"
3333
)
3434

3535
func addTestTenant() (tenant *types.Tenant, err error) {

ciao-controller/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424

2525
"github.com/01org/ciao/ciao-controller/types"
2626
"github.com/01org/ciao/payloads"
27-
"github.com/docker/distribution/uuid"
27+
"github.com/01org/ciao/ssntp/uuid"
2828
"github.com/golang/glog"
2929
"gopkg.in/yaml.v2"
3030
)

ciao-controller/internal/datastore/datastore_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
"github.com/01org/ciao/ciao-controller/types"
3131
"github.com/01org/ciao/payloads"
32-
"github.com/docker/distribution/uuid"
32+
"github.com/01org/ciao/ssntp/uuid"
3333
)
3434

3535
func newTenantHardwareAddr(ip net.IP) (hw net.HardwareAddr) {

ciao-scheduler/scheduler_ssntp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525

2626
"github.com/01org/ciao/payloads"
2727
"github.com/01org/ciao/ssntp"
28+
"github.com/01org/ciao/ssntp/uuid"
2829
"github.com/01org/ciao/testutil"
29-
"github.com/docker/distribution/uuid"
3030
)
3131

3232
/****************************************************************************/

ciao-vendor/packages.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
"version": "fbb7337",
1515
"license": "Apache v2.0"
1616
},
17-
"github.com/docker/distribution": {
18-
"url": "https://github.com/docker/distribution.git",
19-
"version": "v2.4.0",
20-
"license": "Apache v2.0"
21-
},
2217
"github.com/docker/docker": {
2318
"url": "https://github.com/docker/docker.git",
2419
"version": "v1.10.3",

networking/libsnnet/docker_plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"sync"
2929
"time"
3030

31-
"github.com/docker/distribution/uuid"
31+
"github.com/01org/ciao/ssntp/uuid"
3232
"github.com/docker/libnetwork/drivers/remote/api"
3333
ipamapi "github.com/docker/libnetwork/ipams/remote/api"
3434
"github.com/golang/glog"

networking/libsnnet/tests/docker/plugin/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"sync"
3030
"time"
3131

32+
"github.com/01org/ciao/ssntp/uuid"
3233
"github.com/boltdb/bolt"
33-
"github.com/docker/distribution/uuid"
3434
"github.com/docker/libnetwork/drivers/remote/api"
3535
ipamapi "github.com/docker/libnetwork/ipams/remote/api"
3636
"github.com/golang/glog"

payloads/assignpublicIP_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import (
2020
"testing"
2121

2222
. "github.com/01org/ciao/payloads"
23+
"github.com/01org/ciao/ssntp/uuid"
2324
"github.com/01org/ciao/testutil"
24-
"github.com/docker/distribution/uuid"
2525
"gopkg.in/yaml.v2"
2626
)
2727

ssntp/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"time"
2525

2626
"github.com/01org/ciao/payloads"
27-
"github.com/docker/distribution/uuid"
27+
"github.com/01org/ciao/ssntp/uuid"
2828
"gopkg.in/yaml.v2"
2929
)
3030

ssntp/frame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"time"
2222

2323
"github.com/01org/ciao/payloads"
24-
"github.com/docker/distribution/uuid"
24+
"github.com/01org/ciao/ssntp/uuid"
2525
)
2626

2727
// TraceConfig is the SSNTP tracing configuration to be used

ssntp/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"time"
2626

2727
"github.com/01org/ciao/configuration"
28-
"github.com/docker/distribution/uuid"
28+
"github.com/01org/ciao/ssntp/uuid"
2929
)
3030

3131
// ServerNotifier is the SSNTP server notification interface.

ssntp/session.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"net"
2222
"time"
2323

24-
"github.com/docker/distribution/uuid"
24+
"github.com/01org/ciao/ssntp/uuid"
2525
)
2626

2727
func setReadTimeout(conn net.Conn) {

ssntp/ssntp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"sync"
3232
"syscall"
3333

34-
"github.com/docker/distribution/uuid"
34+
"github.com/01org/ciao/ssntp/uuid"
3535
"github.com/golang/glog"
3636
)
3737

ssntp/uuid/uuid.go

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// Copyright (c) 2016 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
// Package uuid can be used to generate 128 bit UUIDs compatible with
18+
// rfc4122. Currently, only version 4 UUIDs, UUIDs generated from random
19+
// data, can be created. The package includes functions for generating
20+
// UUIDs and for converting them to and from strings.
21+
package uuid
22+
23+
import (
24+
"crypto/rand"
25+
"encoding/binary"
26+
"errors"
27+
"fmt"
28+
"io"
29+
"strconv"
30+
"strings"
31+
)
32+
33+
// UUID represents a single 128 bit UUID as an array of 16 bytes.
34+
type UUID [16]byte
35+
36+
var (
37+
// ErrUUIDInvalid indicates that a UIID is invalid. Currently,
38+
// returned by uuid.Parse if the string passed to this function
39+
// does not contain a valid UUID.
40+
ErrUUIDInvalid = errors.New("invalid uuid")
41+
)
42+
43+
func encode4bytes(n uint64, b []byte) {
44+
binary.BigEndian.PutUint32(b, uint32(n))
45+
}
46+
47+
func encode2bytes(n uint64, b []byte) {
48+
binary.BigEndian.PutUint16(b, uint16(n))
49+
}
50+
51+
func encode1byte(n uint64, b []byte) {
52+
b[0] = uint8(n)
53+
}
54+
55+
func encode6bytes(n uint64, b []byte) {
56+
d := make([]byte, 8)
57+
binary.BigEndian.PutUint64(d, n)
58+
copy(b, d[2:])
59+
}
60+
61+
func stringToBE(s string, b []byte, f func(uint64, []byte)) error {
62+
num, err := strconv.ParseUint(s, 16, len(s)*4)
63+
if err != nil {
64+
return ErrUUIDInvalid
65+
}
66+
f(num, b)
67+
return nil
68+
}
69+
70+
// Parse returns the binary encoding of the UUID passed in the s parameter.
71+
// The error ErrUUIDInvalid will be returned if s does not represent a valid
72+
// UUID.
73+
func Parse(s string) (UUID, error) {
74+
var uuid UUID
75+
var segmentSizes = [...]int{8, 4, 4, 4, 12}
76+
77+
segments := strings.Split(s, "-")
78+
if len(segments) != len(segmentSizes) {
79+
return uuid, ErrUUIDInvalid
80+
}
81+
82+
for i, l := range segmentSizes {
83+
if len(segments[i]) != l {
84+
return uuid, ErrUUIDInvalid
85+
}
86+
}
87+
88+
if err := stringToBE(segments[0], uuid[:4], encode4bytes); err != nil {
89+
return uuid, err
90+
}
91+
if err := stringToBE(segments[1], uuid[4:6], encode2bytes); err != nil {
92+
return uuid, err
93+
}
94+
if err := stringToBE(segments[2], uuid[6:8], encode2bytes); err != nil {
95+
return uuid, err
96+
}
97+
if err := stringToBE(segments[3][:2], uuid[8:9], encode1byte); err != nil {
98+
return uuid, err
99+
}
100+
if err := stringToBE(segments[3][2:], uuid[9:10], encode1byte); err != nil {
101+
return uuid, err
102+
}
103+
if err := stringToBE(segments[4], uuid[10:], encode6bytes); err != nil {
104+
return uuid, err
105+
}
106+
107+
return uuid, nil
108+
}
109+
110+
// Generate generates a new v4 UUID, i.e., a random UUID.
111+
func Generate() UUID {
112+
var u UUID
113+
114+
_, err := io.ReadFull(rand.Reader, u[:])
115+
if err != nil {
116+
panic(fmt.Errorf("Unable to read random data : %v", err))
117+
}
118+
119+
u[6] = (u[6] & 0x0f) | 0x40
120+
u[8] = (u[8] & 0x3f) | 0x80
121+
122+
return u
123+
}
124+
125+
func (u UUID) String() string {
126+
timeLow := binary.BigEndian.Uint32(u[:4])
127+
timeMid := binary.BigEndian.Uint16(u[4:6])
128+
timeHi := binary.BigEndian.Uint16(u[6:8])
129+
clkSeqHi := u[8]
130+
clkSeqLow := u[9]
131+
buf := make([]byte, 8)
132+
copy(buf[2:], u[10:])
133+
node := uint64(binary.BigEndian.Uint64(buf))
134+
135+
return fmt.Sprintf("%08x-%04x-%04x-%02x%02x-%012x",
136+
timeLow, timeMid, timeHi, clkSeqHi, clkSeqLow, node)
137+
}

ssntp/uuid/uuid_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//
2+
// Copyright (c) 2016 Intel Corporation
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
package uuid
18+
19+
import "testing"
20+
21+
// Test UUID parsing and string conversation.
22+
//
23+
// This test simply converts a set of strings to UUIDs and back again.
24+
//
25+
// The original strings and the strings generated from the UUIDs match.
26+
func TestUUID(t *testing.T) {
27+
testUUIDs := []string{
28+
"f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
29+
"30dedd5c-48d9-45d3-8b44-f973e4f35e48",
30+
"69e84267-ed01-4738-b15f-b47de06b62e7",
31+
"e35ed972-c46c-4aad-a1e7-ef103ae079a2",
32+
"eba04826-62a5-48bd-876f-9119667b1487",
33+
"ca957444-fa46-11e5-94f9-38607786d9ec",
34+
"ab68111c-03a6-11e6-87de-001320fb6e31",
35+
}
36+
37+
for _, s := range testUUIDs {
38+
uuid, err := Parse(s)
39+
if err != nil {
40+
t.Fatalf("Unable to parse %s: %s", s, err)
41+
}
42+
s2 := uuid.String()
43+
if s != s2 {
44+
t.Fatalf("%s and %s do not match", s, s2)
45+
}
46+
}
47+
}
48+
49+
// Test UUID generation.
50+
//
51+
// This test generates 100 new UUIDs and then verifies that those UUIDs
52+
// can be parsed.
53+
//
54+
// The UUIDs are generated correctly, their version number is correct,
55+
// and they can be parsed.
56+
func TestGenUUID(t *testing.T) {
57+
for i := 0; i < 100; i++ {
58+
u := Generate()
59+
s := u.String()
60+
if s[14] != '4' {
61+
t.Fatalf("Invalid UUID. Version number is incorrect")
62+
}
63+
u2, err := Parse(s)
64+
if err != nil {
65+
t.Fatalf("Failed to parse UUID %s : %s", s, err)
66+
}
67+
if u != u2 {
68+
t.Fatalf("Generated and Parsed UUIDs are not equal")
69+
}
70+
}
71+
}
72+
73+
// Test uuid.Parse on invalid input.
74+
//
75+
// This test attempts to parse a set of invalid UUIDs.
76+
//
77+
// uuid.Parse should return an error for each invalid UUID.
78+
func TestBadUUID(t *testing.T) {
79+
badTestUUIDs := []string{
80+
"",
81+
"48d9-45d3-8b44-f973e4f35e48",
82+
"69e8426--ed01-4738-b15f-b47de06b62e7",
83+
"e35ed972-46c-4aad-a1e7-ef103ae079a2",
84+
"sba04826-62a5-48bd-876f-9119667b1487",
85+
"ca957444fa4611e594f938607786d9ec0000",
86+
"ab68111c-03a6-11e6-87de-001320fb6e31a",
87+
}
88+
89+
for _, s := range badTestUUIDs {
90+
_, err := Parse(s)
91+
if err == nil {
92+
t.Fatalf("uuid.Parse should fail to parse %s", s)
93+
}
94+
}
95+
}

testutil/client_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424

2525
"github.com/01org/ciao/payloads"
2626
"github.com/01org/ciao/ssntp"
27+
"github.com/01org/ciao/ssntp/uuid"
2728
. "github.com/01org/ciao/testutil"
28-
"github.com/docker/distribution/uuid"
2929
)
3030

3131
var server SsntpTestServer

0 commit comments

Comments
 (0)