Beispiel #1
0
func (s *serviceStatusSetterSuite) SetUpTest(c *gc.C) {
	s.statusBaseSuite.SetUpTest(c)

	s.setter = common.NewServiceStatusSetter(s.State, func() (common.AuthFunc, error) {
		return s.authFunc, nil
	})
}
Beispiel #2
0
func (*statusSetterSuite) TestSetServiceStatusNotLeader(c *gc.C) {
	st := &fakeState{
		entities: map[names.Tag]entityWithError{
			u("x/0"): &fakeService{
				tag: serviceTag("x/0"),
				serviceStatus: state.StatusInfo{
					Status:  state.StatusAllocating,
					Message: "blah",
				},
				err: fmt.Errorf("x0 fails"),
			},
		},
	}

	getCanModify := func() (common.AuthFunc, error) {
		return func(_ names.Tag) bool { return true }, nil
	}
	s := common.NewServiceStatusSetter(st, getCanModify)
	args := params.SetStatus{
		Entities: []params.EntityStatus{
			{"unit-x-0", params.StatusInstalling, "bar", nil},
		},
	}
	leaderCheck := func(_ state.EntityFinder, tag string) (bool, error) {
		return false, nil
	}
	result, err := common.ServiceSetStatus(s, args, fakeServiceFromUnitTag, leaderCheck)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, gc.DeepEquals, params.ErrorResults{
		Results: []params.ErrorResult{
			{&params.Error{"this unit is not the leader", ""}},
		},
	})

}
Beispiel #3
0
// NewStatusAPI creates a new server-side Status setter API facade.
func NewStatusAPI(st *state.State, getCanModify common.GetAuthFunc) *StatusAPI {
	unitSetter := common.NewStatusSetter(st, getCanModify)
	unitGetter := common.NewStatusGetter(st, getCanModify)
	serviceSetter := common.NewServiceStatusSetter(st, getCanModify)
	serviceGetter := common.NewServiceStatusGetter(st, getCanModify)
	agentSetter := common.NewStatusSetter(&unitAgentFinder{st}, getCanModify)
	return &StatusAPI{
		agentSetter:   agentSetter,
		unitSetter:    unitSetter,
		unitGetter:    unitGetter,
		serviceSetter: serviceSetter,
		serviceGetter: serviceGetter,
		getCanModify:  getCanModify,
	}
}
Beispiel #4
0
// NewStatusAPI creates a new server-side Status setter API facade.
func NewStatusAPI(st *state.State, getCanModify common.GetAuthFunc) *StatusAPI {
	// TODO(fwereade): so *all* of these have exactly the same auth
	// characteristics? I think not.
	unitSetter := common.NewStatusSetter(st, getCanModify)
	unitGetter := common.NewStatusGetter(st, getCanModify)
	serviceSetter := common.NewServiceStatusSetter(st, getCanModify)
	serviceGetter := common.NewServiceStatusGetter(st, getCanModify)
	agentSetter := common.NewStatusSetter(&common.UnitAgentFinder{st}, getCanModify)
	return &StatusAPI{
		agentSetter:   agentSetter,
		unitSetter:    unitSetter,
		unitGetter:    unitGetter,
		serviceSetter: serviceSetter,
		serviceGetter: serviceGetter,
		getCanModify:  getCanModify,
	}
}
Beispiel #5
0
func (*statusSetterSuite) TestSetServiceStatus(c *gc.C) {
	st := &fakeState{
		entities: map[names.Tag]entityWithError{
			u("x/0"): &fakeService{
				tag: serviceTag("x/0"),
				serviceStatus: state.StatusInfo{
					Status:  state.StatusAllocating,
					Message: "blah",
				},
				err: fmt.Errorf("x0 fails"),
			},
			u("x/1"): &fakeService{
				tag: serviceTag("x/1"),
				serviceStatus: state.StatusInfo{
					Status:  state.StatusInstalling,
					Message: "blah",
				},
			},
			u("x/2"): &fakeService{
				tag: serviceTag("x/2"),
				serviceStatus: state.StatusInfo{
					Status:  state.StatusActive,
					Message: "foo",
				},
			},
			u("x/3"): &fakeService{
				tag: serviceTag("x/3"),
				serviceStatus: state.StatusInfo{
					Status:  state.StatusError,
					Message: "some info",
				},
			},
			u("x/4"): &fakeService{
				tag:           serviceTag("x/4"),
				serviceStatus: state.StatusInfo{},
				fetchError:    "x3 error",
			},
			u("x/5"): &fakeService{
				tag: serviceTag("x/5"),
				serviceStatus: state.StatusInfo{
					Status:  state.StatusStopping,
					Message: "blah",
				},
			},
		},
	}
	getCanModify := func() (common.AuthFunc, error) {
		x0 := serviceTag("x/0")
		x1 := serviceTag("x/1")
		x2 := serviceTag("x/2")
		x3 := serviceTag("x/3")
		x4 := serviceTag("x/4")
		x5 := serviceTag("x/5")
		return func(tag names.Tag) bool {
			return tag == x0 || tag == x1 || tag == x2 || tag == x3 || tag == x4 || tag == x5
		}, nil
	}
	s := common.NewServiceStatusSetter(st, getCanModify)
	args := params.SetStatus{
		Entities: []params.EntityStatus{
			{"unit-x-0", params.StatusInstalling, "bar", nil},
			{"unit-x-1", params.StatusActive, "bar", nil},
			{"unit-x-2", params.StatusStopping, "", nil},
			{"unit-x-3", params.StatusAllocating, "not really", nil},
			{"unit-x-4", params.StatusStopping, "", nil},
			{"unit-x-5", params.StatusStopping, "blah", nil},
		},
	}
	leaderCheck := func(_ state.EntityFinder, tag string) (bool, error) {
		if tag == "unit-x-5" {
			return false, nil
		}
		return true, nil
	}
	result, err := common.ServiceSetStatus(s, args, fakeServiceFromUnitTag, leaderCheck)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, gc.DeepEquals, params.ErrorResults{
		Results: []params.ErrorResult{
			{&params.Error{Message: "x0 fails"}},
			{nil},
			{nil},
			{nil},
			{&params.Error{Message: "x3 error"}},
			{&params.Error{"this unit is not the leader", ""}},
		},
	})
	get := func(tag names.Tag) *fakeService {
		return st.entities[tag].(*fakeService)
	}
	c.Assert(get(u("x/1")).serviceStatus.Status, gc.Equals, state.StatusActive)
	c.Assert(get(u("x/1")).serviceStatus.Message, gc.Equals, "bar")
	c.Assert(get(u("x/2")).serviceStatus.Status, gc.Equals, state.StatusStopping)
	c.Assert(get(u("x/2")).serviceStatus.Message, gc.Equals, "")
	c.Assert(get(u("x/3")).serviceStatus.Status, gc.Equals, state.StatusAllocating)
	c.Assert(get(u("x/3")).serviceStatus.Message, gc.Equals, "not really")
	c.Assert(get(u("x/5")).serviceStatus.Status, gc.Equals, state.StatusStopping)
	c.Assert(get(u("x/5")).serviceStatus.Message, gc.Equals, "blah")

}