func (s *TestSuite) SetUpTest(c *C) {
	s.driver = nil

	err := exec.Command("mkdir", "-p", devCfgRoot).Run()
	c.Assert(err, IsNil)

	err = exec.Command("mkdir", "-p", devDataRoot).Run()
	c.Assert(err, IsNil)

	s.dataFile = filepath.Join(devDataRoot, dataFile)
	s.metadataFile = filepath.Join(devDataRoot, metadataFile)

	err = exec.Command("truncate", "-s", strconv.Itoa(dataSize), s.dataFile).Run()
	c.Assert(err, IsNil)

	err = exec.Command("truncate", "-s", strconv.Itoa(metadataSize), s.metadataFile).Run()
	c.Assert(err, IsNil)

	s.dataDev, err = util.AttachLoopbackDevice(s.dataFile, false)
	c.Assert(err, IsNil)

	s.metadataDev, err = util.AttachLoopbackDevice(s.metadataFile, false)
	c.Assert(err, IsNil)

	s.initDriver(c)
}
func (s *TestSuite) SetUpSuite(c *C) {
	logrus.SetLevel(logrus.DebugLevel)
	logrus.SetOutput(os.Stderr)

	var err error

	err = exec.Command("mkdir", "-p", devRoot).Run()
	c.Assert(err, IsNil)

	err = exec.Command("mkdir", "-p", devMount).Run()
	c.Assert(err, IsNil)

	// Prepare base image
	s.imageFile = filepath.Join(devRoot, imageFile)
	err = exec.Command("truncate", "-s", strconv.Itoa(volumeSize), s.imageFile).Run()
	c.Assert(err, IsNil)

	tmpDev, err := util.AttachLoopbackDevice(s.imageFile, false)
	c.Assert(err, IsNil)

	err = exec.Command("mkfs", "-t", "ext4", tmpDev).Run()
	c.Assert(err, IsNil)

	err = exec.Command("mount", tmpDev, devMount).Run()
	c.Assert(err, IsNil)

	err = exec.Command("touch", filepath.Join(devMount, imageTestFile)).Run()
	c.Assert(err, IsNil)

	err = exec.Command("umount", devMount).Run()
	c.Assert(err, IsNil)

	err = util.DetachLoopbackDevice(s.imageFile, tmpDev)
	c.Assert(err, IsNil)
}
func (d *Driver) ActivateImage(imageUUID, imageFile string) error {
	image := d.loadImage(imageUUID)
	if image != nil {
		return generateError(logrus.Fields{
			LOG_FIELD_IMAGE: imageUUID,
		}, "Image already activated")
	}
	st, err := os.Stat(imageFile)
	if err != nil || st.IsDir() {
		return err
	}
	log.WithFields(logrus.Fields{
		LOG_FIELD_REASON:     LOG_REASON_START,
		LOG_FIELD_EVENT:      LOG_EVENT_ACTIVATE,
		LOG_FIELD_OBJECT:     LOG_OBJECT_IMAGE,
		LOG_FIELD_IMAGE:      imageUUID,
		LOG_FIELD_IMAGE_FILE: imageFile,
	}).Debug()
	loopDev, err := util.AttachLoopbackDevice(imageFile, true)
	if err != nil {
		return err
	}
	image = &Image{
		UUID:      imageUUID,
		Size:      st.Size(),
		FilePath:  imageFile,
		Device:    loopDev,
		VolumeRef: make(map[string]bool),
	}
	if err := d.saveImage(image); err != nil {
		return err
	}
	return nil
}