本文整理汇总了Golang中github.com/juju/juju/environs.PrepareFromName函数的典型用法代码示例。如果您正苦于以下问题:Golang PrepareFromName函数的具体用法?Golang PrepareFromName怎么用?Golang PrepareFromName使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PrepareFromName函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDestroyEnvironmentCommandConfirmation
func (s *destroyEnvSuite) TestDestroyEnvironmentCommandConfirmation(c *gc.C) {
var stdin, stdout bytes.Buffer
ctx, err := cmd.DefaultContext()
c.Assert(err, gc.IsNil)
ctx.Stdout = &stdout
ctx.Stdin = &stdin
// Prepare the environment so we can destroy it.
env, err := environs.PrepareFromName("dummyenv", nullContext(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
assertEnvironNotDestroyed(c, env, s.ConfigStore)
// Ensure confirmation is requested if "-y" is not specified.
stdin.WriteString("n")
opc, errc := runCommand(ctx, new(DestroyEnvironmentCommand), "dummyenv")
c.Check(<-errc, gc.ErrorMatches, "environment destruction aborted")
c.Check(<-opc, gc.IsNil)
c.Check(stdout.String(), gc.Matches, "WARNING!.*dummyenv.*\\(type: dummy\\)(.|\n)*")
assertEnvironNotDestroyed(c, env, s.ConfigStore)
// EOF on stdin: equivalent to answering no.
stdin.Reset()
stdout.Reset()
opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand), "dummyenv")
c.Check(<-opc, gc.IsNil)
c.Check(<-errc, gc.ErrorMatches, "environment destruction aborted")
assertEnvironNotDestroyed(c, env, s.ConfigStore)
// "--yes" passed: no confirmation request.
stdin.Reset()
stdout.Reset()
opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand), "dummyenv", "--yes")
c.Check(<-errc, gc.IsNil)
c.Check((<-opc).(dummy.OpDestroy).Env, gc.Equals, "dummyenv")
c.Check(stdout.String(), gc.Equals, "")
assertEnvironDestroyed(c, env, s.ConfigStore)
// Any of casing of "y" and "yes" will confirm.
for _, answer := range []string{"y", "Y", "yes", "YES"} {
// Prepare the environment so we can destroy it.
s.Reset(c)
env, err := environs.PrepareFromName("dummyenv", nullContext(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
stdin.Reset()
stdout.Reset()
stdin.WriteString(answer)
opc, errc = runCommand(ctx, new(DestroyEnvironmentCommand), "dummyenv")
c.Check(<-errc, gc.IsNil)
c.Check((<-opc).(dummy.OpDestroy).Env, gc.Equals, "dummyenv")
c.Check(stdout.String(), gc.Matches, "WARNING!.*dummyenv.*\\(type: dummy\\)(.|\n)*")
assertEnvironDestroyed(c, env, s.ConfigStore)
}
}
示例2: TestDestroyEnvironmentCommandBroken
func (s *destroyEnvSuite) TestDestroyEnvironmentCommandBroken(c *gc.C) {
oldinfo, err := s.ConfigStore.ReadInfo("dummyenv")
c.Assert(err, gc.IsNil)
bootstrapConfig := oldinfo.BootstrapConfig()
apiEndpoint := oldinfo.APIEndpoint()
apiCredentials := oldinfo.APICredentials()
err = oldinfo.Destroy()
c.Assert(err, gc.IsNil)
newinfo := s.ConfigStore.CreateInfo("dummyenv")
bootstrapConfig["broken"] = "Destroy"
newinfo.SetBootstrapConfig(bootstrapConfig)
newinfo.SetAPIEndpoint(apiEndpoint)
newinfo.SetAPICredentials(apiCredentials)
err = newinfo.Write()
c.Assert(err, gc.IsNil)
// Prepare the environment so we can destroy it.
_, err = environs.PrepareFromName("dummyenv", nullContext(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
// destroy with broken environment
opc, errc := runCommand(nullContext(c), new(DestroyEnvironmentCommand), "dummyenv", "--yes")
op, ok := (<-opc).(dummy.OpDestroy)
c.Assert(ok, jc.IsTrue)
c.Assert(op.Error, gc.ErrorMatches, "dummy.Destroy is broken")
c.Check(<-errc, gc.Equals, op.Error)
c.Check(<-opc, gc.IsNil)
}
示例3: TestSyncToolsCommand
func (s *syncToolsSuite) TestSyncToolsCommand(c *gc.C) {
for i, test := range syncToolsCommandTests {
c.Logf("test %d: %s", i, test.description)
targetEnv, err := environs.PrepareFromName("test-target", nullContext(c), s.configStore)
c.Assert(err, gc.IsNil)
called := false
syncTools = func(sctx *sync.SyncContext) error {
c.Assert(sctx.AllVersions, gc.Equals, test.sctx.AllVersions)
c.Assert(sctx.MajorVersion, gc.Equals, test.sctx.MajorVersion)
c.Assert(sctx.MinorVersion, gc.Equals, test.sctx.MinorVersion)
c.Assert(sctx.DryRun, gc.Equals, test.sctx.DryRun)
c.Assert(sctx.Dev, gc.Equals, test.sctx.Dev)
c.Assert(sctx.Public, gc.Equals, test.sctx.Public)
c.Assert(sctx.Source, gc.Equals, test.sctx.Source)
c.Assert(dummy.IsSameStorage(sctx.Target, targetEnv.Storage()), jc.IsTrue)
called = true
return nil
}
ctx, err := runSyncToolsCommand(c, test.args...)
c.Assert(err, gc.IsNil)
c.Assert(ctx, gc.NotNil)
c.Assert(called, jc.IsTrue)
s.Reset(c)
}
}
示例4: environFromName
// environFromName loads an existing environment or prepares a new
// one. If there are no errors, it returns the environ and a closure to
// clean up in case we need to further up the stack. If an error has
// occurred, the environment and cleanup function will be nil, and the
// error will be filled in.
func environFromName(
ctx *cmd.Context,
envName string,
action string,
) (env environs.Environ, cleanup func(), err error) {
store, err := configstore.Default()
if err != nil {
return nil, nil, err
}
envExisted := false
if environInfo, err := store.ReadInfo(envName); err == nil {
envExisted = true
logger.Warningf(
"ignoring environments.yaml: using bootstrap config in %s",
environInfo.Location(),
)
} else if !errors.IsNotFound(err) {
return nil, nil, err
}
if env, err = environs.PrepareFromName(envName, ctx, store); err != nil {
return nil, nil, err
}
cleanup = func() {
if !envExisted {
destroyPreparedEnviron(ctx, env, store, action)
}
}
return env, cleanup, nil
}
示例5: TestDestroyEnvironmentCommandEFlag
func (s *destroyEnvSuite) TestDestroyEnvironmentCommandEFlag(c *gc.C) {
// Prepare the environment so we can destroy it.
_, err := environs.PrepareFromName("dummyenv", nullContext(c), s.ConfigStore)
c.Assert(err, gc.IsNil)
// check that either environment or the flag is mandatory
opc, errc := runCommand(nullContext(c), new(DestroyEnvironmentCommand))
c.Check(<-errc, gc.Equals, NoEnvironmentError)
// We don't allow them to supply both entries at the same time
opc, errc = runCommand(nullContext(c), new(DestroyEnvironmentCommand), "-e", "dummyenv", "dummyenv", "--yes")
c.Check(<-errc, gc.Equals, DoubleEnvironmentError)
// We treat --environment the same way
opc, errc = runCommand(nullContext(c), new(DestroyEnvironmentCommand), "--environment", "dummyenv", "dummyenv", "--yes")
c.Check(<-errc, gc.Equals, DoubleEnvironmentError)
// destroy using the -e flag
opc, errc = runCommand(nullContext(c), new(DestroyEnvironmentCommand), "-e", "dummyenv", "--yes")
c.Check(<-errc, gc.IsNil)
c.Check((<-opc).(dummy.OpDestroy).Env, gc.Equals, "dummyenv")
// Verify that the environment information has been removed.
_, err = s.ConfigStore.ReadInfo("dummyenv")
c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
示例6: bootstrapEnv
func (s *NewAPIClientSuite) bootstrapEnv(c *gc.C, envName string, store configstore.Storage) {
if store == nil {
store = configstore.NewMem()
}
ctx := envtesting.BootstrapContext(c)
c.Logf("env name: %s", envName)
env, err := environs.PrepareFromName(envName, ctx, store)
c.Assert(err, jc.ErrorIsNil)
storageDir := c.MkDir()
s.PatchValue(&envtools.DefaultBaseURL, storageDir)
stor, err := filestorage.NewFileStorageWriter(storageDir)
c.Assert(err, jc.ErrorIsNil)
envtesting.UploadFakeTools(c, stor, "released", "released")
err = bootstrap.Bootstrap(ctx, env, bootstrap.BootstrapParams{})
c.Assert(err, jc.ErrorIsNil)
info, err := store.ReadInfo(envName)
c.Assert(err, jc.ErrorIsNil)
creds := info.APICredentials()
creds.User = dummy.AdminUserTag().Name()
c.Logf("set creds: %#v", creds)
info.SetAPICredentials(creds)
err = info.Write()
c.Assert(err, jc.ErrorIsNil)
c.Logf("creds: %#v", info.APICredentials())
info, err = store.ReadInfo(envName)
c.Assert(err, jc.ErrorIsNil)
c.Logf("read creds: %#v", info.APICredentials())
c.Logf("store: %#v", store)
}
示例7: setUpConn
func (s *JujuConnSuite) setUpConn(c *gc.C) {
if s.RootDir != "" {
panic("JujuConnSuite.setUpConn without teardown")
}
s.RootDir = c.MkDir()
s.oldHome = utils.Home()
home := filepath.Join(s.RootDir, "/home/ubuntu")
err := os.MkdirAll(home, 0777)
c.Assert(err, gc.IsNil)
utils.SetHome(home)
s.oldJujuHome = osenv.SetJujuHome(filepath.Join(home, ".juju"))
err = os.Mkdir(osenv.JujuHome(), 0777)
c.Assert(err, gc.IsNil)
err = os.MkdirAll(s.DataDir(), 0777)
c.Assert(err, gc.IsNil)
s.PatchEnvironment(osenv.JujuEnvEnvKey, "")
// TODO(rog) remove these files and add them only when
// the tests specifically need them (in cmd/juju for example)
s.writeSampleConfig(c, osenv.JujuHomePath("environments.yaml"))
err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-cert.pem"), []byte(testing.CACert), 0666)
c.Assert(err, gc.IsNil)
err = ioutil.WriteFile(osenv.JujuHomePath("dummyenv-private-key.pem"), []byte(testing.CAKey), 0600)
c.Assert(err, gc.IsNil)
store, err := configstore.Default()
c.Assert(err, gc.IsNil)
s.ConfigStore = store
ctx := testing.Context(c)
environ, err := environs.PrepareFromName("dummyenv", ctx, s.ConfigStore)
c.Assert(err, gc.IsNil)
// sanity check we've got the correct environment.
c.Assert(environ.Config().Name(), gc.Equals, "dummyenv")
s.PatchValue(&dummy.DataDir, s.DataDir())
s.LogDir = c.MkDir()
s.PatchValue(&dummy.LogDir, s.LogDir)
versions := PreferredDefaultVersions(environ.Config(), version.Binary{Number: version.Current.Number, Series: "precise", Arch: "amd64"})
versions = append(versions, version.Current)
// Upload tools for both preferred and fake default series
envtesting.MustUploadFakeToolsVersions(environ.Storage(), versions...)
err = bootstrap.Bootstrap(ctx, environ, bootstrap.BootstrapParams{})
c.Assert(err, gc.IsNil)
s.BackingState = environ.(GetStater).GetStateInAPIServer()
s.State, err = newState(environ, s.BackingState.MongoConnectionInfo())
c.Assert(err, gc.IsNil)
s.APIState, err = juju.NewAPIState(environ, api.DialOpts{})
c.Assert(err, gc.IsNil)
s.Environ = environ
}
示例8: TestPrepareFromName
func (*OpenSuite) TestPrepareFromName(c *gc.C) {
ctx := testing.Context(c)
e, err := environs.PrepareFromName("erewhemos", ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
c.Assert(e.Config().Name(), gc.Equals, "erewhemos")
// Check we can access storage ok, which implies the environment has been prepared.
c.Assert(e.Storage(), gc.NotNil)
}
示例9: SetUpTest
func (s *datasourceSuite) SetUpTest(c *gc.C) {
s.FakeJujuHomeSuite.SetUpTest(c)
testing.WriteEnvironments(c, existingEnv)
environ, err := environs.PrepareFromName("test", testing.Context(c), configstore.NewMem())
c.Assert(err, gc.IsNil)
s.stor = environ.Storage()
s.baseURL, err = s.stor.URL("")
c.Assert(err, gc.IsNil)
}
示例10: TestNewFromName
func (*OpenSuite) TestNewFromName(c *gc.C) {
store := configstore.NewMem()
ctx := testing.Context(c)
e, err := environs.PrepareFromName("erewhemos", ctx, store)
c.Assert(err, gc.IsNil)
e, err = environs.NewFromName("erewhemos", store)
c.Assert(err, gc.IsNil)
c.Assert(e.Config().Name(), gc.Equals, "erewhemos")
}
示例11: TestVerifyStorageFails
func (s *verifyStorageSuite) TestVerifyStorageFails(c *gc.C) {
ctx := testing.Context(c)
environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
stor := environ.Storage()
someError := errors.Unauthorizedf("you shall not pass")
dummy.Poison(stor, environs.VerificationFilename, someError)
err = environs.VerifyStorage(stor)
c.Assert(err, gc.Equals, environs.VerifyStorageError)
}
示例12: bootstrapEnv
func bootstrapEnv(c *gc.C, envName string, store configstore.Storage) {
if store == nil {
store = configstore.NewMem()
}
ctx := coretesting.Context(c)
env, err := environs.PrepareFromName(envName, ctx, store)
c.Assert(err, gc.IsNil)
envtesting.UploadFakeTools(c, env.Storage())
err = bootstrap.Bootstrap(ctx, env, environs.BootstrapParams{})
c.Assert(err, gc.IsNil)
}
示例13: resetJujuHome
// resetJujuHome restores an new, clean Juju home environment without tools.
func resetJujuHome(c *gc.C, envName string) environs.Environ {
jenvDir := gitjujutesting.HomePath(".juju", "environments")
err := os.RemoveAll(jenvDir)
c.Assert(err, jc.ErrorIsNil)
coretesting.WriteEnvironments(c, envConfig)
dummy.Reset()
store, err := configstore.Default()
c.Assert(err, jc.ErrorIsNil)
env, err := environs.PrepareFromName(envName, envcmd.BootstrapContext(cmdtesting.NullContext(c)), store)
c.Assert(err, jc.ErrorIsNil)
return env
}
示例14: resetJujuHome
// resetJujuHome restores an new, clean Juju home environment without tools.
func resetJujuHome(c *gc.C) environs.Environ {
jenvDir := gitjujutesting.HomePath(".juju", "environments")
err := os.RemoveAll(jenvDir)
c.Assert(err, gc.IsNil)
coretesting.WriteEnvironments(c, envConfig)
dummy.Reset()
store, err := configstore.Default()
c.Assert(err, gc.IsNil)
env, err := environs.PrepareFromName("peckham", cmdtesting.NullContext(c), store)
c.Assert(err, gc.IsNil)
envtesting.RemoveAllTools(c, env)
return env
}
示例15: TestCheckEnvironment
func (s *checkEnvironmentSuite) TestCheckEnvironment(c *gc.C) {
ctx := testing.Context(c)
environ, err := environs.PrepareFromName("test", ctx, configstore.NewMem())
c.Assert(err, gc.IsNil)
// VerifyStorage is sufficient for our tests and much simpler
// than Bootstrap which calls it.
stor := environ.Storage()
err = environs.VerifyStorage(stor)
c.Assert(err, gc.IsNil)
err = environs.CheckEnvironment(environ)
c.Assert(err, gc.IsNil)
}