示例#1
0
func (s *cmdControllerSuite) TestSystemKillCallsEnvironDestroyOnHostedEnviron(c *gc.C) {
	st := s.Factory.MakeEnvironment(c, &factory.EnvParams{
		Name: "foo",
	})
	defer st.Close()

	st.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyEnvironment")
	st.Close()

	opc := make(chan dummy.Operation, 200)
	dummy.Listen(opc)

	conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
	c.Assert(err, jc.ErrorIsNil)
	s.AddCleanup(func(*gc.C) { conn.Close() })
	client := undertakerapi.NewClient(conn)

	startTime := time.Date(2015, time.September, 1, 17, 2, 1, 0, time.UTC)
	mClock := testing.NewClock(startTime)
	undertaker.NewUndertaker(client, mClock)

	store, err := configstore.Default()
	_, err = store.ReadInfo("dummyenv")
	c.Assert(err, jc.ErrorIsNil)

	s.run(c, "kill-controller", "dummyenv", "-y")

	// Ensure that Destroy was called on the hosted environment ...
	opRecvTimeout(c, st, opc, dummy.OpDestroy{})

	// ... and that the configstore was removed.
	_, err = store.ReadInfo("dummyenv")
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
示例#2
0
func (s *undertakerSuite) hostedAPI(c *gc.C) (*undertaker.Client, *state.State) {
	otherState := s.Factory.MakeModel(c, &factory.ModelParams{Name: "hosted_env"})

	password, err := utils.RandomPassword()
	c.Assert(err, jc.ErrorIsNil)

	machine := s.Factory.MakeMachine(c, &factory.MachineParams{
		Jobs:     []state.MachineJob{state.JobManageModel},
		Password: password,
		Nonce:    "fake_nonce",
	})

	// Connect to hosted environ from controller.
	info := s.APIInfo(c)
	info.Tag = machine.Tag()
	info.Password = password
	info.Nonce = "fake_nonce"
	info.ModelTag = otherState.ModelTag()

	otherAPIState, err := api.Open(info, api.DefaultDialOpts())
	c.Assert(err, jc.ErrorIsNil)

	undertakerClient := undertaker.NewClient(otherAPIState)
	c.Assert(undertakerClient, gc.NotNil)

	return undertakerClient, otherState
}
示例#3
0
func (s *undertakerSuite) TestWatchEnvironResourcesGetsChange(c *gc.C) {
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			args, response interface{},
		) error {
			if resp, ok := response.(*params.NotifyWatchResults); ok {
				c.Check(objType, gc.Equals, "Undertaker")
				c.Check(id, gc.Equals, "")
				c.Check(request, gc.Equals, "WatchEnvironResources")

				a, ok := args.(params.Entities)
				c.Check(ok, jc.IsTrue)
				c.Check(a.Entities, gc.DeepEquals, []params.Entity{{Tag: "environment-"}})

				resp.Results = []params.NotifyWatchResult{{NotifyWatcherId: "1"}}
			} else {
				c.Check(objType, gc.Equals, "NotifyWatcher")
				c.Check(id, gc.Equals, "1")
				c.Check(request, gc.Equals, "Next")
			}
			return nil
		})

	client := undertaker.NewClient(apiCaller)
	w, err := client.WatchEnvironResources()
	c.Assert(err, jc.ErrorIsNil)

	select {
	case <-w.Changes():
	case <-time.After(coretesting.ShortWait):
		c.Fatalf("timed out waiting for change")
	}
}
示例#4
0
func (s *undertakerSuite) TestStateRemoveEnvironFails(c *gc.C) {
	st, _ := s.OpenAPIAsNewMachine(c, state.JobManageModel)
	undertakerClient, err := undertaker.NewClient(st, apiwatcher.NewNotifyWatcher)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(undertakerClient, gc.NotNil)
	c.Assert(undertakerClient.RemoveModel(), gc.ErrorMatches, "an error occurred, unable to remove model")
}
示例#5
0
// NewFacade creates a Facade from a base.APICaller, by calling the
// constructor in api/undertaker that returns a more specific type.
func NewFacade(apiCaller base.APICaller) (Facade, error) {
	facade, err := undertaker.NewClient(apiCaller, watcher.NewNotifyWatcher)
	if err != nil {
		return nil, errors.Trace(err)
	}
	return facade, nil
}
示例#6
0
func (s *undertakerSuite) TestPermDenied(c *gc.C) {
	nonManagerMachine, _ := s.OpenAPIAsNewMachine(c, state.JobHostUnits)
	for _, conn := range []api.Connection{
		nonManagerMachine,
		s.APIState,
	} {
		undertakerClient := undertaker.NewClient(conn)
		c.Assert(undertakerClient, gc.NotNil)

		_, err := undertakerClient.ModelInfo()
		c.Assert(err, gc.ErrorMatches, "permission denied")
	}
}
示例#7
0
func (s *undertakerSuite) TestPermDenied(c *gc.C) {
	nonManagerMachine, _ := s.OpenAPIAsNewMachine(c, state.JobHostUnits)
	for _, conn := range []api.Connection{
		nonManagerMachine,
		s.APIState,
	} {
		undertakerClient := undertaker.NewClient(conn)
		c.Assert(undertakerClient, gc.NotNil)

		_, err := undertakerClient.ModelInfo()
		c.Assert(errors.Cause(err), gc.DeepEquals, &rpc.RequestError{
			Message: "permission denied",
			Code:    "unauthorized access",
		})
	}
}
示例#8
0
func (s *undertakerSuite) TestStateProcessDyingEnviron(c *gc.C) {
	st, _ := s.OpenAPIAsNewMachine(c, state.JobManageModel)
	undertakerClient := undertaker.NewClient(st)
	c.Assert(undertakerClient, gc.NotNil)

	err := undertakerClient.ProcessDyingModel()
	c.Assert(err, gc.ErrorMatches, "model is not dying")

	env, err := s.State.Model()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(env.Destroy(), jc.ErrorIsNil)
	c.Assert(env.Refresh(), jc.ErrorIsNil)
	c.Assert(env.Life(), gc.Equals, state.Dying)

	err = undertakerClient.ProcessDyingModel()
	c.Assert(err, gc.ErrorMatches, `model not empty, found 1 machine\(s\)`)
}
示例#9
0
func (s *undertakerSuite) TestStateEnvironInfo(c *gc.C) {
	st, _ := s.OpenAPIAsNewMachine(c, state.JobManageModel)
	undertakerClient := undertaker.NewClient(st)
	c.Assert(undertakerClient, gc.NotNil)

	result, err := undertakerClient.ModelInfo()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, gc.NotNil)
	c.Assert(result.Error, gc.IsNil)
	info := result.Result
	c.Assert(info.UUID, gc.Equals, coretesting.ModelTag.Id())
	c.Assert(info.Name, gc.Equals, "dummymodel")
	c.Assert(info.GlobalName, gc.Equals, "user-dummy-admin@local/dummymodel")
	c.Assert(info.IsSystem, jc.IsTrue)
	c.Assert(info.Life, gc.Equals, params.Alive)
	c.Assert(info.TimeOfDeath, gc.IsNil)
}
示例#10
0
func (s *undertakerSuite) TestStateEnvironInfo(c *gc.C) {
	st, _ := s.OpenAPIAsNewMachine(c, state.JobManageModel)
	undertakerClient, err := undertaker.NewClient(st, apiwatcher.NewNotifyWatcher)
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(undertakerClient, gc.NotNil)

	result, err := undertakerClient.ModelInfo()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(result, gc.NotNil)
	c.Assert(result.Error, gc.IsNil)
	info := result.Result
	c.Assert(info.UUID, gc.Equals, coretesting.ModelTag.Id())
	c.Assert(info.Name, gc.Equals, "controller")
	c.Assert(info.GlobalName, gc.Equals, "user-admin/controller")
	c.Assert(info.IsSystem, jc.IsTrue)
	c.Assert(info.Life, gc.Equals, params.Alive)
}
示例#11
0
func (s *undertakerSuite) mockClient(c *gc.C, expectedRequest string, callback func(response interface{})) *undertaker.Client {
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			args, response interface{},
		) error {
			c.Check(objType, gc.Equals, "Undertaker")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, expectedRequest)

			a, ok := args.(params.Entities)
			c.Check(ok, jc.IsTrue)
			c.Check(a.Entities, gc.DeepEquals, []params.Entity{{Tag: "environment-"}})

			callback(response)
			return nil
		})

	return undertaker.NewClient(apiCaller)
}
示例#12
0
func (s *UndertakerSuite) mockClient(c *gc.C, expectedRequest string, callback func(response interface{})) *undertaker.Client {
	apiCaller := basetesting.APICallerFunc(func(
		objType string,
		version int,
		id, request string,
		args, response interface{},
	) error {
		c.Check(objType, gc.Equals, "Undertaker")
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, expectedRequest)

		a, ok := args.(params.Entities)
		c.Check(ok, jc.IsTrue)
		c.Check(a.Entities, gc.DeepEquals, []params.Entity{{Tag: coretesting.ModelTag.String()}})

		callback(response)
		return nil
	})
	client, err := undertaker.NewClient(apiCaller, nil)
	c.Assert(err, jc.ErrorIsNil)
	return client
}
示例#13
0
func (s *UndertakerSuite) TestWatchModelResourcesCreatesWatcher(c *gc.C) {
	apiCaller := basetesting.APICallerFunc(func(
		objType string,
		version int,
		id, request string,
		args, response interface{},
	) error {
		c.Check(objType, gc.Equals, "Undertaker")
		c.Check(id, gc.Equals, "")
		c.Check(request, gc.Equals, "WatchModelResources")

		a, ok := args.(params.Entities)
		c.Check(ok, jc.IsTrue)
		c.Check(a.Entities, gc.DeepEquals, []params.Entity{{Tag: coretesting.ModelTag.String()}})

		resp, ok := response.(*params.NotifyWatchResults)
		c.Assert(ok, jc.IsTrue)
		resp.Results = []params.NotifyWatchResult{{
			NotifyWatcherId: "1001",
		}}
		return nil
	})

	expectWatcher := &fakeWatcher{}
	newWatcher := func(apiCaller base.APICaller, result params.NotifyWatchResult) watcher.NotifyWatcher {
		c.Check(apiCaller, gc.NotNil) // uncomparable
		c.Check(result, gc.Equals, params.NotifyWatchResult{
			NotifyWatcherId: "1001",
		})
		return expectWatcher
	}

	client, err := undertaker.NewClient(apiCaller, newWatcher)
	c.Assert(err, jc.ErrorIsNil)
	w, err := client.WatchModelResources()
	c.Assert(err, jc.ErrorIsNil)
	c.Check(w, gc.Equals, expectWatcher)
}
示例#14
0
func (s *undertakerSuite) TestStateRemoveEnvironFails(c *gc.C) {
	st, _ := s.OpenAPIAsNewMachine(c, state.JobManageEnviron)
	undertakerClient := undertaker.NewClient(st)
	c.Assert(undertakerClient, gc.NotNil)
	c.Assert(undertakerClient.RemoveEnviron(), gc.ErrorMatches, "an error occurred, unable to remove environment")
}