// DiskManager returns a version of the state that provides functionality // required by the diskmanager worker. func (st *State) DiskManager() (*diskmanager.State, error) { machineTag, ok := st.authTag.(names.MachineTag) if !ok { return nil, errors.Errorf("expected MachineTag, got %#v", st.authTag) } return diskmanager.NewState(st, machineTag), nil }
func (s *DiskManagerSuite) TestSetMachineBlockDevicesClientError(c *gc.C) { apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error { return errors.New("blargh") }) st := diskmanager.NewState(apiCaller, names.NewMachineTag("123")) err := st.SetMachineBlockDevices(nil) c.Check(err, gc.ErrorMatches, "blargh") }
// newWorker trivially wraps NewWorker for use in a engine.AgentApiManifold. func newWorker(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) { t := a.CurrentConfig().Tag() tag, ok := t.(names.MachineTag) if !ok { return nil, errors.Errorf("expected MachineTag, got %#v", t) } api := apidiskmanager.NewState(apiCaller, tag) return NewWorker(DefaultListBlockDevices, api), nil }
func (s *DiskManagerSuite) TestSetMachineBlockDevicesServerError(c *gc.C) { apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error { *(result.(*params.ErrorResults)) = params.ErrorResults{ Results: []params.ErrorResult{{ Error: ¶ms.Error{Message: "MSG", Code: "621"}, }}, } return nil }) st := diskmanager.NewState(apiCaller, names.NewMachineTag("123")) err := st.SetMachineBlockDevices(nil) c.Check(err, gc.ErrorMatches, "MSG") }
func (s *DiskManagerSuite) TestSetMachineBlockDevicesResultCountInvalid(c *gc.C) { for _, n := range []int{0, 2} { apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error { var results []params.ErrorResult for i := 0; i < n; i++ { results = append(results, params.ErrorResult{ Error: ¶ms.Error{Message: "MSG", Code: "621"}, }) } *(result.(*params.ErrorResults)) = params.ErrorResults{Results: results} return nil }) st := diskmanager.NewState(apiCaller, names.NewMachineTag("123")) err := st.SetMachineBlockDevices(nil) c.Check(err, gc.ErrorMatches, fmt.Sprintf("expected 1 result, got %d", n)) } }
func (s *DiskManagerSuite) TestSetMachineBlockDevicesNil(c *gc.C) { var callCount int apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error { c.Check(arg, gc.DeepEquals, params.SetMachineBlockDevices{ MachineBlockDevices: []params.MachineBlockDevices{{ Machine: "machine-123", }}, }) c.Assert(result, gc.FitsTypeOf, ¶ms.ErrorResults{}) *(result.(*params.ErrorResults)) = params.ErrorResults{ Results: []params.ErrorResult{{ Error: nil, }}, } callCount++ return nil }) st := diskmanager.NewState(apiCaller, names.NewMachineTag("123")) err := st.SetMachineBlockDevices(nil) c.Check(err, jc.ErrorIsNil) c.Check(callCount, gc.Equals, 1) }
func (s *DiskManagerSuite) TestSetMachineBlockDevices(c *gc.C) { devices := []storage.BlockDevice{{ DeviceName: "sda", Size: 123, }, { DeviceName: "sdb", UUID: "asdadasdasdas", }} var callCount int apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error { c.Check(objType, gc.Equals, "DiskManager") c.Check(version, gc.Equals, 0) c.Check(id, gc.Equals, "") c.Check(request, gc.Equals, "SetMachineBlockDevices") c.Check(arg, gc.DeepEquals, params.SetMachineBlockDevices{ MachineBlockDevices: []params.MachineBlockDevices{{ Machine: "machine-123", BlockDevices: devices, }}, }) c.Assert(result, gc.FitsTypeOf, ¶ms.ErrorResults{}) *(result.(*params.ErrorResults)) = params.ErrorResults{ Results: []params.ErrorResult{{ Error: nil, }}, } callCount++ return nil }) st := diskmanager.NewState(apiCaller, names.NewMachineTag("123")) err := st.SetMachineBlockDevices(devices) c.Check(err, jc.ErrorIsNil) c.Check(callCount, gc.Equals, 1) }