本文整理汇总了Golang中github.com/juju/juju/state/api.Open函数的典型用法代码示例。如果您正苦于以下问题:Golang Open函数的具体用法?Golang Open怎么用?Golang Open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Open函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestOpenPassesEnvironTag
func (s *apiclientSuite) TestOpenPassesEnvironTag(c *gc.C) {
info := s.APIInfo(c)
env, err := s.State.Environment()
c.Assert(err, gc.IsNil)
// TODO(jam): 2014-06-05 http://pad.lv/1326802
// we want to test this eventually, but for now s.APIInfo uses
// conn.StateInfo() which doesn't know about EnvironTag.
// c.Check(info.EnvironTag, gc.Equals, env.Tag())
// c.Assert(info.EnvironTag, gc.Not(gc.Equals), "")
// We start by ensuring we have an invalid tag, and Open should fail.
info.EnvironTag = names.NewEnvironTag("bad-tag")
_, err = api.Open(info, api.DialOpts{})
c.Check(err, gc.ErrorMatches, `unknown environment: "bad-tag"`)
c.Check(params.ErrCode(err), gc.Equals, params.CodeNotFound)
// Now set it to the right tag, and we should succeed.
info.EnvironTag = env.Tag()
st, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
st.Close()
// Backwards compatibility, we should succeed if we do not set an
// environ tag
info.EnvironTag = nil
st, err = api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
st.Close()
}
开发者ID:jiasir,项目名称:juju,代码行数:26,代码来源:apiclient_test.go
示例2: TestOpenAsMachineErrors
func (s *serverSuite) TestOpenAsMachineErrors(c *gc.C) {
assertNotProvisioned := func(err error) {
c.Assert(err, gc.NotNil)
c.Assert(err, jc.Satisfies, params.IsCodeNotProvisioned)
c.Assert(err, gc.ErrorMatches, `machine \d+ is not provisioned`)
}
stm, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = stm.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = stm.SetPassword(password)
c.Assert(err, gc.IsNil)
// This does almost exactly the same as OpenAPIAsMachine but checks
// for failures instead.
info := s.APIInfo(c)
info.Tag = stm.Tag()
info.Password = password
info.Nonce = "invalid-nonce"
st, err := api.Open(info, fastDialOpts)
assertNotProvisioned(err)
c.Assert(st, gc.IsNil)
// Try with empty nonce as well.
info.Nonce = ""
st, err = api.Open(info, fastDialOpts)
assertNotProvisioned(err)
c.Assert(st, gc.IsNil)
// Finally, with the correct one succeeds.
info.Nonce = "fake_nonce"
st, err = api.Open(info, fastDialOpts)
c.Assert(err, gc.IsNil)
c.Assert(st, gc.NotNil)
st.Close()
// Now add another machine, intentionally unprovisioned.
stm1, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = stm1.SetPassword(password)
c.Assert(err, gc.IsNil)
// Try connecting, it will fail.
info.Tag = stm1.Tag()
info.Nonce = ""
st, err = api.Open(info, fastDialOpts)
assertNotProvisioned(err)
c.Assert(st, gc.IsNil)
}
开发者ID:jiasir,项目名称:juju,代码行数:51,代码来源:server_test.go
示例3: ping0
func ping0(apiInfo *api.Info, logf func(string, ...interface{})) (pingTimes, error) {
var times = pingTimes{
addr: apiInfo.Addrs[0],
open: -1,
login: -1,
}
t0 := time.Now()
tag, password := apiInfo.Tag, apiInfo.Password
apiInfo.Tag = ""
apiInfo.Password = ""
logf("start")
st, err := api.Open(apiInfo, dialOpts)
if err != nil {
return times, err
}
times.open = time.Since(t0)
defer st.Close()
logf("opened API")
if err := st.Login(tag, password, ""); err != nil {
return times, fmt.Errorf("cannot log in: %v", err)
}
times.login = time.Since(t0) - times.open
logf("logged in")
return times, nil
}
开发者ID:macressler,项目名称:misc,代码行数:25,代码来源:juju-ping.go
示例4: TestClientNoNeedToPing
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)
}
开发者ID:rogpeppe,项目名称:juju,代码行数:8,代码来源:pinger_test.go
示例5: TestManageEnvironServesAPI
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().(names.MachineTag))
c.Assert(err, gc.IsNil)
c.Assert(m.Life(), gc.Equals, params.Alive)
})
}
开发者ID:klyachin,项目名称:juju,代码行数:10,代码来源:machine_test.go
示例6: OpenAPIWithoutLogin
// OpenAPIWithoutLogin connects to the API and returns an api.State without
// actually calling st.Login already. The returned strings are the "tag" and
// "password" that we would have used to login.
func (s *stateSuite) OpenAPIWithoutLogin(c *gc.C) (*api.State, string, string) {
info := s.APIInfo(c)
tag := info.Tag
password := info.Password
info.Tag = nil
info.Password = ""
apistate, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
return apistate, tag.String(), password
}
开发者ID:klyachin,项目名称:juju,代码行数:13,代码来源:state_test.go
示例7: openAPIAs
// openAPIAs opens the API and ensures that the *api.State returned will be
// closed during the test teardown by using a cleanup function.
func (s *JujuConnSuite) openAPIAs(c *gc.C, tag names.Tag, password, nonce string) *api.State {
apiInfo := s.APIInfo(c)
apiInfo.Tag = tag
apiInfo.Password = password
apiInfo.Nonce = nonce
apiState, err := api.Open(apiInfo, api.DialOpts{})
c.Assert(err, gc.IsNil)
c.Assert(apiState, gc.NotNil)
s.apiStates = append(s.apiStates, apiState)
return apiState
}
开发者ID:klyachin,项目名称:juju,代码行数:13,代码来源:conn.go
示例8: NewAPIState
// NewAPIState creates an api.State object from an Environ
func NewAPIState(environ environs.Environ, dialOpts api.DialOpts) (*api.State, error) {
info, err := environAPIInfo(environ)
if err != nil {
return nil, err
}
st, err := api.Open(info, dialOpts)
if err != nil {
return nil, err
}
return st, nil
}
开发者ID:klyachin,项目名称:juju,代码行数:13,代码来源:api.go
示例9: canLoginToAPIAsMachine
func (s *UpgradeSuite) canLoginToAPIAsMachine(c *gc.C, config agent.Config) bool {
// Ensure logins are always to the API server (machine-0)
info := config.APIInfo()
info.Addrs = s.machine0Config.APIInfo().Addrs
apiState, err := api.Open(info, upgradeTestDialOpts)
if apiState != nil {
apiState.Close()
}
if apiState != nil && err == nil {
return true
}
return false
}
开发者ID:jimmiebtlr,项目名称:juju,代码行数:13,代码来源:upgrade_test.go
示例10: TestOpenMultiple
func (s *apiclientSuite) TestOpenMultiple(c *gc.C) {
// Create a socket that proxies to the API server.
info := s.APIInfo(c)
serverAddr := info.Addrs[0]
server, err := net.Dial("tcp", serverAddr)
c.Assert(err, gc.IsNil)
defer server.Close()
listener, err := net.Listen("tcp", "127.0.0.1:0")
c.Assert(err, gc.IsNil)
defer listener.Close()
go func() {
for {
client, err := listener.Accept()
if err != nil {
return
}
go io.Copy(client, server)
go io.Copy(server, client)
}
}()
// Check that we can use the proxy to connect.
proxyAddr := listener.Addr().String()
info.Addrs = []string{proxyAddr}
st, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
defer st.Close()
c.Assert(st.Addr(), gc.Equals, proxyAddr)
// Now break Addrs[0], and ensure that Addrs[1]
// is successfully connected to.
info.Addrs = []string{proxyAddr, serverAddr}
listener.Close()
st, err = api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
defer st.Close()
c.Assert(st.Addr(), gc.Equals, serverAddr)
}
开发者ID:jiasir,项目名称:juju,代码行数:38,代码来源:apiclient_test.go
示例11: TestStop
func (s *serverSuite) TestStop(c *gc.C) {
// Start our own instance of the server so we have
// a handle on it to stop it.
listener, err := net.Listen("tcp", ":0")
c.Assert(err, gc.IsNil)
srv, err := apiserver.NewServer(s.State, listener, apiserver.ServerConfig{
Cert: []byte(coretesting.ServerCert),
Key: []byte(coretesting.ServerKey),
})
c.Assert(err, gc.IsNil)
defer srv.Stop()
stm, err := s.State.AddMachine("quantal", state.JobHostUnits)
c.Assert(err, gc.IsNil)
err = stm.SetProvisioned("foo", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
password, err := utils.RandomPassword()
c.Assert(err, gc.IsNil)
err = stm.SetPassword(password)
c.Assert(err, gc.IsNil)
// Note we can't use openAs because we're not connecting to
apiInfo := &api.Info{
Tag: stm.Tag(),
Password: password,
Nonce: "fake_nonce",
Addrs: []string{srv.Addr()},
CACert: coretesting.CACert,
}
st, err := api.Open(apiInfo, fastDialOpts)
c.Assert(err, gc.IsNil)
defer st.Close()
_, err = st.Machiner().Machine(stm.Tag().(names.MachineTag))
c.Assert(err, gc.IsNil)
err = srv.Stop()
c.Assert(err, gc.IsNil)
_, err = st.Machiner().Machine(stm.Tag().(names.MachineTag))
// The client has not necessarily seen the server shutdown yet,
// so there are two possible errors.
if err != rpc.ErrShutdown && err != io.ErrUnexpectedEOF {
c.Fatalf("unexpected error from request: %v", err)
}
// Check it can be stopped twice.
err = srv.Stop()
c.Assert(err, gc.IsNil)
}
开发者ID:jiasir,项目名称:juju,代码行数:50,代码来源:server_test.go
示例12: TestOpenUsesEnvironUUIDPaths
func (s *clientSuite) TestOpenUsesEnvironUUIDPaths(c *gc.C) {
info := s.APIInfo(c)
// Backwards compatibility, passing EnvironTag = "" should just work
info.EnvironTag = nil
apistate, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
apistate.Close()
// Passing in the correct environment UUID should also work
environ, err := s.State.Environment()
c.Assert(err, gc.IsNil)
info.EnvironTag = environ.Tag()
apistate, err = api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
apistate.Close()
// Passing in a bad environment UUID should fail with a known error
info.EnvironTag = names.NewEnvironTag("dead-beef-123456")
apistate, err = api.Open(info, api.DialOpts{})
c.Check(err, gc.ErrorMatches, `unknown environment: "dead-beef-123456"`)
c.Check(err, jc.Satisfies, params.IsCodeNotFound)
c.Assert(apistate, gc.IsNil)
}
开发者ID:klyachin,项目名称:juju,代码行数:23,代码来源:client_test.go
示例13: openAs
// openAs connects to the API state as the given entity
// with the default password for that entity.
func (s *baseSuite) openAs(c *gc.C, tag names.Tag) *api.State {
info := s.APIInfo(c)
info.Tag = tag
// Must match defaultPassword()
info.Password = fmt.Sprintf("%s password-1234567890", tag)
// Set this always, so that the login attempts as a machine will
// not fail with ErrNotProvisioned; it's not used otherwise.
info.Nonce = "fake_nonce"
c.Logf("opening state; entity %q; password %q", info.Tag, info.Password)
st, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
c.Assert(st, gc.NotNil)
return st
}
开发者ID:klyachin,项目名称:juju,代码行数:16,代码来源:api_test.go
示例14: TestDebugLogRootPath
func (s *clientSuite) TestDebugLogRootPath(c *gc.C) {
s.PatchValue(api.WebsocketDialConfig, echoURL(c))
// If the server is old, we log at "/log"
info := s.APIInfo(c)
info.EnvironTag = nil
apistate, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
defer apistate.Close()
reader, err := apistate.Client().WatchDebugLog(api.DebugLogParams{})
c.Assert(err, gc.IsNil)
connectURL := connectURLFromReader(c, reader)
c.Assert(connectURL.Path, gc.Matches, "/log")
}
开发者ID:klyachin,项目名称:juju,代码行数:14,代码来源:client_test.go
示例15: SimpleClientFactory
func SimpleClientFactory(info *api.Info) (*Client, error) {
dialOpts := api.DialOpts{}
state, err := api.Open(info, dialOpts)
if err != nil {
return nil, err
}
client := state.Client()
wrapper := &Client{}
wrapper.client = client
wrapper.apiState = state
//defer apiclient.Close()
return wrapper, err
}
开发者ID:jxaas,项目名称:jxaas,代码行数:15,代码来源:connection.go
示例16: TestDebugLogAtUUIDLogPath
func (s *clientSuite) TestDebugLogAtUUIDLogPath(c *gc.C) {
s.PatchValue(api.WebsocketDialConfig, echoURL(c))
// If the server supports it, we should log at "/environment/UUID/log"
environ, err := s.State.Environment()
c.Assert(err, gc.IsNil)
info := s.APIInfo(c)
info.EnvironTag = environ.Tag()
apistate, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
defer apistate.Close()
reader, err := apistate.Client().WatchDebugLog(api.DebugLogParams{})
c.Assert(err, gc.IsNil)
connectURL := connectURLFromReader(c, reader)
c.ExpectFailure("debug log always goes to /log for compatibility http://pad.lv/1326799")
c.Assert(connectURL.Path, gc.Matches, fmt.Sprintf("/%s/log", environ.UUID()))
}
开发者ID:klyachin,项目名称:juju,代码行数:16,代码来源:client_test.go
示例17: TestLoginSetsEnvironTag
func (s *stateSuite) TestLoginSetsEnvironTag(c *gc.C) {
env, err := s.State.Environment()
c.Assert(err, gc.IsNil)
info := s.APIInfo(c)
tag := info.Tag
password := info.Password
info.Tag = ""
info.Password = ""
apistate, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
defer apistate.Close()
// We haven't called Login yet, so the EnvironTag shouldn't be set.
c.Check(apistate.EnvironTag(), gc.Equals, "")
err = apistate.Login(tag, password, "")
c.Assert(err, gc.IsNil)
// Now that we've logged in, EnvironTag should be updated correctly.
c.Check(apistate.EnvironTag(), gc.Equals, env.Tag())
}
开发者ID:rogpeppe,项目名称:juju,代码行数:18,代码来源:state_test.go
示例18: TestOpenMultipleError
func (s *apiclientSuite) TestOpenMultipleError(c *gc.C) {
listener, err := net.Listen("tcp", "127.0.0.1:0")
c.Assert(err, gc.IsNil)
defer listener.Close()
go func() {
for {
client, err := listener.Accept()
if err != nil {
return
}
client.Close()
}
}()
info := s.APIInfo(c)
addr := listener.Addr().String()
info.Addrs = []string{addr, addr, addr}
_, err = api.Open(info, api.DialOpts{})
c.Assert(err, gc.ErrorMatches, `unable to connect to "wss://.*/environment/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/api"`)
}
开发者ID:jiasir,项目名称:juju,代码行数:19,代码来源:apiclient_test.go
示例19: TestAPIHostPortsMovesConnectedValueFirst
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 := network.HostPort{network.Address{
Value: "0.1.2.3",
Type: network.IPv4Address,
NetworkName: "",
Scope: network.ScopeMachineLocal,
}, 1234}
badServer := []network.HostPort{badValue}
extraAddress := network.HostPort{network.Address{
Value: "0.1.2.4",
Type: network.IPv4Address,
NetworkName: "",
Scope: network.ScopeMachineLocal,
}, 5678}
extraAddress2 := network.HostPort{network.Address{
Value: "0.1.2.1",
Type: network.IPv4Address,
NetworkName: "",
Scope: network.ScopeMachineLocal,
}, 9012}
serverExtra := []network.HostPort{extraAddress, goodAddress, extraAddress2}
current := [][]network.HostPort{badServer, serverExtra}
s.State.SetAPIHostPorts(current)
apistate, err := api.Open(info, api.DialOpts{})
c.Assert(err, gc.IsNil)
defer apistate.Close()
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 := []network.HostPort{goodAddress, extraAddress, extraAddress2}
expected := [][]network.HostPort{sortedServer, badServer}
c.Check(hostports, gc.DeepEquals, expected)
}
开发者ID:klyachin,项目名称:juju,代码行数:41,代码来源:state_test.go
示例20: TestLoginReportsEnvironTag
func (s *loginSuite) TestLoginReportsEnvironTag(c *gc.C) {
info, cleanup := s.setupServer(c)
defer cleanup()
// If we call api.Open without giving a username and password, then it
// won't call Login, so we can call it ourselves.
// We Login without passing an EnvironTag, to show that it still lets
// us in, and that we can find out the real EnvironTag from the
// response.
st, err := api.Open(info, fastDialOpts)
c.Assert(err, gc.IsNil)
var result params.LoginResult
creds := ¶ms.Creds{
AuthTag: "user-admin",
Password: "dummy-secret",
}
err = st.Call("Admin", "", "Login", creds, &result)
c.Assert(err, gc.IsNil)
env, err := s.State.Environment()
c.Assert(err, gc.IsNil)
c.Assert(result.EnvironTag, gc.Equals, env.Tag())
}
开发者ID:rogpeppe,项目名称:juju,代码行数:21,代码来源:login_test.go
注:本文中的github.com/juju/juju/state/api.Open函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论