Esempio n. 1
0
func (s *stateSuite) TestClientNoNeedToPing(c *gc.C) {
	s.PatchValue(apiserver.MaxClientPingInterval, time.Duration(0))
	st, err := api.Open(s.APIInfo(c), api.DefaultDialOpts())
	c.Assert(err, gc.IsNil)
	time.Sleep(coretesting.ShortWait)
	err = st.Ping()
	c.Assert(err, gc.IsNil)
}
Esempio n. 2
0
func (s *MachineSuite) TestManageEnvironServesAPI(c *gc.C) {
	s.assertJobWithState(c, state.JobManageEnviron, func(conf agent.Config, agentState *state.State) {
		st, err := api.Open(conf.APIInfo(), fastDialOpts)
		c.Assert(err, gc.IsNil)
		defer st.Close()
		m, err := st.Machiner().Machine(conf.Tag())
		c.Assert(err, gc.IsNil)
		c.Assert(m.Life(), gc.Equals, params.Alive)
	})
}
Esempio n. 3
0
File: api.go Progetto: jkary/core
// NewAPIConn returns a new Conn that uses the
// given environment. The environment must have already
// been bootstrapped.
func NewAPIConn(environ environs.Environ, dialOpts api.DialOpts) (*APIConn, error) {
	info, err := environAPIInfo(environ)
	if err != nil {
		return nil, err
	}

	st, err := api.Open(info, dialOpts)
	// TODO(rog): handle errUnauthorized when the API handles passwords.
	if err != nil {
		return nil, err
	}
	return &APIConn{
		Environ: environ,
		State:   st,
	}, nil
}
Esempio n. 4
0
func (s *stateSuite) TestAPIHostPortsAlwaysIncludesTheConnection(c *gc.C) {
	hostportslist := s.APIState.APIHostPorts()
	c.Check(hostportslist, gc.HasLen, 1)
	serverhostports := hostportslist[0]
	c.Check(serverhostports, gc.HasLen, 1)
	// the other addresses, but always see this one as well.
	info := s.APIInfo(c)
	// We intentionally set this to invalid values
	badValue := instance.HostPort{instance.Address{
		Value:        "0.1.2.3",
		Type:         instance.Ipv4Address,
		NetworkName:  "",
		NetworkScope: instance.NetworkMachineLocal,
	}, 1234}
	badServer := []instance.HostPort{badValue}
	s.State.SetAPIHostPorts([][]instance.HostPort{badServer})
	apistate, err := api.Open(info, api.DialOpts{})
	c.Assert(err, gc.IsNil)
	hostports := apistate.APIHostPorts()
	c.Check(hostports, gc.DeepEquals, [][]instance.HostPort{serverhostports, badServer})
}
Esempio n. 5
0
func (s *stateSuite) TestAPIHostPortsMovesConnectedValueFirst(c *gc.C) {
	hostportslist := s.APIState.APIHostPorts()
	c.Check(hostportslist, gc.HasLen, 1)
	serverhostports := hostportslist[0]
	c.Check(serverhostports, gc.HasLen, 1)
	goodAddress := serverhostports[0]
	// the other addresses, but always see this one as well.
	info := s.APIInfo(c)
	// We intentionally set this to invalid values
	badValue := instance.HostPort{instance.Address{
		Value:        "0.1.2.3",
		Type:         instance.Ipv4Address,
		NetworkName:  "",
		NetworkScope: instance.NetworkMachineLocal,
	}, 1234}
	badServer := []instance.HostPort{badValue}
	extraAddress := instance.HostPort{instance.Address{
		Value:        "0.1.2.4",
		Type:         instance.Ipv4Address,
		NetworkName:  "",
		NetworkScope: instance.NetworkMachineLocal,
	}, 5678}
	extraAddress2 := instance.HostPort{instance.Address{
		Value:        "0.1.2.1",
		Type:         instance.Ipv4Address,
		NetworkName:  "",
		NetworkScope: instance.NetworkMachineLocal,
	}, 9012}
	serverExtra := []instance.HostPort{extraAddress, goodAddress, extraAddress2}
	current := [][]instance.HostPort{badServer, serverExtra}
	s.State.SetAPIHostPorts(current)
	apistate, err := api.Open(info, api.DialOpts{})
	c.Assert(err, gc.IsNil)
	hostports := apistate.APIHostPorts()
	// We should have rotate the server we connected to as the first item,
	// and the address of that server as the first address
	sortedServer := []instance.HostPort{goodAddress, extraAddress, extraAddress2}
	expected := [][]instance.HostPort{sortedServer, badServer}
	c.Check(hostports, gc.DeepEquals, expected)
}
Esempio n. 6
0
File: api.go Progetto: jkary/core
func defaultAPIOpen(info *api.Info, opts api.DialOpts) (apiState, error) {
	return api.Open(info, opts)
}