Merge pull request #4200 from alexlarsson/fix-fedora-tests

Fix fedora tests
This commit is contained in:
Michael Crosby 2014-03-03 10:54:31 -05:00
commit 62d604a81e
4 changed files with 39 additions and 16 deletions

View File

@ -34,6 +34,10 @@ import (
"sync" "sync"
) )
var (
ErrAufsNotSupported = fmt.Errorf("AUFS was not found in /proc/filesystems")
)
func init() { func init() {
graphdriver.Register("aufs", Init) graphdriver.Register("aufs", Init)
} }
@ -100,7 +104,7 @@ func supportsAufs() error {
return nil return nil
} }
} }
return fmt.Errorf("AUFS was not found in /proc/filesystems") return ErrAufsNotSupported
} }
func (a Driver) rootPath() string { func (a Driver) rootPath() string {

View File

@ -5,6 +5,7 @@ import (
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"github.com/dotcloud/docker/archive" "github.com/dotcloud/docker/archive"
"github.com/dotcloud/docker/graphdriver"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
@ -15,15 +16,24 @@ var (
tmp = path.Join(os.TempDir(), "aufs-tests", "aufs") 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 { func newDriver(t *testing.T) *Driver {
if err := os.MkdirAll(tmp, 0755); err != nil { if err := os.MkdirAll(tmp, 0755); err != nil {
t.Fatal(err) t.Fatal(err)
} }
d, err := Init(tmp) d := testInit(tmp, t)
if err != nil {
t.Fatal(err)
}
return d.(*Driver) return d.(*Driver)
} }
@ -32,10 +42,7 @@ func TestNewDriver(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
d, err := Init(tmp) d := testInit(tmp, t)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmp) defer os.RemoveAll(tmp)
if d == nil { if d == nil {
t.Fatalf("Driver should not be nil") t.Fatalf("Driver should not be nil")
@ -74,12 +81,8 @@ func TestNewDriverFromExistingDir(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if _, err := Init(tmp); err != nil { testInit(tmp, t)
t.Fatal(err) testInit(tmp, t)
}
if _, err := Init(tmp); err != nil {
t.Fatal(err)
}
os.RemoveAll(tmp) os.RemoveAll(tmp)
} }

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"fmt" "fmt"
"path" "path"
"strings"
"sync" "sync"
) )
@ -51,6 +52,21 @@ type Database struct {
mux sync.RWMutex 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 // Create a new graph database initialized with a root entity
func NewDatabase(conn *sql.DB, init bool) (*Database, error) { func NewDatabase(conn *sql.DB, init bool) (*Database, error) {
if conn == nil { if conn == nil {

View File

@ -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 // Set the enitity in the graph using the default name specified
if _, err := runtime.containerGraph.Set(name, id); err != nil { 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 return nil, nil, err
} }