示例#1
0
func (s *volumeSuite) TestCreateVolumeItem(c *gc.C) {
	found := storage.CreateVolumeItem(s.api, s.volumeTag.String(), nil)
	c.Assert(found.Error, gc.IsNil)
	c.Assert(found.Error, gc.IsNil)
	expected, err := storage.ConvertStateVolumeToParams(s.api, s.volume)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(found.Volume, gc.DeepEquals, expected)
}
示例#2
0
func (s *volumeSuite) TestCreateVolumeItemNoStorageInstance(c *gc.C) {
	s.volume = &mockVolume{tag: s.volumeTag, hasNoStorage: true}
	found := storage.CreateVolumeItem(s.api, s.volumeTag.String(), nil)
	c.Assert(found.Error, gc.IsNil)
	c.Assert(found.Error, gc.IsNil)
	expected, err := storage.ConvertStateVolumeToParams(s.api, s.volume)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(found.Volume, gc.DeepEquals, expected)
}
示例#3
0
func (s *volumeSuite) TestCreateVolumeItemNoUnit(c *gc.C) {
	s.storageInstance.owner = names.NewServiceTag("test-service")
	found := storage.CreateVolumeItem(s.api, s.volumeTag.String(), nil)
	c.Assert(found.Error, gc.IsNil)
	c.Assert(found.Error, gc.IsNil)
	expected, err := storage.ConvertStateVolumeToParams(s.api, s.volume)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(found.Volume, gc.DeepEquals, expected)
}
示例#4
0
func (s *volumeSuite) TestListVolumesEmptyFilter(c *gc.C) {
	expectedVolume, err := storage.ConvertStateVolumeToParams(s.api, s.volume)
	c.Assert(err, jc.ErrorIsNil)
	expected := params.VolumeItem{
		Volume: expectedVolume,
		Attachments: storage.ConvertStateVolumeAttachmentsToParams(
			[]state.VolumeAttachment{s.volumeAttachment},
		),
	}
	found, err := s.api.ListVolumes(params.VolumeFilter{})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(found.Results, gc.HasLen, 1)
	c.Assert(found.Results[0], gc.DeepEquals, expected)
}
示例#5
0
func (s *volumeSuite) TestVolumeAttachments(c *gc.C) {
	expectedVolume, err := storage.ConvertStateVolumeToParams(s.api, s.volume)
	c.Assert(err, jc.ErrorIsNil)
	expected := params.VolumeItem{
		Volume: expectedVolume,
		Attachments: storage.ConvertStateVolumeAttachmentsToParams(
			[]state.VolumeAttachment{s.volumeAttachment},
		),
	}

	found := storage.VolumeAttachments(s.api, []state.Volume{s.volume})
	c.Assert(found, gc.HasLen, 1)
	c.Assert(found[0], gc.DeepEquals, expected)
}
示例#6
0
func (s *volumeSuite) TestVolumeAttachmentsEmpty(c *gc.C) {
	s.state.volumeAttachments =
		func(volume names.VolumeTag) ([]state.VolumeAttachment, error) {
			return nil, nil
		}
	expectedVolume, err := storage.ConvertStateVolumeToParams(s.api, s.volume)
	c.Assert(err, jc.ErrorIsNil)
	expected := params.VolumeItem{
		Volume: expectedVolume,
	}

	found := storage.VolumeAttachments(s.api, []state.Volume{s.volume})
	c.Assert(found, gc.HasLen, 1)
	c.Assert(found[0], gc.DeepEquals, expected)
}
示例#7
0
func (s *volumeSuite) TestFilterVolumes(c *gc.C) {
	filter := params.VolumeFilter{
		Machines: []string{s.machineTag.String()}}

	expectedVolume, err := storage.ConvertStateVolumeToParams(s.api, s.volume)
	c.Assert(err, jc.ErrorIsNil)
	expected := params.VolumeItem{
		Volume: expectedVolume,
		Attachments: storage.ConvertStateVolumeAttachmentsToParams(
			[]state.VolumeAttachment{s.volumeAttachment},
		),
	}
	found := storage.FilterVolumes(s.api, filter)
	c.Assert(found, gc.HasLen, 1)
	c.Assert(found[0], gc.DeepEquals, expected)
}
示例#8
0
func (s *volumeSuite) TestGetVolumeItems(c *gc.C) {
	machineTag := names.NewMachineTag("0")
	attachments := []state.VolumeAttachment{
		&mockVolumeAttachment{VolumeTag: s.volumeTag, MachineTag: machineTag},
		&mockVolumeAttachment{VolumeTag: s.volumeTag, MachineTag: machineTag},
	}
	expectedVolume, err := storage.ConvertStateVolumeToParams(s.api, s.volume)
	c.Assert(err, jc.ErrorIsNil)
	expected := []params.VolumeItem{
		params.VolumeItem{
			Volume:      expectedVolume,
			Attachments: storage.ConvertStateVolumeAttachmentsToParams(attachments)},
	}
	c.Assert(
		storage.GetVolumeItems(s.api, attachments),
		jc.DeepEquals,
		expected)
}