示例#1
0
文件: state.go 项目: Pankov404/juju
// 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
}
示例#2
0
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")
}
示例#3
0
文件: manifold.go 项目: kat-co/juju
// 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
}
示例#4
0
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: &params.Error{Message: "MSG", Code: "621"},
			}},
		}
		return nil
	})
	st := diskmanager.NewState(apiCaller, names.NewMachineTag("123"))
	err := st.SetMachineBlockDevices(nil)
	c.Check(err, gc.ErrorMatches, "MSG")
}
示例#5
0
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: &params.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))
	}
}
示例#6
0
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, &params.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)
}
示例#7
0
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, &params.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)
}