diff --git a/libnetwork/Godeps/Godeps.json b/libnetwork/Godeps/Godeps.json index 6015d14997..3556a8d404 100644 --- a/libnetwork/Godeps/Godeps.json +++ b/libnetwork/Godeps/Godeps.json @@ -10,11 +10,6 @@ "Comment": "v0.6.4-12-g467d9d5", "Rev": "467d9d55c2d2c17248441a8fc661561161f40d5e" }, - { - "ImportPath": "github.com/docker/docker/pkg/common", - "Comment": "v1.4.1-1379-g8e107a9", - "Rev": "8e107a93210c54f22ec1354d969c771b1abfbe05" - }, { "ImportPath": "github.com/docker/docker/pkg/iptables", "Comment": "v1.4.1-2492-ge690ad9", @@ -36,9 +31,9 @@ "Rev": "e690ad92925a045344bde8d2d59d7a7f602dded6" }, { - "ImportPath": "github.com/docker/libcontainer/utils", - "Comment": "v1.4.0-324-g88989e6", - "Rev": "88989e66d3a1ab960deb37f3dd7f824d85e1b9bc" + "ImportPath": "github.com/docker/docker/pkg/stringid", + "Comment": "v1.4.1-2492-ge690ad9", + "Rev": "e690ad92925a045344bde8d2d59d7a7f602dded6" }, { "ImportPath": "github.com/vishvananda/netlink", diff --git a/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/README.md b/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/README.md new file mode 100644 index 0000000000..37a5098fd9 --- /dev/null +++ b/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/README.md @@ -0,0 +1 @@ +This package provides helper functions for dealing with string identifiers diff --git a/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/common/randomid.go b/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/stringid.go similarity index 83% rename from libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/common/randomid.go rename to libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/stringid.go index 5c6d5920e8..bf39df9b73 100644 --- a/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/common/randomid.go +++ b/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/stringid.go @@ -1,4 +1,4 @@ -package common +package stringid import ( "crypto/rand" @@ -36,12 +36,3 @@ func GenerateRandomID() string { return value } } - -func RandomString() string { - id := make([]byte, 32) - - if _, err := io.ReadFull(rand.Reader, id); err != nil { - panic(err) // This shouldn't happen - } - return hex.EncodeToString(id) -} diff --git a/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/common/randomid_test.go b/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/stringid_test.go similarity index 58% rename from libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/common/randomid_test.go rename to libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/stringid_test.go index 1dba41254b..21f8f8a2fb 100644 --- a/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/common/randomid_test.go +++ b/libnetwork/Godeps/_workspace/src/github.com/docker/docker/pkg/stringid/stringid_test.go @@ -1,8 +1,14 @@ -package common +package stringid -import ( - "testing" -) +import "testing" + +func TestGenerateRandomID(t *testing.T) { + id := GenerateRandomID() + + if len(id) != 64 { + t.Fatalf("Id returned is incorrect: %s", id) + } +} func TestShortenId(t *testing.T) { id := GenerateRandomID() @@ -27,33 +33,3 @@ func TestShortenIdInvalid(t *testing.T) { t.Fatalf("Id returned is incorrect: truncate on %s returned %s", id, truncID) } } - -func TestGenerateRandomID(t *testing.T) { - id := GenerateRandomID() - - if len(id) != 64 { - t.Fatalf("Id returned is incorrect: %s", id) - } -} - -func TestRandomString(t *testing.T) { - id := RandomString() - if len(id) != 64 { - t.Fatalf("Id returned is incorrect: %s", id) - } -} - -func TestRandomStringUniqueness(t *testing.T) { - repeats := 25 - set := make(map[string]struct{}, repeats) - for i := 0; i < repeats; i = i + 1 { - id := RandomString() - if len(id) != 64 { - t.Fatalf("Id returned is incorrect: %s", id) - } - if _, ok := set[id]; ok { - t.Fatalf("Random number is repeated") - } - set[id] = struct{}{} - } -} diff --git a/libnetwork/Godeps/_workspace/src/github.com/docker/libcontainer/utils/utils.go b/libnetwork/Godeps/_workspace/src/github.com/docker/libcontainer/utils/utils.go deleted file mode 100644 index 094bce5300..0000000000 --- a/libnetwork/Godeps/_workspace/src/github.com/docker/libcontainer/utils/utils.go +++ /dev/null @@ -1,68 +0,0 @@ -package utils - -import ( - "crypto/rand" - "encoding/hex" - "io" - "io/ioutil" - "path/filepath" - "strconv" - "syscall" -) - -const ( - exitSignalOffset = 128 -) - -// GenerateRandomName returns a new name joined with a prefix. This size -// specified is used to truncate the randomly generated value -func GenerateRandomName(prefix string, size int) (string, error) { - id := make([]byte, 32) - if _, err := io.ReadFull(rand.Reader, id); err != nil { - return "", err - } - return prefix + hex.EncodeToString(id)[:size], nil -} - -// ResolveRootfs ensures that the current working directory is -// not a symlink and returns the absolute path to the rootfs -func ResolveRootfs(uncleanRootfs string) (string, error) { - rootfs, err := filepath.Abs(uncleanRootfs) - if err != nil { - return "", err - } - return filepath.EvalSymlinks(rootfs) -} - -func CloseExecFrom(minFd int) error { - fdList, err := ioutil.ReadDir("/proc/self/fd") - if err != nil { - return err - } - for _, fi := range fdList { - fd, err := strconv.Atoi(fi.Name()) - if err != nil { - // ignore non-numeric file names - continue - } - - if fd < minFd { - // ignore descriptors lower than our specified minimum - continue - } - - // intentionally ignore errors from syscall.CloseOnExec - syscall.CloseOnExec(fd) - // the cases where this might fail are basically file descriptors that have already been closed (including and especially the one that was created when ioutil.ReadDir did the "opendir" syscall) - } - return nil -} - -// ExitStatus returns the correct exit status for a process based on if it -// was signaled or existed cleanly. -func ExitStatus(status syscall.WaitStatus) int { - if status.Signaled() { - return exitSignalOffset + int(status.Signal()) - } - return status.ExitStatus() -} diff --git a/libnetwork/Godeps/_workspace/src/github.com/docker/libcontainer/utils/utils_test.go b/libnetwork/Godeps/_workspace/src/github.com/docker/libcontainer/utils/utils_test.go deleted file mode 100644 index 41ef1aa3df..0000000000 --- a/libnetwork/Godeps/_workspace/src/github.com/docker/libcontainer/utils/utils_test.go +++ /dev/null @@ -1,15 +0,0 @@ -package utils - -import "testing" - -func TestGenerateName(t *testing.T) { - name, err := GenerateRandomName("veth", 5) - if err != nil { - t.Fatal(err) - } - - expected := 5 + len("veth") - if len(name) != 5+len("veth") { - t.Fatalf("expected name to be %d chars but received %d", expected, len(name)) - } -} diff --git a/libnetwork/network.go b/libnetwork/network.go index d12a13544d..4d11d201a0 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -41,7 +41,7 @@ package libnetwork import ( "sync" - "github.com/docker/docker/pkg/common" + "github.com/docker/docker/pkg/stringid" "github.com/docker/libnetwork/driverapi" ) @@ -152,7 +152,7 @@ func (c *controller) NewNetwork(nd *NetworkDriver, name string, options interfac network := &network{ name: name, - id: driverapi.UUID(common.GenerateRandomID()), + id: driverapi.UUID(stringid.GenerateRandomID()), ctrlr: c, driver: nd} network.endpoints = make(endpointTable) @@ -224,7 +224,7 @@ func (n *network) Delete() error { func (n *network) CreateEndpoint(name string, sboxKey string, options interface{}) (Endpoint, *driverapi.SandboxInfo, error) { ep := &endpoint{name: name} - ep.id = driverapi.UUID(common.GenerateRandomID()) + ep.id = driverapi.UUID(stringid.GenerateRandomID()) ep.network = n d := n.driver.internalDriver diff --git a/libnetwork/sandbox/sandbox_linux_test.go b/libnetwork/sandbox/sandbox_linux_test.go index abbebd7ca4..c07cb6b2a0 100644 --- a/libnetwork/sandbox/sandbox_linux_test.go +++ b/libnetwork/sandbox/sandbox_linux_test.go @@ -6,12 +6,12 @@ import ( "runtime" "testing" - "github.com/docker/libcontainer/utils" + "github.com/docker/libnetwork/netutils" "github.com/vishvananda/netns" ) func newKey(t *testing.T) (string, error) { - name, err := utils.GenerateRandomName("netns", 12) + name, err := netutils.GenerateRandomName("netns", 12) if err != nil { return "", err }