mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Tests: Clean up any old devmapper leftovers before starting tests
This commit is contained in:
parent
071cc18b58
commit
be6fef0254
2 changed files with 46 additions and 0 deletions
|
@ -347,3 +347,20 @@ func UdevWait(cookie uint32) error {
|
||||||
func LogInitVerbose(level int) {
|
func LogInitVerbose(level int) {
|
||||||
C.dm_log_init_verbose(C.int(level))
|
C.dm_log_init_verbose(C.int(level))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Useful helper for cleanup
|
||||||
|
func RemoveDevice(name string) error {
|
||||||
|
task := TaskCreate(DeviceRemove)
|
||||||
|
if task == nil {
|
||||||
|
return fmt.Errorf("Can't create task of type DeviceRemove")
|
||||||
|
}
|
||||||
|
err := task.SetName(name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Can't set task name %s", name)
|
||||||
|
}
|
||||||
|
err = task.Run()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error running removeDevice")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"github.com/dotcloud/docker/devmapper"
|
"github.com/dotcloud/docker/devmapper"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
@ -84,6 +85,32 @@ func layerArchive(tarfile string) (io.Reader, error) {
|
||||||
return f, nil
|
return f, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove any leftover device mapper devices from earlier runs of the unit tests
|
||||||
|
func cleanupDevMapper() {
|
||||||
|
infos, _ := ioutil.ReadDir("/dev/mapper")
|
||||||
|
if infos != nil {
|
||||||
|
hasPool := false
|
||||||
|
for _, info := range infos {
|
||||||
|
name := info.Name()
|
||||||
|
if strings.HasPrefix(name, "docker-unit-tests-devices-") {
|
||||||
|
if name == "docker-unit-tests-devices-pool" {
|
||||||
|
hasPool = true
|
||||||
|
} else {
|
||||||
|
if err := devmapper.RemoveDevice(name); err != nil {
|
||||||
|
panic(fmt.Errorf("Unable to remove existing device %s: %s", name, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// We need to remove the pool last as the other devices block it
|
||||||
|
if hasPool {
|
||||||
|
if err := devmapper.RemoveDevice("docker-unit-tests-devices-pool"); err != nil {
|
||||||
|
panic(fmt.Errorf("Unable to remove existing device docker-unit-tests-devices-pool: %s", name, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
os.Setenv("TEST", "1")
|
os.Setenv("TEST", "1")
|
||||||
|
|
||||||
|
@ -99,6 +126,8 @@ func init() {
|
||||||
|
|
||||||
NetworkBridgeIface = unitTestNetworkBridge
|
NetworkBridgeIface = unitTestNetworkBridge
|
||||||
|
|
||||||
|
cleanupDevMapper()
|
||||||
|
|
||||||
// Always start from a clean set of loopback mounts
|
// Always start from a clean set of loopback mounts
|
||||||
err := os.RemoveAll(unitTestStoreDevicesBase)
|
err := os.RemoveAll(unitTestStoreDevicesBase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue