From e8af7fcf6da03da65a379c12c90e6626c31846ae Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 18 Feb 2014 11:41:11 +0100 Subject: [PATCH 1/2] runtime: Fix unique constraint error checks The sqlite3 version in fedora (3.8) returns a different error string in the unique constraints failure case than the one in hack/ (3.7). This updates the check to detect both, fixing one integration check failure on Fedora. Docker-DCO-1.1-Signed-off-by: Alexander Larsson (github: alexlarsson) --- pkg/graphdb/graphdb.go | 16 ++++++++++++++++ runtime.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/graphdb/graphdb.go b/pkg/graphdb/graphdb.go index 9e2466b69..46a23b1e7 100644 --- a/pkg/graphdb/graphdb.go +++ b/pkg/graphdb/graphdb.go @@ -4,6 +4,7 @@ import ( "database/sql" "fmt" "path" + "strings" "sync" ) @@ -51,6 +52,21 @@ type Database struct { mux sync.RWMutex } +func IsNonUniqueNameError(err error) bool { + str := err.Error() + // sqlite 3.7.17-1ubuntu1 returns: + // Set failure: Abort due to constraint violation: columns parent_id, name are not unique + if strings.HasSuffix(str, "name are not unique") { + return true + } + // sqlite-3.8.3-1.fc20 returns: + // Set failure: Abort due to constraint violation: UNIQUE constraint failed: edge.parent_id, edge.name + if strings.Contains(str, "UNIQUE constraint failed") && strings.Contains(str, "edge.name") { + return true + } + return false +} + // Create a new graph database initialized with a root entity func NewDatabase(conn *sql.DB, init bool) (*Database, error) { if conn == nil { diff --git a/runtime.go b/runtime.go index 0c2c17d7a..6cebab6e1 100644 --- a/runtime.go +++ b/runtime.go @@ -396,7 +396,7 @@ func (runtime *Runtime) Create(config *runconfig.Config, name string) (*Containe // Set the enitity in the graph using the default name specified if _, err := runtime.containerGraph.Set(name, id); err != nil { - if !strings.HasSuffix(err.Error(), "name are not unique") { + if !graphdb.IsNonUniqueNameError(err) { return nil, nil, err } From 9e28c3e3f86664ef8f219f11ef19c74a414346a9 Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Tue, 18 Feb 2014 11:58:38 +0100 Subject: [PATCH 2/2] aufs: Skip tests if aufs not supported This makes it possible to pass the rest of the testsuite without aufs in the kernel. Docker-DCO-1.1-Signed-off-by: Alexander Larsson (github: alexlarsson) --- graphdriver/aufs/aufs.go | 6 +++++- graphdriver/aufs/aufs_test.go | 31 +++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/graphdriver/aufs/aufs.go b/graphdriver/aufs/aufs.go index f2a88a7ac..a15cf6b27 100644 --- a/graphdriver/aufs/aufs.go +++ b/graphdriver/aufs/aufs.go @@ -34,6 +34,10 @@ import ( "sync" ) +var ( + ErrAufsNotSupported = fmt.Errorf("AUFS was not found in /proc/filesystems") +) + func init() { graphdriver.Register("aufs", Init) } @@ -100,7 +104,7 @@ func supportsAufs() error { return nil } } - return fmt.Errorf("AUFS was not found in /proc/filesystems") + return ErrAufsNotSupported } func (a Driver) rootPath() string { diff --git a/graphdriver/aufs/aufs_test.go b/graphdriver/aufs/aufs_test.go index c43bd7403..6002bec5a 100644 --- a/graphdriver/aufs/aufs_test.go +++ b/graphdriver/aufs/aufs_test.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "fmt" "github.com/dotcloud/docker/archive" + "github.com/dotcloud/docker/graphdriver" "io/ioutil" "os" "path" @@ -15,15 +16,24 @@ var ( tmp = path.Join(os.TempDir(), "aufs-tests", "aufs") ) +func testInit(dir string, t *testing.T) graphdriver.Driver { + d, err := Init(dir) + if err != nil { + if err == ErrAufsNotSupported { + t.Skip(err) + } else { + t.Fatal(err) + } + } + return d +} + func newDriver(t *testing.T) *Driver { if err := os.MkdirAll(tmp, 0755); err != nil { t.Fatal(err) } - d, err := Init(tmp) - if err != nil { - t.Fatal(err) - } + d := testInit(tmp, t) return d.(*Driver) } @@ -32,10 +42,7 @@ func TestNewDriver(t *testing.T) { t.Fatal(err) } - d, err := Init(tmp) - if err != nil { - t.Fatal(err) - } + d := testInit(tmp, t) defer os.RemoveAll(tmp) if d == nil { t.Fatalf("Driver should not be nil") @@ -74,12 +81,8 @@ func TestNewDriverFromExistingDir(t *testing.T) { t.Fatal(err) } - if _, err := Init(tmp); err != nil { - t.Fatal(err) - } - if _, err := Init(tmp); err != nil { - t.Fatal(err) - } + testInit(tmp, t) + testInit(tmp, t) os.RemoveAll(tmp) }