Example #1
0
func (s *DiskManagerWorkerSuite) TestBlockDeviceChanges(c *gc.C) {
	var oldDevices []storage.BlockDevice
	var devicesSet [][]storage.BlockDevice
	var setDevices BlockDeviceSetterFunc = func(devices []storage.BlockDevice) error {
		devicesSet = append(devicesSet, devices)
		return nil
	}

	var listDevices diskmanager.ListBlockDevicesFunc = func() ([]storage.BlockDevice, error) {
		return []storage.BlockDevice{{DeviceName: "sda"}}, nil
	}
	for i := 0; i < 2; i++ {
		err := diskmanager.DoWork(listDevices, setDevices, &oldDevices)
		c.Assert(err, jc.ErrorIsNil)
	}

	listDevices = func() ([]storage.BlockDevice, error) {
		return []storage.BlockDevice{{DeviceName: "sdb"}}, nil
	}
	err := diskmanager.DoWork(listDevices, setDevices, &oldDevices)
	c.Assert(err, jc.ErrorIsNil)

	// diskmanager only calls the BlockDeviceSetter when it sees
	// a change in disks.
	c.Assert(devicesSet, gc.HasLen, 2)
	c.Assert(devicesSet[0], gc.DeepEquals, []storage.BlockDevice{{
		DeviceName: "sda",
	}})
	c.Assert(devicesSet[1], gc.DeepEquals, []storage.BlockDevice{{
		DeviceName: "sdb",
	}})
}
Example #2
0
func (s *DiskManagerWorkerSuite) TestBlockDevicesSorted(c *gc.C) {
	var devicesSet [][]storage.BlockDevice
	var setDevices BlockDeviceSetterFunc = func(devices []storage.BlockDevice) error {
		devicesSet = append(devicesSet, devices)
		return nil
	}

	var listDevices diskmanager.ListBlockDevicesFunc = func() ([]storage.BlockDevice, error) {
		return []storage.BlockDevice{{
			DeviceName: "sdb",
		}, {
			DeviceName: "sda",
		}, {
			DeviceName: "sdc",
		}}, nil
	}
	err := diskmanager.DoWork(listDevices, setDevices, new([]storage.BlockDevice))
	c.Assert(err, jc.ErrorIsNil)

	// The block Devices should be sorted when passed to the block
	// device setter.
	c.Assert(devicesSet, gc.DeepEquals, [][]storage.BlockDevice{{{
		DeviceName: "sda",
	}, {
		DeviceName: "sdb",
	}, {
		DeviceName: "sdc",
	}}})
}