Ejemplo n.º 1
0
// getBlockAPI returns a block api for listing blocks.
func getBlockAPI(c *envcmd.EnvCommandBase) (block.BlockListAPI, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, err
	}
	return apiblock.NewClient(root), nil
}
Ejemplo n.º 2
0
// getBlockAPI returns a block api for block manipulation.
func getBlockAPI(c newAPIRoot) (*apiblock.Client, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, err
	}
	return apiblock.NewClient(root), nil
}
Ejemplo n.º 3
0
func (s *blockMockSuite) TestSwitchBlockOff(c *gc.C) {
	called := false
	blockType := state.DestroyBlock.String()

	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, response interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "Block")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "SwitchBlockOff")

			args, ok := a.(params.BlockSwitchParams)
			c.Assert(ok, jc.IsTrue)
			// message is never sent, so this argument should
			// always be empty string.
			c.Assert(args.Message, gc.DeepEquals, "")
			c.Assert(args.Type, gc.DeepEquals, blockType)

			_, ok = response.(*params.ErrorResult)
			c.Assert(ok, jc.IsTrue)

			return nil
		})
	blockClient := block.NewClient(apiCaller)
	err := blockClient.SwitchBlockOff(blockType)
	c.Assert(called, jc.IsTrue)
	c.Assert(err, gc.IsNil)
}
Ejemplo n.º 4
0
// getBlockAPI returns a block api for listing blocks.
func getBlockAPI(c *modelcmd.ModelCommandBase) (listBlocksAPI, error) {
	root, err := c.NewAPIRoot()
	if err != nil {
		return nil, errors.Trace(err)
	}
	return block.NewClient(root), nil
}
Ejemplo n.º 5
0
func (s *blockMockSuite) TestSwitchBlockOn(c *gc.C) {
	called := false
	blockType := state.DestroyBlock.String()
	msg := "for test switch block on"

	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, response interface{},
		) error {
			called = true
			c.Check(objType, gc.Equals, "Block")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "SwitchBlockOn")

			args, ok := a.(params.BlockSwitchParams)
			c.Assert(ok, jc.IsTrue)
			c.Assert(args.Message, gc.DeepEquals, msg)
			c.Assert(args.Type, gc.DeepEquals, blockType)

			_, ok = response.(*params.ErrorResult)
			c.Assert(ok, jc.IsTrue)

			return nil
		})
	blockClient := block.NewClient(apiCaller)
	err := blockClient.SwitchBlockOn(blockType, msg)
	c.Assert(called, jc.IsTrue)
	c.Assert(err, gc.IsNil)
}
Ejemplo n.º 6
0
func (s *blockSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)
	s.blockClient = block.NewClient(s.APIState)
	c.Assert(s.blockClient, gc.NotNil)
	s.AddCleanup(func(*gc.C) {
		s.blockClient.ClientFacade.Close()
	})
}
Ejemplo n.º 7
0
func (s *blockSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)

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

	s.ctx = &mockContext{
		agentConfig: &mockAgentConfig{dataDir: s.DataDir()},
		apiState:    conn,
		state:       s.State,
	}
	s.blockClient = block.NewClient(conn)
}
Ejemplo n.º 8
0
func (s *blockMockSuite) TestSwitchBlockOnError(c *gc.C) {
	called := false
	errmsg := "test error"
	apiCaller := basetesting.APICallerFunc(
		func(objType string,
			version int,
			id, request string,
			a, response interface{},
		) error {
			called = true
			result, ok := response.(*params.ErrorResult)
			c.Assert(ok, jc.IsTrue)
			result.Error = common.ServerError(errors.New(errmsg))

			return nil
		})
	blockClient := block.NewClient(apiCaller)
	err := blockClient.SwitchBlockOn("", "")
	c.Assert(called, jc.IsTrue)
	c.Assert(errors.Cause(err), gc.ErrorMatches, errmsg)
}
Ejemplo n.º 9
0
func (s *blockMockSuite) TestList(c *gc.C) {
	var called bool
	one := params.BlockResult{
		Result: params.Block{
			Id:      "-42",
			Type:    state.DestroyBlock.String(),
			Message: "for test switch on",
			Tag:     "some valid tag, right?",
		},
	}
	errmsg := "another test error"
	two := params.BlockResult{
		Error: common.ServerError(errors.New(errmsg)),
	}
	apiCaller := basetesting.APICallerFunc(
		func(
			objType string,
			version int,
			id, request string,
			a, response interface{}) error {
			called = true
			c.Check(objType, gc.Equals, "Block")
			c.Check(id, gc.Equals, "")
			c.Check(request, gc.Equals, "List")
			c.Assert(a, gc.IsNil)

			result := response.(*params.BlockResults)
			result.Results = []params.BlockResult{one, two}
			return nil
		})
	blockClient := block.NewClient(apiCaller)
	found, err := blockClient.List()
	c.Assert(called, jc.IsTrue)
	c.Assert(errors.Cause(err), gc.ErrorMatches, errmsg)
	c.Assert(found, gc.HasLen, 1)
}
Ejemplo n.º 10
0
// NewBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewBlockHelper(st api.Connection) BlockHelper {
	return BlockHelper{
		blockClient: block.NewClient(st),
	}
}
Ejemplo n.º 11
0
// NewBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewBlockHelper(st *api.State) BlockHelper {
	return BlockHelper{
		blockClient: block.NewClient(st),
	}
}
Ejemplo n.º 12
0
// NewBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewBlockHelper(st api.Connection) BlockHelper {
	return BlockHelper{
		ApiState: st,
		client:   block.NewClient(st),
	}
}
Ejemplo n.º 13
0
func (s *blockSuite) SetUpTest(c *gc.C) {
	s.JujuConnSuite.SetUpTest(c)
	s.blockClient = block.NewClient(s.APIState)
	c.Assert(s.blockClient, gc.NotNil)
}
Ejemplo n.º 14
0
// NewBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewBlockHelper(st *api.State) BlockHelper {
	return BlockHelper{
		ApiState: st,
		client:   block.NewClient(st),
	}
}
Ejemplo n.º 15
0
// NewCmdBlockHelper creates a block switch used in testing
// to manage desired juju blocks.
func NewCmdBlockHelper(api base.APICallCloser) CmdBlockHelper {
	return CmdBlockHelper{
		blockClient: block.NewClient(api),
	}
}